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

306 lines
32 KiB
Plaintext
Raw Normal View History

Ë
j÷]ãóJdZddlZddlZddlZddlZddlZddlZddl Z ddl
m Z ddl m
Z
ddlmZddlmZddlmZdd lmZej*r dd
lmZdd lmZd ed
ej4efdZGdd«ZGdde«Zej<dk\r"dej>d
ej@ee!ffdZ"n!dej>d
ej@ee!ffdZ"Gdde«Z#Gdde«Z$Gdde«Z%Gdde«Z&Gdd e«Z'Gd!„d"e«Z(Gd#„d$e«Z)y)%zKAPI and implementations for loading templates from different data
sources.
éN)Úabc)Úsha1)Ú
import_module)Ú
ModuleTypeé)ÚTemplateNotFound)Ú internalcode)Ú Environment)ÚTemplateÚtemplateÚreturncó^g}|jd«D]}tjj|vsStjjrtjj|vs|tjj
k(r t
|«|sŒ€|dk7sŒ†|j|«Œ˜|S)z‰Split a path into segments and perform a sanity check. If it detects
'..' in the path it will raise a `TemplateNotFound` error.
ú.)ÚsplitÚosÚpathÚsepÚaltsepÚpardirrÚappend)r ÚpiecesÚpieces úQ/home/antigravity/intellecton/venv/lib/python3.12/site-packages/jinja2/loaders.pyÚsplit_template_pathrsð€FØ Óä G‰GK‰K˜5Ñ Ü¤2§7¡7§>¡>°UÑ#:ØœŸŸÒ" 
“|Ø M‰M˜%Õ ð €Móc ó2eZdZdZdZdddedejeejeejejge
fffdZ dejefdZ
e dddd
ed ejejeej fdd fd
«Zy )Ú
BaseLoadera½Baseclass for all loaders. Subclass this and override `get_source` to
implement a custom loading mechanism. The environment provides a
`get_template` method that calls the loader's `load` method to get the
:class:`Template` object.
A very basic example for a loader that looks up templates on the file
system could look like this::
from jinja2 import BaseLoader, TemplateNotFound
from os.path import join, exists, getmtime
class MyLoader(BaseLoader):
def __init__(self, path):
self.path = path
def get_source(self, environment, template):
path = join(self.path, template)
if not exists(path):
raise TemplateNotFound(template)
mtime = getmtime(path)
with open(path) as f:
source = f.read()
return source, path, lambda: mtime == getmtime(path)
environmentr
r r
cór|js!tt|«jd«t |«)Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template.
The source part of the returned tuple must be the source of the
template as a string. The filename should be the name of the
file on the filesystem if it was loaded from there, otherwise
``None``. The filename is used by Python for the tracebacks
if no loader extension is used.
The last item in the tuple is the `uptodate` function. If auto
reloading is enabled it's always called to check if the template
changed. No arguments are passed so the function must store the
old state somewhere (for example in a closure). If it returns `False`
the template will be reloaded.
z$ cannot provide access to the source)Úhas_source_accessÚ RuntimeErrorÚtypeÚ__name__r)Úselfrr s rÚ
get_sourcezBaseLoader.get_sourceKs=ð(×ܘ“:×'Ð'KÐð
ô˜(rcótd«)z”Iterates over all templates. If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.
z-this loader cannot iterate over all templates)Ú TypeError©r%s rÚlist_templateszBaseLoader.list_templatesesôÐHrnameÚglobalsr cóHd}|i}|j||«\}}}|j}| |j||||«} | j}||j |||«}|$ j|| _|j | «|j j||||«S)acLoads a template. This method looks up the template in the cache
or loads one by calling :meth:`get_source`. Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
will not call this method but `get_source` directly.
N)r&Úbytecode_cacheÚ
get_bucketÚcodeÚcompileÚ
set_bucketÚtemplate_classÚ from_code)
r%rr+r,r0ÚsourceÚfilenameÚuptodateÚbccÚbuckets
rÚloadzBaseLoader.loadkðˆØ ˆ?؈Gð&*§_¡_°[À$Ó%GÑ"ˆ˜×Ø ˆ?Ø—^‘^ K°°xÀÓHˆFØ—;‘;ˆ ˆ×& v¨t°XÓ>ˆ
ˆ?˜vŸ{™{ЈFŒKØ N‰N˜ × ˜˜w¨ó
ð
r©N)r$Ú
__module__Ú __qualname__Ú__doc__r!ÚstrÚTupleÚOptionalÚCallableÚboolr&ÚListr*r ÚMutableMappingÚAnyr:©rrrr*ñð<Ðð)Ø47ð
a—j‘o q§z¡z°!·*±*¸¸XÑ2FÑ'GÐGÑ Hó)ð4I §¡ s¡ óIð ð
=Añ )
à)
ðð)
ð˜A×,¨S°!·%±%¨ZÑ9ð )
ð
ò )
óñ)
rrc óþeZdZdZ ddej
edejej
edffdededdfdZ d d
d edejeeejgefffd Z dejefd
Zy)ÚFileSystemLoaderaLoad templates from a directory in the file system.
The path can be relative or absolute. Relative paths are relative to
the current working directory.
.. code-block:: python
loader = FileSystemLoader("templates")
A list of paths can be given. The directories will be searched in
order, stopping at the first matching template.
.. code-block:: python
loader = FileSystemLoader(["/override/templates", "/default/templates"])
:param searchpath: A path, or list of paths, to the directory that
contains the templates.
:param encoding: Use this encoding to read the text from template
files.
:param followlinks: Follow symbolic links in the path.
.. versionchanged:: 2.8
Added the ``followlinks`` parameter.
Ú
searchpathúos.PathLike[str]ÚencodingÚ followlinksr
NcóÔt|tj«rt|t«r|g}|Dcgc]}t j
|«Œc}|_||_||_ycc}wr;) Ú
isinstancerÚIterabler?rÚfspathrKrMrN)r%rKrMrNÚps rÚ__init__zFileSystemLoader.__init__³sPô˜*¤c§l¡lÔ3´zÀ*ÌcÔ7RØ$˜ˆJà1;Ö<¨Aœ2Ÿ9™9 Q<ˆŒØ ˆŒ
Ø&ˆÕùò=s²A%rr
r cód
t|«}|jD]9}tj|g|¢­ŽŠ
tj
j
«sŒ9nSt|j«dk(rdnd}djd|jD««}t||d|d|«t
|j¬«5}|j«}ddd«tj
j
«Š d tfˆ
ˆ fd
} tj
j
«| fS#1swYŒWxYw) NrrÚpathsz, c3ó2K|]}t|«Œy­wr;)Úrepr)Ú.0rSs rú <genexpr>z.FileSystemLoader.get_source.<locals>.<genexpr>Ðsèø€Ò!C¨a¤$ q§'Ñ!Cùsz not found in search z: )rMr
cóh tjj«k(S#t$rYywxYw)NF)rrÚgetmtimeÚOSError)r6Úmtimes€€rr7z-FileSystemLoader.get_source.<locals>.uptodateÛs4ø€ð
Ü—ww×Ó1°UÑ:øÜò
Ùð
ús ƒ!%¥ 1°1)rrKÚ posixpathÚjoinrrÚisfileÚlenrÚopenrMÚreadr\rDÚnormpath) r%rr rrKÚpluralÚ paths_strÚcontentsr7r6r^s @@rr&zFileSystemLoader.get_sourceÂsù€ô% XÓàŸ/™/ò
ˆ!—~~ :°6Ò:ˆw‰w~‰~˜ð
ô # 4§?¡?Ó3°qÒ8V¸gˆŸ ™ Ñ!C°4·?±?Ô!CÓCˆØ3°F°8¸2¸i¸[Ðð
ô
( T§]¡]Ô
 °qØ—v‘v“xˆH÷ ô× Ñ  Óð œ$ö ðœŸ×)¨(Ó3°XÐ ð ús Â?D&Ä&D/cóðt«}|jD}tj||j¬«}|D\}}}|D] }tj
