Files
intellecton/venv/lib/python3.12/site-packages/jinja2/__pycache__/bccache.cpython-312.pyc
T

177 lines
19 KiB
Plaintext
Raw Normal View History

Ë
LÀ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 úQ/home/antigravity/intellecton/venv/lib/python3.12/site-packages/jinja2/bccache.pyÚgetz_MemcachedClient.getó�ó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+r7Úwriter1r2Údumpr&r4)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)r9r)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ÚBinaryIOr9ÚIOrr=r@rDrrrr$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©rrKs rr9zBytecodeCache.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.
rMrOs rÚ
dump_bytecodezBytecodeCache.dump_bytecode‹rPrcó—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’rrÚnameÚfilenamecóž—t|jd««}|�"|jd|›�j««|j«S)z3Returns the unique hash key for this template name.úutf-8ú|)rÚencodeÚupdateÚ hexdigest)rrUrVÚ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.rX)rrZr\)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^rar$r9)rr%rUrVr_r
r&rKs rÚ
get_bucketzBytecodeCache.get_bucket§sG€ð× Ñ   xÓ0ˆØ×+Ñ+¨FÓ3ˆÜ˜  S¨(Ó3ˆØ ×ј6Ô"؈
rcó&—|j|«y)zPut the bucket into the cache.N)rRrOs rÚ
set_bucketzBytecodeCache.set_bucket·s€à ×ј6Õ"rrEr
)rrrrFr$r9rRrTrrrÚUnionr^rarcrerrrrJrJgsÉ„ñð8$ Fð$¨tó$ð$ Fð$¨tó$ó ð?Cñ  Øð  Ø#$§:¡:¨a¯g©g°c©lÑ#;ð  à ó  ð8¨#ð8°#ó8ðà"ðððð—*‘*˜S‘/ð ð
ð ð
ó
ð # ð#¨Dô#rrJcó†—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_dirrirj)rrirjs 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ÚosrUÚhasattrrrÚpathÚjoinÚmkdirÚstatÚS_IRWXUÚOSErrorÚerrnoÚEEXISTÚchmodÚlstatÚst_uidÚS_ISDIRÚst_modeÚS_IMODE)rrpÚtmpdirÚdirnameÚ
actual_dirÚeÚactual_dir_stats rrlz.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ÉIrKcó†—tjj|j|j|j
fz«Sr
)rurwrxrirjr
rOs 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ÚPermissionErrorr9)rrKrVr-s rr9z%FileSystemBytecodeCache.load_bytecodesn€Ø×+Ñ+¨FÓ3ˆð Ü�X˜tÓ$ˆAð ñ $Ø × Ñ  Ô #÷ $ð $øô "Ô#4´oÐFò ñ
ð ú÷
 $ð $ú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
)ruÚremoverUr|)r-s€rÚ
remove_silentz<FileSystemBytecodeCache.dump_bytecode.<locals>.remove_silent$s,ø€ð
Ü— ‘ ˜!Ÿ&™&Õ!øÜò
ñð
ús ƒ#£ /®/rE) r‹rsÚNamedTemporaryFilerurwr†Úbasenamer=Ú
BaseExceptionÚreplacerUr|)rrKrUr›r-s @rrRz%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š)Ú*)
ruršÚfnmatchÚfilterÚlistdirrirjrwrxr|)rršÚfilesrVs rrTzFileSystemBytecodeCache.clear=sp€õ ä—‘œrŸz™z¨$¯.©.Ó9¸4¿<¹<È&Ñ;PÓQˆØò ˆHð
Ù”r—w‘w—|‘| D§N¡N°HÓ=Õ>ñ øôò
Ùð
úsÁ
0B B  B )Nz__jinja2_%s.cacherE)rrrrFrrrr)rlr$r‹r9rRrTrrrrhrh¼s‚„ñð$ATñØŸ™ C™ðØ:=ðà
óð-¨ó-ð^J¨&ðJ°SóJð
$ Fð
$¨tó
$ð$ Fð$¨tó$ôL rrhc ó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>`_