ó
ø¢TQc           @  s¦   d  Z  d d l m Z d d l Z d d l m Z m Z d d l m Z d e f d „  ƒ  YZ	 d e f d	 „  ƒ  YZ
 d
 Z d „  Z d „  Z d e f d „  ƒ  YZ d S(   u   Base Cache class.iÿÿÿÿ(   t   unicode_literalsN(   t   ImproperlyConfiguredt   DjangoRuntimeWarning(   t   import_modulet   InvalidCacheBackendErrorc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyR   	   s   t   CacheKeyWarningc           B  s   e  Z RS(    (   R   R   (    (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyR      s   iú   c         C  s   d | | |  f S(   uë   
    Default function to generate keys.

    Constructs the key used by all other methods. By default it prepends
    the `key_prefix'. KEY_FUNCTION can be used to specify an alternate
    function with custom key making behavior.
    u   %s:%s:%s(    (   t   keyt
   key_prefixt   version(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   default_key_func   s    c         C  sT   |  d k	 rP t |  ƒ r |  S|  j d d ƒ \ } } t | ƒ } t | | ƒ Sn  t S(   u^   
    Function to decide which key function to use.

    Defaults to ``default_key_func``.
    u   .i   N(   t   Nonet   callablet   rsplitR   t   getattrR   (   t   key_funct   key_func_module_patht   key_func_namet   key_func_module(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   get_key_func   s    t	   BaseCachec           B  sà   e  Z d  „  Z d d „ Z d d d „ Z d d d „ Z d d d „ Z d d „ Z d d „ Z	 d d „ Z
 d d d	 „ Z d d d
 „ Z d „  Z d d d „ Z d d „ Z d „  Z d „  Z d d d „ Z d d d „ Z RS(   c         C  sZ  | j  d | j  d d ƒ ƒ } y t | ƒ } Wn t t f k
 rM d } n X| |  _ | j  d i  ƒ } | j  d | j  d d ƒ ƒ } y t | ƒ |  _ Wn  t t f k
 r¼ d |  _ n X| j  d | j  d d	 ƒ ƒ } y t | ƒ |  _ Wn  t t f k
 rd	 |  _ n X| j  d
 d ƒ |  _ | j  d d ƒ |  _ t	 | j  d d  ƒ ƒ |  _ d  S(   Nu   timeoutu   TIMEOUTi,  u   OPTIONSu   max_entriesu   MAX_ENTRIESu   cull_frequencyu   CULL_FREQUENCYi   u
   KEY_PREFIXu    u   VERSIONi   u   KEY_FUNCTION(   t   gett   intt
   ValueErrort	   TypeErrort   default_timeoutt   _max_entriest   _cull_frequencyR	   R
   R   R   R   (   t   selft   paramst   timeoutt   optionst   max_entriest   cull_frequency(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   __init__-   s(    
	c         C  s4   | d k r |  j } n  |  j | |  j | ƒ } | S(   ut  Constructs the key used by all other methods. By default it
        uses the key_func to generate a key (which, by default,
        prepends the `key_prefix' and 'version'). An different key
        function can be provided at the time of cache construction;
        alternatively, you can subclass the cache backend to provide
        custom key making behavior.
        N(   R   R
   R   R	   (   R   R   R
   t   new_key(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   make_keyF   s    c         C  s
   t  ‚ d S(   u  
        Set a value in the cache if the key does not already exist. If
        timeout is given, that timeout will be used for the key; otherwise
        the default cache timeout will be used.

        Returns True if the value was stored, False otherwise.
        N(   t   NotImplementedError(   R   R   t   valueR   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   addT   s    c         C  s
   t  ‚ d S(   u…   
        Fetch a given key from the cache. If the key does not exist, return
        default, which itself defaults to None.
        N(   R&   (   R   R   t   defaultR
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyR   ^   s    c         C  s
   t  ‚ d S(   u¡   
        Set a value in the cache. If timeout is given, that timeout will be
        used for the key; otherwise the default cache timeout will be used.
        N(   R&   (   R   R   R'   R   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   sete   s    c         C  s
   t  ‚ d S(   u@   
        Delete a key from the cache, failing silently.
        N(   R&   (   R   R   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   deletel   s    c         C  sI   i  } x< | D]4 } |  j  | d | ƒ} | d k	 r | | | <q q W| S(   u/  
        Fetch a bunch of keys from the cache. For certain backends (memcached,
        pgsql) this can be *much* faster when fetching multiple values.

        Returns a dict mapping each key in keys to its value. If the given
        key is missing, it will be missing from the response dict.
        R
   N(   R   R   (   R   t   keysR
   t   dt   kt   val(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   get_manyr   s    c         C  s   |  j  | d | ƒd k	 S(   uN   
        Returns True if the key is in the cache and has not expired.
        R
   N(   R   R   (   R   R   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   has_key   s    i   c         C  sX   |  j  | d | ƒ} | d k r4 t d | ƒ ‚ n  | | } |  j | | d | ƒ| S(   us   
        Add delta to value in the cache. If the key does not exist, raise a
        ValueError exception.
        R
   u   Key '%s' not foundN(   R   R   R   R*   (   R   R   t   deltaR
   R'   t	   new_value(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   incr‡   s    
c         C  s   |  j  | | d | ƒS(   uz   
        Subtract delta from value in the cache. If the key does not exist, raise
        a ValueError exception.
        R
   (   R4   (   R   R   R2   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   decr“   s    c         C  s   |  j  | ƒ S(   uN   
        Returns True if the key is in the cache and has not expired.
        (   R1   (   R   R   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   __contains__š   s    c         C  s=   x6 | j  ƒ  D]( \ } } |  j | | d | d | ƒq Wd S(   uM  
        Set a bunch of values in the cache at once from a dict of key/value
        pairs.  For certain backends (memcached), this is much more efficient
        than calling set() multiple times.

        If timeout is given, that timeout will be used for the key; otherwise
        the default cache timeout will be used.
        R   R
   N(   t   itemsR*   (   R   t   dataR   R
   R   R'   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   set_many£   s    	c         C  s(   x! | D] } |  j  | d | ƒq Wd S(   u²   
        Set a bunch of values in the cache at once.  For certain backends
        (memcached), this is much more efficient than calling delete() multiple
        times.
        R
   N(   R+   (   R   R,   R
   R   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   delete_many¯   s    c         C  s
   t  ‚ d S(   u+   Remove *all* values from the cache at once.N(   R&   (   R   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   clear¸   s    c         C  s   t  | ƒ t k r/ t j d | t f t ƒ n  xI | D]A } t | ƒ d k  s` t | ƒ d k r6 t j d | t ƒ q6 q6 Wd S(   u±   
        Warn about keys that would not be portable to the memcached
        backend. This encourages (but does not force) writing backend-portable
        cache code.

        uG   Cache key will cause errors if used with memcached: %s (longer than %s)i!   i   uO   Cache key contains characters that will cause errors if used with memcached: %rN(   t   lent   MEMCACHE_MAX_KEY_LENGTHt   warningst   warnR   t   ord(   R   R   t   char(    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   validate_key¼   s    	

$	c         C  s   | d k r |  j } n  |  j | d | ƒ} | d k rL t d | ƒ ‚ n  |  j | | d | | ƒ|  j | d | ƒ| | S(   u_   Adds delta to the cache version for the supplied key. Returns the
        new version.
        R
   u   Key '%s' not foundN(   R   R
   R   R   R*   R+   (   R   R   R2   R
   R'   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   incr_versionÍ   s    c         C  s   |  j  | | | ƒ S(   ug   Substracts delta from the cache version for the supplied key. Returns
        the new version.
        (   RC   (   R   R   R2   R
   (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   decr_versionÜ   s    N(   R   R   R#   R   R%   R(   R   R*   R+   R0   R1   R4   R5   R6   R9   R:   R;   RB   RC   RD   (    (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyR   ,   s"   	
					(   t   __doc__t
   __future__R    R>   t   django.core.exceptionsR   R   t   django.utils.importlibR   R   R   R=   R   R   t   objectR   (    (    (    s8   ../Django//lib/python/django/core/cache/backends/base.pyt   <module>   s   	
	