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

241 lines
20 KiB
Plaintext
Raw Normal View History

2019-11-17 12:44:16 +01:00
B
<00>/<2F>]<5D>_<00>@stdZddlZddlmZddlmZmZmZmZm Z m
Z
m Z m Z m Z mZmZmZddlmZddlmZddlmZmZddlmZmZmZdd lmZmZmZd
Z Gd d <0C>d e!<21>Z"Gd d<0E>dee"e#<23><02>Z$edd<10><00>Z%dd<12>Z&dd<14>Z'Gdd<16>de$<24>Z(Gdd<18>de$<24>Z)Gdd<1A>de$<24>Z*Gdd<1C>de$<24>Z+Gdd<1E>de$<24>Z,e dfd d!<21>Z-Gd"d#<23>d#e#<23>Z.d$d%<25>Z/e(Z0e)Z1e*Z2e+Z3e,Z4dS)&a 
jinja2.ext
~~~~~~~~~~
Jinja extensions allow to add custom tags similar to the way django custom
tags work. By default two example extensions exist: an i18n and a cache
extension.
:copyright: (c) 2017 by the Jinja Team.
:license: BSD.
<EFBFBD>N)<01>nodes) <0C>BLOCK_START_STRING<4E>BLOCK_END_STRING<4E>VARIABLE_START_STRING<4E>VARIABLE_END_STRING<4E>COMMENT_START_STRING<4E>COMMENT_END_STRING<4E>LINE_STATEMENT_PREFIX<49>LINE_COMMENT_PREFIX<49> TRIM_BLOCKS<4B>NEWLINE_SEQUENCE<43>KEEP_TRAILING_NEWLINE<4E> LSTRIP_BLOCKS)<01> Environment)<01>concat)<02>TemplateAssertionError<6F>TemplateSyntaxError)<03>contextfunction<6F> import_string<6E>Markup)<03>with_metaclass<73> string_types<65> iteritems)<03>_<>gettext<78>ngettextc@seZdZdZdd<03>ZdS)<05>ExtensionRegistryz)Gives the extension an unique identifier.cCs&t<00>||||<03>}|jd|j|_|S)N<>.)<05>type<70>__new__<5F>
__module__<EFBFBD>__name__<5F>
identifier)<05>cls<6C>name<6D>bases<65>d<>rv<72>r(<00>./tmp/pip-install-c3kgu56x/Jinja2/jinja2/ext.pyr%szExtensionRegistry.__new__N)r!r <00> __qualname__<5F>__doc__rr(r(r(r)r"src@sXeZdZdZe<04>ZdZdd<04>Zdd<06>Zddd <09>Z d
d <0B>Z
d d <0A>Z ddd<0F>Z ddd<11>Z dS)<15> ExtensionagExtensions can be used to add extra functionality to the Jinja template
system at the parser level. Custom extensions are bound to an environment
but may not store environment specific data on `self`. The reason for
this is that an extension can be bound to another environment (for
overlays) by creating a copy and reassigning the `environment` attribute.
As extensions are created by the environment they cannot accept any
arguments for configuration. One may want to work around that by using
a factory function, but that is not possible as extensions are identified
by their import name. The correct way to configure the extension is
storing the configuration values on the environment. Because this way the
environment ends up acting as central configuration storage the
attributes may clash which is why extensions have to ensure that the names
they choose for configuration are not too generic. ``prefix`` for example
is a terrible name, ``fragment_cache_prefix`` on the other hand is a good
name as includes the name of the extension (fragment cache).
<20>dcCs
||_dS)N)<01> environment)<02>selfr.r(r(r)<00>__init__HszExtension.__init__cCs$t<00>|j<02>}|j<03>|j<03>||_|S)z=Create a copy of this extension bound to another environment.)<06>objectr<00> __class__<5F>__dict__<5F>updater.)r/r.r'r(r(r)<00>bindKs zExtension.bindNcCs|S)z<>This method is called before the actual lexing and can be used to
preprocess the source. The `filename` is optional. The return value
must be the preprocessed source.
r()r/<00>sourcer$<00>filenamer(r(r)<00>
preprocessRszExtension.preprocesscCs|S)a<>It's passed a :class:`~jinja2.lexer.TokenStream` that can be used
to filter tokens returned. This method has to return an iterable of
:class:`~jinja2.lexer.Token`\s, but it doesn't have to return a
:class:`~jinja2.lexer.TokenStream`.
In the `ext` folder of the Jinja2 source distribution there is a file
called `inlinegettext.py` which implements a filter that utilizes this
method.
r()r/<00>streamr(r(r)<00> filter_streamYs
zExtension.filter_streamcCs
t<00><00>dS)aIf any of the :attr:`tags` matched this method is called with the
parser as first argument. The token the parser stream is pointing at
is the name token that matched. This method has to return one or a
list of multiple nodes.
N)<01>NotImplementedError)r/<00>parserr(r(r)<00>parseeszExtension.parsecCstj|j||d<01>S)z<>Return an attribute node for the current extension. This is useful
to pass constants on extensions to generated template code.
::
self.attr('_my_attribute', lineno=lineno)
)<01>lineno)rZExtensionAttributer")r/r$r>r(r(r)<00>attrmszExtension.attrcCs8|dkr g}|dkrg}tj|j||d<02>|||||d<02>S)zsCall a method of the extension. This is a shortcut for
:meth:`attr` + :class:`jinja2.nodes.Call`.
N)r>)r<00>Callr?)r/r$<00>args<67>kwargs<67>dyn_args<67>
dyn_kwargsr>r(r(r)<00> call_methodws zExtension.call_method)N)N)NNNNN)r!r r*r+<00>set<65>tags<67>priorityr0r5r8r:r=r?rEr(r(r(r)r,+s
 
r,cOs|j|<00>d<01>f|<01>|<02>S)Nr)<02>call<6C>resolve)<03> __contextrArBr(r(r)<00>_gettext_alias<61>srLcst<00>fdd<02><08>}|S)Ncs$|<00><00>|<01>}|jjrt|<03>}||S)N)rI<00>eval_ctx<74>
autoescaper)rKZ__string<6E> variablesr')<01>funcr(r)r<00>s z"_make_new_gettext.<locals>.gettext)r)rPrr()rPr)<00>_make_new_gettext<78>srQcst<00>fdd<02><08>}|S)Ncs4|<04>d|<03>|<00><01>|||<03>}|jjr,t|<05>}||S)N<>num)<05>
setdefaultrIrMrNr)rKZ
__singularZ__pluralZ__numrOr')rPr(r)r<00>s
 z$_make_new_ngettext.<locals>.ngettext)r)rPrr()rPr)<00>_make_new_ngettext<78>srTc@s~eZdZdZedg<01>Zdd<04>Zddd<07>Zddd <09>Zdd
