3
ãde9  ã               @   s*   d dl ZG dd„ dƒZG dd„ deƒZdS )é    Nc               @   sf  e Zd ZdZd)edœdd„Zeje edœdd„Ze	ej
d	œd
d„Ze	ed	œdd„Ze	ejej
 dœdd„Ze	eje	ej
f dœdd„Zd*e	ej
eje eje dœdd„Zd+e	ej
eje edœdd„Zd,eje	ej
f eje ejej
 dœdd„Ze	ejej
 dœdd„Ze	ed	œdd„Zed œd!d"„Zd-e	eeje d$œd%d&„Zd.e	eeje d$œd'd(„ZdS )/Ú	BaseCacheaM  Baseclass for the cache systems.  All the cache systems implement this
    API or a superset of it.

    :param default_timeout: the default timeout (in seconds) that is used if
                            no timeout is specified on :meth:`set`. A timeout
                            of 0 indicates that the cache never expires.
    é,  )Údefault_timeoutc             C   s
   || _ d S )N)r   )Úselfr   © r   úD/var/www/agendate/envp3/lib/python3.6/site-packages/cachelib/base.pyÚ__init__   s    zBaseCache.__init__)ÚtimeoutÚreturnc             C   s   |d kr| j }|S )N)r   )r   r	   r   r   r   Ú_normalize_timeout   s    zBaseCache._normalize_timeout)Úkeyr
   c             C   s   dS )zµLook up key in the cache and return the value for it.

        :param key: the key to be looked up.
        :returns: The value if it exists and is readable, else ``None``.
        Nr   )r   r   r   r   r   Úget   s    zBaseCache.getc             C   s   dS )z¥Delete `key` from the cache.

        :param key: the key to delete.
        :returns: Whether the key existed and has been deleted.
        :rtype: boolean
        Tr   )r   r   r   r   r   Údelete   s    zBaseCache.delete)Úkeysr
   c                s   ‡ fdd„|D ƒS )a<  Returns a list of values for the given keys.
        For each key an item in the list is created::

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

        Has the same error handling as :meth:`get`.

        :param keys: The function accepts multiple keys as positional
                     arguments.
        c                s   g | ]}ˆ j |ƒ‘qS r   )r   )Ú.0Úk)r   r   r   ú
<listcomp>1   s    z&BaseCache.get_many.<locals>.<listcomp>r   )r   r   r   )r   r   Úget_many&   s    zBaseCache.get_manyc             G   s   t t|| j|Ž ƒƒS )zýLike :meth:`get_many` but return a dict::

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

        :param keys: The function accepts multiple keys as positional
                     arguments.
        )ÚdictÚzipr   )r   r   r   r   r   Úget_dict3   s    
zBaseCache.get_dictN)r   Úvaluer	   r
   c             C   s   dS )ak  Add 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 in seconds (if not
                        specified, it uses the default timeout). A timeout of
                        0 indicates that the cache never expires.
        :returns: ``True`` if key has been updated, ``False`` for backend
                  errors. Pickling errors, however, will raise a subclass of
                  ``pickle.PickleError``.
        :rtype: boolean
        Tr   )r   r   r   r	   r   r   r   Úset?   s    zBaseCache.setc             C   s   dS )a  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 in seconds (if not
                        specified, it uses the default timeout). A timeout of
                        0 indicates that the cache never expires.
        :returns: Same as :meth:`set`, but also ``False`` for already
                  existing keys.
        :rtype: boolean
        Tr   )r   r   r   r	   r   r   r   ÚaddQ   s    zBaseCache.add)Úmappingr	   r
   c             C   s6   g }x,|j ƒ D ] \}}| j|||ƒr|j|ƒ qW |S )a£  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 in seconds (if not
                        specified, it uses the default timeout). A timeout of
                        0 indicates that the cache never expires.
        :returns: A list containing all keys sucessfuly set
        :rtype: boolean
        )Úitemsr   Úappend)r   r   r	   Zset_keysr   r   r   r   r   Úset_many`   s
    zBaseCache.set_manyc             G   s*   g }x |D ]}| j |ƒr
|j|ƒ q
W |S )zæDeletes multiple keys at once.

        :param keys: The function accepts multiple keys as positional
                     arguments.
        :returns: A list containing all sucessfuly deleted keys
        :rtype: boolean
        )r   r   )r   r   Zdeleted_keysr   r   r   r   Údelete_manyr   s
    

zBaseCache.delete_manyc             C   s   t dƒ‚dS )zÀChecks if a key exists in the cache without returning it. This is a
        cheap operation that bypasses loading the actual data on the backend.

        :param key: the key to check
        zß%s doesn't have an efficient implementation of `has`. That means it is impossible to check whether a key exists without fully loading the key's data. Consider using `self.get` explicitly if you don't care about performance.N)ÚNotImplementedError)r   r   r   r   r   Úhas€   s    zBaseCache.has)r
   c             C   s   dS )zºClears the cache.  Keep in mind that not all caches support
        completely clearing the cache.

        :returns: Whether the cache has been cleared.
        :rtype: boolean
        Tr   )r   r   r   r   Úclear�   s    zBaseCache.clearé   )r   Údeltar
   c             C   s&   | j |ƒpd| }| j||ƒr"|S dS )aH  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.
        :returns: The new value or ``None`` for backend errors.
        r   N)r   r   )r   r   r#   r   r   r   r   Úinc–   s    
zBaseCache.incc             C   s&   | j |ƒpd| }| j||ƒr"|S dS )aL  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.
        :returns: The new value or `None` for backend errors.
        r   N)r   r   )r   r   r#   r   r   r   r   Údec£   s    
zBaseCache.dec)r   )N)N)N)r"   )r"   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úintr   Ú_tÚOptionalr   ÚstrÚAnyr   Úboolr   ÚListr   ÚDictr   r   r   r   r   r    r!   r$   r%   r   r   r   r   r      s"   		r   c               @   s    e Zd ZdZeedœdd„ZdS )Ú	NullCachezÕ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
   c             C   s   dS )NFr   )r   r   r   r   r   r    ¸   s    zNullCache.hasN)r&   r'   r(   r)   r-   r/   r    r   r   r   r   r2   ±   s   r2   )Útypingr+   r   r2   r   r   r   r   Ú<module>   s    .