U \UV<@sxdZdZdZdZddlmZddlZGdddeZGd d d eZGd d d eZ e Z e Z Gd dde Z e Z e ZdS)zDaniel Greenfeldzpydanny@gmail.comz1.3.0ZBSD)timeNc@s eZdZdZddZddZdS)cached_propertya A property that is only computed once per instance and then replaces itself with an ordinary attribute. Deleting the attribute resets the property. Source: https://github.com/bottlepy/bottle/commit/fa7733e075da0d790d809aa3d2f53071897e6f76 cCst|d|_||_dSN__doc__)getattrrfuncselfrr /cached_property.py__init__s zcached_property.__init__cCs(|dkr |S||}|j|jj<|SN)r__dict____name__)r objclsvaluer r r __get__szcached_property.__get__Nr __module__ __qualname__rr rr r r r r src@s eZdZdZddZddZdS)threaded_cached_property A cached_property version for use in environments where multiple threads might concurrently try to access the property. cCs t|d|_||_t|_dSr)rrr threadingRLocklockrr r r r $s z!threaded_cached_property.__init__c Csz|dkr |S|j}|jj}|jPz||WW5QRStk rj||||YW5QRSXW5QRXdSr )rrrrKeyError setdefault)r rrobj_dictnamer r r r)sz threaded_cached_property.__get__Nrr r r r rsrc@sBeZdZdZdddZddZddZd d Zd d Zd dZ dS)cached_property_with_ttlz A property that is only computed once per instance and then replaces itself with an ordinary attribute. Setting the ttl to a number expresses how long the property will last before being timed out. NcCs*t|r|}d}nd}||_||dSr )callablettl _prepare_func)r r"rr r r r ?s z!cached_property_with_ttl.__init__cCs|||Sr )r#rr r r __call__Hs z!cached_property_with_ttl.__call__c Csz|dkr |St}|j}|j}z||\}}Wntk rBYnX|joV|j||k}|s`|S||}||f||<|Sr )rrrrr"r) r rrZnowrrrZ last_updatedZ ttl_expiredr r r rLs  z cached_property_with_ttl.__get__cCs|j|jddSr )rpopr)r rr r r __delete__`sz#cached_property_with_ttl.__delete__cCs|tf|j|j<dSr )rrr)r rrr r r __set__csz cached_property_with_ttl.__set__cCs&||_|r"|j|_|j|_|j|_dSr )rrrrrr r r r#fs z&cached_property_with_ttl._prepare_func)N) rrrrr r$rr&r'r#r r r r r 8s r cs.eZdZdZdfdd ZfddZZS)!threaded_cached_property_with_ttlrNcstt||t|_dSr )superr(r rrr)r r" __class__r r r xsz*threaded_cached_property_with_ttl.__init__c s0|j tt|||W5QRSQRXdSr )rr)r(r)r rrr*r r r|s z)threaded_cached_property_with_ttl.__get__)N)rrrrr r __classcell__r r r*r r(rsr() __author__Z __email__ __version__Z __license__rrobjectrrr Zcached_property_ttlZtimed_cached_propertyr(Zthreaded_cached_property_ttlZtimed_threaded_cached_propertyr r r r s 6