j
||«t|«djtj
j«jtj
jd«}|dddk(r|dd}||vsŒ|j|«Œ¢Œ­ŒÕt|«S)N)rNréz./)
ÚsetrKrÚwalkrNrr`rbÚstriprÚreplaceÚaddÚsorted) r%ÚfoundrKÚwalk_dirÚdirpathÚ_Ú filenamesr6r s rr*zFileSystemLoader.list_templatesä܈؟/™/ò ,ˆJÜ—ww˜z°t×7GÑ7GÔHˆHØ)1ò
%˜˜IØ )ò ,ŸŸ  W¨hÓ¸J»Ð8IМrŸw™wŸ{™{Ó¤§¡§¡¨cÓð
   | +Ø#+¨A¨B <˜Ø Ÿ ™   
 er)úutf-8F)r$r<r=r>r@ÚUnionr?ÚSequencerDrTrArCr&rEr*rHrrrJrJ˜ñð> Ø
—G Ð# Q§Z¡Z°·±¸Ð=OÐ8OÑ0PÑ%QÐ 
ð

ð
 ð

ó
  >Ø47ð 
c˜1Ÿ:™: b¨$ /Ñ 0ó >ðD §¡  ôrrJ)éé
Úzcód |j}|«S#t$r}td«|d}~wwxYw©NzFThis zip import does not have the required metadata to list templates.)Ú
_get_filesÚAttributeErrorr()r|Ú get_filesÚes rÚ_get_zipimporter_filesrƒøsCð ØŸ ˆIñ ‹{Ðøô ò Üððð
ûð ús • /ž *ª/cóZ |j}|S#t$r}td«|d}~wwxYwr~)Ú_filesr€r()r|Úfilesrs rs@ð Ø—H‘HˆEð ˆ øô ò Üððð
ûð ús  * %¥*c óÀeZdZdZ ddedddeddfdZd d
d edejeeejejge
fffd Z dejefd
Z
y)Ú
PackageLoaderalLoad templates from a directory in a Python package.
:param package_name: Import name of the package that contains the
template directory.
:param package_path: Directory within the imported package that
contains the templates.
:param encoding: Encoding of template files.
The following example looks up templates in the ``pages`` directory
within the ``project.ui`` package.
.. code-block:: python
loader = PackageLoader("project.ui", "pages")
Only packages installed as directories (standard pip behavior) or
zip/egg files (less common) are supported. The Python API for
introspecting data in packages is too limited to support other
installation methods the way this loader requires.
There is limited support for :pep:`420` namespace packages. The
template directory is assumed to only be in one namespace
contributor. Zip files contributing to a namespace are not
supported.
.. versionchanged:: 3.0
No longer uses ``setuptools`` as a dependency.
.. versionchanged:: 3.0
Limited PEP 420 namespace package support.
Ú package_nameÚ package_pathr?rMr
Ncótjj|«jtjj«}|tjj
k(rd}n@|ddtjj
tjjzk(r|dd}||_||_||_t|«tjj|«}|Jd«|j}|Jd«||_d|_t!|t"j$«r~|j&|_t)t+|j,««}tjj/||«jtjj«}||_yg}|j,r|j1|j,«nD|j28|j5tjj7|j2««|st9d|d«|D]L} tjj/| |«} tjj;| «sŒC| }||_yt9d|d|d «)
rkz-An import spec was not found for the package.z'A loader was not found for the package.zThe zC package was not installed in a way that PackageLoader understands.zPackageLoader could not find a z directory in the z package.)rrreÚrstriprÚcurdirrŠr‰rMrÚ importlibÚutilÚ find_specÚloaderÚ_loaderÚ_archiverPÚ zipimportÚ zipimporterÚarchiveÚnextÚiterÚsubmodule_search_locationsr`ÚextendÚoriginrÚdirnameÚ
ValueErrorÚisdirÚ_template_root)
r%r‰rMÚspecrÚpkgdirÚ
template_rootÚrootsÚroots
rrTzPackageLoader.__init__/s!ô —ww× Ó5×<¼R¿W¹W¿[¹[ÓIˆ ð œ2Ÿ7™7Ÿ>™>Ò ‰LØ
˜"˜
¤§¡§¡´"·'±'·+±+Ñ!=Ò
¨Ð+ˆLàÔØÔØ ˆŒ
ô ~‰~× Ó5ˆØÐÐPÐ!PÓØˆØÐLÐ#LÓˆŒ ؈Œ
ä fœi× "ŸN™NˆDŒMÜœ$˜t×@ˆŸG™GŸL™L¨°ÓEÄbÇgÁgÇkÁkÓRˆMð<,ˆÕð9"$ˆ× ˜Ð œRŸW™WŸ_™_¨T¯[©[ÓÜ Ø˜+;ððð
ò
Ü—w‘w—|‘| D¨,Ó7ä—77—== Õ&Ø$(ð,ˆÕð
ô5°lÐ5EðFØ.¨iððrrr
r cóltjjtj|j
gt
|«¢­Ž«Š|j€|tjj«s t|«td«5}|j«}ddd«tjj«Šdtfˆˆfd }n |jj«}d}j#|j$«|fS#1swYŒrxYw#t $r}t|«|d}~wwxYw)rbr
cóŠtjj«xr"tjj«k(Sr;)rrrar\)r^rSs€€rÚ
up_to_datez,PackageLoader.get_source.<locals>.up_to_dateƒs/ø€Ü—ww—~‘~ I¬R¯W©W×-=Ñ-=¸aÓ-@ÀEÑ-IÐIr)rrrer_r`r rr”rarrcrdr\rDr“Úget_datar]ÚdecoderM) r%rr rhr5rr^rSs @@rr&zPackageLoader.get_sourcensù€ô
G‰G× Ñ Ü N‰N˜4× OÔ1DÀXÓ1NÒ 
ˆð
=‰=Ð ä—77—>> & a˜ð
" Ÿ÷
—GG×$ 'ˆ
J¤÷
Jð

Ÿ×.¨qÓ1ðˆJà}‰}˜TŸ]™]Ó+¨Q°
Ð:÷)

"ûôò
& 0°aÐ7ûð
8ús$Â D
ÃDÄ
DÄ D3Ä" D.Ä.D3có@g}|j€„t|j«}tj|j«D]L\Š}}|dj tj j«Š|jˆfd|D««ŒNnút|j«}|jt|j«dj tj j«tj jz}t|«}|D]q}|j|«sŒ|dtj jk7sŒ6|j||djtj jd««Œs|j«|S)Nc3ó®K|]L}tjj|«jtjjd«ŒNy­w)rN)rrr`ror)rYr+rts €rrZz/PackageLoader.list_templates.<locals>.<genexpr>s=øèø€òàô—G‘G—L‘L ¨$Ó¿¹¿ ¹ ÀS×ùsƒAAéÿÿÿÿr)r”rbr rrmÚlstriprrrr“Ú
startswithrroÚsort) r%ÚresultsÚoffsetrurvr†Úprefixr+rts @rr*zPackageLoader.list_templates”sEø€Øà =‰=Ð ä˜×-ˆFä)+¯©°×1DÑ1DÓ)Eò
Ñ%˜˜! & *×1´"·'±'·+±+Ó>Øóà )ôõñ
ô+¨4¯<©<Ó8ˆ×#¤C¨¯
©
Ó$6Ð$8ÐÇÁÇÁÓ—''—+ð
ô˜“[ˆò
Là—?‘? 6Õ*¨t°B©x¼2¿7¹7¿;¹;Ó/FØ—N‘N 4¨¨ =×#8Ñ#8¼¿¹¿¹ÀcÓ#JÕ
Lð
 ŒØˆr)Ú templatesrw)r$r<r=r>r?rTr@rArBrCrDr&rEr*rHrrrˆrˆs”ñðFñ =ð=ð=ð =