d <0B>Z d d <0A>Z
e fdd<0F>Z dd<11>Z e<0E>d<12>fdd<14>Zdd<16>Zdd<18>ZdS)<1C>InternationalizationExtensionz.This extension adds gettext support to Jinja2.ZtranscCs:t<00>||<01>t|jd<|j|j|j|j|j|j dd<03>dS)NrF)Zinstall_gettext_translationsZinstall_null_translationsZinstall_gettext_callablesZuninstall_gettext_translationsZextract_translations<6E>newstyle_gettext)
r,r0rL<00>globals<6C>extend<6E>_install<6C> _install_null<6C>_install_callables<65>
_uninstall<EFBFBD>_extract)r/r.r(r(r)r0<00>s 
z&InternationalizationExtension.__init__NcCsFt|dd<00>}|dkr|j}t|dd<00>}|dkr4|j}|<00>|||<02>dS)NZugettextZ ungettext)<04>getattrrrr[)r/<00> translations<6E>newstylerrr(r(r)rY<00>s  z&InternationalizationExtension._installcCs|<00>dd<02>dd<02>|<01>dS)NcSs|S)Nr()<01>xr(r(r)<00><lambda><3E><00>z=InternationalizationExtension._install_null.<locals>.<lambda>cSs|dkr|fp|fdS)N<>rr()<03>s<>p<>nr(r(r)rb<00>rc)r[)r/r`r(r(r)rZ<00>sz+InternationalizationExtension._install_nullcCs>|dk r||j_|jjr(t|<01>}t|<02>}|jjj||d<01>dS)N)rr)r.rVrQrTrWr4)r/rrr`r(r(r)r[<00>sz0InternationalizationExtension._install_callablescCs"xdD]}|jj<01>|d<00>qWdS)N)rr)r.rW<00>pop)r/r_<00>keyr(r(r)r\<00>s
z(InternationalizationExtension._uninstallcCs t|t<01>r|j<02>|<01>}t||<02>S)N)<05>
isinstancerr.r=<00>extract_from_ast)r/r6<00>gettext_functionsr(r(r)r]<00>s
 z&InternationalizationExtension._extractcCs
