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

[B@sdZddlZddlZddlZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
mZyddlZWnek
rtddlZYnXddlmZmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl!m"Z"ddlm#Z$d	Z%d
ddd
dddgZ&ddZ'dAddZ(ddZ)ddZ*ddZ+dBddZ,ddZ-Gdd
d
e.Z/Gd dde.Z0Gd!dde0Z1da2dCd$d
Z3d%d&Z4d'd(Z5d)d*Z6d+d,Z7d-d.Z8d/d0Z9dDd1d2Z:d3d4Z;d5d6Z<Gd7d8d8e.Z=Gd9d:d:e.Z>d;dZ?d<dZ@d=d>ZAd?d@ZBdS)EzBeaker utilitiesN)
PY2string_typeunicode_textNoneTypedictkeyslistim_classim_funcpicklefunc_signaturedefault_im_func)datetime	timedelta)asbool)
exceptions)localThreadLocalWeakValuedRegistrySyncDictencoded_pathverify_directory	serializedeserializecCs
||_|S)zReturn a function with a given __name__.

    Will assign to __name__ and return the original function if possible on
    the Python implementation, otherwise a new function will be constructed.

    )__name__)fnnamer</opt/alt/python37/lib/python3.7/site-packages/beaker/util.pyfunction_named&srcs*pjddlmfdd}|S)z!Skip a test if predicate is true.r)SkipTestcs$jfdd}t|S)Ncs*rdf}|n
||SdS)Nz'%s' skipped: %sr)argskwmsg)r rfn_name	predicatereasonrrmaybe:s


z(skip_if.<locals>.decorate.<locals>.maybe)rr)rr')r r%r&)rr$rdecorate7szskip_if.<locals>.decorate)rnoser )r%r&r(r)r r%r&rskip_if1s
r*cOs<y|||d}Wn|k
r*d}YnX|s8tddS)zGAssert the given exception is raised by the given function + arguments.FTz#Callable did not raise an exceptionN)AssertionError)Z
except_clsZ	callable_r!r"successrrr
assert_raisesEs

r-cCsJd}x@t|tjsDy|d7}t|Wq|dkr<YqXqWdS)zcverifies and creates a directory.  tries to
    ignore collisions with other threads and processes.rrN)osaccessF_OKmakedirs)dirZtriesrrrrRscCs*tt|j}|r"|ddkr"dSdSdS)z8Return True if the given function has a 'self' argument.r)selfclsTFN)listr
parameters)funcr!rrrhas_self_arg`sr9cCs0t|trtj|tj|dntj||ddS)zIssue a warning.)
stacklevelN)
isinstancerwarningswarnrZ
BeakerWarning)r#r;rrrr>is
r>csfdd}|S)Ncs*fdd}j|_djf|_|S)Ncsttd||S)N)r=r>DeprecationWarning)r!Zkargs)rmessagerrdeprecated_methodssz6deprecated.<locals>.wrapper.<locals>.deprecated_methodz%s

%s)r__doc__)rrB)rA)rrwrapperrszdeprecated.<locals>.wrapperr)rArDr)rAr
deprecatedqsrEc@s>eZdZdZdZddZddZddZdd
dZdd
Z	d	S)rz$stores a value on a per-thread basis_tlocalcCst|_dS)N)rF)r4rrr__init__szThreadLocal.__init__cCs||j_dS)N)rFvalue)r4rHrrrputszThreadLocal.putcCst|jdS)NrH)hasattrrF)r4rrrhasszThreadLocal.hasNcCst|jd|S)NrH)getattrrF)r4defaultrrrgetszThreadLocal.getcCs
|j`dS)N)rFrH)r4rrrremoveszThreadLocal.remove)N)
r
__module____qualname__rC	__slots__rGrIrKrNrOrrrrr}s
c@s`eZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZddZ
dS)ra
    An efficient/threadsafe singleton map algorithm, a.k.a.
    "get a value based on this key, and create if not found or not
    valid" paradigm:

        exists && isvalid ? get : create

    Designed to work with weakref dictionaries to expect items
    to asynchronously disappear from the dictionary.

    Use python 2.3.3 or greater !  a major bug was just fixed in Nov.
    2003 that was driving me nuts with garbage collection/weakrefs in
    this section.

    cCst|_i|_dS)N)
_threadingLockmutexdict)r4rrrrGs
zSyncDict.__init__cOsVy,||jkr|j|S|j||f||SWn$tk
rP|j||f||SXdS)N)rVsync_getKeyError)r4key
createfuncr!kwargsrrrrNs

zSyncDict.getcOsr|jzVy,||jkr"|j|S|j||f||SWn$tk
r\|j||f||SXWd|jXdS)N)rUacquirerV_createrXrelease)r4rYrZr!r[rrrrWs


zSyncDict.sync_getcOs|||||<}|S)Nr)r4rYrZr!r[objrrrr]szSyncDict._createcCs
||jkS)N)rV)r4rYrrrhas_keyszSyncDict.has_keycCs|j|S)N)rV__contains__)r4rYrrrraszSyncDict.__contains__cCs|j|S)N)rV__getitem__)r4rYrrrrbszSyncDict.__getitem__cCs|j||dS)N)rV__setitem__)r4rYrHrrrrcszSyncDict.__setitem__cCs|j|S)N)rV__delitem__)r4rYrrrrdszSyncDict.__delitem__cCs|jdS)N)rVclear)r4rrrreszSyncDict.clearN)rrPrQrCrGrNrWr]r`rarbrcrdrerrrrrs	
c@seZdZddZdS)rcCst|_t|_dS)N)rSRLockrUweakrefWeakValueDictionaryrV)r4rrrrGs
zWeakValuedRegistry.__init__N)rrPrQrGrrrrrs.encTc	Csd|}tdkrddlma|rLt|tr@t|d}nt|}tj	|}g}x$t
d|D]}||d|qhWtjj|f|}t|tj|||S)zsGenerate a unique file-accessible path from the given list of
    identifiers starting at the given root directory._Nr)sha1zutf-8r)
