Files
old-parkingkoncept/parkingkonceptvenv/lib/python3.7/site-packages/jinja2/__pycache__/loaders.cpython-37.pyc

226 lines
16 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>/<2F>]<5D>C<00>@sdZddlZddlZddlZddlmZddlmZddlmZddl m
Z
ddl m Z m Z ddlmZmZd d
<EFBFBD>ZGd d <0C>d e<12>ZGd d<0E>de<13>ZGdd<10>de<13>ZGdd<12>de<13>ZGdd<14>de<13>ZGdd<16>de<13>ZGdd<18>de<13>ZGdd<1A>de<05>ZGdd<1C>de<13>ZdS)z<>
jinja2.loaders
~~~~~~~~~~~~~~
Jinja loader classes.
:copyright: (c) 2017 by the Jinja Team.
:license: BSD, see LICENSE for more details.
<EFBFBD>N)<01>
ModuleType)<01>path)<01>sha1)<01>TemplateNotFound)<02>open_if_exists<74> internalcode)<02> string_types<65> iteritemscCs`g}xV|<00>d<01>D]H}tj|ks8tjr.tj|ks8|tjkrBt|<00><01>q|r|dkr|<01>|<02>qW|S)z<>Split a path into segments and perform a sanity check. If it detects
'..' in the path it will raise a `TemplateNotFound` error.
<20>/<2F>.)<07>splitr<00>sep<65>altsep<65>pardirr<00>append)<03>template<74>piecesZpiece<63>r<00>2/tmp/pip-install-c3kgu56x/Jinja2/jinja2/loaders.py<70>split_template_paths


 rc@s2eZdZdZdZdd<04>Zdd<06>Zed
dd <09><01>ZdS) <0B>
BaseLoadera<EFBFBD>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 file(path) as f:
source = f.read().decode('utf-8')
return source, path, lambda: mtime == getmtime(path)
TcCs"|jstd|jj<00><01>t|<02><01>dS)a<>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 unicode string or a ASCII bytestring. 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&%s cannot provide access to the sourceN)<05>has_source_access<73> RuntimeError<6F> __class__<5F>__name__r)<03>self<6C> environmentrrrr<00>
get_sourceFs zBaseLoader.get_sourcecCs td<01><01>dS)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 templatesN)<01> TypeError)rrrr<00>list_templates]szBaseLoader.list_templatesNc
Cs<>d}|dkri}|<00>||<02>\}}}|j}|dk rF|<08>||||<05>} | j}|dkr\|<01>|||<06>}|dk r~| jdkr~|| _|<08>| <09>|j<06>||||<07>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)rZbytecode_cacheZ
get_bucket<EFBFBD>code<64>compileZ
set_bucket<EFBFBD>template_classZ from_code)
rr<00>name<6D>globalsr <00>source<63>filename<6D>uptodateZbccZbucketrrr<00>loadcs

zBaseLoader.load)N) r<00>
__module__<EFBFBD> __qualname__<5F>__doc__rrrrr(rrrrr%s rc@s*eZdZdZd dd<05>Zdd<07>Zdd <09>Zd
S) <0C>FileSystemLoadera"Loads templates from the file system. This loader can find templates
in folders on the file system and is the preferred way to load them.
The loader takes the path to the templates as string, or if multiple
locations are wanted a list of them which is then looked up in the
given order::
>>> loader = FileSystemLoader('/path/to/templates')
>>> loader = FileSystemLoader(['/path/to/templates', '/other/path'])
Per default the template encoding is ``'utf-8'`` which can be changed
by setting the `encoding` parameter to something else.
To follow symbolic links, set the *followlinks* parameter to ``True``::
>>> loader = FileSystemLoader('/path/to/templates', followlinks=True)
.. versionchanged:: 2.8+
The *followlinks* parameter was added.
<20>utf-8FcCs*t|t<01>r|g}t|<01>|_||_||_dS)N)<06>
isinstancer<00>list<73>
searchpath<EFBFBD>encoding<6E> followlinks)rr0r1r2rrr<00>__init__<5F>s


zFileSystemLoader.__init__c s<>t|<02>}xp|jD]f}tj|f|<03><02><00>t<04><00>}|dkr6qz|<05><05><00>|j<07>}Wd|<05><08>Xt<02> <09><00><01><01><00>fdd<02>}|<06>|fSWt
|<02><01>dS)Ncs(yt<00><01><00><01>kStk
r"dSXdS)NF)r<00>getmtime<6D>OSErrorr)r&<00>mtimerrr'<00>sz-FileSystemLoader.get_source.<locals>.uptodate) rr0r<00>joinr<00>read<61>decoder1<00>closer4r)rrrrr0<00>f<>contentsr'r)r&r6rr<00>s 

 zFileSystemLoader.get_sourcec Cs<>t<00>}x<>|jD]<5D>}tj||jd<01>}x~|D]v\}}}xj|D]b}tj<05>||<07>t|<02>d<00><00>tjj <09><01>
tjj d<02>}|dd<03>dkr<>|dd<00>}||kr8|<01> |<08>q8Wq(WqWt |<01>S)N)r2r
<00>z./) <0A>setr0<00>os<6F>walkr2rr7<00>len<65>stripr <00>replace<63>add<64>sorted) r<00>foundr0Zwalk_dir<69>dirpath<74>dirnames<65> filenamesr&rrrrr<00>s 
   zFileSystemLoader.list_templatesN)r-F)rr)r*r+r3rrrrrrr,<00>s
r,c@s*eZdZdZd dd<05>Zdd<07>Zdd <09>Zd
S) <0C> PackageLoadera,Load templates from python eggs or packages. It is constructed with
the name of the python package and the path to the templates in that
package::
loader = PackageLoader('mypackage', 'views')
If the package path is not given, ``'templates'`` is assumed.
Per default the template encoding is ``'utf-8'`` which can be changed
by setting the `encoding` parameter to something else. Due to the nature
of eggs it's only possible to reload templates if the package was loaded
from the file system and not a zip file.
<20> templates<65>utf-8cCsFddlm}m}m}||<01>}||_|<05>|_t||<04>|_||_||_ dS)Nr)<03>DefaultProvider<65>ResourceManager<65> get_provider)
<EFBFBD> pkg_resourcesrMrNrOr1<00>managerr.<00>filesystem_bound<6E>provider<65> package_path)r<00> package_namerTr1rMrNrOrSrrrr3<00>s zPackageLoader.__init__cs<>t|<02>}d<01>|jft|<03><00>}|j<04>|<04>s2t|<02><01>d<00>}|jrh|j<04>|j |<04><02>t
<EFBFBD> <0B><00><01><01><00>fdd<03>}|j<04> |j |<04>}|<06> |j<0E><01>|fS)Nr
cs(yt<00><01><00><01>kStk
r"dSXdS)NF)rr4r5r)r&r6rrr'<00>sz*PackageLoader.get_source.<locals>.uptodate)rr7rT<00>tuplerS<00> has_resourcerrR<00>get_resource_filenamerQrr4<00>get_resource_stringr9r1)rrrr<00>pr'r%r)r&r6rr<00>s 
zPackageLoader.get_sourcecsb<00>j}|dd<01>dkr$|dd<00>}n |dkr0d}t|<01><01>g<00><02><00><01><02>fdd<06><08><00>|<01><00><02><02><00>S)Nr=z./r <00>csTxN<78>j<00>|<00>D]>}|d|}<02>j<00>|<02>r4<72>|<02>q<0E><02>|<02>d<00><00>d<01><01>qWdS)Nr
)rS<00>resource_listdir<69>resource_isdirr<00>lstrip)rr&<00>fullname)<04>_walk<6C>offset<65>resultsrrrr`s
  