t|j<01>j}d}d}d}i}d}<07>x|jjjdk<03>r6|rD|j<01>d<04>|j<01>d<05>rRP|j<01>d<06>}|j|kr<>|jd|j|jt d<08>|jjjd kr<>t|j<01>|<01>
<EFBFBD>||j<} n8|dkr<>|jd
kr<>|jd k}q$nt <0B> |jd <0C>||j<} |dkr$t | t j<0E><02>r&t <0B> d d <0C>}|||j<t <0B>t <0B> d d<0E>| <09>}n| }|jdk}q$W|j<01>d<03>d}
d} t<10>} |<00>|d<10>\} }| <0A>r<>| <0C>| <0A>|dk<08>r<>t <0B> | dd <0C>}| ddk}|jj<03>d<12><01>r<d} t|j<01>|jjjdk<03>r
|j<01>d<06>}|j|k<07>r<>|jd|j|jt d<08>||j}|jdk}|j<01>d<03>|<00>|d<01>\}}
t|j<01>| <0C>|<0F>n
t|j<01>x(| D] } | |k<07>rLt <0B> | d <0C>|| <<00>qLW| <0B>s|d}n|dk<08>r<>|<01>d|<02>|dk<08>r<>|jjd}|<07>r<>|<00>|<0E>}|
<EFBFBD>r<>|<00>|
<EFBFBD>}
|<00>||
||t| <0C>|<03>o<>| <0B>}|<10>|<02>|dk <09>r||gS|SdS)zParse a translatable tag.FNZ block_end<6E>comma<6D>colonr$z'translatable variable %r defined twice.)<01>excZassign)<02>trimmedZ notrimmedrp<00>loadZ_trans<6E>storerRTrzname:pluralizez%unknown variable %r for pluralizationzpluralize without variableszext.i18n.trimmed)<1A>nextr9r><00>currentr<00>expectZskip_if<69>value<75>failrZparse_expressionr<00>Namerjr@ZAssignrF<00> _parse_blockr4<00>testr.<00>policies<65>_trim_whitespace<63>
_make_node<EFBFBD>boolZ
set_lineno)r/r<r><00>num_called_num<75> plural_exprZplural_expr_assignmentrOrpr$<00>var<61>pluralZ have_plural<61>
referencedZsingular_names<65>singularZ plural_names<65>noder(r(r)r=<00>s<>    



 
 

 
  


 
 



 
 

  

z#InternationalizationExtension.parsez\s*\n\s*cCs|<02>d|<01><01><00>S)N<> )<02>sub<75>strip)r/<00>string<6E>_ws_rer(r(r)r|Bsz.InternationalizationExtension._trim_whitespacecCs g}g}x<>|jjjdkr<|<04>|jjj<04>dd<03><02>t|j<00>q
|jjjdkr<>t|j<00>|j<00>d<05>j}|<03>|<05>|<04>d|<00>|j<00>d<07>q
|jjjdkr<>t|j<00>|jj<01>d <09>r<>Pn|jj<01>d
<EFBFBD>r<>|r<>P|<01> d <0B>|<01> d <0C>q
|jj
r<EFBFBD>|<01> d <0A>q
ds
t d<0F><01>q
W|t |<04>fS)z1Parse until the next block tag with a given name.<2E>data<74>%z%%Zvariable_beginr$z%%(%s)sZ variable_endZ block_beginz name:endtranszname:pluralizez:a translatable section can have only one pluralize sectionz;control structures in translatable sections are not allowedzunclosed translation blockFzinternal parser error) r9rtr<00>appendrv<00>replacersrurzrwZeos<6F>AssertionErrorr)r/r<Zallow_pluralizer<65><00>bufr$r(r(r)ryEs2 



  z*InternationalizationExtension._parse_blockc Cs|s(|jjs(|<01>dd<02>}|r(|<02>dd<02>}|dkrXt<03>dd<05>}t<03>|t<03>|<01>ggdd<03>}n0t<03>dd<05>} t<03>| t<03>|<01>t<03>|<02>|ggdd<03>}|jjr<>xft|<03>D]*\}
} |r<>|
dkr<>q<EFBFBD>|j<08> t<03>
|
| <0B><02>q<>Wn.t<03> |<08>}|r<>t<03> |t<03> dd <09>|<03><0E>D<00><01><01>}t<03>|g<01>S)
z/Generates a useful node from the data provided.z%%r<>NrrqrrRcSs"g|]\}}t<00>t<00>|<01>|<02><02>qSr()rZPair<69>Const)<03>.0rirvr(r(r)<00>
<listcomp><3E>sz<InternationalizationExtension._make_node.<locals>.<listcomp>)r.rVr<>rrxr@r<>rrBr<><00>KeywordZMarkSafeIfAutoescapeZMod<6F>Dict<63>itemsZOutput) r/r<>r<>rOr<>Zvars_referencedrrr<>rrirvr(r(r)r}es2      
 

