• File: container.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib/python3.7/site-packages/beaker/__pycache__/container.cpython-37.pyc
  • Date Modified: 12/01/2019 7:12 PM
  • File size: 23.52 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

[^@sdZddlZddlmZmZmZmZmZddlm	Z	ddl
Z
ddlZddlZddl
mZmZddlmZmZmZmZmZddd	d
ddd
dddddgZe
dZee
jrejZnddZGdddeZGdddeZGdddeZGdddeZ Gdd
d
e Z!GdddeZ"GdddeZ#iZ$e%Z&Gddde'Z(ee(Gd ddeZ)Gd!dde)Z*Gd"d
d
e)Z+Gd#dde)Z,e,Z-dS)$zContainer and Namespace classesN)pickleanydbm
add_metaclassPYVERunicode_text)CreationAbortedErrorMissingCacheParameter)
_threadingfile_synchronizermutex_synchronizerNameLocknull_synchronizerValue	ContainerContainerContextMemoryContainerDBMContainerNamespaceManagerMemoryNamespaceManagerDBMNamespaceManager
FileContainerOpenResourceNamespaceManagerFileNamespaceManagerrzbeaker.containercGsdS)N)messageargsrrA/opt/alt/python37/lib/python3.7/site-packages/beaker/container.pydebugsrc@seZdZdZeddZddZddZdd	Zd
dZ	dd
Z
d%ddZddZddZ
ddZddZd&ddZddZdd Zd!d"Zd#d$ZdS)'raHHandles dictionary operations and locking for a namespace of
    values.

    :class:`.NamespaceManager` provides a dictionary-like interface,
    implementing ``__getitem__()``, ``__setitem__()``, and
    ``__contains__()``, as well as functions related to lock
    acquisition.

    The implementation for setting and retrieving the namespace data is
    handled by subclasses.

    NamespaceManager may be used alone, or may be accessed by
    one or more :class:`.Value` objects.  :class:`.Value` objects provide per-key
    services like expiration times and automatic recreation of values.

    Multiple NamespaceManagers created with a particular name will all
    share access to the same underlying datasource and will attempt to
    synchronize against a common mutex object.  The scope of this
    sharing may be within a single process or across multiple
    processes, depending on the type of NamespaceManager used.

    The NamespaceManager itself is generally threadsafe, except in the
    case of the DBMNamespaceManager in conjunction with the gdbm dbm
    implementation.

    cCsdS)z`Initialize module-level dependent libraries required
        by this :class:`.NamespaceManager`.Nr)clsrrr_init_dependencies:sz#NamespaceManager._init_dependenciescCs|||_dS)N)r 	namespace)selfr!rrr__init__?szNamespaceManager.__init__cCs
tdS)a+Return a locking object that is used to synchronize
        multiple threads or processes which wish to generate a new
        cache value.

        This function is typically an instance of
        :class:`.FileSynchronizer`, :class:`.ConditionSynchronizer`,
        or :class:`.null_synchronizer`.

        The creation lock is only used when a requested value
        does not exist, or has been expired, and is only used
        by the :class:`.Value` key-management object in conjunction
        with a "createfunc" value-creation function.

        N)NotImplementedError)r"keyrrrget_creation_lockCsz"NamespaceManager.get_creation_lockcCs
tdS)aImplement removal of the entire contents of this
        :class:`.NamespaceManager`.

        e.g. for a file-based namespace, this would remove
        all the files.

        The front-end to this method is the
        :meth:`.NamespaceManager.remove` method.

        N)r$)r"rrr	do_removeTszNamespaceManager.do_removecCsdS)zEstablish a read lock.

        This operation is called before a key is read.    By
        default the function does nothing.

        Nr)r"rrracquire_read_lockasz"NamespaceManager.acquire_read_lockcCsdS)zRelease a read lock.

        This operation is called after a key is read.    By
        default the function does nothing.

        Nr)r"rrrrelease_read_lockisz"NamespaceManager.release_read_lockTFcCsdS)aEstablish a write lock.

        This operation is called before a key is written.
        A return value of ``True`` indicates the lock has
        been acquired.

        By default the function returns ``True`` unconditionally.

        'replace' is a hint indicating the full contents
        of the namespace may be safely discarded. Some backends
        may implement this (i.e. file backend won't unpickle the
        current contents).

        Tr)r"waitreplacerrracquire_write_lockqsz#NamespaceManager.acquire_write_lockcCsdS)zRelease a write lock.

        This operation is called after a new value is written.
        By default this function does nothing.

        Nr)r"rrrrelease_write_locksz#NamespaceManager.release_write_lockcCs
||S)zYReturn ``True`` if the given key is present in this
        :class:`.Namespace`.
        )__contains__)r"r%rrrhas_keyszNamespaceManager.has_keycCs
tdS)N)r$)r"r%rrr__getitem__szNamespaceManager.__getitem__cCs
tdS)N)r$)r"r%valuerrr__setitem__szNamespaceManager.__setitem__NcCs|||<dS)zSets a value in this :class:`.NamespaceManager`.

        This is the same as ``__setitem__()``, but
        also allows an expiration time to be passed
        at the same time.

        Nr)r"r%r1
expiretimerrr	set_valueszNamespaceManager.set_valuecCs
tdS)N)r$)r"r%rrrr.szNamespaceManager.__contains__cCs
tdS)N)r$)r"r%rrr__delitem__szNamespaceManager.__delitem__cCs
tdS)zReturn the list of all keys.

        This method may not be supported by all
        :class:`.NamespaceManager` implementations.

        N)r$)r"rrrkeysszNamespaceManager.keyscCs|dS)zRemove the entire contents of this
        :class:`.NamespaceManager`.

        e.g. for a file-based namespace, this would remove
        all the files.
        N)r')r"rrrremoveszNamespaceManager.remove)TF)N)__name__
__module____qualname____doc__classmethodr r#r&r'r(r)r,r-r/r0r2r4r.r5r6r7rrrrrs"



	c@sneZdZdZddZddZddZdd	Zd
dZdd
Z	dddZ
ddZdddZdddZ
ddZdS)rzzA NamespaceManager where read/write operations require opening/
    closing of a resource which is possibly mutexed.

    cCs*t||||_d|_t|_dS)Nr)rr#get_access_lockaccess_lockopenersr
Lockmutex)r"r!rrrr#s
z%OpenResourceNamespaceManager.__init__cCs
tdS)N)r$)r"rrrr=sz,OpenResourceNamespaceManager.get_access_lockcCs
tdS)N)r$)r"flagsr+rrrdo_opensz$OpenResourceNamespaceManager.do_opencCs
tdS)N)r$)r"rrrdo_closesz%OpenResourceNamespaceManager.do_closecCs:|jy|jdddWn|jYnXdS)NrT)
checkcount)r>r(openr))r"rrrr(s

z.OpenResourceNamespaceManager.acquire_read_lockcCs"z|jddWd|jXdS)NT)rF)closer>r))r"rrrr)sz.OpenResourceNamespaceManager.release_read_lockTFcCsF|j|}y|s|r&|jdd|d|S|jYnXdS)NcT)rFr+)r>r,rGr-)r"r*r+rErrrr,s
z/OpenResourceNamespaceManager.acquire_write_lockcCs"z|jddWd|jXdS)NT)rF)rHr>r-)r"rrrr-sz/OpenResourceNamespaceManager.release_write_lockcCs\|jz@|r6|jdkr&||||jd7_n|||d|_Wd|jXdS)Nrr)rAacquirer?rCrelease)r"rBrFr+rrrrGs


z!OpenResourceNamespaceManager.opencCs^|jzB|r2|jd8_|jdkrJ|n|jdkrD|d|_Wd|jXdS)Nrr)rArJr?rDrK)r"rFrrrrHs




z"OpenResourceNamespaceManager.closecCs4|jz|jdd|Wd|jXdS)NF)rF)r>r,rHr'r-)r"rrrr7s

z#OpenResourceNamespaceManager.removeN)TF)FF)F)r8r9r:r;r#r=rCrDr(r)r,r-rGrHr7rrrrrs



c@s`eZdZdZdZdddZddZdd	Zd
dZdd
Z	ddZ
ddZdddZddZ
dS)rzImplements synchronization, expiration, and value-creation logic
    for a single value stored in a :class:`.NamespaceManager`.

    )r%