ó =,ð~$$;Ø47ð$
c˜1Ÿ:™: a§j¡j°°T°Ñ&:Ñ;Ñ <ó$;ðL §¡  ôrc ó¶eZdZdZdej
eefddfdZdddedejedejge
fffd „Z dejefd
Z
y) Ú
DictLoaderaLoads a template from a Python dict mapping template names to
template source. This loader is useful for unittesting:
>>> loader = DictLoader({'index.html': 'source here'})
Because auto reloading is rarely useful this is disabled by default.
Úmappingr
Ncó||_yr;)r¸)r%r¸s rrTzDictLoader.__init__½ó ؈ rrr
r cóljvrjŠdˆˆˆfdfSt«)Ncó@jj«k(Sr;)r¸Úget)r%r5r s€€€rú<lambda>z'DictLoader.get_source.<locals>.<lambda>Åsø€¨°4·<±<×3CÑ3CÀHÓ3MÑ)M€r)r¸r)r%rr r5s` `@rr&zDictLoader.get_sourceÀs8ú€ð t—|‘|Ñ —\‘\ (Ñ+ˆFؘ4Õ!MÐ ˜(rcó,t|j«Sr;)rqr¸r)s rr*zDictLoader.list_templatesÈsÜd—l#r)r$r<r=r>r@ÚMappingr?rTrArCrDr&rEr*rHrr´suñð § ¡ ¨#¨s¨(Ñ 3ð¸óð)Ø47ð
d˜AŸJ™J r¨4 0Ñ 1ó$ §¡  ô$rc
ópeZdZdZdej
egejejeejeejeejej
ge
ffffddfdZ dddedejeejeejej
ge
fffd „Z y)
ÚFunctionLoadera­A loader that is passed a function which does the loading. The
function receives the name of the template and has to return either
a string with the template source, a tuple in the form ``(source,
filename, uptodatefunc)`` or `None` if the template does not exist.
>>> def load_template(name):
... if name == 'index.html':
... return '...'
...
>>> loader = FunctionLoader(load_template)
The `uptodatefunc` is a function that is called if autoreload is enabled
and has to return `True` if the template is still up to date. For more
details have a look at :meth:`BaseLoader.get_source` which has the same
return value.
Ú load_funcr
Ncó||_yr;))r%s rrTzFunctionLoader.__init__Þs ð#ˆrrr
r cól|j|«}| t|«t|t«r|ddfS|Sr;)rrPr?)r%rr Úrvs rr&zFunctionLoader.get_sourceës=ð^‰^˜HÓ
%ˆà
ˆ"  bœ#Ô Øt˜T ˆ r)
r$r<r=r>r@rCr?rBrxrArDrTr&rHrrÌñð" —:
ˆ
J‰JØØ˜Ÿ  a§j¡j°¡o°q·z±zÀ!Ç*Á*ÈRÐQUÈXÑBVÑ7WÐ!WÑñ
ð
ñ
ð 
ó  Ø Ø47ð à