o
    {,h8                     @   s   d dl Z d dlZd dlZd dlmZ G dd dZG dd dZG dd dZd	d
 Zdd Z	dd Z
dd Zdd Ze Zdd ZG dd dZdd ZG dd deZdd ZdS )    N)wrapsc                   @   s:   e Zd ZdZdZedd Zdd Zdd Zdd	d
Z	dS )cached_propertyz
    Decorator that converts a method with a single self argument into a
    property cached on the instance.

    A cached property can be made out of an existing method:
    (e.g. ``url = cached_property(get_absolute_url)``).
    Nc                 C      t d)NzICannot use cached_property instance without calling __set_name__() on it.	TypeError)instance r   M/var/www/html/rh/venv/lib/python3.10/site-packages/django/utils/functional.pyfunc   s   zcached_property.funcc                 C   s   || _ t|d| _d S )N__doc__)	real_funcgetattrr   selfr
   r   r   r	   __init__   s   zcached_property.__init__c                 C   s<   | j d u r|| _ | j| _d S || j krtd| j |f d S )NzJCannot assign the same cached_property to two different names (%r and %r).)namer   r
   r   )r   ownerr   r   r   r	   __set_name__   s   

zcached_property.__set_name__c                 C   s&   |du r| S |  | }|j| j< |S )z
        Call the function and put the return value in instance.__dict__ so that
        subsequent attribute access on the instance returns the cached value
        instead of calling cached_property.__get__().
        N)r
   __dict__r   )r   r   clsresr   r   r	   __get__'   s   zcached_property.__get__N)
__name__
__module____qualname__r   r   staticmethodr
   r   r   r   r   r   r   r	   r      s    

r   c                   @   s,   e Zd ZdZd	ddZd	ddZdd ZdS )
classpropertyz
    Decorator that converts a method with a single cls argument into a property
    that can be accessed directly from the class.
    Nc                 C   s
   || _ d S r   fgetr   methodr   r   r	   r   9      
zclassproperty.__init__c                 C   s
   |  |S r   r   )r   r   r   r   r   r	   r   <   r"   zclassproperty.__get__c                 C   s
   || _ | S r   r   r    r   r   r	   getter?   s   zclassproperty.getterr   )r   r   r   r   r   r   r#   r   r   r   r	   r   3   s
    

r   c                   @   s   e Zd ZdZdS )Promisez
    Base class for the proxy class created in the closure of the lazy function.
    It's used to recognize promises in code.
    N)r   r   r   r   r   r   r   r	   r$   D   s    r$   c                    s|   G fdddt  D ]$}| D ]}|jD ]}t |r q|dfdd
}t || qqqt fdd}|S )a  
    Turn any callable into a lazy evaluated callable. result classes or types
    is required -- 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d Z fddZ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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.
        c                 S   s   || _ || _d S r   _args_kw)r   argskwr   r   r	   r   \   s   
z lazy.<locals>.__proxy__.__init__c                    s   t  | j| jf fS r   )_lazy_proxy_unpickler&   r'   r   r
   resultclassesr   r	   
