Files
intellecton/venv/lib/python3.12/site-packages/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"rddlZddlmZGdd ej,«Zd
Zd ej2ed «zej2ej4dd
zej4dzd «zZGdd«ZGdd«ZGdde«ZGdde«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 óReZdZdedefdZ ddededejeddfdZ y) Ú_MemcachedClientÚkeyÚreturncóy©)Úselfr
s úQ/home/antigravity/intellecton/venv/lib/python3.12/site-packages/jinja2/bccache.pyÚgetz_MemcachedClient.getóóvalueÚtimeoutcóyr
r)rr
rrs rÚsetz_MemcachedClient.setsàrr
)
Ú__name__Ú
__module__Ú __qualname__ÚstrÚbytesrÚOptionalÚintrrrrr r sCØ-˜- FJñ Øð Ø#(ð Ø34·:±:¸c±?ð à
ô rr ésj2éécóšeZdZdZdddededdfdZdd „Zd
ejddfd Z d
eje ddfd Z d
e ddfdZ
de fdZy)Ú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›ˆDIøÜœ*¤iÐ Ø 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Ð ÜÐ  ÔÜ D—M‘M 1 aÔ T—YY Õ"rÚstringcó8|jt|««y)zLoad bytecode from bytes.N)r9r)rr>s rÚbytecode_from_stringzBucket.bytecode_from_string\sà ×Ñœ7 6›?Õ+rcóXt«}|j|«|j«S)zReturn the bytecode as bytes.)rr=Úgetvalue)rÚouts rÚbytecode_to_stringzBucket.bytecode_to_string`s#äØ ×ј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ó rr$c
óÚeZdZdZdeddfdZdeddfdZddZ dded e je jedefd
Z d edefd Z
d
dded e jed edef
dZdeddfdZy)Ú
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_bytecoderPrcó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.clearrrÚ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˜:˜× ~‰~ÓÐrÚsourcecóRt|jd««j«S)z"Returns a checksum for the source.rX)rrZr\)rr_s rÚget_source_checksumz!BytecodeCache.get_source_checksum£säF—MM +×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ÓØ×+¨FÓܘ  S¨(ÓØ ×ј6Ôˆ
rcó&|j|«y)zPut the bucket into the cache.N)rRrOs rÚ
set_bucketzBytecodeCache.set_bucket·sà ×ј"rrEr
)rrrrFr$r9rRrTrrrÚUnionr^rarcrerrrrJrJgñð8$ Fð$¨tó$ $¨tó ð?Cñ  Øð  Ø#$§:¡:¨a¯g©g°c©lÑ#;ð  à ó  ð8¨#ð8°#óàððð—*‘*˜S‘/ð ð
ð ð
ó
ð # ð#¨Dô#rrJcó†eZdZdZ d
dej
ededdfdZdefdZde 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&ð Ð Ø×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)}|jtjk7rYd}~Œld}~wwxYw#t$r(}|jtjk7rYd}~Œï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Üðð
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Úactual_dir_stats rrlz.FileSystemBytecodeCache._get_default_cache_dirÖsó ô ×&ˆô 7‰7dŠ?؈MÜ”r˜ ŒMà"¤2§9¡9£; 0ˆÜ—WW—\\ &¨'Ó2ˆ
ð Ü H‰H§¡Ô  Ü H‰H§¡Ô  Ÿh™h 2ˆ×&¬"¯)©)«+Ò—|| O×$;Ñ$;Ô—<< × 7Ñ 7Ó8¼D¿L¹LÒ
ô
Ÿ(™( .ˆà × "¤b§i¡i£kÒ —<< × 7Ñ 7Ô|‰|˜O׿ ¹ Ò Œ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ÓIrcóÄ|j|«} t|d«}|5|j |«ddd«y#tttf$rYywxYw#1swYyxYw)rb)rÚopenÚFileNotFoundErrorÚIsADirectoryErrorÚPermissionErrorr9)rrKrVr-s rr9z%FileSystemBytecodeCache.load_bytecodesnØ×+¨FÓð ÜX˜tÓ$ˆAð ñ × Ñ  Ô  $øô "Ô#4´ ñ
ð ú÷
 $ús <¡A¼AÁAÁAcóæ|j|«}tjdtjj |«tjj
|«dd¬«Šdˆfd } 5|j«ddd« tjj|«y#1swYŒ+xYw#t$r |«wxYw#t$r
|«Yyt$r |«wxYw)wbz.tmpF)ÚmodeÚdirÚprefixÚsuffixÚdeletecód tjj«y#t$rYywxYwr
)ruÚremoverUr|)r-s€rÚ
remove_silentz<FileSystemBytecodeCache.dump_bytecode.<locals>.remove_silent$s,ø€ð
Ü ˜!Ÿ&™&Õ!øÜò
ñð
ús ƒ#£ /®/rE) rrsÚNamedTemporaryFilerurwr†Úbasenamer=Ú
BaseExceptionÚreplacerUr|)rrKrUrr-s @rrRz%FileSystemBytecodeCache.dump_bytecodeø€ð×Ó/ˆÜ × Ü Ó—7‘7×# DÓØô 
ˆõ ð Øñ
×% 
 Ü J‰Jq—vv˜ 

)ûäò Ù Œ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))Ú*)
ruÚfnmatchÚfilterÚlistdirrirjrwrxr|)rÚfilesrVs rrTzFileSystemBytecodeCache.clear=spõ äœrŸz™z¨$¯.©.Ó9¸4¿<¹<È&Ñ;PÓQˆØò ˆ
Ù”r—w‘w—|| D§N¡N°HÓ øôò
Ùð
úsÁ
0B B  B )Nz__jinja2_%s.cacherE)rrrrFrrrr)rlr$rr9rRrTrrrrhrh¼sñð$ATñØŸ C™ðØ:=ðà
óð-¨ó-ð^J¨&ðJ°SóJð
$ 
$¨tó
$ $¨tó$ôL rrhc ójeZdZdZ d
dddedej edefdZ 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>`_