
 XM<                 @   sM  d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d d   Z
 Gd d   d e  Z Gd	 d
   d
 e  Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z e   Z d d   Z Gd d   d e  Z d d   Z Gd d   d e  Z Gd d    d  e  Z d! d"   Z d S)#    N)total_orderingwraps)six)RemovedInDjango20Warningc                s       f d d   } | S)Nc                 s      |  t   |    S)N)dict)ZmoreargsZ
morekwargs)_curried_funcargskwargs E/home/ubuntu/projects/ifolica/build/django/django/utils/functional.py_curried   s    zcurry.<locals>._curriedr
   )r   r   r	   r   r
   )r   r   r	   r   curry   s    r   c               @   s4   e  Z d  Z d Z d d d  Z d d d  Z d S)cached_propertya
  
    Decorator that converts a method with a single self argument into a
    property cached on the instance.

    Optional ``name`` argument allows you to make cached properties of other
    methods. (e.g.  url = cached_property(get_absolute_url, name='url') )
    Nc             C   s1   | |  _  t | d  |  _ | p' | j |  _ d  S)N__doc__)funcgetattrr   __name__name)selfr   r   r
   r
   r   __init__   s    	zcached_property.__init__c             C   s1   | d  k r |  S|  j  |  } | j |  j <| S)N)r   __dict__r   )r   instanceclsresr
   r
   r   __get__    s    zcached_property.__get__)r   
__module____qualname__r   r   r   r
   r
   r
   r   r      s   r   c               @   s   e  Z d  Z d Z d S)Promisez
    This is just a base class for the proxy class created in
    the closure of the lazy function. It can be used to recognize
    promises in code.
    N)r   r   r   r   r
   r
   r
   r   r   '   s   r   c                sG   t  G  f d d   d t     t     f d d    } | S)a  
    Turns any callable into a lazy evaluated callable. You need to give result
    classes or types -- at least one is needed so that the automatic forcing of
    the lazy evaluation code is triggered. Results are not memoized; the
    function is evaluated on every access.
    c                   s	  e  Z d  Z d Z d Z d d   Z    f d d   Z e  f d d    Z e   f d	 d
    Z	   f d d   Z
   f d d   Z   f d d   Z   f d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d   Z d d    Z d! S)"zlazy.<locals>.__proxy__z
        Encapsulate a function call and act as a proxy for methods that are
        called on the result of that function. The function is not evaluated
        until one of the methods on the result is called.
        Fc             S   s5   | |  _  | |  _ |  j s( |  j   n  d |  _ d  S)NT)_proxy____args_proxy____kw_proxy____prepared__prepare_class__)r   r   kwr
   r
   r   r   A   s
    			z lazy.<locals>.__proxy__.__init__c                s   t    |  j |  j f  f S)N)_lazy_proxy_unpickler   r   )r   )r   resultclassesr
   r   
__reduce__H   s    z"lazy.<locals>.__proxy__.__reduce__c                s&  xs   D]k } xb | j    D]T } xK | j j   D]: } t |  |  rK q0 n  |  j |  } t |  | |  q0 Wq Wq Wt   k |  _ t j	   k |  _
 |  j o |  j
 s t d   |  j
 r t j r |  j |  _ q"|  j |  _ |  j |  _ n0 |  j r"t j r|  j |  _ q"|  j |  _ n  d  S)Nz9Cannot call lazy() with both bytes and text return types.)mror   keyshasattr__promise__setattrbytes_delegate_bytesr   	text_type_delegate_textAssertionErrorPY3_proxy____text_cast__str____unicode___proxy____bytes_cast_encoded_proxy____bytes_cast	__bytes__)r   Zresultclasstype_method_namemeth)r$   r
   r   r!   N   s(    					z)lazy.<locals>.__proxy__.__prepare_class__c                s      f d d   } | S)Nc                s+     |  j  |  j   } t |   | |   S)N)r   r   r   )r   r   r"   r   )r   r8   r
   r   __wrapper__l   s    z8lazy.<locals>.__proxy__.__promise__.<locals>.__wrapper__r
   )r   r8   r:   )r   )r8   r   r)   i   s    z#lazy.<locals>.__proxy__.__promise__c                s     |  j  |  j   S)N)r   r   )r   )r   r
   r   Z__text_casts   s    z#lazy.<locals>.__proxy__.__text_castc                s   t    |  j |  j    S)N)r+   r   r   )r   )r   r
   r   Z__bytes_castv   s    z$lazy.<locals>.__proxy__.__bytes_castc                s     |  j  |  j   j d  S)Nzutf-8)r   r   encode)r   )r   r
   r   Z__bytes_cast_encodedy   s    z,lazy.<locals>.__proxy__.__bytes_cast_encodedc                s=   |  j  r |  j   S|  j r& |  j   S  |  j |  j   Sd  S)N)r,   r5   r.   r1   r   r   )r   )r   r
   r   __cast|   s
    	
	
