/opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__
NameSizeModeActions
cache.cpython-37.pyc200000644editdlrm
container.cpython-37.pyc240870644editdlrm
converters.cpython-37.pyc8880644editdlrm
cookie.cpython-37.pyc17790644editdlrm
exceptions.cpython-37.pyc12980644editdlrm
middleware.cpython-37.pyc56490644editdlrm
session.cpython-37.pyc269730644editdlrm
synchronization.cpython-37.pyc106310644editdlrm
util.cpython-37.pyc167830644editdlrm
_compat.cpython-37.pyc42170644editdlrm
__init__.cpython-37.pyc1730644editdlrm
Edit: /opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__/cache.cpython-37.pyc (20000B)
B [U @srdZddlZddlmZddlmZmZmZmZddl m Z ddl m Z ddl mZddlmZmZddlmZddlmmZddlmmZddlmmZddlmmZddlmmZddlmm Z ddl!m"Z"iZ#iZ$Gd d d e%Z&e&e j'e j(e j)ej*ej+ej,ej-ej.e j/d Z0d d Z1ddZ2Gddde%Z3Gddde%Z4ddZ5ddZ6dS)zThis package contains the "front end" classes and functions for Beaker caching. Included are the :class:`.Cache` and :class:`.CacheManager` classes, as well as the function decorators :func:`.region_decorate`, :func:`.region_invalidate`. N)chain)u_ unicode_textfunc_signature bindfuncargs)sha1)BeakerExceptionInvalidCacheBackendError) _threading)wrapsc@s(eZdZdZddZddZddZdS) _backendsFcCs||_t|_dS)N)_clsmapr Lock_mutex)selfclsmapr=/opt/alt/python37/lib/python3.7/site-packages/beaker/cache.py__init__<sz_backends.__init__c Csry |j|Stk rl}zD|jsX|jz|jsB|d|_|j|S|jX|Wdd}~XYnXdS)NT)r KeyError initializedracquire_initrelease)rkeyerrr __getitem__@s    z_backends.__getitem__c Cs yddl}x|dD]}y2|}|j}||jkrBtd|||j|<Wqttfk rfYqddl}ddlm }t | d|sddl }yddl m }Wn tk rddlm }YnX|} |j| dtd|| ftd YqXqWWntk rYnXdS) Nrzbeaker.backendsz2NamespaceManager name conflict,'%s' already loaded)DistributionNotFound)StringIO)filez5Unable to load NamespaceManager entry point: '%s': %s) pkg_resourcesiter_entry_pointsloadnamer rr SyntaxErrorsysr isinstanceexc_info tracebackr ImportErrorio print_excwarningswarngetvalueRuntimeWarning) rr"Z entry_pointZnamespace_managerr%r'rr*rtbrrrrQs<    z_backends._initN)__name__ __module__ __qualname__rrrrrrrrr 9sr ) memoryZdbmr z ext:memcachedz ext:databasezext:sqlaz ext:googlez ext:mongodbz ext:rediscGst|dd|S)a Decorate a function such that its return result is cached, using a "region" to indicate the cache arguments. Example:: from beaker.cache import cache_regions, cache_region # configure regions cache_regions.update({ 'short_term':{ 'expire':60, 'type':'memory' } }) @cache_region('short_term', 'load_things') def load(search_term, limit, offset): '''Load from a database given a search term, limit, offset.''' return database.query(search_term)[offset:offset + limit] The decorator can also be used with object methods. The ``self`` argument is not part of the cache key. This is based on the actual string name ``self`` being in the first argument position (new in 1.6):: class MyThing(object): @cache_region('short_term', 'load_things') def load(self, search_term, limit, offset): '''Load from a database given a search term, limit, offset.''' return database.query(search_term)[offset:offset + limit] Classmethods work as well - use ``cls`` as the name of the class argument, and place the decorator around the function underneath ``@classmethod`` (new in 1.6):: class MyThing(object): @classmethod @cache_region('short_term', 'load_things') def load(cls, search_term, limit, offset): '''Load from a database given a search term, limit, offset.''' return database.query(search_term)[offset:offset + limit] :param region: String name of the region corresponding to the desired caching arguments, established in :attr:`.cache_regions`. :param \*args: Optional ``str()``-compatible arguments which will uniquely identify the key used by this decorated function, in addition to the positional arguments passed to the function itself at call time. This is recommended as it is needed to distinguish between any two functions or methods that have the same name (regardless of parent class or not). .. note:: The function being decorated must only be called with positional arguments, and the arguments must support being stringified with ``str()``. The concatenation of the ``str()`` version of each argument, combined with that of the ``*args`` sent to the decorator, forms the unique cache key. .. note:: When a method on a class is decorated, the ``self`` or ``cls`` argument in the first position is not included in the "key" used for caching. New in 1.6. N)_cache_decorate)regionargsrrr cache_regionsDr:cGsTt|r|s|j}|j}|s&tdnt|}t||}t||dt j |dS)aB Invalidate a cache region corresponding to a function decorated with :func:`.cache_region`. :param namespace: The namespace of the cache to invalidate. This is typically a reference to the original function (as returned by the :func:`.cache_region` decorator), where the :func:`.cache_region` decorator applies a "memo" to the function in order to locate the string name of the namespace. :param region: String name of the region used with the decorator. This can be ``None`` in the usual case that the decorated function itself is passed, not the string name of the namespace. :param args: Stringifyable arguments that are used to locate the correct key. This consists of the ``*args`` sent to the :func:`.cache_region` decorator itself, plus the ``*args`` sent to the function itself at runtime. Example:: from beaker.cache import cache_regions, cache_region, region_invalidate # configure regions cache_regions.update({ 'short_term':{ 'expire':60, 'type':'memory' } }) @cache_region('short_term', 'load_data') def load(search_term, limit, offset): '''Load from a database given a search term, limit, offset.''' return database.query(search_term)[offset:offset + limit] def invalidate_search(search_term, limit, offset): '''Invalidate the cached storage for a given search term, limit, offset.''' region_invalidate(load, 'short_term', 'load_data', search_term, limit, offset) Note that when a method on a class is decorated, the first argument ``cls`` or ``self`` is not included in the cache key. This means you don't send it to :func:`.region_invalidate`:: class MyThing(object): @cache_region('short_term', 'some_data') def load(self, search_term, limit, offset): '''Load from a database given a search term, limit, offset.''' return database.query(search_term)[offset:offset + limit] def invalidate_search(self, search_term, limit, offset): '''Invalidate the cached storage for a given search term, limit, offset.''' region_invalidate(self.load, 'short_term', 'some_data', search_term, limit, offset) z1Region or callable function namespace is required key_lengthN) callable _arg_region_arg_namespacer cache_regionsCache _get_cache_cache_decorator_invalidategetutilDEFAULT_CACHE_KEY_LENGTH) namespacer8r9cacherrrregion_invalidates6   rHc@seZdZdZdddZeddZdd ZeZd d Z e Z d d Z e Z ddZ edddZddZddZddZddZddZddZdS) r@aEFront-end to the containment API implementing a data cache. :param namespace: the namespace of this Cache :param type: type of cache to use :param expire: seconds to keep cached data :param expiretime: seconds to keep cached data (legacy support) :param starttime: time when cache was cache was r6NcKszyt|}t|tr|Wn tk r:td|YnX|dk rLt|}||_||f||_|pf||_||_ ||_ dS)NzUnknown cache implementation %r) rr(r r TypeErrorintnamespace_namerF expiretime starttimensargs)rrFtyperLrMZexpirerNclsrrrr!s  zCache.__init__cCsB|t|}yt|Stk r<||f|t|<}|SXdS)N)strcache_managersr)rPrFkwrrGrrrrA3s  zCache._get_cachecKs|j|f||dS)N) _get_value set_value)rrvaluerSrrrput<sz Cache.putcKs|j|f|S)z*Retrieve a cached value from the container)rT get_value)rrrSrrrrC@sz Cache.getcKs|j|f|}|dS)N)rTZ clear_value)rrrSZ mycontainerrrr remove_valueEszCache.remove_valuecKsZt|tr|dd}d|kr,|j|f|S|d|j|d|jtj||j f|S)NasciibackslashreplacerOrLrM) r(rencode_legacy_get_value setdefaultrLrM containerValuerF)rrrSrrrrTJs  zCache._get_valuezSpecifying a 'type' and other namespace configuration with cache.get()/put()/etc. is deprecated. Specify 'type' and other namespace configuration to cache_manager.get_cache() and/or the Cache constructor instead.c Ksd|d|j}|dd}|dd}|j}||t|jjfd|i|}|j||||dS)NrLrM createfuncrO)rLrarM)poprLrNcopyupdater@rFrT) rrrOrSrLrMrakwargscrrrr]Vs     zCache._legacy_get_valuecCs|jdS)z'Clear all the values from the namespaceN)rFremove)rrrrcleardsz Cache.clearcCs ||S)N)rC)rrrrrriszCache.__getitem__cCs||S)N)rTZhas_current_value)rrrrr __contains__lszCache.__contains__cCs||kS)Nr)rrrrrhas_keyosz Cache.has_keycCs||dS)N)rY)rrrrr __delitem__rszCache.__delitem__cCs|||dS)N)rW)rrrVrrr __setitem__uszCache.__setitem__)r6NNN)r3r4r5__doc__r classmethodrArWrUrCrXrYrgrTrDZ deprecatedr]rhrrirjrkrlrrrrr@s$    r@c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS) CacheManagercKs$||_|di|_t|jdS)zInitialize a CacheManager object with a set of options Options should be parsed with the :func:`~beaker.util.parse_cache_config_options` function to ensure only valid options are used. r?N)rerbregionsr?rd)rrerrrrzszCacheManager.__init__cKs |j}||t||S)N)rercrdr@rA)rr%rerSrrr get_caches  zCacheManager.get_cachecCs,||jkrtd||j|}t||S)NzCache region not configured: %s)rprr@rA)rr%r8rSrrrget_cache_regions   zCacheManager.get_cache_regioncGst|f|S)aHDecorate a function to cache itself using a cache region The region decorator requires arguments if there are more than two of the same named function, in the same module. This is because the namespace used for the functions cache is based on the functions name and the module. Example:: # Assuming a cache object is available like: cache = CacheManager(dict_of_config_options) def populate_things(): @cache.region('short_term', 'some_data') def load(search_term, limit, offset): return load_the_data(search_term, limit, offset) return load('rabbits', 20, 0) .. note:: The function being decorated must only be called with positional arguments. )r:)rr8r9rrrr8szCacheManager.regioncGst||f|S)aInvalidate a cache region namespace or decorated function This function only invalidates cache spaces created with the cache_region decorator. :param namespace: Either the namespace of the result to invalidate, or the cached function :param region: The region the function was cached to. If the function was cached to a single region then this argument can be None :param args: Arguments that were used to differentiate the cached function as well as the arguments passed to the decorated function Example:: # Assuming a cache object is available like: cache = CacheManager(dict_of_config_options) def populate_things(invalidate=False): @cache.region('short_term', 'some_data') def load(search_term, limit, offset): return load_the_data(search_term, limit, offset) # If the results should be invalidated first if invalidate: cache.region_invalidate(load, None, 'some_data', 'rabbits', 20, 0) return load('rabbits', 20, 0) )rH)rrFr8r9rrrrHs#zCacheManager.region_invalidatecOst|||dS)aDecorate a function to cache itself with supplied parameters :param args: Used to make the key unique for this function, as in region() above. :param kwargs: Parameters to be passed to get_cache(), will override defaults Example:: # Assuming a cache object is available like: cache = CacheManager(dict_of_config_options) def populate_things(): @cache.cache('mycache', expire=15) def load(search_term, limit, offset): return load_the_data(search_term, limit, offset) return load('rabbits', 20, 0) .. note:: The function being decorated must only be called with positional arguments. N)r7)rr9rerrrrGszCacheManager.cachecOsV|j}|j|f|}t|dr8t|j}|dtj}n|dtj}t |||dS)a4Invalidate a cache decorated function This function only invalidates cache spaces created with the cache decorator. :param func: Decorated function to invalidate :param args: Used to make the key unique for this function, as in region() above. :param kwargs: Parameters that were passed for use by get_cache(), note that this is only required if a ``type`` was specified for the function Example:: # Assuming a cache object is available like: cache = CacheManager(dict_of_config_options) def populate_things(invalidate=False): @cache.cache('mycache', type="file", expire=15) def load(search_term, limit, offset): return load_the_data(search_term, limit, offset) # If the results should be invalidated first if invalidate: cache.invalidate(load, 'mycache', 'rabbits', 20, 0, type="file") return load('rabbits', 20, 0) r=r;N) r>rqhasattrr?r=rCrDrErbrB)rfuncr9rerFrGcacheregr;rrr invalidates!  zCacheManager.invalidateN) r3r4r5rrqrrr8rHrGrvrrrrroys%rocsdgfdd}|S)z$Return a caching function decorator.Nc sXttttf dd}|_dk rT|_|S)Nc sTdstdk rTtkr$tdt}|ddsBSt|d<n rljfd<ntdg}rt \ddD}} rdd}t d  t t t ||}rt}|d t j}nd t j}t|tt|kr$t|d }fd d }djf|_dj||dS)NrzCache region not configured: %senabledTz3'manager + kwargs' or 'region' argument is requiredcSs*g|]"\}}tdt|t|fqS):)rjoin).0rrVrrr AszE_cache_decorate..decorate..cached..r r;zutf-8cs S)Nrr)r9rtrerrgoTsz=_cache_decorate..decorate..cached..goz _cached_%s)ra)r?rrCr@rArq ExceptionritemsrrymaprrDrErblenrJrr\ hexdigestr3rX) r9reZregZcache_key_kwargsZcache_key_args cache_keyrur;r}) rG deco_argsrtmanagerrFoptionsr8 signature skip_self)r9rercached+s:    z1_cache_decorate..decorate..cached)rDZfunc_namespaceZ has_self_argrr r>r=)rtr)rGrrrr8)rtrFrrrdecorate&s  $/z!_cache_decorate..decorater)rrrr8rr)rGrrrr8rr7!s8r7cCsJtdtt|}t|t|j|krsF      ? GGf)@