https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/genshi/template/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/genshi/template/__pycache__/text.cpython-310.pyc
o

!�b�0�@s�dZddlZddlZddlmZddlmZmZmZm	Z	m
Z
mZddlm
Z
ddlTddlmZgd�Zd	ZGd
d�de�ZGdd
�d
e�ZeZdS)a�Plain text templating engine.

This module implements two template language syntaxes, at least for a certain
transitional period. `OldTextTemplate` (aliased to just `TextTemplate`) defines
a syntax that was inspired by Cheetah/Velocity. `NewTextTemplate` on the other
hand is inspired by the syntax of the Django template language, which has more
explicit delimiting of directives, and is more flexible with regards to
white space and line breaks.

In a future release, `OldTextTemplate` will be phased out in favor of
`NewTextTemplate`, as the names imply. Therefore the new syntax is strongly
recommended for new projects, and existing projects may want to migrate to the
new syntax to remain compatible with future Genshi releases.
�N)�TEXT)�BadDirectiveError�Template�TemplateSyntaxError�EXEC�INCLUDE�SUB)�Suite)�*)�interpolate)�NewTextTemplate�OldTextTemplate�TextTemplatezrestructuredtext enc@s~eZdZdZdefdefdefdefdefde	fde
fgZd	Zd
Z
dZ			ddd�Zdd�Zdd�Zeeed�Zdd�ZdS)ra�Implementation of a simple text-based template engine. This class will
    replace `OldTextTemplate` in a future release.
    
    It uses a more explicit delimiting style for directives: instead of the old
    style which required putting directives on separate lines that were prefixed
    with a ``#`` sign, directives and commenbtsr are enclosed in delimiter pairs
    (by default ``{% ... %}`` and ``{# ... #}``, respectively).
    
    Variable substitution uses the same interpolation syntax as for markup
    languages: simple references are prefixed with a dollar sign, more complex
    expression enclosed in curly braces.
    
    >>> tmpl = NewTextTemplate('''Dear $name,
    ... 
    ... {# This is a comment #}
    ... We have the following items for you:
    ... {% for item in items %}
    ...  * ${'Item %d' % item}
    ... {% end %}
    ... ''')
    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render(encoding=None))
    Dear Joe,
    <BLANKLINE>
    <BLANKLINE>
    We have the following items for you:
    <BLANKLINE>
     * Item 1
    <BLANKLINE>
     * Item 2
    <BLANKLINE>
     * Item 3
    <BLANKLINE>
    <BLANKLINE>
    
    By default, no spaces or line breaks are removed. If a line break should
    not be included in the output, prefix it with a backslash:
    
    >>> tmpl = NewTextTemplate('''Dear $name,
    ... 
    ... {# This is a comment #}\
    ... We have the following items for you:
    ... {% for item in items %}\
    ...  * $item
    ... {% end %}\
    ... ''')
    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render(encoding=None))
    Dear Joe,
    <BLANKLINE>
    We have the following items for you:
     * 1
     * 2
     * 3
    <BLANKLINE>
    
    Backslashes are also used to escape the start delimiter of directives and
    comments:

    >>> tmpl = NewTextTemplate('''Dear $name,
    ... 
    ... \\{# This is a comment #}
    ... We have the following items for you:
    ... {% for item in items %}\
    ...  * $item
    ... {% end %}\
    ... ''')
    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render(encoding=None))
    Dear Joe,
    <BLANKLINE>
    {# This is a comment #}
    We have the following items for you:
     * 1
     * 2
     * 3
    <BLANKLINE>
    
    :since: version 0.5
    �def�when�	otherwise�for�if�choose�with�textz/((?<!\\)%s\s*(\w+)\s*(.*?)\s*%s|(?<!\\)%s.*?%s)z \\\n|\\\r\n|\\(\\)|\\(%s)|\\(%s)N�strictF�z{%z%}z{#z#}c			Cs"||_tj|||||||d�dS)N)�filepath�filename�loader�encoding�lookup)�
delimitersr�__init__)	�self�sourcerrrrr�
allow_exec�delims�r$�6/usr/lib/python3/dist-packages/genshi/template/text.pyr�s
�zNewTextTemplate.__init__cCs|jS)N)�_delims)r r$r$r%�_get_delims�szNewTextTemplate._get_delimsc	Cslt|�dkr
td��||_t�|jtdd�|D��tj�|_t�|j	tdd�|ddd�D���|_
dS)N�z/delimiers tuple must have exactly four elementscS�g|]}t�|��qSr$��re�escape��.0�dr$r$r%�
<listcomp>��z/NewTextTemplate._set_delims.<locals>.<listcomp>cSr)r$r*r-r$r$r%r0�r1�)�len�
ValueErrorr&r+�compile�
_DIRECTIVE_RE�tuple�DOTALL�
_directive_re�
_ESCAPE_RE�
_escape_re)r r#r$r$r%�_set_delims�s
��
�zNewTextTemplate._set_delimsz�    The delimiters for directives and comments. This should be a four item tuple
    of the form ``(directive_start, directive_end, comment_start,
    comment_end)``, where each item is a string.
    cCs�g}i}d}|��}t|tj�s|�|pdd�}d}d}|jj}dd�}	t|j�	|��D�]\}
}|�
d�\}}
||kre||	|||��}t||j||j
d�D]
\}}}|�|||f�qO|t|���7}|t|||
����7}|�dd	�\}}|d
kr�|j|df}tt||j|d|j
d��}t|�dkr�|ddtur�|dd}|�t|dgf|f�n�|dkr�|js�td
|j|��zt||j||j
d�}Wnty�}zt||j||jp�dd��d}~ww|j|df}|�t||f�nU|dk�r!|d8}||v�r |�|�\}}||d�}t|g|f|j|dffg||d�<n(|�rI|�|�}|du�r2t|��d||d|j|dff}|t|�f||<|d7}|
}q,|t|�k�ru||	||d��}t||j||j
d�D]\}}}|�|||f��qf|S)�#Parse the template from text input.r�utf-8�replace�cSs"dd�|��D�}|s
dS|dS)NcSsg|]}|r|�qSr$r$)r.�gr$r$r%r0�sz@NewTextTemplate._parse.<locals>._escape_repl.<locals>.<listcomp>�r)�groups)�morCr$r$r%�_escape_repl�sz,NewTextTemplate._parse.<locals>._escape_repl�rr2��includeN�pythonzPython code blocks not allowed�end) �read�
isinstance�six�	text_type�decoder;�sub�	enumerater9�finditer�spanrrr�appendr3�
splitlines�groupr�listrrr"rr	�SyntaxError�linenor�popr�
get_directiver)r r!r�stream�dirmap�depth�offsetrY�_escape_subrE�idxrD�startrJr�kind�data�pos�command�value�suite�err�	directive�start_offset�	substream�clsr$r$r%�_parse�s�
���

����



��


�zNewTextTemplate._parse)NNNNrFr)�__name__�
__module__�__qualname__�__doc__�DefDirective�
WhenDirective�OtherwiseDirective�ForDirective�IfDirective�ChooseDirective�
WithDirective�
directives�
serializerr6r:rr'r<�propertyrrnr$r$r$r%r,s*M�
�
rc@sXeZdZdZdefdefdefdefdefde	fde
fgZd	Ze
�d
e
j�Zdd�Zd
S)r
a�Legacy implementation of the old syntax text-based templates. This class
    is provided in a transition phase for backwards compatibility. New code
    should use the `NewTextTemplate` class and the improved syntax it provides.
    
    >>> tmpl = OldTextTemplate('''Dear $name,
    ... 
    ... We have the following items for you:
    ... #for item in items
    ...  * $item
    ... #end
    ... 
    ... All the best,
    ... Foobar''')
    >>> print(tmpl.generate(name='Joe', items=[1, 2, 3]).render(encoding=None))
    Dear Joe,
    <BLANKLINE>
    We have the following items for you:
     * 1
     * 2
     * 3
    <BLANKLINE>
    All the best,
    Foobar
    rrrrrrrrzA(?:^[ \t]*(?<!\\)#(end).*\n?)|(?:^[ \t]*(?<!\\)#((?:\w+|#).*)\n?)cCs<g}i}d}|��}t|tj�s|�|pdd�}d}d}t|j�|��D]�\}}	|	��\}
}|
|krX|||
�}t	||j
||jd�D]
\}
}}|�|
||f�qB|t
|���7}||
|���dd�}|t
|���7}|�dd�}t
|�dkr}|\}}n|dd}}|dkr�|d8}||vr�|�|�\}}||d�}t|g|f|j
|dffg||d�<n@|dkr�|j|df}|�t|��dgf|f�n(|d	kr�|�|�}|dur�t|��d||d|j
|dff}|t
|�f||<|d7}|}q$|t
|�k�r||d��d
d	�}t	||j
||jd�D]\}
}}|�|
||f��q
|S)r=rr>r?r@rFNrJrH�#z\#)rKrLrMrNrOrQr6rRrSrrrrTr3rU�lstrip�splitrZrrr�stripr[rr?)r r!rr\r]r^r_rYrarDrbrJrrcrdrerjrfrgrkrlrmr$r$r%rnsd
�


��

�zOldTextTemplate._parseN)rorprqrrrsrtrurvrwrxryrzr{r+r5�	MULTILINEr6rnr$r$r$r%r
�s��r
)rrr+rM�genshi.corer�genshi.template.baserrrrrr�genshi.template.evalr	�genshi.template.directives�genshi.template.interpolationr�__all__�
__docformat__rr
rr$r$r$r%�<module>s
 C`

https://t.me/RX1948 - 2025