Your IP : 18.190.239.189


Current Path : /opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib/python3.7/site-packages/jinja2/__pycache__/ext.cpython-37.opt-1.pyc

B

�˝`z}�
@sPUdZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddl
mZdd	l
mZdd
lmZddlmZddlmZdd
lmZddlmZej�rddlZddlmZddlmZddlmZGdd�dej�Z Gdd�de �Z!ej"e e!fZ#dZ$ej%e&dfe'd<e�(d�Z)Gdd�d�Z*eeej+ej+ej"ej+efd�dd��Z,ej-e&ge&fej-de&fd�d d!�Z.ej-e&e&e/ge&fej-de&fd�d"d#�Z0ej-e&e&ge&fej-de&fd�d$d%�Z1ej-e&e&e&e/ge&fej-de&fd�d&d'�Z2Gd(d)�d)e*�Z3Gd*d+�d+e*�Z4Gd,d-�d-e*�Z5Gd.d/�d/e*�Z6Gd0d1�d1e*�Z7Gd2d3�d3e*�Z8e$d4fe
j9ej:e&e;ej<ej%e/e&ej"ej=e&ej%ej=e&dfffd5�d6d7�Z>Gd8d9�d9�Z?ej@ej:e&ej:e&ejAe&ej+fej<ej%e/e&ej"ej=e&ej%ej=e&dffejBe&fd:�d;d<�ZCe3ZDe4ZEe5ZFe6ZGe7ZHe8ZIdS)=z2Extension API for adding custom tags and behavior.�N)�Markup�)�defaults)�nodes)�Environment)�TemplateAssertionError)�TemplateSyntaxError)�concat)�Context)�	Undefined)�
import_string)�pass_context)�Token)�TokenStream)�Parserc@s0eZdZeed�dd�Zeeeed�dd�ZdS)�_TranslationsBasic)�message�returncCsdS)N�)�selfrrr�;/opt/alt/python37/lib/python3.7/site-packages/jinja2/ext.py�gettextsz_TranslationsBasic.gettext)�singular�plural�nrcCsdS)Nr)rrrrrrr�ngettextsz_TranslationsBasic.ngettextN)�__name__�
__module__�__qualname__�strr�intrrrrrrsrc@s4eZdZeeed�dd�Zeeeeed�dd�ZdS)�_TranslationsContext)�contextrrcCsdS)Nr)rr"rrrr�pgettext"sz_TranslationsContext.pgettext)r"rrrrcCsdS)Nr)rr"rrrrrr�	npgettext%sz_TranslationsContext.npgettextN)rrrrr#r r$rrrrr!!sr!)�_rrr#r$.�GETTEXT_FUNCTIONSz\s*\n\s*c	@s8eZdZUdZejeed<dd�dd�Ze	�Z
ejeed<dZe
dd	�d
d�Ze
dd	�dd
�Zd eejeejeed�dd�Zdejdejdfd�dd�Zdejejejejfd�dd�Zd!eejeejd�dd�Zd"eejejejejejejejejejejejeejd�dd�ZdS)#�	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).
    �
identifierN)rcCs|j�d|j��|_dS)N�.)rrr()�clsrrr�__init_subclass__LszExtension.__init_subclass__�tags�d)�environmentrcCs
||_dS)N)r.)rr.rrr�__init__YszExtension.__init__cCs,t�tt�|j��}|j�|j�||_|S)z=Create a copy of this extension bound to another environment.)	�t�castr'�object�__new__�	__class__�__dict__�updater.)rr.�rvrrr�bind\szExtension.bind)�source�name�filenamercCs|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)rr9r:r;rrr�
preprocesscszExtension.preprocessrr)�streamrcCs|S)aIt'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`.
        r)rr=rrr�
filter_streamlszExtension.filter_streamr)�parserrcCs
t��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)�NotImplementedError)rr?rrr�parsevszExtension.parse)r:�linenorcCstj|j||d�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)
        )rB)r�ExtensionAttributer()rr:rBrrr�attr~s