zlazy.<locals>.__proxy__.__castc             S   s   t  |  j    S)N)str_proxy____cast)r   r
   r
   r   r2      s    zlazy.<locals>.__proxy__.__str__c             S   s.   t  | t  r | j   } n  |  j   | k S)N)
isinstancer   r>   )r   otherr
   r
   r   __ne__   s    zlazy.<locals>.__proxy__.__ne__c             S   s.   t  | t  r | j   } n  |  j   | k S)N)r?   r   r>   )r   r@   r
   r
   r   __eq__   s    zlazy.<locals>.__proxy__.__eq__c             S   s.   t  | t  r | j   } n  |  j   | k  S)N)r?   r   r>   )r   r@   r
   r
   r   __lt__   s    zlazy.<locals>.__proxy__.__lt__c             S   s   t  |  j    S)N)hashr>   )r   r
   r
   r   __hash__   s    z lazy.<locals>.__proxy__.__hash__c             S   sH   |  j  r  t j r  t |   | S|  j r: t j |   | S|  j   | S)N)r,   r   PY2r+   r.   r-   r>   )r   Zrhsr
   r
   r   __mod__   s
    	zlazy.<locals>.__proxy__.__mod__c             S   s   |  | t  |   <|  S)N)id)r   memor
   r
   r   __deepcopy__   s    z$lazy.<locals>.__proxy__.__deepcopy__N)r   r   r   r   r    r   r%   classmethodr!   r)   r1   r5   r4   r>   r2   rA   rB   rC   rE   rG   rJ   r
   )r   r$   r
   r   	__proxy__8   s"   
rL   c                 s     |  |  S)Nr
   )r   r"   )rL   r
   r   r:      s    zlazy.<locals>.__wrapper__)r   r   r   )r   r$   r:   r
   )rL   r   r$   r   lazy0   s    prM   c             G   s   t  |  |  | |   S)N)rM   )r   r   r	   r$   r
   r
   r   r#      s    r#   c             C   s&   d d l  m } t | t j  |   S)zK
    Shortcut for the common case of a lazy callable that returns str.
    r   )
force_text)Zdjango.utils.encodingrN   rM   r   r-   )textrN   r
   r
   r   lazystr   s    rP   c             G   s#   t  j d t d  t |   |   S)Nzbdjango.utils.functional.allow_lazy() is deprecated in favor of django.utils.functional.keep_lazy()   )warningswarnr   	keep_lazy)r   r$   r
   r
   r   
allow_lazy   s    
rU   c                 s+     s t  d   n    f d d   } | S)z
    A decorator that allows a function to be called with one or more lazy
    arguments. If none of the args are lazy, the function is evaluated
    immediately, otherwise a __proxy__ is returned that will evaluate the
    function when needed.
    z3You must pass at least one argument to keep_lazy().c                s4   t       t       f d d    } | S)Nc                 sW   xG t  |   t  t j |   D] } t | t  r  Pq  q  W  |  |   S |  |   S)N)listr   
itervaluesr?   r   )r   r	   arg)r   	lazy_funcr
   r   wrapper   s
    &z-keep_lazy.<locals>.decorator.<locals>.wrapper)rM   r   )r   rZ   )r$   )r   rY   r   	decorator   s    !zkeep_lazy.<locals>.decorator)	TypeError)r$   r[   r
   )r$   r   rT      s    rT   c             C   s   t  t j  |   S)zO
    A decorator for functions that accept lazy arguments and return text.
    )rT   r   r-   )r   r
   r
   r   keep_lazy_text   s    r]   c                s     f d d   } | S)Nc                s,   |  j  t k r |  j   n    |  j  |  S)N)_wrappedempty_setup)r   r   )r   r
   r   inner   s    znew_method_proxy.<locals>.innerr
   )r   ra   r
   )r   r   new_method_proxy   s    rb   c               @   s  e  Z d  Z d Z d Z d d   Z e e  Z d d   Z	 d d   Z
 d	 d
   Z d d   Z d d   Z d d   Z d d   Z e j r e e  Z e e  Z e e  Z n$ e e  Z e e  Z e e  Z e e  Z e e e j d    Z  e e j!  Z" e e j#  Z$ e e%  Z& e e j'  Z( e e j)  Z* e e j+  Z, e e-  Z. e e/  Z0 e e j1  Z2 d S)