createfuncr3expire_argument	starttime
storedtimer!NcCs(||_||_||_||_d|_||_dS)N)r%rLrMrNrOr!)r"r%r!rLr3rNrrrr#szValue.__init__cCs(|jz|j|jkS|jXdS)zrreturn true if the container has a value stored.

        This is regardless of it being expired or not.

        N)r!r(r%r))r"rrr	has_value s
zValue.has_valuecCs|p|jdk	S)N)has_current_valuerL)r"rrrcan_have_value,szValue.can_have_valuecCsb|jzF|j|jk}|rNy|\}}}|||Stk
rLYnXdS|jXdS)NF)r!r(r%
_get_value_is_expiredKeyErrorr))r"rQstoredexpiredr1rrrrR/s
zValue.has_current_valuecCs,|jdk	r||jkp*|dk	o*t||kS)z1Return true if this container's value is expired.N)rNtime)r"rOr3rrrrU=s

zValue._is_expiredcCsb|jz\|}|rTy"|\}}}|||s8|SWntk
rRd}YnX|jsdt|jWd|jXd}|j	|j}|r|j
ddstd|Stdd}|std|
tdz|jzJ|ry$|\}}}|||s|SWntk
rYnXWd|jXtd|}|||S|
td	XdS)
NF)r*z6get_value returning old value while new one is createdzlock_creatfunc (didnt wait)Tzlock_createfunc (waiting)zlock_createfunc (waited)zget_value creating new valuezreleased create lock)r!r(rQrTrUrVrLr%r)r&rJrr4rK)r"rQrWrXr1Zhas_createlockZ
creation_lockvrrr	get_valueKsT