zExtension.attr)r:�args�kwargs�dyn_args�
dyn_kwargsrBrcCs8|dkrg}|dkrg}tj|j||d�|||||d�S)zsCall a method of the extension.  This is a shortcut for
        :meth:`attr` + :class:`jinja2.nodes.Call`.
        N)rB)r�CallrD)rr:rErFrGrHrBrrr�call_method�szExtension.call_method)N)N)NNNNN) rrr�__doc__r0ZClassVarr�__annotations__r+�setr,�SetZpriorityrr/r8�Optionalr<�Union�Iterabler>r�Node�ListrAr rCrD�Expr�KeywordrIrJrrrrr'7s(
$	
@r')�	__contextrErFrcOs|j|�d�f|�|�S)Nr)�callZresolve)rVrErFrrr�_gettext_alias�srX)�funcrcs"ttttjtd��fdd��}|S)N)rV�__string�	variablesrcs$|��|�}|jjrt|�}||S)N)rW�eval_ctx�
autoescaper)rVrZr[r7)rYrrr�sz"_make_new_gettext.<locals>.gettext)r
r
rr0�Any)rYrr)rYr�_make_new_gettext�s	r_cs&ttttttjtd��fdd��}|S)N)rV�
__singular�__plural�__numr[rcs4|�d|�|��|||�}|jjr,t|�}||S)N�num)�
setdefaultrWr\r]r)rVr`rarbr[r7)rYrrr�s
z$_make_new_ngettext.<locals>.ngettext)r
r
rr r0r^)rYrr)rYr�_make_new_ngettext�srecs$tttttjtd��fdd��}|S)N)rV�__string_ctxrZr[rcs2|�d|�|��||�}|jjr*t|�}||S)Nr")rdrWr\r]r)rVrfrZr[r7)rYrrr#�s
z$_make_new_pgettext.<locals>.pgettext)r
r
rr0r^)rYr#r)rYr�_make_new_pgettext�s

rgc	s(tttttttjtd��fdd��}|S)N)rVrfr`rarbr[rcsB|�d|�|�d|�|��||||�}|jjr:t|�}||S)Nr"rc)rdrWr\r]r)rVrfr`rarbr[r7)rYrrr$�s	z&_make_new_npgettext.<locals>.npgettext)r
r
rr r0r^)rYr$r)rYr�_make_new_npgettext�srhcs�eZdZdZdhZedd��fdd�Zd%deje	dd�d	d
�Z
d&eje	dd�dd
�Zd'eje
ge
feje
e
ege
feje	ejeje
e
ge
fejeje
e
e
ege
fdd�dd�Zddd�dd�Zefeje
ejfeje
ejejee
ejeje
ejeje
dfffd�dd�Zdejejejejfd�dd�Zefe
eje
e
d�dd�Zde	ejeje
e
fd�d d!�Ze
eje
ej e
ej!fejej!e	e	ej"d"�d#d$�Z#�Z$S)(�InternationalizationExtensionz-This extension adds gettext support to Jinja.ZtransN)r.rcs:t��|�t|jd<|j|j|j|j|j|j	dd�dS)Nr%F)Zinstall_gettext_translationsZinstall_null_translationsZinstall_gettext_callablesZuninstall_gettext_translationsZextract_translations�newstyle_gettext)
�superr/rX�globals�extend�_install�
_install_null�_install_callables�
_uninstall�_extract)rr.)r4rrr/s
z&InternationalizationExtension.__init__�_SupportedTranslations)�translations�newstylercCsdt|dd�}|dkr|j}t|dd�}|dkr4|j}t|dd�}t|dd�}|j|||||d�dS)NZugettextZ	ungettextr#r$)rur#r$)�getattrrrrp)rrtrurrr#r$rrrrnsz&InternationalizationExtension._install)rurcCsxddl}|��}t|d�r"|j}ntttd�dd�}t|d�rF|j}ntttttd�dd	�}|j|j|j|||d
�dS)Nrr#)�c�srcSs|S)Nr)rwrxrrrr#*sz=InternationalizationExtension._install_null.<locals>.pgettextr$)rwrx�prrcSs|dkr|S|S)Nrr)rwrxryrrrrr$1sz>InternationalizationExtension._install_null.<locals>.npgettext)rrrur#r$)	rZNullTranslations�hasattrr#rr$r rpr)rrurrtr#r$rrrro s

