403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.221.20.252
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__/cache.cpython-37.pyc
B

��[�U�@srdZddlZddlmZddlmZmZmZmZddl	m
Z
ddlm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
�Z1dd�Z2Gdd�de%�Z3Gdd�de%�Z4dd�Z5dd�Z6dS)z�This 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_text�func_signature�bindfuncargs)�sha1)�BeakerException�InvalidCacheBackendError)�
_threading)�wrapsc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�	_backendsFcCs||_t��|_dS)N)�_clsmapr
�Lock�_mutex)�self�clsmap�r�=/opt/alt/python37/lib/python3.7/site-packages/beaker/cache.py�__init__<sz_backends.__init__cCsry
|j|Stk
rl}zD|jsX|j��z|jsB|��d|_|j|S|j��X|�Wdd}~XYnXdS)NT)r
�KeyError�initializedr�acquire�_init�release)r�key�errr�__getitem__@s


z_backends.__getitem__c
Cs �yddl}x�|�d�D]�}y2|��}|j}||jkrBtd|��||j|<Wqttfk
rfYqddl}ddlm	}t
|��d|�s�ddl}yddl
m
}Wn tk
r�ddlm
}YnX|�}	|j|	d�t�d||	��ftd	�YqXqWWntk
�rYnXdS)
Nrzbeaker.backendsz2NamespaceManager name conflict,'%s' already loaded)�DistributionNotFound�)�StringIO)�filez5Unable to load NamespaceManager entry point: '%s': %s�)�
pkg_resources�iter_entry_points�load�namer
rr	�SyntaxError�sysr�
isinstance�exc_info�	tracebackr�ImportError�io�	print_exc�warnings�warn�getvalue�RuntimeWarning)
rr"Zentry_pointZnamespace_managerr%r'rr*r�tbrrrrQs<

z_backends._initN)�__name__�
__module__�__qualname__rrrrrrrrr9sr)	�memoryZdbmr z
ext:memcachedzext:databasezext:sqlaz
ext:googlezext: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)�region�argsrrr�cache_region�sDr:cGsTt|�r|s|j}|j}|s&td��nt|}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_regions�Cache�
_get_cache�_cache_decorator_invalidate�get�util�DEFAULT_CACHE_KEY_LENGTH)�	namespacer8r9�cacherrr�region_invalidate�s6
rHc@s�eZdZdZddd�Zedd��Zdd	�ZeZd
d�Z	e	Z
dd
�ZeZdd�Z
e�d�dd��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS) 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|t�r|�Wn tk
r:td|��YnX|dk	rLt|�}||_||f|�|_|pf||_||_	||_
dS)NzUnknown cache implementation %r)rr(r	r�	TypeError�int�namespace_namerF�
expiretime�	starttime�nsargs)rrF�typerLrMZexpirerN�clsrrrr!s

zCache.__init__cCsB|t|�}yt|Stk
r<||f|�t|<}|SXdS)N)�str�cache_managersr)rPrF�kwrrGrrrrA3szCache._get_cachecKs|j|f|��|�dS)N)�
_get_value�	set_value)rr�valuerSrrr�put<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)rTZclear_value)rrrSZmycontainerrrr�remove_valueEszCache.remove_valuecKsZt|t�r|�dd�}d|kr,|j|f|�S|�d|j�|�d|j�tj||j	f|�S)N�ascii�backslashreplacerOrLrM)
r(r�encode�_legacy_get_value�
setdefaultrLrM�	container�ValuerF)rrrSrrrrTJs
zCache._get_valuez�Specifying 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||||d�S)NrLrM�
createfuncrO)rLrarM)�poprLrN�copy�updater@rFrT)	rrrOrSrLrMra�kwargs�crrrr]Vs


