ó
P'—^c           @   sP  d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z m Z m Z m Z m	 Z	 d  d l
 m Z d d l m Z d  d l m Z d  d l m Z d d l m Z d	 „  Z d
 „  Z e d „  ƒ Z d e f d „  ƒ  YZ d „  Z e d „  ƒ Z d „  Z d d „ Z d d „ Z d „  Z d  d l  m! Z! e! d ƒ Z" e! d ƒ Z# d „  Z$ d S(   iÿÿÿÿN(   t   memoizet   composet   wrapst   anyt   any_fnt   select_values(   t   lmapcati   (   t   md5hex(   t   models(   t   HttpRequest(   t   model_profilec         C   s   t  d „  |  j Dƒ d  ƒ S(   Nc         s   sP   |  ]F } t  | t j ƒ r | t j k	 r | j j r | j j r | Vq d  S(   N(   t
   issubclassR   t   Modelt   _metat   proxyt   abstract(   t   .0t   b(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pys	   <genexpr>   s    $(   t   nextt   __mro__t   None(   t   model(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   get_concrete_model   s    c            s1   ‡  f d †  ‰  ˆ  |  j  j p- t |  ƒ p- |  ƒ S(   s_   
    Returns a list of all proxy models, including subclasess, superclassses and siblings.
    c            s   |  g t  ˆ  |  j ƒ  ƒ S(   N(   R   t   __subclasses__(   t   cls(   t
   class_tree(    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyR      s    (   R   t   concrete_modelR   (   R   (    (   R   s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   model_family   s    c         C   s   t  t t |  ƒ ƒ S(   N(   R   R
   R   (   R   (    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   family_has_profile!   s    t   MonkeyProxyc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyR   &   s   c         C   s®   t  |  d ƒ s t d ƒ ‚ t ƒ  |  _ t t j t j ƒ } t | | j	 ƒ } xX | j
 ƒ  D]J \ } } t  |  | ƒ r– t |  j | t |  | ƒ ƒ n  t |  | | ƒ q\ Wd S(   s€  
    Mixes a mixin into existing class.
    Does not use actual multi-inheritance mixins, just monkey patches methods.
    Mixin methods can call copies of original ones stored in `_no_monkey` proxy:

    class SomeMixin(object):
        def do_smth(self, arg):
            ... do smth else before
            self._no_monkey.do_smth(self, arg)
            ... do smth else after
    t
   _no_monkeys!   Multiple monkey mix not supportedN(   t   hasattrt   AssertionErrorR   R    R   t   inspectt
   isfunctiont   ismethoddescriptorR   t   __dict__t   itemst   setattrt   getattr(   R   t   mixint   testt   methodst   namet   method(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt
   monkey_mix)   s    c         C   s,   t  t d „  |  j j Dƒ ƒ ƒ } t | ƒ S(   s9   
    Returns serialized description of model fields.
    c         s   s-   |  ]# } | j  | j | j | j f Vq d  S(   N(   R-   t   attnamet	   db_columnt	   __class__(   R   t   f(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pys	   <genexpr>F   s    (   t   strt   sortedR   t   fieldsR   (   R   t   stamp(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   stamp_fieldsA   s    "c         C   s   t  |  t j ƒ r2 d |  j j |  j j |  j f St j |  ƒ r |  j	 |  j
 g } t |  d ƒ r‹ |  j j d ƒ r‹ | j |  j j ƒ n  | St |  ƒ Sd  S(   Ns   %s.%s.%st   __code__t   CACHEOPS_DEBUG(   t
   isinstanceR   R   R   t	   app_labelt
   model_namet   pkR#   R$   R   R   R!   t   __globals__t   gett   appendR9   t   co_firstlinenoR4   (   t   objt   factors(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   obj_keyL   s     "c         C   s1   |  | | | g } t  t j | d t d t ƒƒ S(   s9   
    Calculate cache key based on func and arguments
    t	   sort_keyst   default(   R   t   jsont   dumpst   TrueRE   (   t   funct   argst   kwargst   extraRD   (    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   func_cache_keyX   s    c         C   sT   t  | d d ƒ r& | d j ƒ  } n
 | d } d t |  | d | d | | f ƒS(   so   
    Calculate cache key for view func.
    Use url instead of not properly serializable request argument.
    i    t   build_absolute_uris   v:i   RN   (   R!   RP   RO   (   RK   RL   RM   RN   t   uri(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   view_cache_key_   s    
c            s   d „  ‰ ‡  ‡ f d †  } | S(   Nc         S   s/   t  |  d ƒ r+ t |  j ƒ r+ |  j ƒ  n  |  S(   Nt   render(   R!   t   callableRS   (   t   response(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   force_renderk   s    c             s   ‡ ‡  ‡ ‡ f d †  } | S(   Nc            st   t  ˆ d <ˆ ˆ ˆ Ž  t ˆ ˆ ƒ ƒ ‰  t ˆ ƒ ‡  ‡ f d †  ƒ } t ˆ  d ƒ rp ˆ  j | _ ˆ  j | _ n  | S(   Nt   key_funcc            sJ   t  |  t ƒ s t d ƒ ‚ |  j d k r: ˆ |  | | Ž Sˆ  |  | | Ž S(   Ns:   A view should be passed with HttpRequest as first argumentt   GETt   HEAD(   RX   RY   (   R;   R	   R"   R.   (   t   requestRL   RM   (   t   cached_funcRK   (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   wrapperu   s
    	t
   invalidate(   RR   R   R   R!   R]   t   key(   RK   R\   (   t   _cachedt   dargst   dkwargsRV   (   R[   RK   s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt	   decoratorq   s    
	(    (   R`   Ra   Rb   (   R_   RV   (   R`   Ra   s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   cached_viewp   s    (    (   R_   Rc   (    (   R_   RV   s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   cached_view_fabj   s    	(   t	   mark_safes   >
<s   > <c         C   s"   d „  } t  j d | |  ƒ }  |  S(   Nc         S   s   d |  j  d ƒ k r t St S(   Ns   
i    (   t   groupt   NEWLINE_BETWEEN_TAGSt   SPACE_BETWEEN_TAGS(   t   m(    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   repl   s    s   >\s{2,}<(   t   ret   sub(   t   textRj   (    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   carefully_strip_whitespaceŽ   s    	(%   Rk   RH   R#   t   funcyR    R   R   R   R   R   t	   funcy.py3R   t   crossR   t	   django.dbR   t   django.httpR	   t   confR
   R   R   R   t   objectR   R/   R8   RE   R   RO   RR   Rd   t   django.utils.safestringRe   Rg   Rh   Rn   (    (    (    s0   /tmp/pip-unpacked-wheel-CLcuMp/cacheops/utils.pyt   <module>   s,   .					