z+InternationalizationExtension._install_null)rrrur#r$rcCsb|dk	r||j_|jjrHt|�}t|�}|dk	r8t|�}|dk	rHt|�}|jjj||||d�dS)N)rrr#r$)r.rjr_rergrhrlr6)rrrrur#r$rrrrp<sz0InternationalizationExtension._install_callables)rtrcCs"xdD]}|jj�|d�qWdS)N)rrr#r$)r.rl�pop)rrt�keyrrrrqTs
z(InternationalizationExtension._uninstall.)r9�gettext_functionsrcCs t|t�r|j�|�}t||�S)N)�
isinstancerr.rA�extract_from_ast)rr9r}rrrrrXs
z&InternationalizationExtension._extractr)r?rcCst|j�j}d}d}d}i}d}�x|jjjdk�r:|rD|j�d�|j�d�rRP|j�d�}|j|kr�|jd|j�d�|jt	d	�|jjjd
kr�t|j�|�
�||j<}	n8|dkr�|jdkr�|jdk}q$nt�|jd
�||j<}	|dkr$t
|	tj��r*t�dd
�}|||j<t�t�dd�|	�}n|	}|jdk}q$W|j�d�d}
d}t�}|�|d�\}
}|
�r�|�|
�|dk�r�t�|
dd
�}|
ddk}|jj�d��rDd}t|j�|jjjdk�r|j�d�}|j|k�r�|jd|j�d�|jt	d	�||j}|jdk}|j�d�|�|d�\}}
t|j�|�|�n
t|j�x(|D] }||k�rTt�|d
�||<�qTW|�s�d}n|dk�r�|�d|�|dk�r�|jjd}|�r�|�|�}|
�r�|�|
�}
|�||
||t|�|�o�|�}|�|�|dk	�r
||gS|SdS)zParse a translatable tag.FNZ	block_endZcommaZcolonr:ztranslatable variable z defined twice.)�excZassign)�trimmedZ	notrimmedr��loadZ_transZstorercTrzname:pluralizezunknown variable z for pluralizationzpluralize without variableszext.i18n.trimmed)�nextr=rB�current�type�expectZskip_if�value�failrZparse_expressionr�Namer~rIZAssignrM�_parse_blockr6�testr.�policies�_trim_whitespace�
_make_node�boolZ
set_lineno)rr?rB�num_called_num�plural_exprZplural_expr_assignmentr[r��token�varrZhave_plural�
referencedZsingular_namesrZplural_namesr:�noderrrrAcs�


















z#InternationalizationExtension.parse)�string�_ws_rercCs|�d|���S)N� )�sub�strip)rr�r�rrrr��sz.InternationalizationExtension._trim_whitespace)r?�allow_pluralizercCsg}g}x�|jjjdkr<|�|jjj�dd��t|j�q
|jjjdkr�t|j�|j�d�j}|�|�|�d|�d��|j�d�q
|jjjd	kr�t|j�|jj�d
�r�Pn|jj�d�r�|r�P|�	d�|�	d
�q
|jj
r�|�	d�q
td��q
W|t|�fS)z1Parse until the next block tag with a given name.�data�%z%%Zvariable_beginr:z%(z)sZvariable_endZblock_beginz
name:endtranszname:pluralizez:a translatable section can have only one pluralize sectionz;control structures in translatable sections are not allowedzunclosed translation blockzinternal parser error)
r=r�r��appendr��replacer�r�r�r�Zeos�RuntimeErrorr	)rr?r�r�Zbufr:rrrr��s6