zCache._legacy_get_valuecCs|j��dS)z'Clear all the values from the namespaceN)rF�remove)rrrr�cleardszCache.clearcCs
|�|�S)N)rC)rrrrrriszCache.__getitem__cCs|�|���S)N)rTZhas_current_value)rrrrr�__contains__lszCache.__contains__cCs||kS)Nr)rrrrr�has_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@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�CacheManagercKs$||_|�di�|_t�|j�dS)z�Initialize 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)rerb�regionsr?rd)rrerrrrzszCacheManager.__init__cKs |j��}|�|�t�||�S)N)rercrdr@rA)rr%rerSrrr�	get_cache�s

zCacheManager.get_cachecCs,||jkrtd|��|j|}t�||�S)NzCache region not configured: %s)rprr@rA)rr%r8rSrrr�get_cache_region�s

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:)rr8r9rrrr8�szCacheManager.regioncGst||f|��S)a�Invalidate 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)rrFr8r9rrrrH�s#zCacheManager.region_invalidatecOst|||d�S)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)rr9rerrrrG�szCacheManager.cachecOsV|j}|j|f|�}t|d�r8t|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>rq�hasattrr?r=rCrDrErbrB)r�funcr9rerFrG�cacheregr;rrr�
invalidate�s!

zCacheManager.invalidateN)
r3r4r5rrqrrr8rHrGrvrrrrroys%rocsdg������fdd�}|S)z$Return a caching function decorator.Nc
sXt����t����t���t�����������f	dd��}�|_�dk	rT�|_|S)Nc	sT�dst�dk	rT�tkr$td���t�}|�dd�sB����St��|��d<n �rl�j�f���d<ntd��g}�r�t�	���\��dd����D�}�}�
r��dd�}t	d	��
tt	t�||���}�r�t�}|�d
t
j�}n��d
t
j�}t|�t��t|�k�r$t|�d����}���fdd
�}d�jf|_�dj||d�S)NrzCache region not configured: %s�enabledTz3'manager + kwargs' or 'region' argument is requiredcSs*g|]"\}}td��t|�t|�f��qS)�:)r�join)�.0rrVrrr�
<listcomp>AszE_cache_decorate.<locals>.decorate.<locals>.cached.<locals>.<listcomp>r� r;zutf-8cs
����S)Nrr)r9rtrerr�goTsz=_cache_decorate.<locals>.decorate.<locals>.cached.<locals>.goz
_cached_%s)ra)r?rrCr@rArq�	Exceptionr�itemsrry�maprrDrErb�lenrJrr\�	hexdigestr3rX)	r9reZregZcache_key_kwargsZcache_key_args�	cache_keyrur;r})	rG�	deco_argsrt�managerrF�optionsr8�	signature�	skip_self)r9rer�cached+s:

z1_cache_decorate.<locals>.decorate.<locals>.cached)rDZfunc_namespaceZhas_self_argrrr>r=)rtr�)rGr�r�r�r8)rtrFr�r�r�decorate&s

$/z!_cache_decorate.<locals>.decorater)r�r�r�r8r�r)rGr�r�r�r8rr7!s8r7cCsJtd��tt|��}t|�t|j�|kr<t|�d����}|�|�dS)z3Invalidate a cache key based on function arguments.r|zutf-8N)	rryr�r�rKrr\r�rY)rGr;r9r�rrrrBasrB)7rmr.�	itertoolsrZbeaker._compatrrrrZbeaker.containerr_Zbeaker.utilrDZbeaker.crypto.utilrZbeaker.exceptionsrr	Zbeaker.synchronizationr
Zbeaker.ext.memcached�extZ	memcachedZbeaker.ext.databaseZdatabaseZbeaker.ext.sqlaZsqlaZbeaker.ext.googleZgoogleZbeaker.ext.mongodbZmongodbZbeaker.ext.redisnmZredisnm�	functoolsrr?rR�objectrZMemoryNamespaceManagerZDBMNamespaceManagerZFileNamespaceManagerZMemcachedNamespaceManagerZDatabaseNamespaceManagerZSqlaNamespaceManagerZGoogleNamespaceManagerZMongoNamespaceManagerZRedisNamespaceManagerrr:rHr@ror7rBrrrr�<module>sF?GGf)@

Youez - 2016 - github.com/yon3zu
LinuXploit