Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/site-packages/coverage/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/site-packages/coverage/__pycache__/templite.cpython-35.pyc



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/python35/lib64/python3.5/site-packages/coverage/templite.pyrsrc@seZdZdZdS)�TempliteValueErrorz7Raised when an expression won't evaluate in a template.N)rrrrrrrr	r
sr
c@sseZdZdZddd�Zdd�Zdd�Zd	d
�ZdZdd
�Z	dd�Z
dd�ZdS)�CodeBuilderzBuild source code conveniently.rcCsg|_||_dS)N)�code�indent_level)�self�indentrrr	�__init__s	zCodeBuilder.__init__cCsdjdd�|jD��S)N�css|]}t|�VqdS)N)�str)�.0�crrr	�	<genexpr>$sz&CodeBuilder.__str__.<locals>.<genexpr>)�joinr)rrrr	�__str__#szCodeBuilder.__str__cCs$|jjd|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_linecCs#t|j�}|jj|�|S)z!Add a section, a sub-CodeBuilder.)rr
r�append)r�sectionrrr	�add_section.szCodeBuilder.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.dedentcCs8|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)rrrrrrrrr!rr"r%rrrr	rsrc@saeZdZdZdd�Zdd�Zdd�Zdd	�Zd
dd�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'],
        })

    csi|_x|D]}|jj|�qWt�|_t�|_t���jd��j��j�}�jd��jd��jd�t	j
r��jd�n
�jd�g���fdd�}g}tjd	|�}d
}x�|D]�}	|	j
d�rbd'\}
}|	d(dk}|r8d)}|	j
d�rMq�q�|	j
d�r�|j|	|
|�j��}�jd|�q�|�|	|
|�j�j�}
|
ddkrt|
�dkr�|jd|	�|jd��jd|j|
d���j�q�|
ddkr�t|
�dksN|
ddkr^|jd|	�|jd�|j|
d|j��jd|
d|j|
d
�f��j�q�|
dj
d�rKt|
�dkr�|jd|	�|
dd
d�}|s|jd|	�|j�}||kr>|jd |��j�q�|jd!|
d�q�|rt|	j�}	|	r��jt|	��q�W|r�|jd"|d*�|�x/|j|jD]}|jd#||f�q�W�jd$��j��j�d%|_dS)+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 = strcsgt��dkr*�jd�d�n,t��dkrV�jddj����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�ifzDon'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 tagzc_%s = context[%r]zreturn "".join(result)Zrender_function���)r,r3���r4���)�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�startr2�expr�wordsZend_whatZ
start_what�var_namer)r)rr	rqs�	
	




	



"




zTemplite.__init__cCs�d|kro|jd�}|j|d�}x�|dd�D])}|j||j�d||f}q?Wn�d|kr�|jd�}|j|d�}djdd	�|dd�D��}d
||f}n|j||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_errorcCs3tjd|�s"|jd|�|j|�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�szTemplite._variableNcCs5t|j�}|r"|j|�|j||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.rendercGs�x�|D]�}yt||�}WnQtk
rsy||}Wn.ttfk
rntd||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)
rrrrrr>r@rArZrYrrrr	r&Js&vr&)
rr;�coverager�
ValueErrorrr
�objectrr&rrrr	�<module>	s.