Files
cms-website/.deps_siteforge_v812/jinja2/__pycache__/bccache.cpython-312.pyc
T

177 lines
19 KiB
Plaintext
Raw Normal View History

Ë
íÅÙjí6ãó¶—dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z
ddl m Z ddl
mZddlmZe
j"rddlZddlmZGd„d ej,«Zd
Zd ej2ed «zej2ej4dd
zej4dzd «zZGd„d«ZGd„d«ZGd„de«ZGd„de«Zy)a The optional bytecode cache system. This is useful if you have very
complex template situations and the compilation of all those templates
slows down your application too much.
Situations where this is useful are often forking web applications that
are initialized on the first request.
éN)Úsha1)ÚBytesIO)ÚCodeTypeé)Ú Environmentc óR—eZdZdedefd„Z ddededejeddfd„Z y) Ú_MemcachedClientÚkeyÚreturncó—y©N©)Úselfr
s úRC:\Users\30997\AppData\Local\Temp\pip-target-6g32zz5s\lib\python\jinja2/bccache.pyÚgetz_MemcachedClient.gets€¨#óNÚvalueÚtimeoutcó—yr
r)rr
rrs rÚsetz_MemcachedClient.sets€àrr
)
Ú__name__Ú
__module__Ú __qualname__ÚstrÚbytesrÚtÚOptionalÚintrrrrr r sC„Ø-˜3Ð- 5Ó-ðFJñ Øð Ø#(ð Ø34·:±:¸c±?ð à
ô rr ésj2éécóš—eZdZdZdddededdfd„Zdd „Zd
ejddfd „Z d
eje ddfd „Z d
e ddfd„Z
de fd„Zy)ÚBucketauBuckets are used to store the bytecode for one template. It's created
and initialized by the bytecode cache and passed to the loading functions.
The buckets get an internal checksum from the cache assigned and use this
to automatically reject outdated cache material. Individual bytecode
cache subclasses don't have to care about cache invalidation.
Ú environmentrr
Úchecksumr NcóN—||_||_||_|j«yr
)r$r
r%Úreset)rr$r
r%s rÚ__init__zBucket.__init__7s!€Ø&ˆÔ؈ŒØ ˆŒ
Ø �
‰
� rcó—d|_y)z)Resets the bucket (unloads the bytecode).N)Úcode©rs rr'z Bucket.reset=s €à*.ˆ� rÚfcóh—|jtt««}|tk7r|j«yt j
|«}|j |k7r|j«y tj
|«|_y#tttf$r|j«YywxYw)z/Loads bytecode from a file or file like object.N) ÚreadÚlenÚbc_magicr'ÚpickleÚloadr%Úmarshalr*ÚEOFErrorÚ
ValueErrorÚ TypeError)rr,Úmagicr%s rÚ
load_bytecodezBucket.load_bytecodeAs…€ð—‘”sœ8“}Ó%ˆØ ”HÒ Ø �J‰JŒLØ ä—;‘;˜q“>ˆØ �=‰=˜HÒ $Ø �J‰JŒLØ ð ÜŸ ™  Q›ˆD�IøÜœ*¤iÐ0ò Ø �J‰JŒLÙ ð úsÁ/B
Â
$B1Â0B1cóÞ—|j€ td«‚|jt«t j
|j |d«tj
|j|«y)z;Dump the bytecode into the file or file like object passed.Nzcan't write empty bucketr )r*r6Úwriter0r1Údumpr%r3)rr,s rÚwrite_bytecodezBucket.write_bytecodeTsJ€à �9‰9Ð ÜÐ6Ó7Ð 7Ø �‰”ÔÜ� ‰ �D—M‘M 1 aÔ(Ü� ‰ �T—Y‘Y Õ"rÚstringcó8—|jt|««y)zLoad bytecode from bytes.N)r8r)rr=s rÚbytecode_from_stringzBucket.bytecode_from_string\s€à ×Ñœ7 6›?Õ+rcóX—t«}|j|«|j«S)zReturn the bytecode as bytes.)rr<Úgetvalue)rÚouts rÚbytecode_to_stringzBucket.bytecode_to_string`s#€ä‹iˆØ ×јCÔ Ø�|‰|‹~Ðr©r N)rrrÚ__doc__rr(r'rÚBinaryIOr8ÚIOrr<r?rCrrrr#r#.s~„ñð Mð¸ðÀsðÈtóó /ð˜qŸz™zð¨dóð&# §¡ U¡ ð#°ó#ð,¨5ð,°Tó,ð Eôrr#c
óÚ—eZdZdZdeddfd„Zdeddfd„Zdd„Z dded e je jedefd
„Z d edefd „Z
d
dded e jed edef
d„Zdeddfd„Zy)Ú
BytecodeCacheaÞTo implement your own bytecode cache you have to subclass this class
and override :meth:`load_bytecode` and :meth:`dump_bytecode`. Both of
these methods are passed a :class:`~jinja2.bccache.Bucket`.
A very basic bytecode cache that saves the bytecode on the file system::
from os import path
class MyCache(BytecodeCache):
def __init__(self, directory):
self.directory = directory
def load_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
if path.exists(filename):
with open(filename, 'rb') as f:
bucket.load_bytecode(f)
def dump_bytecode(self, bucket):
filename = path.join(self.directory, bucket.key)
with open(filename, 'wb') as f:
bucket.write_bytecode(f)
A more advanced version of a filesystem based bytecode cache is part of
Jinja.
Úbucketr Ncó—t«‚)z¹Subclasses have to override this method to load bytecode into a
bucket. If they are not able to find code in the cache for the
bucket, it must not do anything.
©ÚNotImplementedError©rrJs rr8zBytecodeCache.load_bytecode„ó
€ô
"Ó#Ð#rcó—t«‚)zÀSubclasses have to override this method to write the bytecode
from a bucket back to the cache. If it unable to do so it must not
fail silently but raise an exception.
rLrNs rÚ
dump_bytecodezBytecodeCache.dump_bytecode‹rOrcó—y)zºClears the cache. This method is not used by Jinja but should be
implemented to allow applications to clear the bytecode cache used
by a particular environment.
Nrr+s rÚclearzBytecodeCache.clear’s�rÚnameÚfilenamecóž—t|jd««}|�"|jd|›�j««|j«S)z3Returns the unique hash key for this template name.úutf-8Ú|)rÚencodeÚupdateÚ hexdigest)rrTrUÚhashs rÚ
get_cache_keyzBytecodeCache.get_cache_key˜sE€ô�D—K‘K Ó(Ó)ˆà Ð Ø �K‰K˜!˜H˜:˜×-Ñ-Ó/Ô 0à�~‰~ÓÐrÚsourcecóR—t|jd««j«S)z"Returns a checksum for the source.rW)rrYr[)rr^s rÚget_source_checksumz!BytecodeCache.get_source_checksum£s€ä�F—M‘M 'Ó*Ó+×5Ñ5Ó7Ð7rr$rcóˆ—|j||«}|j|«}t|||«}|j|«|S)zwReturn a cache bucket for the given template. All arguments are
mandatory but filename may be `None`.
)r]r`r#r8)rr$rTrUr^r
r%rJs rÚ
get_bucketzBytecodeCache.get_bucket§sG€ð× Ñ   xÓ0ˆØ×+Ñ+¨FÓ3ˆÜ˜  S¨(Ó3ˆØ ×ј6Ô"؈
rcó&—|j|«y)zPut the bucket into the cache.N)rQrNs rÚ
set_bucketzBytecodeCache.set_bucket·s€à ×ј6Õ"rrDr
)rrrrEr#r8rQrSrrrÚUnionr]r`rbrdrrrrIrIgsÉ„ñð8$ Fð$¨tó$ð$ Fð$¨tó$ó ð?Cñ  Øð  Ø#$§:¡:¨a¯g©g°c©lÑ#;ð  à ó  ð8¨#ð8°#ó8ðà"ðððð—*‘*˜S‘/ð ð
ð ð
ó
ð # ð#¨Dô#rrIcó†—eZdZdZ d
dej
ededdfd„Zdefd„Zde defd „Z
de ddfd
„Z de ddfd „Z dd „Z
y)ÚFileSystemBytecodeCacheaïA bytecode cache that stores bytecode on the filesystem. It accepts
two arguments: The directory where the cache items are stored and a
pattern string that is used to build the filename.
If no directory is specified a default cache directory is selected. On
Windows the user's temp directory is used, on UNIX systems a directory
is created for the user in the system temp directory.
The pattern can be used to have multiple separate caches operate on the
same directory. The default pattern is ``'__jinja2_%s.cache'``. ``%s``
is replaced with the cache key.
>>> bcc = FileSystemBytecodeCache('/tmp/jinja_cache', '%s.cache')
This bytecode cache supports clearing of the cache using the clear method.
NÚ directoryÚpatternr cóD—|€|j«}||_||_yr
)Ú_get_default_cache_dirrhri)rrhris rr(z FileSystemBytecodeCache.__init__Îs&€ð Ð Ø×3Ñ3Ó5ˆIØ"ˆŒØˆ� rcó’—dd„}tj«}tjdk(r|St td«s|«dtj
«›�}tj j||«} tj|tj« tj|tj«tj|«}|j tj
«k7sOtj"|j$«r0tj&|j$«tjk7r|«tj|«}|j tj
«k7sOtj"|j$«r0tj&|j$«tjk7r|«|S#t$r)}|jtjk7r‚Yd}~�Œld}~wwxYw#t$r(}|jtjk7r‚Yd}~Œïd}~wwxYw)Ncó—td«‚)NzJCannot determine safe temp directory. You need to explicitly provide one.)Ú RuntimeErrorrrrÚ _unsafe_dirzCFileSystemBytecodeCache._get_default_cache_dir.<locals>._unsafe_dir×s€Üð2óð
rÚntÚgetuidz_jinja2-cache-)r z te.NoReturn)ÚtempfileÚ
gettempdirÚosrTÚhasattrrqÚpathÚjoinÚmkdirÚstatÚS_IRWXUÚOSErrorÚerrnoÚEEXISTÚchmodÚlstatÚst_uidÚS_ISDIRÚst_modeÚS_IMODE)rroÚtmpdirÚdirnameÚ
actual_dirÚeÚactual_dir_stats rrkz.FileSystemBytecodeCache._get_default_cache_dirÖs�€ó ô ×$Ñ$Ó&ˆô �7‰7�dŠ?؈MÜ”r˜8Ô$Ù ŒMà"¤2§9¡9£; -Ð0ˆÜ—W‘W—\‘\ &¨'Ó2ˆ
ð Ü �H‰H�Z¤§¡Ô .ð Ü �H‰H�Z¤§¡Ô .Ü Ÿh™h zÓ2ˆOà×&Ñ&¬"¯)©)«+Ò5Ü—|‘| O×$;Ñ$;Ô<Ü—<‘< × 7Ñ 7Ó8¼D¿L¹LÒHá”
ô
Ÿ(™( :Ó.ˆà × "Ñ "¤b§i¡i£kÒ 1Ü—<‘< × 7Ñ 7Ô8Ü�|‰|˜O×3Ñ3Ó4¼¿ ¹ ÒDá ŒMàÐøô1ò Ø�w‰wœ%Ÿ,™,Ò&Øõ'ûð ûôò Ø�w‰wœ%Ÿ,™,Ò&Øô'ûð ús1Á=$G Â"B0HÇ HÇ)H
È
HÈ IÈIÉIrJcó†—tjj|j|j|j
fz«Sr
)rtrvrwrhrir
rNs rÚ_get_cache_filenamez+FileSystemBytecodeCache._get_cache_filenames*€Ü�w‰w�|‰|˜DŸN™N¨D¯L©L¸F¿J¹J¸=Ñ,HÓIÐIrcóÄ—|j|«} t|d«}|5|j |«ddd«y#tttf$rYywxYw#1swYyxYw)NÚrb)rŠÚopenÚFileNotFoundErrorÚIsADirectoryErrorÚPermissionErrorr8)rrJrUr,s rr8z%FileSystemBytecodeCache.load_bytecodesc€Ø×+Ñ+¨FÓ3ˆð Ü�X˜tÓ$ˆAò Ø × Ñ  Ô #÷ˆQøô "Ô#4´oÐFò ñ
ð ú÷
ˆQús“ <¡A¼AÁAÁAc󿇗|j|«}tjdtjj |«tjj
|«dd¬«Šdˆfd„ } ‰5|j‰«ddd« tj‰j|«y#1swYŒ+xYw#t$r |«‚wxYw#t$r
|«Yyt$r |«‚wxYw)NÚwbz.tmpF)ÚmodeÚdirÚprefixÚsuffixÚdeletecód•— tj‰j«y#t$rYywxYwr
)rtÚremoverTr{)r,s€rÚ
remove_silentz<FileSystemBytecodeCache.dump_bytecode.<locals>.remove_silent$s,ø€ð
Ü— ‘ ˜!Ÿ&™&Õ!øÜò
ñð
ús ƒ#£ /®/rD) rŠrrÚNamedTemporaryFilertrvr…Úbasenamer<Ú
BaseExceptionÚreplacerTr{)rrJrTršr,s @rrQz%FileSystemBytecodeCache.dump_bytecodesÌø€ð×'Ñ'¨Ó/ˆÜ × 'Ñ 'ØÜ—‘—‘ Ó%Ü—7‘7×#Ñ# DÓ)ØØô 
ˆõ ð ÚØ×%Ñ% aÔ(÷ð  Ü �J‰J�q—v‘v˜tÕ $÷�ûäò Ù ŒOØ ð ûô ò ñ
ŽOÜò Ù ŒOØ ð ús6Á.B8Á0B,ÂB8Â C
Â,B5Â1B8Â8C
Ã
C0ÃC0có—ddlm}tjtj|j
«|j dz«}|D]3} |tjj|j
|««Œ5y#t$rYŒBwxYw)Nr)r™)Ú*)
rtr™ÚfnmatchÚfilterÚlistdirrhrirvrwr{)rr™ÚfilesrUs rrSzFileSystemBytecodeCache.clear=sk€õ ä—‘œrŸz™z¨$¯.©.Ó9¸4¿<¹<È&Ñ;PÓQˆÛˆHð
Ù”r—w‘w—|‘| D§N¡N°HÓ=Õ>ñøôò
Ùð
úsÁ
0B B  B )Nz__jinja2_%s.cacherD)rrrrErrrr(rkr#rŠr8rQrSrrrrgrg¼s‚„ñð$ATñØŸ™ C™ðØ:=ðà
óð-¨ó-ð^J¨&ðJ°SóJð
$ Fð
$¨tó
$ð$ Fð$¨tó$ôL rrgc ój—eZdZdZ d
dddedej edefd„Z d e
d
dfd „Z d e
d
dfd „Z y)ÚMemcachedBytecodeCachea'This class implements a bytecode cache that uses a memcache cache for
storing the information. It does not enforce a specific memcache library
(tummy's memcache or cmemcache) but will accept any class that provides
the minimal interface required.
Libraries compatible with this class:
- `cachelib <https://github.com/pallets/cachelib>`_
- `python-memcached <https://pypi.org/project/python-memcached/>`_
(Unfortunately the django cache interface is not compatible because it
does not support storing binary data, only text. You can however pass