%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/beaker/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyo

�
���Kc@sXdZddlZddljZddljZddlmZmZddl	j
jZddlj
j
Z
ddlj
jZddlj
jZiejd6ejd6ejd6ejd6e
jd6ejd	6ejd
6ZiZiZyddlZx	ejd�D]�ZyBej�Z ej!Z!e!ekrBede!��ne ee!<Wqee"fk
rfqddl#Z#dd
lm$Z$e%e#j&�de$�s�ddl'Z'ddl(m(Z(e(�Z)e'j*de)�ej+dee)j,�fe-d�q�qXqWWne.k
rnXd�Z/d�Z0de1fd��YZ2de1fd��YZ3dS(s�Cache object

The Cache object is used to manage a set of cache files and their
associated backend. The backends can be rotated on the fly by
specifying an alternate type when used.

Advanced users can add new backends in beaker.backends

i����N(tBeakerExceptiontInvalidCacheBackendErrortmemorytdbmtfiles
ext:memcachedsext:databasesext:sqlas
ext:googlesbeaker.backendss2NamespaceManager name conflict,'%s' already loaded(tDistributionNotFoundi(tStringIOs5Unable to load NamespaceManager entry point: '%s': %sics"dg����fd�}|S(s#Decorate a function to cache itself using a cache region
    
    The region decorator requires arguments if there are more than
    2 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::
        
        # Add cache region settings to beaker:
        beaker.cache.cache_regions.update(dict_of_config_region_options))
        
        @cache_region('short_term', 'some_data')
        def populate_things(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.
    
    cs@tj��������fd�}�|_�|_|S(Ncs�t�}|jdt�s&���S�dsh�tkrOtd���ntj�|��d<ndjtt����}��fd�}�dj	|d|�S(NtenabledisCache region not configured: %st cs
���S(N(((targstfunc(s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytgoost
createfunc(
t
cache_regionstgettTrueRtCachet
_get_cachetjointmaptstrt	get_value(R	tregt	cache_keyR(tcachet	deco_argsR
t	namespacetregion(R	s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytcachedds


(tutiltfunc_namespacet_arg_namespacet_arg_region(R
R(RRR(R
Rs=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytdecoratebs
		N(tNone(RRR!((RRRs=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytcache_regionFs	cGs�t|�r*|s|j}n|j}n|s?td��n
t|}tj||�}djd�|D��}|j|�dS(s�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 reference
    
    :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::
        
        # Add cache region settings to beaker:
        beaker.cache.cache_regions.update(dict_of_config_region_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:
                region_invalidate(load, None, 'some_data',
                                        'rabbits', 20, 0)
            return load('rabbits', 20, 0)
    
    s1Region or callable function namespace is requiredRcss|]}t|�VqdS(N(R(t.0tx((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pys	<genexpr>�sN(	tcallableR RRR
RRRtremove_value(RRR	RR((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytregion_invalidateys"
RcBs�eZdZddddd�Zed��Zd�ZeZd�Z	e	Z
d�ZeZd�Z
ejd�d	��Zd
�Zd�Zd�Zd
�Zd�Zd�ZRS(sIFront-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
    
    RcKs�y&t|}t|t�r%|�nWn!tk
rItd|��nX|||�|_|pe||_||_||_dS(NsUnknown cache implementation %r(	tclsmapt
isinstanceRtKeyErrort	TypeErrorRt
expiretimet	starttimetnsargs(tselfRttypeR-R.texpireR/tcls((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt__init__�s


	cCsL|t|�}yt|SWn)tk
rG|||�t|<}|SXdS(N(Rtcache_managersR+(R3RtkwtkeyR((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR�s
cKs|j||�j|�dS(N(t
_get_valuet	set_value(R0R7tvalueR6((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytput�scKs|j||�j�S(s*Retrieve a cached value from the container(R8R(R0R7R6((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR�scKs/|j||�}|j�r+|j�ndS(N(R8thas_current_valuetclear_value(R0R7R6tmycontainer((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR'�scKs|t|t�r$|jdd�}nd|kr@|j||�S|jd|j�|jd|j�tj||j	|�S(NtasciitbackslashreplaceR1R-R.(
R*tunicodetencodet_legacy_get_valuet
setdefaultR-R.t	containertValueR(R0R7R6((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR8�ss�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	Ks�|jd|j�}|jdd�}|jdd�}|jj�}|j|�t|jjd||�}|j|d|d|d|�S(NR-R.RR1(	tpopR-R"R/tcopytupdateRRR8(	R0R7R1R6R-R.Rtkwargstc((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyRC�s
cCs|jj�dS(s'Clear all the values from the namespaceN(Rtremove(R0((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytclear�scCs
|j|�S(N(R(R0R7((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt__getitem__�scCs|j|�j�S(N(R8R<(R0R7((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt__contains__scCs
||kS(N((R0R7((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pythas_keyscCs|j|�dS(N(R'(R0R7((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt__delitem__scCs|j||�dS(N(R;(R0R7R:((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt__setitem__
sN(t__name__t
__module__t__doc__R"R4tclassmethodRR;R9RRR'RLR8Rt
deprecatedRCRMRNRORPRQRR(((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR�s$

										tCacheManagercBsGeZd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(cKs2||_|jdi�|_tj|j�dS(s�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(RJRGtregionsR
RI(R0RJ((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR4s	cKs,|jj�}|j|�tj||�S(N(RJRHRIRR(R0tnameRJR6((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt	get_caches
cCs?||jkr"td|��n|j|}tj||�S(NsCache region not configured: %s(RYRRR(R0RZRR6((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pytget_cache_region"s
cGs
t||�S(s�Decorate a function to cache itself using a cache region
        
        The region decorator requires arguments if there are more than
        2 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#(R0RR	((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR(scGs�t|||�St|�r:|s.|j}n|j}n|sOtd��n
|j|}|j||�}djd�|D��}|j|�dS(sLInvalidate 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
           name of 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)
            
        
        s1Region or callable function namespace is requiredRcss|]}t|�VqdS(N(R(R$R%((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pys	<genexpr>wsN(	R(R&R RRRYR[RR'(R0RRR	RR((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR(Gs#
cs>dg�djd�|D�������fd�}|S(sRDecorate 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. 

        Rcss|]}t|�VqdS(N(R(R$R%((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pys	<genexpr>�scs:tj���������fd�}�|_|S(Ncsm�ds#�j����d<n�ddjd��D��}��fd�}�dj|d|�S(NiRcss|]}t|�VqdS(N(R(R$R%((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pys	<genexpr>�scs
���S(N(((R	R
(s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR�sR(R[RR(R	RR(RR
R7RJRR0(R	s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR�s

!(RRR(R
R(RR7RJR0(R
Rs=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyR!�s	N(R"R(R0R	RJR!((RR7RJR0s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyRzs	cOsE|j}|j||�}djd�|D��}|j|�dS(s�Invalidate 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)
        
        Rcss|]}t|�VqdS(N(R(R$R%((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pys	<genexpr>�sN(RR[RR'(R0R
R	RJRRR((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt
invalidate�s!	(	RSRTR4R[R\RR(RR](((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyRXs					3	,(4RUtwarningstbeaker.containerREtbeaker.utilRtbeaker.exceptionsRRtbeaker.ext.memcachedtextt	memcachedtbeaker.ext.databasetdatabasetbeaker.ext.sqlatsqlatbeaker.ext.googletgoogletMemoryNamespaceManagertDBMNamespaceManagertFileNamespaceManagertMemcachedNamespaceManagertDatabaseNamespaceManagertSqlaNamespaceManagertGoogleNamespaceManagerR)R
R5t
pkg_resourcestiter_entry_pointstentry_pointtloadtNamespaceManagerRZtSyntaxErrortsysRR*texc_infot	tracebackRttbt	print_exctwarntgetvaluetRuntimeWarningtImportErrorR#R(tobjectRRX(((s=/opt/alt/python27/lib/python2.7/site-packages/beaker/cache.pyt<module>	s^






	
		
	3	2c

Zerion Mini Shell 1.0