a fWc@sdZddlmZmZmZddlZeeZddl m Z m Z ddl Z ddl mZddlmZgdZGdd d eZGd d d eZd d ZGdddeZdddZdddZdS)z7 passlib.utils.decor -- helper decorators & properties )absolute_importdivisionprint_functionN)wrapsupdate_wrapper)warn)PY3) classproperty hybrid_methodmemoize_single_valuememoized_propertydeprecated_functiondeprecated_methodc@s,eZdZdZddZddZeddZdS) r zjFunction decorator which acts like a combination of classmethod+property (limited to read-only properties)cCs ||_dSNim_funcselffuncr7/usr/lib/python3.9/site-packages/passlib/utils/decor.py__init__#szclassproperty.__init__cCs ||Srrrobjclsrrr__get__&szclassproperty.__get__cCs|jS)zpy3 compatible aliasrrrrr__func__)szclassproperty.__func__N)__name__ __module__ __qualname____doc__rrpropertyrrrrrr s r c@s eZdZdZddZddZdS)r z decorator which invokes function with class if called as class method, and with object if called at instance level. cCs||_t||dSr)rrrrrrr4szhybrid_method.__init__cCs2|dur |}trt|j|St|j||SdSr)rtypes MethodTyperrrrrr8s zhybrid_method.__get__N)rrr r!rrrrrrr .sr cs0itfdd}fdd}||_|S)z decorator for function which takes no args, and memoizes result. exposes a ``.clear_cache`` method to clear the cached value. cs0z dWStyYn0}d<|SNT)KeyError)valuecacherrrwrapperLs   z%memoize_single_value..wrappercsdddSr%)popr)r)rr clear_cacheUsz)memoize_single_value..clear_cache)rr,)rr*r,rr(rr Ds  r c@sBeZdZdZddZddZes,eddZdd Z d d d Z d S)r zM decorator which invokes method once, then replaces attr with result cCs||_|j|_|j|_dSr)rrr!rrrrr_szmemoized_property.__init__cCs(|dur |S||}t||j||Sr)rsetattrr)rrrr'rrrrds  zmemoized_property.__get__cCs|jS)z py2 alias)rrrrrrmszmemoized_property.im_funccCs|j|jddS)z class-level helper to clear stored value (if any). usage: :samp:`type(self).{attr}.clear_cache(self)` N)__dict__r+r)rrrrrr,rszmemoized_property.clear_cacheNcCs|j|j|S)z class-level helper to peek at stored value usage: :samp:`value = type(self).{attr}.clear_cache(self)` )r.getr)rrdefaultrrr peek_cachezszmemoized_property.peek_cache)N) rrr r!rrrr"rr,r1rrrrr [s r TFcsbdurFrdndr"d7r.d7r>d7d7fdd }|S) abdecorator 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.cs*o ttr dtjtp*jjdrPfdd}nfdd}t| rsr|j rd|j vrpd}s r|d7}r|df7} rڈr|d 7}|d 7}|d 7}|j d  d s|j d 7_ |j d|f7_ r&t|}|S)N)modname deprecatedremovedcsP}r|dn|dj}|j|j|jdt|tdd|i|S)Nr)klassr3 stacklevel)copy __class__updaterrrDeprecationWarning)argskwdstmpr7)ris_classmethodmsgoptsrrr*s z3deprecated_function..build..wrappercsttdd|i|S)Nr8r9)rr>)r?r@)rtextrrr*sz.. deprecated::z z!and will be removed in version %sz, zuse %s insteadr2  z .. deprecated:: %s ) isinstance classmethodrtyperdictrrrr!stripendswith)rr*Ztxt _is_methodr5 func_modulerCr6 replacementupdoc)rrBrDrErbuildsF  z"deprecated_function..buildr)rCr5r6rSrRrPrQrTrrOrr s  *r cCst|||||ddS)aZdecorator 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)rP)r )rCr5r6rSrRrrrrs r)NNNTNFN)NNNTN)r!Z __future__rrrZloggingZ getLoggerrlog functoolsrrr#warningsrZpasslib.utils.compatr__all__objectr r r r r rrrrrs&   < C