o
    _6d                     @   s   d Z ddlmZmZmZ ddlZe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	 d	eZG d
d deZdd ZG dd deZ			dddZ		d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                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	r	   zjFunction decorator which acts like a combination of classmethod+property (limited to read-only properties)c                 C   s
   || _ d S Nim_funcselffunc r   jC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\passlib/utils/decor.py__init__#      
zclassproperty.__init__c                 C   s
   |  |S r   r   r   objclsr   r   r   __get__&   r   zclassproperty.__get__c                 C      | j S )zpy3 compatible aliasr   r   r   r   r   __func__)      zclassproperty.__func__N)__name__
__module____qualname____doc__r   r   propertyr   r   r   r   r   r	       s    r	   c                   @   s    e Zd ZdZdd Zd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                 C   s   || _ t| | d S r   )r   r   r   r   r   r   r   4   s   zhybrid_method.__init__c                 C   s.   |d u r|}t rt| j|S t| j||S r   )r   types
MethodTyper   r   r   r   r   r   8   s
   zhybrid_method.__get__N)r!   r"   r#   r$   r   r   r   r   r   r   r
   .   s    r
   c                    s0   i  t  fdd} fdd}||_|S )z
    decorator for function which takes no args,
    and memoizes result.  exposes a ``.clear_cache`` method
    to clear the cached value.
    c                     s0   z d W S  t y   Y nw   }  d< | S NT)KeyError)valuecacher   r   r   wrapperL   s   
z%memoize_single_value.<locals>.wrapperc                      s     dd  d S r(   )popr   )r,   r   r   clear_cacheU   s   z)memoize_single_value.<locals>.clear_cache)r   r/   )r   r-   r/   r   r+   r   r   D   s   r   c                   @   sB   e Zd ZdZdd Zdd Zesedd Zdd	 Z	dddZ
d
S )r   zM
    decorator which invokes method once, then replaces attr with result
    c                 C   s   || _ |j| _|j| _d S r   )r   r!   r$   r   r   r   r   r   _   s   zmemoized_property.__init__c                 C   s(   |d u r| S |  |}t|| j| |S r   )r   setattrr!   )r   r   r   r*   r   r   r   r   d   s
   
zmemoized_property.__get__c                 C   r   )z	py2 alias)r   r   r   r   r   r   m   r    zmemoized_property.im_funcc                 C   s   |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__r.   r!   )r   r   r   r   r   r/   r   s   zmemoized_property.clear_cacheNc                 C   s   |j | j|S )z
        class-level helper to peek at stored value

        usage: :samp:`value = type(self).{attr}.clear_cache(self)`
        )r1   getr!   )r   r   defaultr   r   r   
peek_cachez   s   zmemoized_property.peek_cacher   )r!   r"   r#   r$   r   r   r   r%   r   r/   r4   r   r   r   r   r   [   s    
r   TFc                    sb   du r# r	dndrd7 rd7 rd 7 d7  fd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                    s  ot  tr d tj tp j jdr( fdd}n  fdd}t|  
rs>r|j	rd|j	vrpId}sN	rm|d7 }r[|df 7 }	rirc|d	7 }|d
	 7 }|d7 }|j	
dds}| j	d7  _	| j	d|f 7  _	rt|}|S )N)modname
deprecatedremovedc                     sP     }r
| d n| d j}|j|j|jd t| tdd  | i |S )Nr   )klassr6      
stacklevel)copy	__class__updater!   r"   r   DeprecationWarning)argskwdstmpr:   )r   is_classmethodmsgoptsr   r   r-      s
   z3deprecated_function.<locals>.build.<locals>.wrapperc                     s   t tdd  | i |S )Nr;   r<   )r   rA   )rB   rC   )r   textr   r   r-      s   z.. deprecated:: z
    z!and will be removed in version %sz, zuse %s insteadr5    
z
.. deprecated:: %s
)
isinstanceclassmethodr   typer   dictr"   r!   r   r$   stripendswith)r   r-   txt
_is_methodr8   func_modulerF   r9   replacementupdoc)r   rE   rG   rH   r   build   sD   

z"deprecated_function.<locals>.buildr   )rF   r8   r9   rW   rV   rT   rU   rX   r   rS   r   r      s   *r   c                 C   s   t | ||||d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)rT   )r   )rF   r8   r9   rW   rV   r   r   r   r      s   
r   )NNNTNFN)NNNTN)r$   
__future__r   r   r   logging	getLoggerr!   log	functoolsr   r   r&   warningsr   Zpasslib.utils.compatr   __all__objectr	   r
   r   r   r   r   r   r   r   r   <module>   s(    
<
C