Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
ó
ëEYc@€slddlmZddlmZmZddlmZddlmZddlmZm	Z	m
Z
ddlmZmZdd	l
mZmZdd
lmZddlmZddlZddlZdd
lmZddlmZddlZedƒZejZddlmZdZdefd„ƒYZ de fd„ƒYZ!defd„ƒYZ"d„Z#dS(iÿÿÿÿ(twith_statementi(tLocktNeedRegenerationException(tNameRegistryi(t	exception(tPluginLoadertmemoized_propertytcoerce_string_conf(tfunction_key_generatortfunction_multi_key_generator(tNO_VALUEtCachedValue(tProxyBackend(tcompatN(tNumber(twrapss
dogpile.cache(tbackendstRegionInvalidationStrategycB€sGeZdZed„Zd„Zd„Zd„Zd„Zd„Z	RS(s7	Region invalidation strategy interface

    Implement this interface and pass implementation instance
    to :meth:`.CacheRegion.configure` to override default region invalidation.

    Example::

        class CustomInvalidationStrategy(RegionInvalidationStrategy):

            def __init__(self):
                self._soft_invalidated = None
                self._hard_invalidated = None

            def invalidate(self, hard=None):
                if hard:
                    self._soft_invalidated = None
                    self._hard_invalidated = time.time()
                else:
                    self._soft_invalidated = time.time()
                    self._hard_invalidated = None

            def is_invalidated(self, timestamp):
                return ((self._soft_invalidated and
                         timestamp < self._soft_invalidated) or
                        (self._hard_invalidated and
                         timestamp < self._hard_invalidated))

            def was_hard_invalidated(self):
                return bool(self._hard_invalidated)

            def is_hard_invalidated(self, timestamp):
                return (self._hard_invalidated and
                        timestamp < self._hard_invalidated)

            def was_soft_invalidated(self):
                return bool(self._soft_invalidated)

            def is_soft_invalidated(self, timestamp):
                return (self._soft_invalidated and
                        timestamp < self._soft_invalidated)

    The custom implementation is injected into a :class:`.CacheRegion`
    at configure time using the
    :paramref:`.CacheRegion.configure.region_invalidator` parameter::

        region = CacheRegion()

        region = region.configure(region_invalidator=CustomInvalidationStrategy())

    Invalidation strategies that wish to have access to the
    :class:`.CacheRegion` itself should construct the invalidator given the
    region as an argument::

        class MyInvalidator(RegionInvalidationStrategy):
            def __init__(self, region):
                self.region = region
                # ...

            # ...

        region = CacheRegion()
        region = region.configure(region_invalidator=MyInvalidator(region))

    .. versionadded:: 0.6.2

    .. seealso::

        :paramref:`.CacheRegion.configure.region_invalidator`

    cC€s
tƒ‚dS(sýRegion invalidation.

        :class:`.CacheRegion` propagated call.
        The default invalidation system works by setting
        a current timestamp (using ``time.time()``) to consider all older
        timestamps effectively invalidated.

        N(tNotImplementedError(tselfthard((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt
invalidateds
cC€s
tƒ‚dS(sÝCheck timestamp to determine if it was hard invalidated.

        :return: Boolean. True if ``timestamp`` is older than
         the last region invalidation time and region is invalidated
         in hard mode.

        N(R(Rt	timestamp((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytis_hard_invalidatedps	cC€s
tƒ‚dS(sÝCheck timestamp to determine if it was soft invalidated.

        :return: Boolean. True if ``timestamp`` is older than
         the last region invalidation time and region is invalidated
         in soft mode.

        N(R(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytis_soft_invalidated{s	cC€s
tƒ‚dS(s¨Check timestamp to determine if it was invalidated.

        :return: Boolean. True if ``timestamp`` is older than
         the last region invalidation time.

        N(R(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytis_invalidated†scC€s
tƒ‚dS(sƒIndicate the region was invalidated in soft mode.

        :return: Boolean. True if region was invalidated in soft mode.

        N(R(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytwas_soft_invalidatedscC€s
tƒ‚dS(sƒIndicate the region was invalidated in hard mode.

        :return: Boolean. True if region was invalidated in hard mode.

        N(R(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytwas_hard_invalidated™s(
t__name__t
__module__t__doc__tTrueRRRRRR(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRsF			
		tDefaultInvalidationStrategycB€sJeZd„Zed„Zd„Zd„Zd„Zd„Zd„Z	RS(cC€sd|_d|_dS(N(tNonet_is_hard_invalidatedt_invalidated(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt__init__¥s	cC€s"t|ƒ|_tjƒ|_dS(N(tboolR"ttimeR#(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR©scC€s|jdk	o||jkS(N(R#R!(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR­scC€s
|jtkS(N(R"R(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR±scC€s|jƒo|j|ƒS(N(RR(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR´scC€s
|jtkS(N(R"tFalse(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR·scC€s|jƒo|j|ƒS(N(RR(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRºs(
RRR$RRRRRRR(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR £s					tCacheRegioncB€sSeZdZdeeddd„Zdddddedd„Zd„Z	d„Z
defd„ƒYZd„Z
ed„Zd	„Zed
„ƒZed„ƒZded„Zd
„Zded„Zddd„Zddd„Zd„Zd„Zd„Zd„Zd„Zdddej dd„Z!dddeej dd„Z"RS(sA front end to a particular cache backend.

    :param name: Optional, a string name for the region.
     This isn't used internally
     but can be accessed via the ``.name`` parameter, helpful
     for configuring a region from a config file.
    :param function_key_generator:  Optional.  A
     function that will produce a "cache key" given
     a data creation function and arguments, when using
     the :meth:`.CacheRegion.cache_on_arguments` method.
     The structure of this function
     should be two levels: given the data creation function,
     return a new function that generates the key based on
     the given arguments.  Such as::

        def my_key_generator(namespace, fn, **kw):
            fname = fn.__name__
            def generate_key(*arg):
                return namespace + "_" + fname + "_".join(str(s) for s in arg)
            return generate_key


        region = make_region(
            function_key_generator = my_key_generator
        ).configure(
            "dogpile.cache.dbm",
            expiration_time=300,
            arguments={
                "filename":"file.dbm"
            }
        )

     The ``namespace`` is that passed to
     :meth:`.CacheRegion.cache_on_arguments`.  It's not consulted
     outside this function, so in fact can be of any form.
     For example, it can be passed as a tuple, used to specify
     arguments to pluck from \**kw::

        def my_key_generator(namespace, fn):
            def generate_key(*arg, **kw):
                return ":".join(
                        [kw[k] for k in namespace] +
                        [str(x) for x in arg]
                    )
            return generate_key


     Where the decorator might be used as::

        @my_region.cache_on_arguments(namespace=('x', 'y'))
        def my_function(a, b, **kw):
            return my_data()

     .. seealso::

        :func:`.function_key_generator` - default key generator

        :func:`.kwarg_function_key_generator` - optional gen that also
        uses keyword arguments

    :param function_multi_key_generator: Optional.
     Similar to ``function_key_generator`` parameter, but it's used in
     :meth:`.CacheRegion.cache_multi_on_arguments`. Generated function
     should return list of keys. For example::

        def my_multi_key_generator(namespace, fn, **kw):
            namespace = fn.__name__ + (namespace or '')

            def generate_keys(*args):
                return [namespace + ':' + str(a) for a in args]

            return generate_keys

    :param key_mangler: Function which will be used on all incoming
     keys before passing to the backend.  Defaults to ``None``,
     in which case the key mangling function recommended by
     the cache backend will be used.    A typical mangler
     is the SHA1 mangler found at :func:`.sha1_mangle_key`
     which coerces keys into a SHA1
     hash, so that the string length is fixed.  To
     disable all key mangling, set to ``False``.   Another typical
     mangler is the built-in Python function ``str``, which can be used
     to convert non-string or Unicode keys to bytestrings, which is
     needed when using a backend such as bsddb or dbm under Python 2.x
     in conjunction with Unicode keys.
    :param async_creation_runner:  A callable that, when specified,
     will be passed to and called by dogpile.lock when
     there is a stale value present in the cache.  It will be passed the
     mutex and is responsible releasing that mutex when finished.
     This can be used to defer the computation of expensive creator
     functions to later points in the future by way of, for example, a
     background thread, a long-running queue, or a task manager system
     like Celery.

     For a specific example using async_creation_runner, new values can
     be created in a background thread like so::

        import threading

        def async_creation_runner(cache, somekey, creator, mutex):
            ''' Used by dogpile.core:Lock when appropriate  '''
            def runner():
                try:
                    value = creator()
                    cache.set(somekey, value)
                finally:
                    mutex.release()

            thread = threading.Thread(target=runner)
            thread.start()


        region = make_region(
            async_creation_runner=async_creation_runner,
        ).configure(
            'dogpile.cache.memcached',
            expiration_time=5,
            arguments={
                'url': '127.0.0.1:11211',
                'distributed_lock': True,
            }
        )

     Remember that the first request for a key with no associated
     value will always block; async_creator will not be invoked.
     However, subsequent requests for cached-but-expired values will
     still return promptly.  They will be refreshed by whatever
     asynchronous means the provided async_creation_runner callable
     implements.

     By default the async_creation_runner is disabled and is set
     to ``None``.

     .. versionadded:: 0.4.2 added the async_creation_runner
        feature.

    cC€sD||_||_||_||_|_||_tƒ|_dS(s&Construct a new :class:`.CacheRegion`.N(tnameRR	tkey_manglert_user_defined_key_manglertasync_creation_runnerR tregion_invalidator(RR)RR	R*R,((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR$Is					c	C€sKd|jkr/|r/tjd|jƒ‚ntj|ƒ}	|r\|	j||ƒ|_n|	|phiƒ|_|s‡t|tƒr“||_	n<t|t
jƒrÀtt
j|ƒƒ|_	ntjdƒ‚|jsê|jj|_nt|jƒ|_t|dtƒr5x$t|ƒD]}
|j|
ƒqWn|rG||_n|S(s‹Configure a :class:`.CacheRegion`.

        The :class:`.CacheRegion` itself
        is returned.

        :param backend:   Required.  This is the name of the
         :class:`.CacheBackend` to use, and is resolved by loading
         the class from the ``dogpile.cache`` entrypoint.

        :param expiration_time:   Optional.  The expiration time passed
         to the dogpile system.  May be passed as an integer number
         of seconds, or as a ``datetime.timedelta`` value.

         .. versionadded 0.5.0
            ``expiration_time`` may be optionally passed as a
            ``datetime.timedelta`` value.

         The :meth:`.CacheRegion.get_or_create`
         method as well as the :meth:`.CacheRegion.cache_on_arguments`
         decorator (though note:  **not** the :meth:`.CacheRegion.get`
         method) will call upon the value creation function after this
         time period has passed since the last generation.

        :param arguments: Optional.  The structure here is passed
         directly to the constructor of the :class:`.CacheBackend`
         in use, though is typically a dictionary.

        :param wrap: Optional.  A list of :class:`.ProxyBackend`
         classes and/or instances, each of which will be applied
         in a chain to ultimately wrap the original backend,
         so that custom functionality augmentation can be applied.

         .. versionadded:: 0.5.0

         .. seealso::

            :ref:`changing_backend_behavior`

        :param replace_existing_backend: if True, the existing cache backend
         will be replaced.  Without this flag, an exception is raised if
         a backend is already configured.

         .. versionadded:: 0.5.7

        :param region_invalidator: Optional. Override default invalidation
         strategy with custom implementation of
         :class:`.RegionInvalidationStrategy`.

         .. versionadded:: 0.6.2

         tbackendsfThis region is already configured with backend: %s.  Specify replace_existing_backend=True to replace.s-expiration_time is not a number or timedelta.t__iter__(t__dict__RtRegionAlreadyConfiguredR.t_backend_loadertloadtfrom_config_dictt
isinstanceRtexpiration_timetdatetimet	timedeltatintR
ttimedelta_total_secondstValidationErrorR+R*Rt
_create_mutext_lock_registrytgetattrR'treversedtwrapR-(RR.R6t	argumentst_config_argument_dictt_config_prefixR@treplace_existing_backendR-tbackend_clstwrapper((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt	configureYs4>		cC€set|ƒtkr|ƒ}ntt|ƒtƒsLtdt|ƒƒ‚n|j|jƒ|_dS(sP Takes a ProxyBackend instance or class and wraps the
        attached backend. s#Type %s is not a valid ProxyBackendN(ttypet
issubclassRt	TypeErrorR@R.(Rtproxy((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR@½scC€s|jj|ƒS(N(R=tget(Rtkey((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt_mutexÌst_LockWrappercB€s,eZdZd„Zed„Zd„ZRS(s*weakref-capable wrapper for threading.LockcC€stjƒ|_dS(N(t	threadingRtlock(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR$ÑscC€s|jj|ƒS(N(RQtacquire(Rtwait((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRRÔscC€s|jjƒdS(N(RQtrelease(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRT×s(RRRR$RRRRT(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyROÏs	cC€s0|jj|ƒ}|dk	r"|S|jƒSdS(N(R.t	get_mutexR!RO(RRMtmutex((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR<ÚscC€s|jj|ƒdS(sÙInvalidate this :class:`.CacheRegion`.

        The default invalidation system works by setting
        a current timestamp (using ``time.time()``)
        representing the "minimum creation time" for
        a value.  Any retrieved value whose creation
        time is prior to this timestamp
        is considered to be stale.  It does not
        affect the data in the cache in any way, and is also
        local to this instance of :class:`.CacheRegion`.

        Once set, the invalidation time is honored by
        the :meth:`.CacheRegion.get_or_create`,
        :meth:`.CacheRegion.get_or_create_multi` and
        :meth:`.CacheRegion.get` methods.

        The method supports both "hard" and "soft" invalidation
        options.  With "hard" invalidation,
        :meth:`.CacheRegion.get_or_create` will force an immediate
        regeneration of the value which all getters will wait for.
        With "soft" invalidation, subsequent getters will return the
        "old" value until the new one is available.

        Usage of "soft" invalidation requires that the region or the method
        is given a non-None expiration time.

        .. versionadded:: 0.3.0

        :param hard: if True, cache values will all require immediate
         regeneration; dogpile logic won't be used.  If False, the
         creation time of existing values will be pushed back before
         the expiration time so that a return+regen will be invoked.

         .. versionadded:: 0.5.1

        N(R-R(RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRás%cC€sst|ƒ}|j|d|d|jd|dƒd|dd|d|jd|dƒd	|jd
|tƒƒS(sOConfigure from a configuration dictionary
        and a prefix.

        Example::

            local_region = make_region()
            memcached_region = make_region()

            # regions are ready to use for function
            # decorators, but not yet for actual caching

            # later, when config is available
            myconfig = {
                "cache.local.backend":"dogpile.cache.dbm",
                "cache.local.arguments.filename":"/path/to/dbmfile.dbm",
                "cache.memcached.backend":"dogpile.cache.pylibmc",
                "cache.memcached.arguments.url":"127.0.0.1, 10.0.0.1",
            }
            local_region.configure_from_config(myconfig, "cache.local.")
            memcached_region.configure_from_config(myconfig,
                                                "cache.memcached.")

        s	%sbackendR6s%sexpiration_timeRBRCs%sarguments.R@s%swrapRDs%sreplace_existing_backendN(RRGRLR!R'(Rtconfig_dicttprefix((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytconfigure_from_configs
cC€stjdƒ‚dS(Ns(No backend is configured on this region.(RtRegionNotConfigured(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR.-scC€s
d|jkS(s˜Return True if the backend has been configured via the
        :meth:`.CacheRegion.configure` method already.

        .. versionadded:: 0.5.1

        R.(R0(R((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt
is_configured2scC€sL|jr|j|ƒ}n|jj|ƒ}|j||ƒ|ƒ}|jS(sÚReturn a value from the cache, based on the given key.

        If the value is not present, the method returns the token
        ``NO_VALUE``. ``NO_VALUE`` evaluates to False, but is separate from
        ``None`` to distinguish between a cached value of ``None``.

        By default, the configured expiration time of the
        :class:`.CacheRegion`, or alternatively the expiration
        time supplied by the ``expiration_time`` argument,
        is tested against the creation time of the retrieved
        value versus the current time (as reported by ``time.time()``).
        If stale, the cached value is ignored and the ``NO_VALUE``
        token is returned.  Passing the flag ``ignore_expiration=True``
        bypasses the expiration time check.

        .. versionchanged:: 0.3.0
           :meth:`.CacheRegion.get` now checks the value's creation time
           against the expiration time, rather than returning
           the value unconditionally.

        The method also interprets the cached value in terms
        of the current "invalidation" time as set by
        the :meth:`.invalidate` method.   If a value is present,
        but its creation time is older than the current
        invalidation time, the ``NO_VALUE`` token is returned.
        Passing the flag ``ignore_expiration=True`` bypasses
        the invalidation time check.

        .. versionadded:: 0.3.0
           Support for the :meth:`.CacheRegion.invalidate`
           method.

        :param key: Key to be retrieved. While it's typical for a key to be a
         string, it is ultimately passed directly down to the cache backend,
         before being optionally processed by the key_mangler function, so can
         be of any type recognized by the backend or by the key_mangler
         function, if present.

        :param expiration_time: Optional expiration time value
         which will supersede that configured on the :class:`.CacheRegion`
         itself.

         .. versionadded:: 0.3.0

        :param ignore_expiration: if ``True``, the value is returned
         from the cache if present, regardless of configured
         expiration times or whether or not :meth:`.invalidate`
         was called.

         .. versionadded:: 0.3.0

        (R*R.RLt_unexpired_value_fntpayload(RRMR6tignore_expirationtvalue((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRL<s6	c€sN|r
d„Sˆdkr%ˆj‰ntjƒ‰‡‡‡fd†}|SdS(NcS€s|S(N((R_((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt<lambda>|sc€s\|tkr|Sˆdk	r7ˆ|jdˆkr7tSˆjj|jdƒrTtS|SdS(Ntct(R
R!tmetadataR-R(R_(tcurrent_timeR6R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytvalue_fnƒs	(R!R6R&(RR6R^Rd((RcR6RsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR\zsc€s”|s
gSˆjr4tt‡fd†|ƒƒ}nˆjj|ƒ}ˆj||ƒ‰g‡fd†|DƒD]!}|tk	rŠ|jn|^qoS(sReturn multiple values from the cache, based on the given keys.

        Returns values as a list matching the keys given.

        E.g.::

            values = region.get_multi(["one", "two", "three"])

        To convert values to a dictionary, use ``zip()``::

            keys = ["one", "two", "three"]
            values = region.get_multi(keys)
            dictionary = dict(zip(keys, values))

        Keys which aren't present in the list are returned as
        the ``NO_VALUE`` token.  ``NO_VALUE`` evaluates to False,
        but is separate from
        ``None`` to distinguish between a cached value of ``None``.

        By default, the configured expiration time of the
        :class:`.CacheRegion`, or alternatively the expiration
        time supplied by the ``expiration_time`` argument,
        is tested against the creation time of the retrieved
        value versus the current time (as reported by ``time.time()``).
        If stale, the cached value is ignored and the ``NO_VALUE``
        token is returned.  Passing the flag ``ignore_expiration=True``
        bypasses the expiration time check.

        .. versionadded:: 0.5.0

        c€s
ˆj|ƒS(N(R*(RM(R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR`µsc3€s|]}ˆ|ƒVqdS(N((t.0R_(R\(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>¿s(R*tlisttmapR.t	get_multiR\R
R](RtkeysR6R^tbackend_valuesR_((R\RsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRh‘s 	!c	€sˆ‰ˆjr!ˆjˆƒ‰n‡‡‡fd†}‡‡‡‡fd†}ˆdkrfˆj‰nˆdkr“ˆjjƒr“tjdƒ‚nˆdkr¨d‰nˆjrɇ‡‡fd†}nd}tˆj	ˆƒ||ˆ|ƒ}|SWdQXdS(sÄReturn a cached value based on the given key.

        If the value does not exist or is considered to be expired
        based on its creation time, the given
        creation function may or may not be used to recreate the value
        and persist the newly generated value in the cache.

        Whether or not the function is used depends on if the
        *dogpile lock* can be acquired or not.  If it can't, it means
        a different thread or process is already running a creation
        function for this key against the cache.  When the dogpile
        lock cannot be acquired, the method will block if no
        previous value is available, until the lock is released and
        a new value available.  If a previous value
        is available, that value is returned immediately without blocking.

        If the :meth:`.invalidate` method has been called, and
        the retrieved value's timestamp is older than the invalidation
        timestamp, the value is unconditionally prevented from
        being returned.  The method will attempt to acquire the dogpile
        lock to generate a new value, or will wait
        until the lock is released to return the new value.

        .. versionchanged:: 0.3.0
          The value is unconditionally regenerated if the creation
          time is older than the last call to :meth:`.invalidate`.

        :param key: Key to be retrieved. While it's typical for a key to be a
         string, it is ultimately passed directly down to the cache backend,
         before being optionally processed by the key_mangler function, so can
         be of any type recognized by the backend or by the key_mangler
         function, if present.

        :param creator: function which creates a new value.

        :param expiration_time: optional expiration time which will overide
         the expiration time already configured on this :class:`.CacheRegion`
         if not None.   To set no expiration, use the value -1.

        :param should_cache_fn: optional callable function which will receive
         the value returned by the "creator", and will then return True or
         False, indicating if the value should actually be cached or not.  If
         it returns False, the value is still returned, but isn't cached.
         E.g.::

            def dont_cache_none(value):
                return value is not None

            value = region.get_or_create("some key",
                                create_value,
                                should_cache_fn=dont_cache_none)

         Above, the function returns the value of create_value() if
         the cache is invalid, however if the return value is None,
         it won't be cached.

         .. versionadded:: 0.4.3

        .. seealso::

            :meth:`.CacheRegion.cache_on_arguments` - applies
            :meth:`.get_or_create` to any function using a decorator.

            :meth:`.CacheRegion.get_or_create_multi` - multiple key/value
             version

        c€s™ˆjjˆƒ}|tksJ|jdtksJˆjj|jdƒrVtƒ‚n|jd}ˆjj|ƒrŒt	j	ƒˆd}n|j
|fS(NtvRag-Cëâ6?(R.RLR
Rbt
value_versionR-RRRR&R](R_Ra(R6RMR(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt	get_value
s	
c€sUˆƒ}ˆj|ƒ}ˆs+ˆ|ƒrAˆjjˆ|ƒn|j|jdfS(NRa(t_valueR.tsetR]Rb(t
created_valueR_(tcreatorRMRtshould_cache_fn(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt	gen_values	s7Non-None expiration time required for soft invalidationiÿÿÿÿc€sˆjˆˆˆ|ƒS(N(R,(RV(Rqtorig_keyR(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt
async_creator0sN(
R*R!R6R-RRtDogpileCacheExceptionR,RRN(	RRMRqR6RrRmRsRuR_((RqR6RMRtRRrsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt
get_or_createÄs.E	
		c

€sS‡‡‡	fd†‰d„}‡fd†‰ˆd	krEˆj‰nˆd	krrˆjjƒrrtjdƒ‚nˆdkr‡d	‰ni‰tt|ƒƒ}ˆjrÍg|D]}ˆj|ƒ^q¯}n|}t	t
||ƒƒ‰t	t
|ˆjj|ƒƒƒ‰	x]ˆj
ƒD]O\‰‰tˆjˆƒ|‡‡fd†ˆd‡‡fd†ƒWd	QXqWzÁˆrtˆƒ}	||	Œ}
t	‡‡fd
†t
|	|
ƒDƒƒ}ˆsˈjj|ƒn,ˆjjt	‡fd†|j
ƒDƒƒƒˆ	j|ƒng|D]}ˆ	ˆ|j^qSWd	xˆjƒD]}|jƒq:WXd	S(srReturn a sequence of cached values based on a sequence of keys.

        The behavior for generation of values based on keys corresponds
        to that of :meth:`.Region.get_or_create`, with the exception that
        the ``creator()`` function may be asked to generate any subset of
        the given keys.   The list of keys to be generated is passed to
        ``creator()``, and ``creator()`` should return the generated values
        as a sequence corresponding to the order of the keys.

        The method uses the same approach as :meth:`.Region.get_multi`
        and :meth:`.Region.set_multi` to get and set values from the
        backend.

        If you are using a :class:`.CacheBackend` or :class:`.ProxyBackend`
        that modifies values, take note this function invokes
        ``.set_multi()`` for newly generated values using the same values it
        returns to the calling function. A correct implementation of
        ``.set_multi()`` will not modify values in-place on the submitted
        ``mapping`` dict.

        :param keys: Sequence of keys to be retrieved.

        :param creator: function which accepts a sequence of keys and
         returns a sequence of new values.

        :param expiration_time: optional expiration time which will overide
         the expiration time already configured on this :class:`.CacheRegion`
         if not None.   To set no expiration, use the value -1.

        :param should_cache_fn: optional callable function which will receive
         each value returned by the "creator", and will then return True or
         False, indicating if the value should actually be cached or not.  If
         it returns False, the value is still returned, but isn't cached.

        .. versionadded:: 0.5.0

        .. seealso::


            :meth:`.CacheRegion.cache_multi_on_arguments`

            :meth:`.CacheRegion.get_or_create`

        c€sžˆj|tƒ}|tksJ|jdtksJˆjj|jdƒrW|jdfS|jd}ˆjj|ƒrtjƒˆd}n|j|fSdS(NRkiRag-Cëâ6?(	RLR
RbRlR-RR]RR&(RMR_Ra(R6Rtvalues(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRmms	

cS€s
tƒ‚dS(N(R(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRs~sc€s|ˆ|<dS(N((RMRV(tmutexes(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRuss7Non-None expiration time required for soft invalidationiÿÿÿÿc€s
ˆˆƒS(N(((Rmtmangled_key(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR`¡sRuc€s
ˆˆ|ƒS(N((RV(RuRt(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR`£sNc3€s.|]$\}}ˆ|ˆj|ƒfVqdS(N(Rn(RetkRk(torig_to_mangledR(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>®sc3€s1|]'\}}ˆ|dƒr||fVqdS(iN((ReR{Rk(Rr(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>¶s	(R!R6R-RRRvtsortedRoR*tdicttzipR.RhtitemsRRNt	set_multitupdateR]RxRT(
RRiRqR6RrRstsorted_unique_keysR{tmangled_keystkeys_to_gett
new_valuestvalues_w_createdRV((
RuR6RmRzRyRtR|RRrRxsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytget_or_create_multi>sT/			%!
&cC€s!t|itjƒd6td6ƒS(s-Return a :class:`.CachedValue` given a value.RaRk(RR&Rl(RR_((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRnÁs

cC€s;|jr|j|ƒ}n|jj||j|ƒƒdS(s3Place a new value in the cache under the given key.N(R*R.RoRn(RRMR_((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRoÊs	c€sn|s
dSˆjr8t‡fd†|jƒDƒƒ}n"t‡fd†|jƒDƒƒ}ˆjj|ƒdS(s^Place new values in the cache under the given keys.

        .. versionadded:: 0.5.0

        Nc3€s3|])\}}ˆj|ƒˆj|ƒfVqdS(N(R*Rn(ReR{Rk(R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>Ûsc3€s*|] \}}|ˆj|ƒfVqdS(N(Rn(ReR{Rk(R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>ßs(R*R~R€R.R(Rtmapping((RsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRÑs	"cC€s/|jr|j|ƒ}n|jj|ƒdS(s–Remove a value from the cache.

        This operation is idempotent (can be called multiple times, or on a
        non-existent key, safely)
        N(R*R.tdelete(RRM((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRŠâs	c€s>ˆjr*tt‡fd†|ƒƒ}nˆjj|ƒdS(sÀRemove multiple values from the cache.

        This operation is idempotent (can be called multiple times, or on a
        non-existent key, safely)

        .. versionadded:: 0.5.0

        c€s
ˆj|ƒS(N(R*(RM(R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR`ùsN(R*RfRgR.tdelete_multi(RRi((RsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR‹îs
	!c€sLtjˆƒ‰ˆdkr'ˆj‰n‡‡‡‡‡‡‡fd†}|S(sŠA function decorator that will cache the return
        value of the function using a key derived from the
        function itself and its arguments.

        The decorator internally makes use of the
        :meth:`.CacheRegion.get_or_create` method to access the
        cache and conditionally call the function.  See that
        method for additional behavioral details.

        E.g.::

            @someregion.cache_on_arguments()
            def generate_something(x, y):
                return somedatabase.query(x, y)

        The decorated function can then be called normally, where
        data will be pulled from the cache region unless a new
        value is needed::

            result = generate_something(5, 6)

        The function is also given an attribute ``invalidate()``, which
        provides for invalidation of the value.  Pass to ``invalidate()``
        the same arguments you'd pass to the function itself to represent
        a particular value::

            generate_something.invalidate(5, 6)

        Another attribute ``set()`` is added to provide extra caching
        possibilities relative to the function.   This is a convenience
        method for :meth:`.CacheRegion.set` which will store a given
        value directly without calling the decorated function.
        The value to be cached is passed as the first argument, and the
        arguments which would normally be passed to the function
        should follow::

            generate_something.set(3, 5, 6)

        The above example is equivalent to calling
        ``generate_something(5, 6)``, if the function were to produce
        the value ``3`` as the value to be cached.

        .. versionadded:: 0.4.1 Added ``set()`` method to decorated function.

        Similar to ``set()`` is ``refresh()``.   This attribute will
        invoke the decorated function and populate a new value into
        the cache with the new value, as well as returning that value::

            newvalue = generate_something.refresh(5, 6)

        .. versionadded:: 0.5.0 Added ``refresh()`` method to decorated
           function.

        Lastly, the ``get()`` method returns either the value cached
        for the given key, or the token ``NO_VALUE`` if no such key
        exists::

            value = generate_something.get(5, 6)

        .. versionadded:: 0.5.3 Added ``get()`` method to decorated
           function.

        The default key generation will use the name
        of the function, the module name for the function,
        the arguments passed, as well as an optional "namespace"
        parameter in order to generate a cache key.

        Given a function ``one`` inside the module
        ``myapp.tools``::

            @region.cache_on_arguments(namespace="foo")
            def one(a, b):
                return a + b

        Above, calling ``one(3, 4)`` will produce a
        cache key as follows::

            myapp.tools:one|foo|3 4

        The key generator will ignore an initial argument
        of ``self`` or ``cls``, making the decorator suitable
        (with caveats) for use with instance or class methods.
        Given the example::

            class MyClass(object):
                @region.cache_on_arguments(namespace="foo")
                def one(self, a, b):
                    return a + b

        The cache key above for ``MyClass().one(3, 4)`` will
        again produce the same cache key of ``myapp.tools:one|foo|3 4`` -
        the name ``self`` is skipped.

        The ``namespace`` parameter is optional, and is used
        normally to disambiguate two functions of the same
        name within the same module, as can occur when decorating
        instance or class methods as below::

            class MyClass(object):
                @region.cache_on_arguments(namespace='MC')
                def somemethod(self, x, y):
                    ""

            class MyOtherClass(object):
                @region.cache_on_arguments(namespace='MOC')
                def somemethod(self, x, y):
                    ""

        Above, the ``namespace`` parameter disambiguates
        between ``somemethod`` on ``MyClass`` and ``MyOtherClass``.
        Python class declaration mechanics otherwise prevent
        the decorator from having awareness of the ``MyClass``
        and ``MyOtherClass`` names, as the function is received
        by the decorator before it becomes an instance method.

        The function key generation can be entirely replaced
        on a per-region basis using the ``function_key_generator``
        argument present on :func:`.make_region` and
        :class:`.CacheRegion`. If defaults to
        :func:`.function_key_generator`.

        :param namespace: optional string argument which will be
         established as part of the cache key.   This may be needed
         to disambiguate functions of the same name within the same
         source file, such as those
         associated with classes - note that the decorator itself
         can't see the parent class on a function as the class is
         being declared.

        :param expiration_time: if not None, will override the normal
         expiration time.

         May be specified as a callable, taking no arguments, that
         returns a value to be used as the ``expiration_time``. This callable
         will be called whenever the decorated function itself is called, in
         caching or retrieving. Thus, this can be used to
         determine a *dynamic* expiration time for the cached function
         result.  Example use cases include "cache the result until the
         end of the day, week or time period" and "cache until a certain date
         or time passes".

         .. versionchanged:: 0.5.0
            ``expiration_time`` may be passed as a callable to
            :meth:`.CacheRegion.cache_on_arguments`.

        :param should_cache_fn: passed to :meth:`.CacheRegion.get_or_create`.

         .. versionadded:: 0.4.3

        :param to_str: callable, will be called on each function argument
         in order to convert to a string.  Defaults to ``str()``.  If the
         function accepts non-ascii unicode arguments on Python 2.x, the
         ``unicode()`` builtin can be substituted, but note this will
         produce unicode cache keys which may require key mangling before
         reaching the cache.

         .. versionadded:: 0.5.0

        :param function_key_generator: a function that will produce a
         "cache key". This function will supersede the one configured on the
         :class:`.CacheRegion` itself.

         .. versionadded:: 0.5.5

        .. seealso::

            :meth:`.CacheRegion.cache_multi_on_arguments`

            :meth:`.CacheRegion.get_or_create`

        c€s܈tjkr!ˆˆˆƒ‰nˆˆˆdˆƒ‰tˆƒ‡‡‡‡‡‡fd†ƒ}‡‡fd†}‡‡fd†}‡‡fd†}‡‡‡fd†}||_||_||_||_ˆ|_|S(Ntto_strc€s[ˆˆˆŽ}tˆƒ‡‡‡fd†ƒ}ˆr?ˆƒnˆ}ˆj|||ˆƒS(Nc€s
ˆˆˆŽS(N(((targtfntkw(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRqÀs(RRw(RRRMRqttimeout(R6texpiration_time_is_callableRŽt
key_generatorRRr(RRsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytdecorate¼s!c€s ˆ||Ž}ˆj|ƒdS(N(RŠ(RRRM(R’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRÈsc€s#ˆ||Ž}ˆj||ƒdS(N(Ro(R_RRRM(R’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytset_Ìsc€sˆ||Ž}ˆj|ƒS(N(RL(RRRM(R’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRLÐsc€s2ˆ||Ž}ˆ||Ž}ˆj||ƒ|S(N(Ro(RRRMR_(RŽR’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytrefreshÔs(R
tstring_typeRRoRR•RLtoriginal(RŽR“RR”RLR•(R6R‘Rt	namespaceRRrRŒ(RŽR’sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt	decorator³s 		*					N(R
tcallableR!R(RR˜R6RrRŒRR™((R6R‘RR˜RRrRŒsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytcache_on_argumentsýs
±!.c€sOtjˆƒ‰ˆdkr'ˆj‰n‡‡‡‡‡‡‡‡fd†}|S(sA function decorator that will cache multiple return
        values from the function using a sequence of keys derived from the
        function itself and the arguments passed to it.

        This method is the "multiple key" analogue to the
        :meth:`.CacheRegion.cache_on_arguments` method.

        Example::

            @someregion.cache_multi_on_arguments()
            def generate_something(*keys):
                return [
                    somedatabase.query(key)
                    for key in keys
                ]

        The decorated function can be called normally.  The decorator
        will produce a list of cache keys using a mechanism similar to
        that of :meth:`.CacheRegion.cache_on_arguments`, combining the
        name of the function with the optional namespace and with the
        string form of each key.  It will then consult the cache using
        the same mechanism as that of :meth:`.CacheRegion.get_multi`
        to retrieve all current values; the originally passed keys
        corresponding to those values which aren't generated or need
        regeneration will be assembled into a new argument list, and
        the decorated function is then called with that subset of
        arguments.

        The returned result is a list::

            result = generate_something("key1", "key2", "key3")

        The decorator internally makes use of the
        :meth:`.CacheRegion.get_or_create_multi` method to access the
        cache and conditionally call the function.  See that
        method for additional behavioral details.

        Unlike the :meth:`.CacheRegion.cache_on_arguments` method,
        :meth:`.CacheRegion.cache_multi_on_arguments` works only with
        a single function signature, one which takes a simple list of
        keys as arguments.

        Like :meth:`.CacheRegion.cache_on_arguments`, the decorated function
        is also provided with a ``set()`` method, which here accepts a
        mapping of keys and values to set in the cache::

            generate_something.set({"k1": "value1",
                                    "k2": "value2", "k3": "value3"})

        ...an ``invalidate()`` method, which has the effect of deleting
        the given sequence of keys using the same mechanism as that of
        :meth:`.CacheRegion.delete_multi`::

            generate_something.invalidate("k1", "k2", "k3")

        ...a ``refresh()`` method, which will call the creation
        function, cache the new values, and return them::

            values = generate_something.refresh("k1", "k2", "k3")

        ...and a ``get()`` method, which will return values
        based on the given arguments::

            values = generate_something.get("k1", "k2", "k3")

        .. versionadded:: 0.5.3 Added ``get()`` method to decorated
           function.

        Parameters passed to :meth:`.CacheRegion.cache_multi_on_arguments`
        have the same meaning as those passed to
        :meth:`.CacheRegion.cache_on_arguments`.

        :param namespace: optional string argument which will be
         established as part of each cache key.

        :param expiration_time: if not None, will override the normal
         expiration time.  May be passed as an integer or a
         callable.

        :param should_cache_fn: passed to
         :meth:`.CacheRegion.get_or_create_multi`. This function is given a
         value as returned by the creator, and only if it returns True will
         that value be placed in the cache.

        :param asdict: if ``True``, the decorated function should return
         its result as a dictionary of keys->values, and the final result
         of calling the decorated function will also be a dictionary.
         If left at its default value of ``False``, the decorated function
         should return its result as a list of values, and the final
         result of calling the decorated function will also be a list.

         When ``asdict==True`` if the dictionary returned by the decorated
         function is missing keys, those keys will not be cached.

        :param to_str: callable, will be called on each function argument
         in order to convert to a string.  Defaults to ``str()``.  If the
         function accepts non-ascii unicode arguments on Python 2.x, the
         ``unicode()`` builtin can be substituted, but note this will
         produce unicode cache keys which may require key mangling before
         reaching the cache.

        .. versionadded:: 0.5.0

        :param function_multi_key_generator: a function that will produce a
         list of keys. This function will supersede the one configured on the
         :class:`.CacheRegion` itself.

         .. versionadded:: 0.5.5

        .. seealso::

            :meth:`.CacheRegion.cache_on_arguments`

            :meth:`.CacheRegion.get_or_create_multi`

        c€s¸ˆˆˆdˆ	ƒ‰tˆƒ‡‡‡‡‡‡‡fd†ƒ}‡‡fd†}‡‡fd†}‡‡fd†}‡‡‡‡fd†}||_||_||_||_|S(NRŒc€sÚ|}ˆ||Ž}tt||ƒƒ‰tˆƒ‡‡fd†ƒ‰ˆrWˆƒnˆ}ˆr¾‡‡fd†}‡fd†}ˆj||||ƒ}td„t||ƒDƒƒ}nˆj|ˆ|ˆƒ}|S(Nc€s!ˆg|D]}ˆ|^q
ŒS(N((tkeys_to_createR{(RŽt
key_lookup(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRqlsc€s3ˆ|Œ}g|D]}|jˆ|tƒ^qS(N(RLR
(Ritd_valuesR{(RqR(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytdict_createtsc€s(|tkrtSˆstSˆ|ƒSdS(N(R
R'R(R_(Rr(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt
wrap_cache_fnzs
cs€s-|]#\}}|tk	r||fVqdS(N(R
(ReR{Rk((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>…s	(R~RRRˆ(RRt
cache_keysRiRRŸR tresult(tasdictR6R‘RŽR’RRr(RqRsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR“fs"		c€sˆ|Œ}ˆj|ƒdS(N(R‹(RRi(R’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRŽsc€sHtˆƒ}ˆ|Œ}ˆjt‡fd†t||ƒDƒƒƒdS(Nc3€s%|]\}}|ˆ|fVqdS(N((Retgen_keyRM(R‰(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pys	<genexpr>–s(RfRR~R(R‰Ritgen_keys(R’R(R‰sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR”’s
	c€sˆ|Œ}ˆj|ƒS(N(Rh(RRi(R’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyRL›sc€syˆ|Œ}ˆ|Œ}ˆrUˆjtt|g|D]}||^q4ƒƒƒ|Sˆjtt||ƒƒƒ|SdS(N(RR~R(RRiRxta(R£RŽR’R(sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR•Ÿs-(RRoRR•RL(RŽR“RR”RLR•(R£R6R‘R	R˜RRrRŒ(RŽR’sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR™as		-(					N(R
RšR!R	(RR˜R6RrR£RŒR	R™((R£R6R‘R	R˜RRrRŒsI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytcache_multi_on_argumentsãs
y$RN(#RRRR!RR	R$R'RGR@RNtobjectROR<RRRYRR.tpropertyR[RLR\RhRwRˆRnRoRRŠR‹R
R–R›R§(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyR(¾sP‰\			'	%
>	4z‚						â	cO€s
t||ŽS(s±Instantiate a new :class:`.CacheRegion`.

    Currently, :func:`.make_region` is a passthrough
    to :class:`.CacheRegion`.  See that class for
    constructor arguments.

    (R((RR((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pytmake_region¶s($t
__future__RtRRtutilRRRRRRR	tapiR
RRKRR
R&R7tnumbersRt	functoolsRRPR2tregistertregister_backendRRlR¨RR R(Rª(((sI/home/tvault/.virtenv/lib/python2.7/site-packages/dogpile/cache/region.pyt<module>s2	‡ÿÿÿÿü