zValue.get_valuecCs|j|j}y|\}}}Wnztk
rxt|dks8|\}}|j}td||j|j||||jYnt	k
rt
|jYnX|||fS)Nz*get_value upgrading time %r expire time %r)r!r%
ValueErrorlenrMrr)r4r(	TypeErrorrV)r"r1rWrXrrrrTs
zValue._get_valuecCs\|jz@|dkrt}td||j|jj|j||j|f|jdWd|jXdS)Nz'set_value stored time %r expire time %r)r3)r!r,rYrrMr4r%r-)r"r1rOrrrr4s
zValue.set_valuecCs^|jzBtd|j|jkrDy|j|j=Wntk
rBYnXd|_Wd|jXdS)Nclear_valuerP)r!r,rr%rVrOr-)r"rrrr`s

zValue.clear_value)NNN)N)r8r9r:r;	__slots__r#rQrSrRrUr[rTr4r`rrrrrs
8
c@sPeZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZdS)AbstractDictionaryNSManageraA subclassable NamespaceManager that places data in a dictionary.

    Subclasses should provide a "dictionary" attribute or descriptor
    which returns a dict-like object.   The dictionary will store keys
    that are local to the "namespace" attribute of this manager, so
    ensure that the dictionary will not be used by any other namespace.

    e.g.::

        import collections
        cached_data = collections.defaultdict(dict)

        class MyDictionaryManager(AbstractDictionaryNSManager):
            def __init__(self, namespace):
                AbstractDictionaryNSManager.__init__(self, namespace)
                self.dictionary = cached_data[self.namespace]

    The above stores data in a global dictionary called "cached_data",
    which is structured as a dictionary of dictionaries, keyed
    first on namespace name to a sub-dictionary, then on actual
    cache key to value.

    cCstd|j|fddS)Nzmemorynamespace/funclock/%s/%sT)
