
    lg                         d Z ddlmZmZmZ ddlZ ej        e          Zddl	m
Z
mZ ddlZddlmZ ddlmZ g dZ G d d	e          Z G d
 de          Zd Z G d de          Z	 	 	 ddZ	 	 ddZdS )z7
passlib.utils.decor -- helper decorators & properties
    )absolute_importdivisionprint_functionN)wrapsupdate_wrapper)warn)PY3)classpropertyhybrid_methodmemoize_single_valuememoized_propertydeprecated_functiondeprecated_methodc                   4    e Zd ZdZd Zd Zed             ZdS )r
   zjFunction decorator which acts like a combination of classmethod+property (limited to read-only properties)c                     || _         d S Nim_funcselffuncs     N/var/www/html/nourish/venv/lib/python3.11/site-packages/passlib/utils/decor.py__init__zclassproperty.__init__#   s        c                 ,    |                      |          S r   r   r   objclss      r   __get__zclassproperty.__get__&   s    ||C   r   c                     | j         S )zpy3 compatible aliasr   r   s    r   __func__zclassproperty.__func__)   s     |r   N)__name__
__module____qualname____doc__r   r   propertyr"    r   r   r
   r
       sS        tt  ! ! !   X  r   r
   c                       e Zd ZdZd Zd ZdS )r   z
    decorator which invokes function with class if called as class method,
    and with object if called at instance level.
    c                 4    || _         t          | |           d S r   )r   r   r   s     r   r   zhybrid_method.__init__4   s    	tT"""""r   c                     ||}t           rt          j        | j        |          S t          j        | j        ||          S r   )r	   types
MethodTyper   r   s      r   r   zhybrid_method.__get__8   s@    ;C 	9#DIs333#DIsC888r   N)r#   r$   r%   r&   r   r   r(   r   r   r   r   .   s<         
# # #9 9 9 9 9r   r   c                 \     i t                      fd            }fd}||_        |S )z
    decorator for function which takes no args,
    and memoizes result.  exposes a ``.clear_cache`` method
    to clear the cached value.
    c                  X    	 d         S # t           $ r Y nw xY w             x} d<   | S NT)KeyError)valuecacher   s    r   wrapperz%memoize_single_value.<locals>.wrapperL   sK    	; 	 	 	D	"dff$ds    
c                  4                          dd            d S r0   )pop)r3   s   r   clear_cachez)memoize_single_value.<locals>.clear_cacheU   s    		$r   )r   r7   )r   r4   r7   r3   s   `  @r   r   r   D   s_     E
4[[     [    %GNr   c                   F    e Zd ZdZd Zd Zesed             Zd Z	ddZ
dS )	r   zM
    decorator which invokes method once, then replaces attr with result
    c                 D    || _         |j        | _        |j        | _        d S r   )r"   r#   r&   r   s     r   r   zmemoized_property.__init___   s    |r   c                 d    || S |                      |          }t          || j        |           |S r   )r"   setattrr#   )r   r   r   r2   s       r   r   zmemoized_property.__get__d   s6    ;Kc""T]E***r   c                     | j         S )z	py2 alias)r"   r!   s    r   r   zmemoized_property.im_funcm   s     = r   c                 F    |j                             | j        d           dS )z
        class-level helper to clear stored value (if any).

        usage: :samp:`type(self).{attr}.clear_cache(self)`
        N)__dict__r6   r#   )r   r   s     r   r7   zmemoized_property.clear_cacher   s$     	-----r   Nc                 B    |j                             | j        |          S )z
        class-level helper to peek at stored value

        usage: :samp:`value = type(self).{attr}.clear_cache(self)`
        )r>   getr#   )r   r   defaults      r   
peek_cachezmemoized_property.peek_cachez   s     |w777r   r   )r#   r$   r%   r&   r   r   r	   r'   r   r7   rB   r(   r   r   r   r   [   s         $ $ $
    !		! 	! 
	!. . .8 8 8 8 8 8r   r   TFc                 v      $rd nd r dz   r dz   r dz  z    dz    fd}|S )	ab  decorator to deprecate a function.

    :arg msg: optional msg, default chosen if omitted
    :kwd deprecated: version when function was first deprecated
    :kwd removed: version when function will be removed
    :kwd replacement: alternate name / instructions for replacing this function.
    :kwd updoc: add notice to docstring (default ``True``)
    Nz5the method %(mod)s.%(klass)s.%(name)s() is deprecatedz-the function %(mod)s.%(name)s() is deprecatedz as of Passlib %(deprecated)sz,, and will be removed in Passlib %(removed)sz, use %s instead.c                 V    ot           t                    r                      d t                    j         t          p j         j        
          r	 	fd}n	z   fd}t          |            rs
r|j	        rd|j	        vr~pd}
sr%|dz  }
r|d
z  }r
r|dz  }|d	z  z  }|d
z  }|j	        
                    d                              d          s|xj	        dz  c_	        |xj	        d|dz  c_	        rt          |          }|S )N)modname
deprecatedremovedc                                                       }r| d         n| d         j        }|                    |j        |j                   t          |z  t          d            | i |S )Nr   )klassrF      
stacklevel)copy	__class__updater#   r$   r   DeprecationWarning)argskwdstmprK   r   is_classmethodmsgoptss       r   r4   z3deprecated_function.<locals>.build.<locals>.wrapper   ss    iikk#1HQtAw7H

U5E
FFFS3Y 2qAAAAtT*T***r   c                  B    t          t          d            | i |S )NrL   rM   )r   rR   )rS   rT   r   texts     r   r4   z3deprecated_function.<locals>.build.<locals>.wrapper   s.    T-!<<<<tT*T***r   z.. deprecated:: z
    zand will be removed in version z, zuse %s insteadrD    
z
.. deprecated:: )
isinstanceclassmethodr   typer"   dictr$   r#   r   r&   stripendswith)r   r4   txtrV   rX   rZ   
_is_methodrH   func_modulerW   rI   replacementupdocs   `  @@@r   buildz"deprecated_function.<locals>.build   s   #E
4(E(E 	5<<d++4D.t!	    	++ + + + + + + + + :D+ + + + + + 	w%%% 	Aj 	AG 	A?	A'8'O'O"C + x LC''KKC : $t+k99Cs
?((--66t<< (4'OOO333@@OO 	+!'**Gr   r(   )rW   rH   rI   rh   rg   re   rf   ri   s   ``````` r   r   r      s     { 	BICCAC 	322C 	BAAC 	4%33Cs
) ) ) ) ) ) ) ) ) ) )T Lr   c                 ,    t          | ||||d          S )aZ  decorator to deprecate a method.

    :arg msg: optional msg, default chosen if omitted
    :kwd deprecated: version when method was first deprecated
    :kwd removed: version when method will be removed
    :kwd replacement: alternate name / instructions for replacing this method.
    :kwd updoc: add notice to docstring (default ``True``)
    T)re   )r   )rW   rH   rI   rh   rg   s        r   r   r      s(     sJ*.0 0 0 0r   )NNNTNFN)NNNTN)r&   
__future__r   r   r   logging	getLoggerr#   log	functoolsr   r   r,   warningsr   passlib.utils.compatr	   __all__objectr
   r   r   r   r   r   r(   r   r   <module>rt      s    A @ @ @ @ @ @ @ @ @ g!! + + + + + + + +        % $ $ $ $ $	 	 	    F   9 9 9 9 9F 9 9 9,  .%8 %8 %8 %8 %8 %8 %8 %8x HL5:$(A A A AF FJ"&0 0 0 0 0 0r   