z*InternationalizationExtension._parse_block)rrr[r��vars_referencedr�rc
Cs|jj}|s,|s,|�dd�}|r,|�dd�}|dkr\t�dd�}t�|t�|�ggdd�}	n0t�dd�}
t�|
t�|�t�|�|ggdd�}	|r�xf|��D]*\}}|r�|dkr�q�|	j�	t�
||��q�Wn.t�|	�}	|r�t�|	t�
dd	�|��D���}	t�|	g�S)
z/Generates a useful node from the data provided.z%%r�Nrr�rrccSs"g|]\}}t�t�|�|��qSr)rZPair�Const)�.0r|r�rrr�
<listcomp>7sz<InternationalizationExtension._make_node.<locals>.<listcomp>)r.rjr�rr�rIr��itemsrFr�rUZMarkSafeIfAutoescapeZMod�Dict�Output)
rrrr[r�r�r�rurr�rr|r�rrrr��s8

z(InternationalizationExtension._make_node)N)N)NNN)%rrrrKr,rr/r0rOr�rnro�Callablerr rprqr&rPr�Template�Sequence�Iterator�TuplerrrRrSrAr��Patternr�r�r�rTr�r��
__classcell__rr)r4rri�s2	
 Z<$s%
ric@s(eZdZdZdhZdejd�dd�ZdS)�ExprStmtExtensionzrAdds a `do` tag to Jinja that works like the print statement just
    that it doesn't print the return value.
    �dor)r?rcCs"tjt|j�jd�}|��|_|S)N)rB)r�ExprStmtr�r=rBZparse_tupler�)rr?r�rrrrAFs
zExprStmtExtension.parseN)rrrrKr,rr�rArrrrr�?sr�c@s6eZdZdZddhZdejejej	fd�dd�Z
dS)	�LoopControlExtensionz/Adds break and continue to the template engine.�break�continuer)r?rcCs0t|j�}|jdkr"tj|jd�Stj|jd�S)Nr�)rB)r�r=r�r�BreakrB�Continue)rr?r�rrrrAQs