__reduce__`   s   z"lazy.<locals>.__proxy__.__reduce__c                 S   s   | |t | < | S r   )id)r   memor   r   r	   __deepcopy__f   s   z$lazy.<locals>.__proxy__.__deepcopy__c                    s    | j i | jS r   r%   r+   r
   r   r	   __castm   s   zlazy.<locals>.__proxy__.__castc                 S      t |  S r   )repr_proxy____castr+   r   r   r	   __repr__s      z lazy.<locals>.__proxy__.__repr__c                 S   r4   r   )strr6   r+   r   r   r	   __str__v   r8   zlazy.<locals>.__proxy__.__str__c                 S   s   t |tr	| }|  |kS r   
isinstancer$   r6   r   otherr   r   r	   __eq__y      
zlazy.<locals>.__proxy__.__eq__c                 S   s   t |tr	| }|  |kS r   r;   r=   r   r   r	   __ne__~   r@   zlazy.<locals>.__proxy__.__ne__c                 S   s   t |tr	| }|  |k S r   r;   r=   r   r   r	   __lt__   r@   zlazy.<locals>.__proxy__.__lt__c                 S   s   t |tr	| }|  |kS r   r;   r=   r   r   r	   __le__   r@   zlazy.<locals>.__proxy__.__le__c                 S   s   t |tr	| }|  |kS r   r;   r=   r   r   r	   __gt__   r@   zlazy.<locals>.__proxy__.__gt__c                 S   s   t |tr	| }|  |kS r   r;   r=   r   r   r	   __ge__   r@   zlazy.<locals>.__proxy__.__ge__c                 S   r4   r   )hashr6   r+   r   r   r	   __hash__   r8   z lazy.<locals>.__proxy__.__hash__c                 S   s   t |  |S r   )formatr6   )r   format_specr   r   r	   
__format__      z"lazy.<locals>.__proxy__.__format__c                 S   s   |   | S r   r6   r=   r   r   r	   __add__   r8   zlazy.<locals>.__proxy__.__add__c                 S   s   ||    S r   rL   r=   r   r   r	   __radd__   r8   z lazy.<locals>.__proxy__.__radd__c                 S   s   |   | S r   rL   r=   r   r   r	   __mod__   r8   zlazy.<locals>.__proxy__.__mod__c                 S   s   |   | S r   rL   r=   r   r   r	   __mul__   r8   zlazy.<locals>.__proxy__.__mul__N)r   r   r   r   r   r.   r1   r6   r7   r:   r?   rA   rB   rC   rD   rE   rG   rJ   rM   rN   rO   rP   r   r,   r   r	   	__proxy__U   s(    rQ   )__method_namec                   s&    | j i | j}t|||i |S r   )r&   r'   r   )r   rR   r(   r)   resultr2   r   r	   __wrapper__   s   zlazy.<locals>.__wrapper__c                     s
    | |S r   r   )r(   r)   )rQ   r   r	   rT         
)r$   mror   hasattrsetattrr   )r
   r-   resultclasstype_method_namerT   r   )rQ   r
   r-   r	   lazyM   s   Y

r\   c                 G   s   t | g|R  |i |S r   )r\   )r
   r(   kwargsr-   r   r   r	   r*      s   r*   c                 C   s   t tt| S )zK
    Shortcut for the common case of a lazy callable that returns str.
    )r\   r9   )textr   r   r	   lazystr   s   r_   c                     s    st d 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                    s*   t  gR  t  fdd}|S )Nc                     s:   t dd t| | D r| i |S  | i |S )Nc                 s   s    | ]}t |tV  qd S r   )r<   r$   ).0argr   r   r	   	<genexpr>   s
    
z@keep_lazy.<locals>.decorator.<locals>.wrapper.<locals>.<genexpr>)any	itertoolschainvalues)r(   r]   r
   	lazy_funcr   r	   wrapper   s
   z-keep_lazy.<locals>.decorator.<locals>.wrapper)r\   r   )r
   ri   r-   rg   r	   	decorator   s   zkeep_lazy.<locals>.decoratorr   )r-   rk   r   rj   r	   	keep_lazy   s   rl   c                 C   s   t t| S )zO
    A decorator for functions that accept lazy arguments and return text.
    )rl   r9   r2   r   r   r	   keep_lazy_text   s   rm   c                    s    fdd}d|_ |S )Nc                    s,   | j  }tu r|   | j } |g|R  S r   )_wrappedempty_setup)r   r(   rn   r2   r   r	   inner   s   znew_method_proxy.<locals>.innerF)_mask_wrapped)r
   rq   r   r2   r	   new_method_proxy   s   rs   c                       s   e Zd ZdZdZdd Z fddZeeZ	dd Z
d	d
 Zdd Zdd Zdd Zdd ZeeZeeZeeZeeZeeedZeejZeej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.Z/eej0Z1  Z2S )
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 r   )ro   rn   r+   r   r   r	   r     rU   zLazyObject.__init__c                    s4   |dkr
t  |S t  |}t|ddst|S )Nrn   rr   T)super__getattribute__r   AttributeErrorr   r   value	__class__r   r	   rv     s   zLazyObject.__getattribute__c                 C   s:   |dkr|| j d< d S | jtu r|   t| j|| d S )Nrn   )r   rn   ro   rp   rX   rx   r   r   r	   __setattr__!  s
   
zLazyObject.__setattr__c                 C   s2   |dkrt d| jtu r|   t| j| d S )Nrn   zcan't delete _wrapped.)r   rn   ro   rp   delattr)r   r   r   r   r	   __delattr__*  s
   
zLazyObject.__delattr__c                 C   r   )zU
        Must be implemented by subclasses to initialize the wrapped object.
        z7subclasses of LazyObject must provide a _setup() method)NotImplementedErrorr+   r   r   r	   rp   1  s   zLazyObject._setupc                 C   s   | j tu r	|   t| j ffS r   )rn   ro   rp   unpickle_lazyobjectr+   r   r   r	   r.   G  r@   zLazyObject.__reduce__c                 C   s    | j tu r
t|  S t| j S r   )rn   ro   typecopyr+   r   r   r	   __copy__L     

zLazyObject.__copy__c                 C   s2   | j tu rt|  }||t| < |S t| j |S r   )rn   ro   r   r/   r   deepcopyr   r0   rS   r   r   r	   r1   U  
   

zLazyObject.__deepcopy__r{   )3r   r   r   r   rn   r   rv   rs   r   __getattr__r|   r~   rp   r.   r   r1   bytes	__bytes__r9   r:   bool__bool__dir__dir__propertyoperator
attrgetterr{   eqr?   ltrB   gtrD   nerA   rF   rG   getitem__getitem__setitem__setitem__delitem__delitem__iter__iter__len__len__contains__contains____classcell__r   r   rz   r	   rt     s8    				






rt   c                 C   s   | S )zh
    Used to unpickle lazy objects. Just return its argument, which will be the
    wrapped object.
    r   )wrappedr   r   r	   r   w  s   r   c                       sV   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Ze	e
jZe	dd Z  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   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   ru   r   r   rz   r   r	   r     s   
	zSimpleLazyObject.__init__c                 C   s   |   | _d S r   )r   rn   r+   r   r   r	   rp     rK   zSimpleLazyObject._setupc                 C   s*   | j tu r	| j}n| j }dt| j|f S )Nz<%s: %r>)rn   ro   r   r   r   )r   	repr_attrr   r   r	   r7     s   
zSimpleLazyObject.__repr__c                 C   s    | j tu r
t| jS t| j S r   )rn   ro   r   r   r   r+   r   r   r	   r     r   zSimpleLazyObject.__copy__c                 C   s2   | j tu rt| j}||t| < |S t| j |S r   )rn   ro   r   r   r/   r   r   r   r   r   r	   r1     r   zSimpleLazyObject.__deepcopy__c                 C   s   ||  S r   r   r=   r   r   r	   rN     s   zSimpleLazyObject.__radd__)r   r   r   r   r   rp   r7   r   r1   rs   r   addrM   rN   r   r   r   rz   r	   r     s    	
	r   c                 C   s(   g g f}|D ]}|| |  | q|S )z
    Split 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)	predicaterf   resultsitemr   r   r	   	partition  s   r   )r   rd   r   	functoolsr   r   r   r$   r\   r*   r_   rl   rm   objectro   rs   rt   r   r   r   r   r   r   r	   <module>   s$    ,	{t9