joinrkZ
beaker.cryptor<rencode	hexdigestr/pathbasenamerangeappendr)	rootZidentifiers	extensiondepthZdigest_filenamesidenttokensdr3rrrrs

cCs8t|tr|St|tr,td|r,t|StddS)Nz^\d+$zThis is not a proper int)r<intrrematch	Exception)r_rrrasints

r}cCst||st|ts|f}d}x|D]}yn|ttfkrLdd|dD}nD|tkrZt}n.|tkrht}n |tt	fkrt||st
d|||}d}WnYnX|r$Pq$W|st
|nt|tr|st
d||S)NFcSsg|]}|qSr)strip).0xrrr
<listcomp>	sz"verify_options.<locals>.<listcomp>,z%s requires a timedelta typeTz!Empty strings are invalid for: %s)
r<tupler6splitboolrryr}rr
r|strr~)opttypeserrorZcoercedtyprrrverify_optionss4





rcCs4x.|D]&\}}}||krt||||||<qW|S)N)r)paramsZrulesetrYrrArrrverify_rulessrcCsPdttfdfdttfdfdttfdfdttttfdfd	ttfd
fdttfdfd
tfdfdtfdfdttfdfdttfdfdttfdfdttfdfdttfdfdttfdfdttfdfdttfd fd!ttfd"fd#ttfd$fd%tfd&fg}t||}|d}|r&t|tr&t|ts&t|d'|d<|ddk	rL|dd(sLt	d)|S)*Ndata_dirz3data_dir must be a string referring to a directory.lock_dirz3lock_dir must be a string referring to a directory.typezSession type must be a string.cookie_expireszGCookie expires was not a boolean, datetime, int, or timedelta instance.Z
cookie_domainzCookie domain must be a string.Zcookie_pathzCookie path must be a string.idzSession id must be a string.rYzSession key must be a string.Zsecretz Session secret must be a string.Zvalidate_keyz%Session encrypt_key must be a string.Zencrypt_keyz&Session validate_key must be a string.Zencrypt_nonce_bitsz+Session encrypt_nonce_bits must be a numberZsecurez!Session secure must be a boolean.Zhttponlyz#Session httponly must be a boolean.timeoutz#Session timeout must be an integer.Zsave_accessed_timez@Session save_accessed_time must be a boolean (defaults to true).autozSession is created if accessed.Zwebtest_varnamez!Session varname must be a string.Zdata_serializerz!data_serializer must be a string.)secondsTz.save_accessed_time must be true to use timeout)
rrrr
rryrrNr<r|)rrulesoptsrrrrcoerce_session_params&s:



rc	Csbdttfdfdttfdfdtfdfdttfdfd	ttfd
fdtttfdfd
ttfdfg}t||S)Nrz3data_dir must be a string referring to a directory.rz3lock_dir must be a string referring to a directory.rzCache type must be a string.enabledz&enabled must be true/false if present.expirezNexpire must be an integer representing how many seconds the cache is valid forregionsz7Regions must be a comma separated list of valid regions
key_lengthzUkey_length must be an integer which indicates the longest a key can be before hashing)rrrryr6rr)rrrrrcoerce_cache_paramsJs

