³ò
Ae|Mc           @   sn  d  Z  d d k Z d d k i Z d d k i Z d d k l Z l Z d d k	 i
 i Z d d k i
 i Z d d k i
 i Z d d k i
 i Z h  e i d <e i d <e i d <e i d <e i d <e i d	 <e i d
 <Z h  Z h  Z y"d d k Z xe i d ƒ D]þ Z yD e i ƒ  Z  e i! Z! e! e j o e d e! ƒ ‚ n e  e e! <Wqe e" f j
 o qd d k# Z# d d k l$ Z$ e% e# i& ƒ  d e$ ƒ p\ d d k' Z' d d k( l( Z( e( ƒ  Z) e' i* d e) ƒ e i+ d e e) i, ƒ  f e- d ƒ qqXqWWn e. j
 o n Xd „  Z/ d „  Z0 d e1 f d „  ƒ  YZ2 d e1 f d „  ƒ  YZ3 d S(   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(   t   BeakerExceptiont   InvalidCacheBackendErrort   memoryt   dbmt   files   ext:memcacheds   ext:databases   ext:sqlas
   ext:googles   beaker.backendss2   NamespaceManager name conflict,'%s' already loaded(   t   DistributionNotFoundi   (   t   StringIOs5   Unable to load NamespaceManager entry point: '%s': %si   c            s"   d g ‰ ‡ ‡  ‡ f d †  } | 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.
    
    c            s@   t  i ˆ ƒ ‰  ‡ ‡ ‡ ‡  ‡ f d †  } ˆ  | _ ˆ | _ | S(   Nc             s¶   t  ˆ } | i d t ƒ p ˆ ˆ  Œ  Sn ˆ d p; ˆ t  j o t d ˆ ƒ ‚ n t i ˆ | ƒ ˆ d <n d i t t ˆ ˆ  ƒ ƒ } ‡  ‡ f d †  } ˆ d i	 | d | ƒS(   Nt   enabledi    s   Cache region not configured: %st    c              s
   ˆ ˆ  Œ  S(   N(    (    (   t   argst   func(    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   goo   s    t
   createfunc(
   t   cache_regionst   gett   TrueR    t   Cachet
   _get_cachet   joint   mapt   strt	   get_value(   R	   t   regt	   cache_keyR   (   t   cachet	   deco_argst   regiont	   namespaceR
   (   R	   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   cachedd   s    
(   t   utilt   func_namespacet   _arg_namespacet   _arg_region(   R
   R   (   R   R   R   (   R   R
   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   decorateb   s
    		N(   t   None(   R   R   R!   (    (   R   R   R   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   cache_regionF   s    	c         G   s‹   t  |  ƒ o! | p |  i } n |  i }  n | p t d ƒ ‚ n t | } t i |  | ƒ } d i d „  | Dƒ ƒ } | i | ƒ d S(   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)
    
    s1   Region or callable function namespace is requiredR   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R   (   t   .0t   x(    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys	   <genexpr>§   s   	 N(	   t   callableR    R   R    R   R   R   R   t   remove_value(   R   R   R	   R   R   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   region_invalidatey   s    "
R   c           B   s¶   e  Z d  Z d d d d d „ Z e d „  ƒ Z d „  Z e Z d „  Z	 e	 Z
 d „  Z e Z d „  Z e i d ƒ d	 „  ƒ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sI  Front-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
    
    R   c         K   s†   y( t  | } t | t ƒ o
 | ‚ n Wn# t j
 o t d | ƒ ‚ n X| | |  |  _ | p | |  _ | |  _ | |  _ d  S(   Ns   Unknown cache implementation %r(	   t   clsmapt
   isinstanceR   t   KeyErrort	   TypeErrorR   t
   expiretimet	   starttimet   nsargs(   t   selfR   t   typeR-   R.   t   expireR/   t   cls(    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   __init__¹   s    
	c         C   sQ   | t  | ƒ } y t | SWn. t j
 o" |  | |  t | <} | Sn Xd  S(   N(   R   t   cache_managersR+   (   R3   R   t   kwt   keyR   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   Ç   s    c         K   s   |  i  | |  i | ƒ d  S(   N(   t
   _get_valuet	   set_value(   R0   R7   t   valueR6   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   putÐ   s    c         K   s   |  i  | |  i ƒ  S(   s*   Retrieve a cached value from the container(   R8   R   (   R0   R7   R6   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   Ô   s    c         K   s1   |  i  | |  } | i ƒ  o | i ƒ  n d  S(   N(   R8   t   has_current_valuet   clear_value(   R0   R7   R6   t   mycontainer(    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR'   Ù   s    c         K   sƒ   t  | t ƒ o | i d d ƒ } n d | j o |  i | |  Sn | i d |  i ƒ | i d |  i ƒ t i | |  i	 |  S(   Nt   asciit   backslashreplaceR1   R-   R.   (
   R*   t   unicodet   encodet   _legacy_get_valuet
   setdefaultR-   R.   t	   containert   ValueR   (   R0   R7   R6   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/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   	      K   s   | i  d |  i ƒ } | i  d d  ƒ } | i  d d  ƒ } |  i i ƒ  } | i | ƒ t |  i i d | | } | i | d | d | d | ƒS(   NR-   R.   R   R1   (	   t   popR-   R"   R/   t   copyt   updateR   R   R8   (	   R0   R7   R1   R6   R-   R.   R   t   kwargst   c(    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyRC   ë   s    c         C   s   |  i  i ƒ  d S(   s'   Clear all the values from the namespaceN(   R   t   remove(   R0   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   clearù   s    c         C   s   |  i  | ƒ S(   N(   R   (   R0   R7   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   __getitem__þ   s    c         C   s   |  i  | ƒ i ƒ  S(   N(   R8   R<   (   R0   R7   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   __contains__  s    c         C   s
   | |  j S(   N(    (   R0   R7   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   has_key  s    c         C   s   |  i  | ƒ d  S(   N(   R'   (   R0   R7   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   __delitem__  s    c         C   s   |  i  | | ƒ d  S(   N(   R;   (   R0   R7   R:   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   __setitem__
  s    N(   t   __name__t
   __module__t   __doc__R"   R4   t   classmethodR   R;   R9   R   R   R'   RL   R8   R   t
   deprecatedRC   RM   RN   RO   RP   RQ   RR   (    (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   «   s$   										t   CacheManagerc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         K   s2   | |  _  | i d h  ƒ |  _ t i |  i ƒ d S(   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(   RJ   RG   t   regionsR   RI   (   R0   RJ   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR4     s    	c         K   s,   |  i  i ƒ  } | i | ƒ t i | | ƒ S(   N(   RJ   RH   RI   R   R   (   R0   t   nameRJ   R6   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt	   get_cache  s    c         C   sA   | |  i  j o t d | ƒ ‚ n |  i  | } t i | | ƒ S(   Ns   Cache region not configured: %s(   RY   R    R   R   (   R0   RZ   R   R6   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt   get_cache_region"  s    c         G   s   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#   (   R0   R   R	   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   (  s    c         G   sž   t  | | | Œ St | ƒ o! | p | i } n | i } n | p t d ƒ ‚ n |  i | } |  i | |  } d i d „  | Dƒ ƒ } | i | ƒ d S(   sL  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
           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)
            
        
        s1   Region or callable function namespace is requiredR   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R   (   R$   R%   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys	   <genexpr>w  s   	 N(	   R(   R&   R    R   R    RY   R[   R   R'   (   R0   R   R   R	   R   R   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR(   G  s    #c            s>   d g ‰ d i d „  | Dƒ ƒ ‰ ‡  ‡ ‡ ‡ f d †  } | S(   sR  Decorate 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. 

        R   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R   (   R$   R%   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys	   <genexpr>—  s   	 c            s:   t  i ˆ  ƒ ‰ ‡  ‡ ‡ ‡ ‡ ‡ f d †  } ˆ | _ | S(   Nc             so   ˆ d p ˆ i  ˆ ˆ  ˆ d <n ˆ d d i d „  ˆ  Dƒ ƒ } ‡  ‡ f d †  } ˆ d i | d | ƒS(   Ni    R   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R   (   R$   R%   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys	   <genexpr>ž  s   	 c              s
   ˆ ˆ  Œ  S(   N(    (    (   R	   R
   (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   Ÿ  s    R   (   R[   R   R   (   R	   R   R   (   R
   R0   R   R   R7   RJ   (   R	   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   ›  s
    !(   R   R   R   (   R
   R   (   R0   R   R7   RJ   (   R
   R   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR!   ™  s    	N(   R"   R   (   R0   R	   RJ   R!   (    (   R0   R   R7   RJ   se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyR   z  s    	c         O   sE   | i  } |  i | |  } d i d „  | Dƒ ƒ } | i | ƒ d S(   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)
        
        R   c         s   s   x |  ] } t  | ƒ Vq Wd  S(   N(   R   (   R$   R%   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys	   <genexpr>Ê  s   	 N(   R   R[   R   R'   (   R0   R
   R	   RJ   R   R   R   (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyt
   invalidate¦  s    !	(	   RS   RT   R4   R[   R\   R   R(   R   R]   (    (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pyRX     s   					3	,(4   RU   t   warningst   beaker.containerRE   t   beaker.utilR   t   beaker.exceptionsR    R   t   beaker.ext.memcachedt   extt	   memcachedt   beaker.ext.databaset   databaset   beaker.ext.sqlat   sqlat   beaker.ext.googlet   googlet   MemoryNamespaceManagert   DBMNamespaceManagert   FileNamespaceManagert   MemcachedNamespaceManagert   DatabaseNamespaceManagert   SqlaNamespaceManagert   GoogleNamespaceManagerR)   R   R5   t   pkg_resourcest   iter_entry_pointst   entry_pointt   loadt   NamespaceManagerRZ   t   SyntaxErrort   sysR   R*   t   exc_infot	   tracebackR   t   tbt	   print_exct   warnt   getvaluet   RuntimeWarningt   ImportErrorR#   R(   t   objectR   RX   (    (    (    se   /afs/athena.mit.edu/user/x/a/xavid/lib/python2.5/site-packages/Beaker-1.5.4-py2.5.egg/beaker/cache.pys   <module>	   s`    				3	2c