identifierZ	reentrant)r
r!)r"r%rrrr&s
z-AbstractDictionaryNSManager.get_creation_lockcCs
|j|S)N)
dictionary)r"r%rrrr0sz'AbstractDictionaryNSManager.__getitem__cCs|j|S)N)rdr.)r"r%rrrr.sz(AbstractDictionaryNSManager.__contains__cCs|j|S)N)rdr.)r"r%rrrr/sz#AbstractDictionaryNSManager.has_keycCs||j|<dS)N)rd)r"r%r1rrrr2sz'AbstractDictionaryNSManager.__setitem__cCs|j|=dS)N)rd)r"r%rrrr5sz'AbstractDictionaryNSManager.__delitem__cCs|jdS)N)rdclear)r"rrrr'sz%AbstractDictionaryNSManager.do_removecCs
|jS)N)rdr6)r"rrrr6sz AbstractDictionaryNSManager.keysN)r8r9r:r;r&r0r.r/r2r5r'r6rrrrrbsrbc@s eZdZdZeZddZdS)rzE:class:`.NamespaceManager` that uses a Python dictionary for storage.cKs"t||tj|jt|_dS)N)rbr#r
namespacesgetr!dictrd)r"r!kwargsrrrr#szMemoryNamespaceManager.__init__N)r8r9r:r;utilZSyncDictrfr#rrrrrsc@seZdZdZd"ddZddZdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
ddZddZddZddZd d!ZdS)#rz?:class:`.NamespaceManager` that uses ``dbm`` files for storage.NTcKs||_|s|stdn|r$||_n
|d|_t|j|sL|sLtdn|rX||_n
|d|_t|j|ptt|_d|_t	
||tj|j|jgd|jd|_
td|j
|dS)Nzdata_dir or dbm_dir is requiredz/container_dbmz data_dir or lock_dir is requiredz/container_dbm_lockz.dbm)rootidentifiers	extensiondigest_filenameszdata file %s)rnr	dbm_dirrjverify_directorylock_dirr	dbmmoduledbmrr#encoded_pathr!filer
_checkfile)r"r!rrdata_dirrorqrnrirrrr#s,




zDBMNamespaceManager.__init__cCst|j|jdS)N)rcrq)rr!rq)r"rrrr=sz#DBMNamespaceManager.get_access_lockcCstd|j|f|jdS)Nzdbmcontainer/funclock/%s/%s)rcrq)rr!rq)r"r%rrrr&s
z%DBMNamespaceManager.get_creation_lockcCs@t|tjrdSx(dD] }t|tj|tjrdSqWdS)NT)dbdatpagdirF)osaccessF_OKextsep)r"ruextrrrfile_exists$s
zDBMNamespaceManager.file_existscCs&tj|}tj|s"t|dS)N)r|pathdirnameexistsrjrp)r"filenamerrrr
_ensuredir.szDBMNamespaceManager._ensuredircCs4||js0||j|j|jd}|dS)NrI)rrurrrrGrH)r"grrrrv3szDBMNamespaceManager._checkfilecCsbg}t|jtjr ||jx<dD]4}t|jtj|tjr&||jtj|q&W|S)N)rzr{rxry)r|r}rur~appendr)r"listrrrr
get_filenames9s
z!DBMNamespaceManager.get_filenamescCsNtd|jy|j|j||_Wn&||j|j||_YnXdS)Nzopening dbm file %s)rrurrrGrsrv)r"rBr+rrrrCCszDBMNamespaceManager.do_opencCs$|jdk	r td|j|jdS)Nzclosing dbm file %s)rsrrurH)r"rrrrDKs
zDBMNamespaceManager.do_closecCs x|D]}t|q
WdS)N)rr|r7)r"frrrr'PszDBMNamespaceManager.do_removecCst|j|S)N)rloadsrs)r"r%rrrr0TszDBMNamespaceManager.__getitem__cCs&tdkrt|tr|d}||jkS)N)r\zUTF-8)r
isinstancerencoders)r"r%rrrr.Ws

z DBMNamespaceManager.__contains__cCst||j|<dS)N)rdumpsrs)r"r%r1rrrr2_szDBMNamespaceManager.__setitem__cCs|j|=dS)N)rs)r"r%rrrr5bszDBMNamespaceManager.__delitem__cCs
|jS)N)rsr6)r"rrrr6eszDBMNamespaceManager.keys)NNNNT)r8r9r:r;r#r=r&rrrvrrCrDr'r0r.r2r5r6rrrrrs$
 