z+PackageLoader.list_templates.<locals>._walk)rTrA<00>sort)rrr)r`rarbrrr<00>szPackageLoader.list_templatesN)rKrL)rr)r*r+r3rrrrrrrJ<00>s
 
rJc@s(eZdZdZdd<03>Zdd<05>Zdd<07>ZdS) <09>
DictLoaderaLoads a template from a python dict. It's passed a dict of unicode
strings bound to template names. This loader is useful for unittesting:
>>> loader = DictLoader({'index.html': 'source here'})
Because auto reloading is rarely useful this is disabled per default.
cCs
||_dS)N)<01>mapping)rrerrrr3szDictLoader.__init__cs6<00><02>jkr*<2A>j<00><00><01>d<00><00><01>fdd<02>fSt<01><02><01>dS)Ncs<00><01>j<00><01><02>kS)N)re<00>getr)rr%rrr<00><lambda><00>z'DictLoader.get_source.<locals>.<lambda>)rer)rrrr)rr%rrrs

zDictLoader.get_sourcecCs
t|j<01>S)N)rEre)rrrrr szDictLoader.list_templatesN)rr)r*r+r3rrrrrrrdsrdc@s eZdZdZdd<03>Zdd<05>ZdS)<07>FunctionLoadera<72>A loader that is passed a function which does the loading. The
function receives the name of the template and has to return either
an unicode 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.
cCs
||_dS)N)<01> load_func)rrjrrrr36szFunctionLoader.__init__cCs4|<00>|<02>}|dkrt|<02><01>nt|t<03>r0|ddfS|S)N)rjrr.r)rrr<00>rvrrrr9s 



zFunctionLoader.get_sourceN)rr)r*r+r3rrrrrri$sric@s@eZdZdZddd<04>Zdd<06>Zdd<08>Zedd
d <0B><01>Zd d <0A>Z d S)<10> PrefixLoaderaA loader that is passed a dict of loaders where each loader is bound
to a prefix. The prefix is delimited from the template by a slash per
default, which can be changed by setting the `delimiter` argument to
something else::
loader = PrefixLoader({
'app1': PackageLoader('mypackage.app1'),
'app2': PackageLoader('mypackage.app2')
})
By loading ``'app1/index.html'`` the file from the app1 package is loaded,
by loading ``'app2/index.html'`` the file from the second.
r
cCs||_||_dS)N)re<00> delimiter)rrermrrrr3QszPrefixLoader.__init__c CsJy |<01>|jd<01>\}}|j|}Wn ttfk
r@t|<01><01>YnX||fS)N<>)r rmre<00>
ValueError<EFBFBD>KeyErrorr)rr<00>prefixr#<00>loaderrrr<00>
get_loaderUs zPrefixLoader.get_loadercCs<|<00>|<02>\}}y |<03>||<04>Stk
r6t|<02><01>YnXdS)N)rsrr)rrrrrr#rrrr]s
 zPrefixLoader.get_sourceNcCs>|<00>|<02>\}}y|<04>|||<03>Stk
r8t|<02><01>YnXdS)N)rsr(r)rrr#r$rrZ
local_namerrrr(fs
zPrefixLoader.loadcCsFg}x<t|j<01>D].\}}x$|<03><02>D]}|<01>||j|<00>q"WqW|S)N)r rerrrm)r<00>resultrqrrrrrrrps
zPrefixLoader.list_templates)r
)N)
rr)r*r+r3rsrrr(rrrrrrlBs 
  rlc@s6eZdZdZdd<03>Zdd<05>Zed dd<08><01>Zd d
<EFBFBD>ZdS) <0C> ChoiceLoadera<72>This loader works like the `PrefixLoader` just that no prefix is
specified. If a template could not be found by one loader the next one
is tried.
>>> loader = ChoiceLoader([
... FileSystemLoader('/path/to/user/templates'),
... FileSystemLoader('/path/to/system/templates')
... ])
This is useful if you want to allow users to override builtin templates
from a different location.
cCs
||_dS)N)<01>loaders)rrvrrrr3<00>szChoiceLoader.__init__c Cs>x0|jD]&}y |<03>||<02>Stk
r,YqXqWt|<02><01>dS)N)rvrr)rrrrrrrrr<00>s   
zChoiceLoader.get_sourceNc Cs@x2|jD](}y|<04>|||<03>Stk
r.YqXqWt|<02><01>dS)N)rvr(r)rrr#r$rrrrrr(<00>s  
zChoiceLoader.loadcCs,t<00>}x|jD]}|<01>|<02><03><00>qWt|<01>S)N)r>rv<00>updaterrE)rrFrrrrrr<00>s zChoiceLoader.list_templates)N) rr)r*r+r3rrr(rrrrrruxs   ruc@seZdZdZdS)<03>_TemplateModulez9Like a normal module but with support for weak referencesN)rr)r*r+rrrrrx<00>srxc@sBeZdZdZdZdd<04>Zedd<06><00>Zedd<08><00>Ze d d
d <0B><01>Z
d S) <0A> ModuleLoadera6This loader loads templates from precompiled templates.
Example usage:
>>> loader = ChoiceLoader([
... ModuleLoader('/path/to/compiled/templates'),
... FileSystemLoader('/path/to/templates')
... ])
Templates can be precompiled with :meth:`Environment.compile_templates`.
Fcs^dt|<00><00>t<01><00>}t|t<03>r&|g}nt|<01>}||_t<06>|<02>fdd<03><08>tj <09><||_
<EFBFBD>|_ dS)Nz_jinja2_module_templates_%xcstj<01><02>d<00>S)N)<03>sys<79>modules<65>pop)<01>x)rUrrrg<00>rhz'ModuleLoader.__init__.<locals>.<lambda>) <0C>idrxr.rr/<00>__path__<5F>weakref<65>proxyrzr{<00>modulerU)rr<00>modr)rUrr3<00>s 
zModuleLoader.__init__cCsdt|<00>d<02><01><01><02>S)NZtmpl_zutf-8)r<00>encode<64> hexdigest)r#rrr<00>get_template_key<65>szModuleLoader.get_template_keycCst<00>|<00>dS)Nz.py)ryr<>)r#rrr<00>get_module_filename<6D>sz ModuleLoader.get_module_filenameNcCs<>|<00>|<02>}d|j|f}t|j|d<00>}|dkrnyt|dddg<01>}Wntk
r^t|<02><01>YnXtj<08> |d<00>|j
<EFBFBD> ||j |<03>S)Nz%s.%s<>root) r<>rU<00>getattrr<72><00>
__import__<EFBFBD> ImportErrorrrzr{r|r"Zfrom_module_dict<63>__dict__)rrr#r$<00>keyr<79>r<>rrrr(<00>s
zModuleLoader.load)N) rr)r*r+rr3<00> staticmethodr<64>r<>rr(rrrrry<00>s   ry)r+r?rzr<><00>typesrr<00>hashlibrZjinja2.exceptionsrZ jinja2.utilsrrZjinja2._compatrr r<00>objectrr,rJrdrirlrurxryrrrr<00><module>
s&    eCA6)