zLoopControlExtension.parseN)rrrrKr,r0rPrr�r�rArrrrr�Lsr�cs$eZdZedd��fdd�Z�ZS)�
WithExtensionN)r.rcs t��|�tjdtdd�dS)NzZThe 'with' extension is deprecated and will be removed in Jinja 3.1. This is built in now.�)�
stacklevel)rkr/�warnings�warn�DeprecationWarning)rr.)r4rrr/Ys
zWithExtension.__init__)rrrrr/r�rr)r4rr�Xsr�cs$eZdZedd��fdd�Z�ZS)�AutoEscapeExtensionN)r.rcs t��|�tjdtdd�dS)Nz`The 'autoescape' extension is deprecated and will be removed in Jinja 3.1. This is built in now.r�)r�)rkr/r�r�r�)rr.)r4rrr/ds
zAutoEscapeExtension.__init__)rrrrr/r�rr)r4rr�csr�c@s8eZdZdZdhZdejd�dd�Zee	d�dd	�Z
d
S)�DebugExtensiona�A ``{% debug %}`` tag that dumps the available variables,
    filters, and tests.

    .. code-block:: html+jinja

        <pre>{% debug %}</pre>

    .. code-block:: text

        {'context': {'cycler': <class 'jinja2.utils.Cycler'>,
                     ...,
                     'namespace': <class 'jinja2.utils.Namespace'>},
         'filters': ['abs', 'attr', 'batch', 'capitalize', 'center', 'count', 'd',
                     ..., 'urlencode', 'urlize', 'wordcount', 'wordwrap', 'xmlattr'],
         'tests': ['!=', '<', '<=', '==', '>', '>=', 'callable', 'defined',
                   ..., 'odd', 'sameas', 'sequence', 'string', 'undefined', 'upper']}

    .. versionadded:: 2.11.0
    �debugr)r?rcCs8|j�d�j}t��}|jd|g|d�}tj|g|d�S)Nz
name:debug�_render)rB)r=r�rBrZContextReferencerJr�)rr?rBr"�resultrrrrA�szDebugExtension.parse)r"rcCs8|��t|jj���t|jj���d�}tj|ddd�S)N)r"�filters�testsr�T)ZdepthZcompact)Zget_all�sortedr.r��keysr��pprintZpformat)rr"r�rrrr��szDebugExtension._renderN)rrrrKr,rr�rAr
rr�rrrrr�nsr�T)�astr}�babel_stylerccs�x|�tj�D]�}t|jtj�r|jj|kr0qg}x>|jD]4}t|tj�rft|j	t
�rf|�|j	�q<|�d�q<Wx|jD]}|�d�q|W|j
dk	r�|�d�|jdk	r�|�d�|s�tdd�|D��}|s�qnt|�dkr�|d}nt|�}|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, or a tuple of strings 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��xrrr�	<genexpr>�sz#extract_from_ast.<locals>.<genexpr>rr)Zfind_allrrIr~r�r�r:rEr�r�rr�rFrGrH�tuple�lenrB)r�r}r�r�Zstrings�argr%�outrrrr�s.+




rc@sfeZdZdZejejeeefejedd�dd�Z	eej
ed�dd�Zeej
ed	�d
d�ZdS)�_CommentFinderz�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.
    N)�tokens�comment_tagsrcCs||_||_d|_d|_dS)Nr)r�r��offset�last_lineno)rr�r�rrrr/�sz_CommentFinder.__init__)r�rc	Cs~zpxjt|j|j|��D]R\}}}|dkry|�dd�\}}Wntk
rTwYnX||jkr|��gSqWgS||_XdS)N)�commentZlinecommentr)�reversedr�r��split�
ValueErrorr��rstrip)rr�r%�
token_typeZtoken_value�prefixr�rrr�find_backwards�s
z_CommentFinder.find_backwards)rBrcCsd|jr|j|krgSx>t|j|jd��D]&\}\}}}||kr*|�|j|�Sq*W|�t|j��S)N)r�r��	enumerater�r�r�r�)rrB�idxZtoken_linenor%rrr�
find_commentss$z_CommentFinder.find_comments)
rrrrKr0r�r�r rr/rSr�r�rrrrr��s
r�)�fileobj�keywordsr��optionsrccs�i}x4|�dd��d�D]}|��}|s*qd|t|�<qWt|krJd|t<dtjttftttd�dd�}||d	d
�}t	|�dt
j�|�dt
j�|�d
t
j
�|�dt
j�|�dt
j�|�dt
j�|�d�p�t
j|�d�p�t
j||dt
j�||dt
j�t
j||dt
j�t|�ddd�}||d��r*d
|jd<||d��r<d
|_|���|�dd��}	y"|�|	�}
t|�|�|	���}Wnt k
�r�|�s��dSXt!||�}x.t"|
|�D] \}
}}|
|||�#|
�fV�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 preceding 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)
    �
extensions��,NF)r�r|�defaultrcSs|�|t|����dkS)N>�yes�1�true�on)�getr�lower)r�r|r�rrr�getbool?szbabel_extract.<locals>.getbool�silentTZblock_start_stringZblock_end_stringZvariable_start_stringZvariable_end_stringZcomment_start_stringZcomment_end_stringZline_statement_prefixZline_comment_prefixZtrim_blocksZ
lstrip_blocksZkeep_trailing_newliner)Z
cache_sizeZauto_reloadr�zext.i18n.trimmedrj�encodingzutf-8)F)$r�r�r�rrir0�Mappingrr�rrZBLOCK_START_STRINGZBLOCK_END_STRINGZVARIABLE_START_STRINGZVARIABLE_END_STRINGZCOMMENT_START_STRINGZCOMMENT_END_STRINGZLINE_STATEMENT_PREFIXZLINE_COMMENT_PREFIXZTRIM_BLOCKSZ
LSTRIP_BLOCKSZNEWLINE_SEQUENCEZKEEP_TRAILING_NEWLINEr�r�rj�read�decoderA�listZlexr<rr�rr�)r�r�r�r�r�Zextension_namer�r�r.r9r�r��finderrBrYrrrr�
babel_extract
sR% 


r�)JrKr��re�typingr0r�Z
markupsaferr�rrr.r�
exceptionsrrZruntimer	r
rZutilsrr
Z
TYPE_CHECKINGZtyping_extensionsZteZlexerrrr?rZProtocolrr!rPrsr&r�rrL�compiler�r'r^rXr�r_r rergrhrir�r�r�r�r�r�r�r�r�rOrr�ZBinaryIOr�rSr�Zi18nr�ZloopcontrolsZwith_r]r�rrrr�<module>sx
m
&*(K
*<J)@V

?>