Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
B

Ep-2ÍEuûã@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ú/build/wlanpi-profiler-MIf3Xw/wlanpi-profiler-1.0.8/debian/wlanpi-profiler/opt/wlanpi-profiler/lib/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 #}

    Lines between `{% joined %}` and `{% endjoined %}` will have lines stripped
    and joined.  Be careful, this could join words together!

    Any of these constructs can have a hyphen 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	svi|_x|D]}|j |¡qWtƒ|_tƒ|_tƒ‰ˆ d¡ˆ ¡ˆ ¡}ˆ d¡ˆ d¡ˆ d¡t	j
r€ˆ d¡n
ˆ d¡g‰‡‡fdd„}g}t d	|¡}d
}}	xT|D]J}
|
 
d¡rÎd\}}|
d
dk}|rêd
}|
 
d¡rúq¼q|
 
d¡r.| |
||… ¡¡}
ˆ d|
¡q|ƒ|
||… ¡ ¡}|ddkržt|ƒdkrp| d|
¡| d¡ˆ d| |d¡¡ˆ ¡q|ddkrt|ƒdksÈ|ddkrÔ| d|
¡| d¡| |d|j¡ˆ d|d| |d¡f¡ˆ ¡n²|ddkr8| d¡d}	n”|d 
d ¡r¼t|ƒdkrb| d!|
¡|ddd"…}|s„| d#|
¡| ¡}||kr¢| d$|¡|dkr²d
}	nˆ ¡n| d%|d¡q¼|	rèt d&d'|
 ¡¡}
n|rö|
 ¡}
|
r¼ˆ t|
ƒ¡q¼W|r"| d(|d)¡|ƒx(|j|jD]}| d*||f¡q6Wˆ 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:éZjoinedTÚendzDon't understand endNz
Too many endszMismatched end tagzDon't understand tagz\s*\n\s*rzUnmatched 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"ÚsubÚlstripÚreprr%Ú_render_function)rÚtextZcontextsr6Z	vars_coder*Z	ops_stackÚtokensZsquashZ	in_joinedÚtokenÚstartr4ÚexprÚwordsZend_whatZ
start_whatÚvar_namer)r)rr	rtsž














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)rE)rÚdrrr	rýsz&Templite._expr_code.<locals>.<genexpr>zdo_dots(%s, %s)zc_%s)r<r>rAr9r)rrKZpipesrÚ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	rAs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.

        )Údictr6r7rFÚ_do_dots)rr6Zrender_contextrrr	Úrenders

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ÚvaluerRÚdotrrr	rZ s

zTemplite._do_dots)N)
rrrrrr>r@rAr[rZrrrr	r&Js)~
r&)
rr;ZcoveragerÚ
ValueErrorrr
Úobjectrr&rrrr	Ú<module>	s.