ó
`¾Tc           @   s[  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z y d d l Z Wn e	 k
 ry d d l Z n Xd d l
 m Z m Z m Z m Z m Z d d l m Z d „  Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ e j d ƒ j Z d e f d „  ƒ  YZ e Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s|  
    werkzeug.contrib.cache
    ~~~~~~~~~~~~~~~~~~~~~~

    The main problem with dynamic Web sites is, well, they're dynamic.  Each
    time a user requests a page, the webserver executes a lot of code, queries
    the database, renders templates until the visitor gets the page he sees.

    This is a lot more expensive than just loading a file from the file system
    and sending it to the visitor.

    For most Web applications, this overhead isn't a big deal but once it
    becomes, you will be glad to have a cache system in place.

    How Caching Works
    =================

    Caching is pretty simple.  Basically you have a cache object lurking around
    somewhere that is connected to a remote cache or the file system or
    something else.  When the request comes in you check if the current page
    is already in the cache and if so, you're returning it from the cache.
    Otherwise you generate the page and put it into the cache. (Or a fragment
    of the page, you don't have to cache the full thing)

    Here is a simple example of how to cache a sidebar for a template::

        def get_sidebar(user):
            identifier = 'sidebar_for/user%d' % user.id
            value = cache.get(identifier)
            if value is not None:
                return value
            value = generate_sidebar_for(user=user)
            cache.set(identifier, value, timeout=60 * 5)
            return value

    Creating a Cache Object
    =======================

    To create a cache object you just import the cache system of your choice
    from the cache module and instantiate it.  Then you can start working
    with that object:

    >>> from werkzeug.contrib.cache import SimpleCache
    >>> c = SimpleCache()
    >>> c.set("foo", "value")
    >>> c.get("foo")
    'value'
    >>> c.get("missing") is None
    True

    Please keep in mind that you have to create the cache and put it somewhere
    you have access to it (either as a module global you can import or you just
    put it into your WSGI application).

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   md5(   t   time(   t	   iteritemst   string_typest	   text_typet   integer_typest   to_bytes(   t   renamec         C   s6   t  |  d ƒ r |  j ƒ  St  |  d ƒ r2 |  j ƒ  S|  S(   s  Wrapper for efficient iteration over mappings represented by dicts
    or sequences::

        >>> for k, v in _items((i, i*i) for i in xrange(5)):
        ...    assert k*k == v

        >>> for k, v in _items(dict((i, i*i) for i in xrange(5))):
        ...    assert k*k == v

    R   t   items(   t   hasattrR   R   (   t   mappingorseq(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   _itemsJ   s
    

t	   BaseCachec           B   sŒ   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d d „ Z	 d d „ Z
 d d	 „ Z d
 „  Z d „  Z d d „ Z d d „ Z RS(   sí   Baseclass for the cache systems.  All the cache systems implement this
    API or a superset of it.

    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`set`.
    i,  c         C   s   | |  _  d  S(   N(   t   default_timeout(   t   selfR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   __init__d   s    c         C   s   d S(   s¬   Looks up key in the cache and returns the value for it.
        If the key does not exist `None` is returned instead.

        :param key: the key to be looked up.
        N(   t   None(   R   t   key(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   getg   s    c         C   s   d S(   sŠ   Deletes `key` from the cache.  If it does not exist in the cache
        nothing happens.

        :param key: the key to delete.
        N(    (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   deleteo   s    c         G   s   t  |  j | ƒ S(   sf  Returns a list of values for the given keys.
        For each key a item in the list is created.  Example::

            foo, bar = cache.get_many("foo", "bar")

        If a key can't be looked up `None` is returned for that key
        instead.

        :param keys: The function accepts multiple keys as positional
                     arguments.
        (   t   mapR   (   R   t   keys(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   get_manyw   s    c         G   s   t  t | |  j | Œ  ƒ ƒ S(   s  Works like :meth:`get_many` but returns a dict::

            d = cache.get_dict("foo", "bar")
            foo = d["foo"]
            bar = d["bar"]

        :param keys: The function accepts multiple keys as positional
                     arguments.
        (   t   dictt   zipR   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   get_dict…   s    
c         C   s   d S(   s9  Adds a new key/value to the cache (overwrites value, if key already
        exists in the cache).

        :param key: the key to set
        :param value: the value for the key
        :param timeout: the cache timeout for the key (if not specified,
                        it uses the default timeout).
        N(    (   R   R   t   valuet   timeout(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   set‘   s    	c         C   s   d S(   s*  Works like :meth:`set` but does not overwrite the values of already
        existing keys.

        :param key: the key to set
        :param value: the value for the key
        :param timeout: the cache timeout for the key or the default
                        timeout if not specified.
        N(    (   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   addœ   s    	c         C   s4   x- t  | ƒ D] \ } } |  j | | | ƒ q Wd S(   sõ   Sets multiple keys and values from a mapping.

        :param mapping: a mapping with the keys/values to set.
        :param timeout: the cache timeout for the key (if not specified,
                        it uses the default timeout).
        N(   R   R   (   R   t   mappingR   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   set_many§   s    c         G   s"   x | D] } |  j  | ƒ q Wd S(   sŽ   Deletes multiple keys at once.

        :param keys: The function accepts multiple keys as positional
                     arguments.
        N(   R   (   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   delete_many±   s    c         C   s   d S(   sk   Clears the cache.  Keep in mind that not all caches support
        completely clearing the cache.
        N(    (   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   clearº   s    i   c         C   s'   |  j  | |  j | ƒ p d | ƒ d S(   s  Increments the value of a key by `delta`.  If the key does
        not yet exist it is initialized with `delta`.

        For supporting caches this is an atomic operation.

        :param key: the key to increment.
        :param delta: the delta to add.
        i    N(   R   R   (   R   R   t   delta(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   incÀ   s    	c         C   s'   |  j  | |  j | ƒ p d | ƒ d S(   s  Decrements the value of a key by `delta`.  If the key does
        not yet exist it is initialized with `-delta`.

        For supporting caches this is an atomic operation.

        :param key: the key to increment.
        :param delta: the delta to subtract.
        i    N(   R   R   (   R   R   R"   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   decË   s    	N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   R   R   R    R!   R#   R$   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   \   s   				
			t	   NullCachec           B   s   e  Z d  Z RS(   sÕ   A cache that doesn't cache.  This can be useful for unit testing.

    :param default_timeout: a dummy parameter that is ignored but exists
                            for API compatibility with other caches.
    (   R%   R&   R'   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR(   ×   s   t   SimpleCachec           B   sP   e  Z d  Z d d d „ Z d „  Z d „  Z d	 d „ Z d	 d „ Z d „  Z	 RS(
   s<  Simple memory cache for single process environments.  This class exists
    mainly for the development server and is not 100% thread safe.  It tries
    to use as many atomic operations as possible and no locks for simplicity
    but it could happen under heavy load that keys are added multiple times.

    :param threshold: the maximum number of items the cache stores before
                      it starts deleting some.
    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`~BaseCache.set`.
    iô  i,  c         C   s5   t  j |  | ƒ i  |  _ |  j j |  _ | |  _ d  S(   N(   R   R   t   _cacheR!   t
   _threshold(   R   t	   thresholdR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ë   s    	c         C   sŒ   t  |  j ƒ |  j k rˆ t ƒ  } xd t |  j j ƒ  ƒ D]J \ } \ } \ } } | | k sk | d d k r7 |  j j | d  ƒ q7 q7 Wn  d  S(   Ni   i    (   t   lenR*   R+   R   t	   enumerateR   t   popR   (   R   t   nowt   idxR   t   expirest   _(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   _pruneñ   s
    	.c         C   s;   |  j  j | d ƒ \ } } | t ƒ  k r7 t j | ƒ Sd  S(   Ni    (   i    N(   R*   R   R   R   t   picklet   loads(   R   R   R2   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ø   s    c         C   sO   | d  k r |  j } n  |  j ƒ  t ƒ  | t j | t j ƒ f |  j | <d  S(   N(   R   R   R4   R   R5   t   dumpst   HIGHEST_PROTOCOLR*   (   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ý   s
    
c         C   sv   | d  k r |  j } n  t |  j ƒ |  j k r= |  j ƒ  n  t ƒ  | t j | t j	 ƒ f } |  j j
 | | ƒ d  S(   N(   R   R   R-   R*   R+   R4   R   R5   R7   R8   t
   setdefault(   R   R   R   R   t   item(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    c         C   s   |  j  j | d  ƒ d  S(   N(   R*   R/   R   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    N(
   R%   R&   R'   R   R4   R   R   R   R   R   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR)   ß   s   
			s   [^\x00-\x21\xff]{1,250}$t   MemcachedCachec           B   s›   e  Z d  Z d d d d „ Z d „  Z d „  Z d d „ Z d d „ Z d „  Z	 d d „ Z
 d	 „  Z d
 „  Z d „  Z d d „ Z d d „ Z d „  Z RS(   sd  A cache that uses memcached as backend.

    The first argument can either be an object that resembles the API of a
    :class:`memcache.Client` or a tuple/list of server addresses. In the
    event that a tuple/list is passed, Werkzeug tries to import the best
    available memcache library.

    Implementation notes:  This cache backend works around some limitations in
    memcached to simplify the interface.  For example unicode keys are encoded
    to utf-8 on the fly.  Methods such as :meth:`~BaseCache.get_dict` return
    the keys in the same format as passed.  Furthermore all get methods
    silently ignore key errors to not cause problems when untrusted user data
    is passed to the get methods which is often the case in web applications.

    :param servers: a list or tuple of server addresses or alternatively
                    a :class:`memcache.Client` or a compatible client.
    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`~BaseCache.set`.
    :param key_prefix: a prefix that is added before all keys.  This makes it
                       possible to use the same memcached server for different
                       applications.  Keep in mind that
                       :meth:`~BaseCache.clear` will also clear keys with a
                       different prefix.
    i,  c         C   s˜   t  j |  | ƒ | d  k s1 t | t t f ƒ r| | d  k rI d g } n  |  j | ƒ |  _ |  j d  k r… t d ƒ ‚ q… n	 | |  _ t	 | ƒ |  _
 d  S(   Ns   127.0.0.1:11211s   no memcache module found(   R   R   R   t
   isinstancet   listt   tuplet   import_preferred_memcache_libt   _clientt   RuntimeErrorR   t
   key_prefix(   R   t   serversR   RB   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   -  s    !	c         C   sZ   t  | t ƒ r! | j d ƒ } n  |  j r: |  j | } n  t | ƒ rV |  j j | ƒ Sd  S(   Ns   utf-8(   R<   R   t   encodeRB   t   _test_memcached_keyR@   R   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   <  s    	c   	      G   s$  i  } t  } xm | D]e } t | t ƒ r@ | j d ƒ } t } n | } |  j r_ |  j | } n  t | ƒ r | | | <q q W|  j j | j	 ƒ  ƒ } } | s§ |  j rÛ i  } x+ t
 | ƒ D] \ } } | | | | <qº Wn  t | ƒ t | ƒ k  r x* | D] } | | k rú d  | | <qú qú Wn  | S(   Ns   utf-8(   t   FalseR<   t   unicodeRD   t   TrueRB   RE   R@   t	   get_multiR   R   R-   R   (	   R   R   t   key_mappingt   have_encoded_keysR   t   encoded_keyt   dt   rvR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   G  s*    		c         C   sl   | d  k r |  j } n  t | t ƒ r9 | j d ƒ } n  |  j rR |  j | } n  |  j j | | | ƒ d  S(   Ns   utf-8(   R   R   R<   R   RD   RB   R@   R   (   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   _  s    	c         C   sl   | d  k r |  j } n  t | t ƒ r9 | j d ƒ } n  |  j rR |  j | } n  |  j j | | | ƒ d  S(   Ns   utf-8(   R   R   R<   R   RD   RB   R@   R   (   R   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   h  s    	c         G   s*   |  j  | Œ  } g  | D] } | | ^ q S(   N(   R   (   R   R   RM   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   q  s    c         C   s–   | d  k r |  j } n  i  } x^ t | ƒ D]P \ } } t | t ƒ rX | j d ƒ } n  |  j rq |  j | } n  | | | <q+ W|  j j | | ƒ d  S(   Ns   utf-8(	   R   R   R   R<   R   RD   RB   R@   t	   set_multi(   R   R   R   t   new_mappingR   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   u  s    	c         C   s]   t  | t ƒ r! | j d ƒ } n  |  j r: |  j | } n  t | ƒ rY |  j j | ƒ n  d  S(   Ns   utf-8(   R<   RG   RD   RB   RE   R@   R   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    	c         G   s   g  } xd | D]\ } t  | t ƒ r4 | j d ƒ } n  |  j rM |  j | } n  t | ƒ r | j | ƒ q q W|  j j | ƒ d  S(   Ns   utf-8(   R<   RG   RD   RB   RE   t   appendR@   t   delete_multi(   R   R   t   new_keysR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR    ‰  s    	c         C   s   |  j  j ƒ  d  S(   N(   R@   t	   flush_all(   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR!   ”  s    i   c         C   sQ   t  | t ƒ r! | j d ƒ } n  |  j r: |  j | } n  |  j j | | ƒ d  S(   Ns   utf-8(   R<   RG   RD   RB   R@   t   incr(   R   R   R"   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR#   —  s
    	c         C   sQ   t  | t ƒ r! | j d ƒ } n  |  j r: |  j | } n  |  j j | | ƒ d  S(   Ns   utf-8(   R<   RG   RD   RB   R@   t   decr(   R   R   R"   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR$   ž  s
    	c         C   s˜   y d d l  } Wn t k
 r# n X| j | ƒ Sy d d l m } Wn t k
 rX n X| j ƒ  Sy d d l } Wn t k
 r† n X| j | ƒ Sd S(   sA   Returns an initialized memcache client.  Used by the constructor.iÿÿÿÿN(   t   memcache(   t   pylibmct   ImportErrort   Clientt   google.appengine.apiRW   (   R   RC   RX   RW   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR?   ¥  s    
N(   R%   R&   R'   R   R   R   R   R   R   R   R   R   R    R!   R#   R$   R?   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR;     s   								t
   RedisCachec           B   s¤   e  Z d  Z d d d d d d d „ Z d „  Z d „  Z d „  Z d	 „  Z d d
 „ Z	 d d „ Z
 d d „ Z d „  Z d „  Z d „  Z d d „ Z d d „ Z RS(   sq  Uses the Redis key-value store as a cache backend.

    The first argument can be either a string denoting address of the Redis
    server or an object resembling an instance of a redis.Redis class.

    Note: Python Redis API already takes care of encoding unicode strings on
    the fly.

    .. versionadded:: 0.7

    .. versionadded:: 0.8
       `key_prefix` was added.

    .. versionchanged:: 0.8
       This cache backend now properly serializes objects.

    .. versionchanged:: 0.8.3
       This cache backend now supports password authentication.

    :param host: address of the Redis server or an object which API is
                 compatible with the official Python Redis client (redis-py).
    :param port: port number on which Redis server listens for connections.
    :param password: password authentication for the Redis server.
    :param db: db (zero-based numeric index) on Redis Server to connect.
    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`~BaseCache.set`.
    :param key_prefix: A prefix that should be added to all keys.
    t	   localhostië  i    i,  c      	   C   s•   t  j |  | ƒ t | t ƒ ry y d d  l } Wn t k
 rN t d ƒ ‚ n X| j d | d | d | d | ƒ |  _ n	 | |  _ | p‹ d |  _	 d  S(   Niÿÿÿÿs   no redis module foundt   hostt   portt   passwordt   dbt    (
   R   R   R<   R   t   redisRY   RA   t   RedisR@   RB   (   R   R^   R_   R`   Ra   R   RB   Rc   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ß  s    *	c         C   s<   t  | ƒ } | t k r+ t | ƒ j d ƒ Sd t j | ƒ S(   s   Dumps an object into a string for redis.  By default it serializes
        integers as regular string and pickle dumps everything else.
        t   asciit   !(   t   typeR   t   strRD   R5   R7   (   R   R   t   t(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   dump_objectì  s    c         C   sW   | d k r d S| j d ƒ r0 t j | d ƒ Sy t | ƒ SWn t k
 rR | SXd S(   sV   The reversal of :meth:`dump_object`.  This might be callde with
        None.
        Rf   i   N(   R   t
   startswithR5   R6   t   intt
   ValueError(   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   load_objectõ  s    c         C   s    |  j  |  j j |  j | ƒ ƒ S(   N(   Rn   R@   R   RB   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    c         G   sX   |  j  r, g  | D] } |  j  | ^ q } n  g  |  j j | ƒ D] } |  j | ƒ ^ q? S(   N(   RB   R@   t   mgetRn   (   R   R   R   t   x(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    	#c         C   sH   | d  k r |  j } n  |  j | ƒ } |  j j |  j | | | ƒ d  S(   N(   R   R   Rj   R@   t   setexRB   (   R   R   R   R   t   dump(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    c         C   sj   | d  k r |  j } n  |  j | ƒ } |  j j |  j | | ƒ } | rf |  j j |  j | | ƒ n  d  S(   N(   R   R   Rj   R@   t   setnxRB   t   expire(   R   R   R   R   Rr   t   added(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    c         C   s{   | d  k r |  j } n  |  j j ƒ  } xC t | ƒ D]5 \ } } |  j | ƒ } | j |  j | | | ƒ q4 W| j ƒ  d  S(   N(	   R   R   R@   t   pipelineR   Rj   Rq   RB   t   execute(   R   R   R   t   pipeR   R   Rr   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s    c         C   s   |  j  j |  j | ƒ d  S(   N(   R@   R   RB   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   "  s    c         G   sJ   | s
 d  S|  j  r6 g  | D] } |  j  | ^ q } n  |  j j | Œ  d  S(   N(   RB   R@   R   (   R   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR    %  s
    	#c         C   sO   |  j  r> |  j j |  j  d ƒ } | rK |  j j | Œ  qK n |  j j ƒ  d  S(   Nt   *(   RB   R@   R   R   t   flushdb(   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR!   ,  s
    	i   c         C   s   |  j  j |  j | | ƒ S(   N(   R@   RU   RB   (   R   R   R"   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR#   4  s    c         C   s   |  j  j |  j | | ƒ S(   N(   R@   RV   RB   (   R   R   R"   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR$   7  s    N(   R%   R&   R'   R   R   Rj   Rn   R   R   R   R   R   R   R    R!   R#   R$   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR\   Á  s   										t   FileSystemCachec           B   st   e  Z d  Z d Z d d d d „ Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z	 d d „ Z d d „ Z d „  Z RS(   s“  A cache that stores the items on the file system.  This cache depends
    on being the only user of the `cache_dir`.  Make absolutely sure that
    nobody but this cache stores files there or otherwise the cache will
    randomly delete files therein.

    :param cache_dir: the directory where cache files are stored.
    :param threshold: the maximum number of items the cache stores before
                      it starts deleting some.
    :param default_timeout: the default timeout that is used if no timeout is
                            specified on :meth:`~BaseCache.set`.
    :param mode: the file mode wanted for the cache files, default 0600
    s   .__wz_cacheiô  i,  i€  c         C   sW   t  j |  | ƒ | |  _ | |  _ | |  _ t j j |  j ƒ sS t j |  j ƒ n  d  S(   N(	   R   R   t   _pathR+   t   _modet   ost   patht   existst   makedirs(   R   t	   cache_dirR,   R   t   mode(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   L  s    			c         C   sG   g  t  j |  j ƒ D]0 } | j |  j ƒ s t  j j |  j | ƒ ^ q S(   s;   return a list of (fully qualified) cache filenames
        (   R~   t   listdirR|   t   endswitht   _fs_transaction_suffixR   t   join(   R   t   fn(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt	   _list_dirT  s    c         C   s  |  j  ƒ  } t | ƒ |  j k rý t ƒ  } xÐ t | ƒ D]¿ \ } } t } d  } y_ z> t | d ƒ } t j	 | ƒ } | | k pŒ | d d k } Wd  | d  k	 r¬ | j
 ƒ  n  XWn t k
 rÁ n X| r7 y t j | ƒ Wqö t t f k
 rò qö Xq7 q7 Wn  d  S(   Nt   rbi   i    (   R‰   R-   R+   R   R.   RF   R   t   openR5   t   loadt   closet	   ExceptionR~   t   removet   IOErrort   OSError(   R   t   entriesR0   R1   t   fnameR   t   fR2   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR4   Z  s(    	 c         C   sF   x? |  j  ƒ  D]1 } y t j | ƒ Wq t t f k
 r= q Xq Wd  S(   N(   R‰   R~   R   R   R‘   (   R   R“   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR!   q  s
    c         C   sI   t  | t ƒ r! | j d ƒ } n  t | ƒ j ƒ  } t j j |  j | ƒ S(   Ns   utf-8(	   R<   R   RD   R    t	   hexdigestR~   R   R‡   R|   (   R   R   t   hash(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   _get_filenamex  s    c         C   s   |  j  | ƒ } yW t | d ƒ } z) t j | ƒ t ƒ  k rI t j | ƒ SWd  | j ƒ  Xt j | ƒ Wn t k
 rz d  SXd  S(   NRŠ   (
   R—   R‹   R5   RŒ   R   R   R~   R   RŽ   R   (   R   R   t   filenameR”   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ~  s    c         C   s;   |  j  | ƒ } t j j | ƒ s7 |  j | | | ƒ n  d  S(   N(   R—   R~   R   R€   R   (   R   R   R   R   R˜   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   ‹  s    c         C   sñ   | d  k r |  j } n  |  j | ƒ } |  j ƒ  y¢ t j d |  j d |  j ƒ \ } } t j	 | d ƒ } z: t
 j t t ƒ  | ƒ | d ƒ t
 j | | t
 j ƒ Wd  | j ƒ  Xt | | ƒ t j | |  j ƒ Wn t t f k
 rì n Xd  S(   Nt   suffixt   dirt   wbi   (   R   R   R—   R4   t   tempfilet   mkstempR†   R|   R~   t   fdopenR5   Rr   Rl   R   R8   R   R   t   chmodR}   R   R‘   (   R   R   R   R   R˜   t   fdt   tmpR”   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR     s     
 c         C   s8   y t  j |  j | ƒ ƒ Wn t t f k
 r3 n Xd  S(   N(   R~   R   R—   R   R‘   (   R   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR   £  s    N(   R%   R&   R'   R†   R   R‰   R4   R!   R—   R   R   R   R   R   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyR{   ;  s   					(   R'   R~   t   reRœ   t   hashlibR    R   t   cPickleR5   RY   t   werkzeug._compatR   R   R   R   R   t   werkzeug.posixemulationR   R   t   objectR   R(   R)   t   compilet   matchRE   R;   t   GAEMemcachedCacheR\   R{   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/contrib/cache.pyt   <module>:   s(   (	{2«z