Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/coverage/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/coverage/__pycache__/templite.cpython-37.pyc

B

E�W�&�@s\dZddlZddlmZGdd�de�ZGdd�de�ZGdd	�d	e�ZGd
d�de�Z	dS)z�A simple Python template renderer, for a nano-subset of Django syntax.

For a detailed discussion of this code, see this chapter from 500 Lines:
http://aosabook.org/en/500L/a-template-engine.html

�N)�envc@seZdZdZdS)�TempliteSyntaxErrorz*Raised when a template has a syntax error.N)�__name__�
__module__�__qualname__�__doc__�rr�D/opt/alt/python37/lib64/python3.7/site-packages/coverage/templite.pyrsrc@seZdZdZdS)�TempliteValueErrorz7Raised when an expression won't evaluate in a template.N)rrrrrrrr	r
sr
c@sNeZdZdZddd�Zdd�Zdd�Zd	d
�ZdZdd
�Z	dd�Z
dd�ZdS)�CodeBuilderzBuild source code conveniently.rcCsg|_||_dS)N)�code�indent_level)�self�indentrrr	�__init__szCodeBuilder.__init__cCsd�dd�|jD��S)N�css|]}t|�VqdS)N)�str)�.0�crrr	�	<genexpr>$sz&CodeBuilder.__str__.<locals>.<genexpr>)�joinr)rrrr	�__str__#szCodeBuilder.__str__cCs|j�d|j|dg�dS)zwAdd a line of source to the code.

        Indentation and newline will be added for you, don't provide them.

        � �
N)r�extendr
)r�linerrr	�add_line&szCodeBuilder.add_linecCst|j�}|j�|�|S)z!Add a section, a sub-CodeBuilder.)rr
r�append)r�sectionrrr	�add_section.s
zCodeBuilder.add_section�cCs|j|j7_dS)z0Increase the current indent for following lines.N)r
�INDENT_STEP)rrrr	r6szCodeBuilder.indentcCs|j|j8_dS)z0Decrease the current indent for following lines.N)r
r!)rrrr	�dedent:szCodeBuilder.dedentcCs(|jdkst�t|�}i}t||�|S)z:Execute the code, and return a dict of globals it defines.r)r
�AssertionErrorr�exec)rZ
python_sourceZglobal_namespacerrr	�get_globals>s

zCodeBuilder.get_globalsN)r)rrrrrrrrr!rr"r%rrrr	rs
rc@sBeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	d
S)�Templitea�A simple template renderer, for a nano-subset of Django syntax.

    Supported constructs are extended variable access::

        {{var.modifier.modifier|filter|filter}}

    loops::

        {% for var in list %}...{% endfor %}

    and ifs::

        {% if var %}...{% endif %}

    Comments are within curly-hash markers::

        {# This will be ignored #}

    Any of these constructs can have a hypen at the end (`-}}`, `-%}`, `-#}`),
    which will collapse the whitespace following the tag.

    Construct a Templite with the template text, then use `render` against a
    dictionary context to create a finished string::

        templite = Templite('''
            <h1>Hello {{name|upper}}!</h1>
            {% for topic in topics %}
                <p>You are interested in {{topic}}.</p>
            {% endif %}
            ''',
            {'upper': str.upper},
        )
        text = templite.render({
            'name': "Ned",
            'topics': ['Python', 'Geometry', 'Juggling'],
        })

    c	s*i|_x|D]}|j�|�qWt�|_t�|_t����d�������}��d���d���d�t	j
r���d�n
��d�g���fdd�}g}t�d	|�}d
}�x|D�]}	|	�
d��r�d\}
}|	d
dk}|r�d
}|	�
d�r�q��q�|	�
d��r*|�|	|
|����}��d|��q�|�|	|
|�����}
|
ddk�r�t|
�dk�rl|�d|	�|�d���d|�|
d������q�|
ddk�rt|
�dk�s�|
ddk�r�|�d|	�|�d�|�|
d|j���d|
d|�|
d�f����n�|
d�
d��r�t|
�dk�r@|�d|	�|
ddd �}|�sb|�d!|	�|��}||k�r�|�d"|����n|�d#|
d�q�|�r�|	��}	|	r���t|	��q�W|�r�|�d$|d%�|�x(|j|jD]}|�d&||f��q�W��d'�������d(|_d S))z�Construct a Templite with the given `text`.

        `contexts` are dictionaries of values to use for future renderings.
        These are good for filters and global values.

        z&def render_function(context, do_dots):zresult = []zappend_result = result.appendzextend_result = result.extendzto_str = unicodezto_str = strcsNt��dkr ��d�d�n t��dkr@��dd�����dd�=dS)z%Force `buffered` to the code builder.�zappend_result(%s)rzextend_result([%s])z, N)�lenrrr)�bufferedrrr	�flush_output�s
z'Templite.__init__.<locals>.flush_outputz(?s)({{.*?}}|{%.*?%}|{#.*?#})F�{)��������-z{#z{{z
to_str(%s)r�ifr,zDon't understand ifzif %s:r'�forr �inzDon't understand forzfor c_%s in %s:��endzDon't understand endNz
Too many endszMismatched end tagzDon't understand tagzUnmatched action tag���zc_%s = context[%r]zreturn "".join(result)Zrender_function)�context�update�set�all_varsZ	loop_varsrrrrr�PY2�re�split�
startswith�
_expr_code�striprr(�
_syntax_error�	_variable�popr"�lstrip�reprr%�_render_function)r�textZcontextsr6Z	vars_coder*Z	ops_stack�tokensZsquash�token�startr4�expr�wordsZend_whatZ
start_what�var_namer)r)rr	rqs�












zTemplite.__init__cCs�d|krR|�d�}|�|d�}x�|dd�D]}|�||j�d||f}q.Wn`d|kr�|�d�}|�|d�}d�dd	�|dd�D��}d
||f}n|�||j�d|}|S)z(Generate a Python expression for `expr`.�|rr'Nzc_%s(%s)�.z, css|]}t|�VqdS)N)rD)r�drrr	r�sz&Templite._expr_code.<locals>.<genexpr>zdo_dots(%s, %s)zc_%s)r<r>rAr9r)rrJZpipesr�func�dots�argsrrr	r>�s

zTemplite._expr_codecCstd||f��dS)z6Raise a syntax error using `msg`, and showing `thing`.z%s: %rN)r)r�msg�thingrrr	r@�szTemplite._syntax_errorcCs&t�d|�s|�d|�|�|�dS)z�Track that `name` is used as a variable.

        Adds the name to `vars_set`, a set of variable names.

        Raises an syntax error if `name` is not a valid name.

        z[_a-zA-Z][_a-zA-Z0-9]*$zNot a valid nameN)r;�matchr@�add)r�nameZvars_setrrr	rA�szTemplite._variableNcCs&t|j�}|r|�|�|�||j�S)z�Render this template by applying it to `context`.

        `context` is a dictionary of values to use in this rendering.

        )�dictr6r7rE�_do_dots)rr6Zrender_contextrrr	�render	s

zTemplite.renderc
Gszxt|D]l}yt||�}WnJtk
rby||}Wn(ttfk
r\td||f��YnXYnXt|�r|�}qW|S)z(Evaluate dotted expressions at run-time.zCouldn't evaluate %r.%s)�getattr�AttributeError�	TypeError�KeyErrorr
�callable)r�valuerQ�dotrrr	rYs

zTemplite._do_dots)N)
rrrrrr>r@rArZrYrrrr	r&Js&v
r&)
rr;�coverager�
ValueErrorrr
�objectrr&rrrr	�<module>	s.