rcCs>dttfdfdttfdfdtfdfdtfdfd	tfd
fdtfdfd
ttfdfdtfdfdttfdfdtfdfdttfdfdttfdfdttfdfdttfdfdttfdfdtfd fd!ttfd"fd#tfd$fd%tfd&fd'tfd(fd)ttfd*fd+tfd,fd-tfd.fd/tfd0fd1tfd2fd3tfd4fd5ttfd6fd7tfd8fg}t||S)9NZcasz#cas must be a boolean or an integerZno_blockz(no_block must be a boolean or an integerZreceive_timeoutz"receive_timeout must be an integerZsend_timeoutzsend_timeout must be an integerZketama_hashzHketama_hash must be a string designating a valid hashing strategy optionZ
_poll_timeoutz _poll_timeout must be an integerZ
auto_ejectzauto_eject must be an integerZ
retry_timeoutz retry_timeout must be an integerZ_sort_hostsz_sort_hosts must be an integerZ_io_msg_watermarkz$_io_msg_watermark must be an integerZketamaz&ketama must be a boolean or an integerZketama_weightedz/ketama_weighted must be a boolean or an integerZ_io_key_prefetchz0_io_key_prefetch must be a boolean or an integerZ_hash_with_prefix_keyz5_hash_with_prefix_key must be a boolean or an integerZtcp_nodelayz+tcp_nodelay must be a boolean or an integerZ
failure_limitz failure_limit must be an integerZbuffer_requestsz/buffer_requests must be a boolean or an integerZ_socket_send_sizez$_socket_send_size must be an integerZnum_replicasznum_replicas must be an integerZ
remove_failedz remove_failed must be an integerZ_noreplyz(_noreply must be a boolean or an integerZ_io_bytes_watermarkz&_io_bytes_watermark must be an integerZ_socket_recv_sizez$_socket_recv_size must be an integerdistributionzEdistribution must be a string designating a valid distribution optionZconnect_timeoutz"connect_timeout must be an integerhashz8hash must be a string designating a valid hashing optionZverify_keysz+verify_keys must be a boolean or an integerZdead_timeoutzdead_timeout must be an integer)rryrr)	behaviorsrrrrcoerce_memcached_behaviorsZs@












rcCs@|rtddddd}ni}xH|D]<\}}|drF|||dd<|dr$|||dd<q$Wt|d|kr|rd	|d<|d
d}|r<i}x|D]}|sqt|d|d|d
|d|d|dtd}d|}	t|	}
x0t|D]$}||	r|||||
d<qWt||||<qW||d<|S)zJParse configuration options and validate for use with the
    CacheManagerZmemoryN)rrrZlog_filez
beaker.cache.
zcache.rTrrrrrr)rrrrrrz%s.Z
cache_regions)	rVitems
startswithrpoprNDEFAULT_CACHE_KEY_LENGTHlenr)configZinclude_defaultsoptionsrYvalrZregion_configsZregionZregion_optionsZ
region_prefixZ
region_lenrrrparse_cache_config_optionssB





rcCs@i}x.|D]"\}}|dr|||dd<qWt||S)zParse behavior options and validate for use with pylibmc
    client/PylibMCNamespaceManager, or potentially other memcached
    NamespaceManagers that support behaviorsz	behavior.	N)rrr)rrrYrrrrparse_memcached_behaviorss
rcCsTd}t|dst|dr(t|}t|}|r<d|j|jfSdt||jfSdS)z+Generates a unique namespace for a functionNr	__func__z%s.%sz%s|%s)rJrr	rPrinspect
getsourcefile)r8Zklsrrrfunc_namespacesrc@seZdZddZddZdS)PickleSerializercCs
t|S)N)r
loads)r4data_stringrrrrszPickleSerializer.loadscCst|dS)Nr?)r
dumps)r4datarrrrszPickleSerializer.dumpsN)rrPrQrrrrrrrsrc@seZdZddZddZdS)JsonSerializercCstt|dS)Nzutf-8)jsonrzlib
decompressdecode)r4rrrrrszJsonSerializer.loadscCstt|dS)Nzutf-8)rcompressrrrm)r4rrrrrszJsonSerializer.dumpsN)rrPrQrrrrrrrsrcCs |dkrt}nt}||S)Nr)rrr)rmethod
serializerrrrrscCs |dkrt}nt}||S)Nr)rrr)rrrrrrrscCsJt}ts |tn|tt|	dd
dS)Nrr:ascii)hashlibmd5rupdatesocketgethostnamermbinasciihexlifydigestr)Zmachine_hashrrrmachine_identifiers
rcCs\tjdkr<d|}t|d}|||t||nt|d}|||dS)Nposixz%s.tempwb)r/ropenwritecloserename)filepathcontentstempnameZfhrrr
safe_writes




r)N)r:)rir:T)T)CrCrrr_compatrrrrrrr	r
rr	threadingrSImportErrorZdummy_threadingr
rr/rzstringrrgr=sysrrrZbeaker.convertersrbeakerrrrFr__all__rr*r-rr9r>rEobjectrrrrkrr}rrrrrrrrrrrrrrrrrr<module>sl0

	
A
	$%
.