LazyObjectz
    A wrapper for another class that can be used to delay instantiation of the
    wrapped class.

    By subclassing, you have the opportunity to intercept and alter the
    instantiation. If you don't need to do that, use SimpleLazyObject.
    Nc             C   s   t  |  _ d  S)N)r_   r^   )r   r
   r
   r   r      s    zLazyObject.__init__c             C   sO   | d k r | |  j  d <n/ |  j t k r8 |  j   n  t |  j | |  d  S)Nr^   )r   r^   r_   r`   r*   )r   r   valuer
   r
   r   __setattr__  s
    zLazyObject.__setattr__c             C   sK   | d k r t  d   n  |  j t k r7 |  j   n  t |  j |  d  S)Nr^   zcan't delete _wrapped.)r\   r^   r_   r`   delattr)r   r   r
   r
   r   __delattr__  s
    zLazyObject.__delattr__c             C   s   t  d   d S)zU
        Must be implemented by subclasses to initialize the wrapped object.
        z7subclasses of LazyObject must provide a _setup() methodN)NotImplementedError)r   r
   r
   r   r`     s    zLazyObject._setupc             C   s,   |  j  t k r |  j   n  t |  j  f f S)N)r^   r_   r`   unpickle_lazyobject)r   r
   r
   r   r%   &  s    zLazyObject.__reduce__c             C   s   i  S)Nr
   )r   r
   r
   r   __getstate__/  s    zLazyObject.__getstate__c             C   s0   |  j  t k r t |     St j |  j   Sd  S)N)r^   r_   typecopy)r   r
   r
   r   __copy__2  s    zLazyObject.__copy__c             C   sE   |  j  t k r2 t |     } | | t |   <| St j |  j  |  S)N)r^   r_   rk   rH   rl   deepcopy)r   rI   resultr
   r
   r   rJ   ;  s
    zLazyObject.__deepcopy__	__class__)3r   r   r   r   r^   r   rb   r   __getattr__re   rg   r`   r%   rj   rm   rJ   r   r0   r+   r6   r=   r2   bool__bool__unicoder3   __nonzero__dir__dir__propertyoperator
attrgetterrp   eqrB   nerA   rD   rE   getitem__getitem__setitem__setitem__delitem__delitem__iter__iter__len__len__contains__contains__r
   r
   r
   r   rc      s:   					rc   c             C   s   |  S)zh
    Used to unpickle lazy objects. Just return its argument, which will be the
    wrapped object.
    r
   )wrappedr
   r
   r   ri   `  s    ri   c                   sX   e  Z d  Z d Z   f d d   Z d d   Z d d   Z d d	   Z d
 d   Z   S)SimpleLazyObjectz
    A lazy object initialized from any function.

    Designed for compound objects of unknown type. For builtins or objects of
    known type, use django.utils.functional.lazy.
    c                s$   | |  j  d <t t |   j   d S)aC  
        Pass in a callable that returns the object to be wrapped.

        If copies are made of the resulting SimpleLazyObject, which can happen
        in various circumstances within Django, then you must ensure that the
        callable can be safely run more than once and will return the same
        value.
        
_setupfuncN)r   superr   r   )r   r   )rp   r
   r   r   o  s    	zSimpleLazyObject.__init__c             C   s   |  j    |  _ d  S)N)r   r^   )r   r
   r
   r   r`   {  s    zSimpleLazyObject._setupc             C   s;   |  j  t k r |  j } n	 |  j  } d t |   j | f S)Nz<%s: %r>)r^   r_   r   rk   r   )r   Z	repr_attrr
   r
   r   __repr__  s    	zSimpleLazyObject.__repr__c             C   s0   |  j  t k r t |  j  St j |  j   Sd  S)N)r^   r_   r   r   rl   )r   r
   r
   r   rm     s    zSimpleLazyObject.__copy__c             C   sE   |  j  t k r2 t |  j  } | | t |   <| St j |  j  |  S)N)r^   r_   r   r   rH   rl   rn   )r   rI   ro   r
   r
   r   rJ     s
    zSimpleLazyObject.__deepcopy__)	r   r   r   r   r   r`   r   rm   rJ   r
   r
   )rp   r   r   h  s   	r   c               @   s.   e  Z d  Z d Z d d d d d d  Z d S)lazy_propertyzj
    A property that works with subclasses by wrapping the decorated
    functions of the base class.
    Nc             C   s   | d  k	 r0 t  |  d  | j d d   } n  | d  k	 r] t  |  | j d d   } n  | d  k	 r t  |  | j d d   } n  t | | | |  S)Nc             S   s   t  |  |    S)N)r   )r   Zinstance_typer   r
   r
   r   fget  s    z#lazy_property.__new__.<locals>.fgetc             S   s   t  |  |  |  S)N)r   )r   rd   r   r
   r
   r   fset  s    z#lazy_property.__new__.<locals>.fsetc             S   s   t  |  |    S)N)r   )r   r   r
   r
   r   fdel  s    z#lazy_property.__new__.<locals>.fdel)r   r   rx   )r   r   r   r   docr
   r
   r   __new__  s    			zlazy_property.__new__)r   r   r   r   r   r
   r
   r
   r   r     s   r   c             C   s8   g  g  f } x% | D] } | |  |  j  |  q W| S)z
    Splits the values into two sets, based on the return value of the function
    (True/False). e.g.:

        >>> partition(lambda x: x > 3, range(5))
        [0, 1, 2, 3], [4]
    )append)	predicatevaluesresultsitemr
   r
   r   	partition  s    r   )rl   ry   rR   	functoolsr   r   Zdjango.utilsr   Zdjango.utils.deprecationr   r   objectr   r   rM   r#   rP   rU   rT   r]   r_   rb   rc   ri   r   rx   r   r   r
   r
   r
   r   <module>   s*   		q2