c@sreZdZdZdddZddZdd	Zd
dZdd
ZddZ	ddZ
ddZddZddZ
ddZddZdS)rz:class:`.NamespaceManager` that uses binary files for storage.

    Each namespace is implemented as a single file storing a
    dictionary of key/value pairs, serialized using the Python
    ``pickle`` module.

    NTcKs||_|s|stdn|r$||_n
|d|_t|j|sL|sLtdn|rX||_n
|d|_t|jt||tj|j|j	gd|jd|_
i|_td|j
dS)Nz data_dir or file_dir is requiredz/container_filez data_dir or lock_dir is requiredz/container_file_lockz.cache)rkrlrmrnzdata file %s)
rnr	file_dirrjrprqrr#rtr!ruhashr)r"r!rwrrqrnrirrrr#qs(



zFileNamespaceManager.__init__cCst|j|jdS)N)rcrq)rr!rq)r"rrrr=sz$FileNamespaceManager.get_access_lockcCstd|j|f|jdS)Nzdbmcontainer/funclock/%s/%s)rcrq)rr!rq)r"r%rrrr&s
z&FileNamespaceManager.get_creation_lockcCst|tjS)N)r|r}r~)r"rurrrrsz FileNamespaceManager.file_existsc
Csz|sp||jrpy(t|jd}t||_WdQRXWn6tk
rn}z|jtjtj	gkr^Wdd}~XYnX||_
dS)Nrb)rrurGrloadrIOErrorerrnoEACCESENOENTrB)r"rBr+ZfherrrrCszFileNamespaceManager.do_opencCs>|jdks|jdkr.t|j}t|j|i|_d|_dS)NrIw)rBrrrrjZ
safe_writeru)r"ZpickledrrrrDs
zFileNamespaceManager.do_closecCs0yt|jWntk
r$YnXi|_dS)N)r|r7ruOSErrorr)r"rrrr's
zFileNamespaceManager.do_removecCs
|j|S)N)r)r"r%rrrr0sz FileNamespaceManager.__getitem__cCs
||jkS)N)r)r"r%rrrr.sz!FileNamespaceManager.__contains__cCs||j|<dS)N)r)r"r%r1rrrr2sz FileNamespaceManager.__setitem__cCs|j|=dS)N)r)r"r%rrrr5sz FileNamespaceManager.__delitem__cCs
|jS)N)rr6)r"rrrr6szFileNamespaceManager.keys)NNNT)r8r9r:r;r#r=r&rrCrDr'r0r.r2r5r6rrrrris

	c@seZdZddZdddZdS)
ContainerMetacCs|jt|<t||||S)N)namespace_classnamespace_classestyper#)r	classnamebasesZdict_rrrr#s
zContainerMeta.__init__Nc
Ks@||kr||}nt|}	|	|f|||<}t|||||dS)N)rLr3rN)rr)
r"r%contextr!rLr3rNrinsZnsclsrrr__call__s
zContainerMeta.__call__)NNN)r8r9r:r#rrrrrrsrc@seZdZdZeZdS)rzImplements synchronization and value-creation logic
    for a 'value' stored in a :class:`.NamespaceManager`.

    :class:`.Container` and its subclasses are deprecated.   The
    :class:`.Value` class is now used for this purpose.

    N)r8r9r:r;rrrrrrrsc@seZdZeZdS)rN)r8r9r:rrrrrrrsc@seZdZeZdS)rN)r8r9r:rrrrrrrsc@seZdZeZdS)rN)r8r9r:rrrrrrrs).r;r_compatrrrrrZbeaker.utilrjZloggingr|rYZbeaker.exceptionsrr	Zbeaker.synchronizationr
rrr
r__all__Z	getLoggerloggerZisEnabledForDEBUGrobjectrrrrbrrrrrhrrrrrrrZDbmContainerrrrr<module>sF
V$6vd