z(InternationalizationExtension._make_node)N)N)N)r!r r*r+rFrGr0rYrZr[r\<00>GETTEXT_FUNCTIONSr]r=<00>re<72>compiler|ryr}r(r(r(r)rU<00>s


 i rUc@s"eZdZdZedg<01>Zdd<04>ZdS)<06>ExprStmtExtensionzsAdds a `do` tag to Jinja2 that works like the print statement just
that it doesn't print the return value.
<20>docCs"tjt|j<03>jd<01>}|<01><05>|_|S)N)r>)rZExprStmtrsr9r>Z parse_tupler<65>)r/r<r<>r(r(r)r=<00>s
zExprStmtExtension.parseN)r!r r*r+rFrGr=r(r(r(r)r<><00>s
r<>c@s$eZdZdZeddg<02>Zdd<05>ZdS)<07>LoopControlExtensionz/Adds break and continue to the template engine.<2E>break<61>continuecCs0t|j<01>}|jdkr"tj|jd<02>Stj|jd<02>S)Nr<4E>)r>)rsr9rvrZBreakr><00>Continue)r/r<<00>tokenr(r(r)r=<00>s

zLoopControlExtension.parseN)r!r r*r+rFrGr=r(r(r(r)r<><00>s r<>c@s eZdZdS)<02> WithExtensionN)r!r r*r(r(r(r)r<><00>sr<>c@s eZdZdS)<02>AutoEscapeExtensionN)r!r r*r(r(r(r)r<><00>sr<>Tccs <00>x|<00>tj<02>D]<5D>}t|jtj<05>r|jj|kr0qg}x>|jD]4}t|tj<08>rft|j t
<EFBFBD>rf|<03> |j <09>q<|<03> d<01>q<Wx|j D]}|<03> d<01>q|W|j dk r<>|<03> d<01>|jdk r<>|<03> d<01>|s<>tdd<03>|D<00><01>}|s<>qnt|<03>dkr<>|d}nt|<03>}|j|jj|fVqWdS)a<>Extract localizable strings from the given template node. Per
default this function returns matches in babel style that means non string
parameters as well as keyword arguments are returned as `None`. This
allows Babel to figure out what you really meant if you are using
gettext functions that allow keyword arguments for placeholder expansion.
If you don't want that behavior set the `babel_style` parameter to `False`
which causes only strings to be returned and parameters are always stored
in tuples. As a consequence invalid gettext calls (calls without a single
string parameter or string parameters after non-string parameters) are
skipped.
This example explains the behavior:
>>> from jinja2 import Environment
>>> env = Environment()
>>> node = env.parse('{{ (_("foo"), _(), ngettext("foo", "bar", 42)) }}')
>>> list(extract_from_ast(node))
[(1, '_', 'foo'), (1, '_', ()), (1, 'ngettext', ('foo', 'bar', None))]
>>> list(extract_from_ast(node, babel_style=False))
[(1, '_', ('foo',)), (1, 'ngettext', ('foo', 'bar'))]
For every string found this function yields a ``(lineno, function,
message)`` tuple, where:
* ``lineno`` is the number of the line on which the string was found,
* ``function`` is the name of the ``gettext`` function used (if the
string was extracted from embedded Python code), and
* ``message`` is the string itself (a ``unicode`` object, or a tuple
of ``unicode`` objects for functions with multiple string arguments).
This extraction function operates on the AST and is because of that unable
to extract any comments. For comment support you have to use the babel
extraction interface or extract comments yourself.
Ncss|]}|dk r|VqdS)Nr()r<>rar(r(r)<00> <genexpr><3E>sz#extract_from_ast.<locals>.<genexpr>rdr)Zfind_allrr@rjr<>rxr$rAr<>rvrr<>rBrCrD<00>tuple<6C>lenr>)r<>rlZ babel_style<6C>strings<67>argr(r(r)rk<00>s0$     



 
rkc@s(eZdZdZdd<03>Zdd<05>Zdd<07>ZdS) <09>_CommentFinderz<72>Helper class to find comments in a token stream. Can only
find comments for gettext calls forwards. Once the comment
from line 4 is found, a comment for line 1 will not return a
usable value.
cCs||_||_d|_d|_dS)Nr)<04>tokens<6E> comment_tags<67>offset<65> last_lineno)r/r<>r<>r(r(r)r0sz_CommentFinder.__init__c Cs~zpxjt|j|j|<01><00>D]R\}}}|dkry|<04>dd<02>\}}Wntk
rTwYnX||jkr|<06><06>gSqWgS||_XdS)N)<02>commentZ linecommentrd)<07>reversedr<64>r<><00>split<69>
ValueErrorr<EFBFBD><00>rstrip)r/r<>r<00>
token_typeZ token_value<75>prefixr<78>r(r(r)<00>find_backwardss
z_CommentFinder.find_backwardscCsd|jr|j|krgSx>t|j|jd<00><00>D]&\}\}}}||kr*|<00>|j|<00>Sq*W|<00>t|j<03><01>S)N)r<>r<><00> enumerater<65>r<>r<>r<>)r/r><00>idxZ token_linenorr(r(r)<00> find_commentss $z_CommentFinder.find_commentsN)r!r r*r+r0r<>r<>r(r(r(r)r<><00>sr<>ccs<>t<00>}x6|<03>dd<02><02>d<03>D] }|<05><03>}|s,q|<04>t|<05><01>qWt|krP|<04>t<06>ddd<06>}||dd<08>}t|<03>d t<08>|<03>d
t <09>|<03>d t
<EFBFBD>|<03>d t <0B>|<03>d t <0C>|<03>dt <0A>|<03>d<0F>p<>t|<03>d<10>p<>t||dt<10>||dt<11>t||dt<13>t|<04>ddd<15>}||d<16><02>rd|jd<||d<18><02>rd|_|<00><17><00>|<03>dd<1A><02>} y"|<08>| <09>}
t|<08>|<08>| <09><01><01>} Wn,tk
<EFBFBD>rx} z |<07>sh<73>dSd} ~ XYnXt| |<02>} x.t|
|<01>D] \}}}|||| <0A> |<0E>fV<00>q<>WdS)aBabel extraction method for Jinja templates.
.. versionchanged:: 2.3
Basic support for translation comments was added. If `comment_tags`
is now set to a list of keywords for extraction, the extractor will
try to find the best preceeding comment that begins with one of the
keywords. For best results, make sure to not have more than one
gettext call in one line of code and the matching comment in the
same line or the line before.
.. versionchanged:: 2.5.1
The `newstyle_gettext` flag can be set to `True` to enable newstyle
gettext calls.
.. versionchanged:: 2.7
A `silent` option can now be provided. If set to `False` template
syntax errors are propagated instead of being ignored.
:param fileobj: the file-like object the messages should be extracted from
:param keywords: a list of keywords (i.e. function names) that should be
recognized as translation functions
:param comment_tags: a list of translator tags to search for and include
in the results.
:param options: a dictionary of additional options (optional)
:return: an iterator over ``(lineno, funcname, message, comments)`` tuples.
(comments will be empty currently)
<20>
extensions<EFBFBD><00>,FcSs|<00>|t|<02><01><02><02>dkS)N)<04>1<>on<6F>yes<65>true)<03>get<65>str<74>lower)<03>optionsri<00>defaultr(r(r)<00>getboolCszbabel_extract.<locals>.getbool<6F>silentTZblock_start_stringZblock_end_stringZvariable_start_stringZvariable_end_stringZcomment_start_stringZcomment_end_stringZline_statement_prefixZline_comment_prefixZ trim_blocksZ lstrip_blocksZkeep_trailing_newliner)Z
cache_sizeZ auto_reloadrpzext.i18n.trimmedrV<00>encodingzutf-8N)F)!rFr<>r<>r<><00>addrrUrrrrrrrr r
r rr r <00> frozensetr{rV<00>read<61>decoder=<00>list<73>lexr8rr<>rkr<>)<11>fileobj<62>keywordsr<73>r<>r<><00> extensionr<6E>r<>r.r6r<>r<><00>e<>finderr>rP<00>messager(r(r)<00> babel_extractsR

 





  


 
 

r<>)5r+r<>Zjinja2rZjinja2.defaultsrrrrrrr r
r r r rZjinja2.environmentrZjinja2.runtimerZjinja2.exceptionsrrZ jinja2.utilsrrrZjinja2._compatrrrr<>rrr1r,rLrQrTrUr<>r<>r<>r<>rkr<>r<>Zi18nr<6E>Z loopcontrolsZwith_rNr(r(r(r)<00><module> s: 8   Y 
 y   C%Q