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

Fƒg1“x
Âã@sLdZddlZGdd„deƒZGdd„deƒZGdd„dƒZGd	d
„d
ƒZdS)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

éNc@seZdZdZdS)ÚTempliteSyntaxErrorz*Raised when a template has a syntax error.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__©rrú/build/wlanpi-profiler-7IIg1Q/wlanpi-profiler-1.0.11/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)rrrrrrrrr	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)r
rrrÚ__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.)r
r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)r
rrrr4szCodeBuilder.indentcCs|j|j8_dS)z0Decrease the current indent for following lines.N)rr )r
rrrÚdedent8szCodeBuilder.dedentcCs(|jdkst‚t|ƒ}i}t||ƒ|S)z:Execute the code, and return a dict of globals it defines.r)rÚAssertionErrorrÚexec)r
Z
python_sourceZglobal_namespacerrrÚget_globals<s

zCodeBuilder.get_globalsN)r)rrrrrrrrr rr!r$rrrrr
s
r
c@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
sji|_x|D]}|j |¡qWtƒ|_tƒ|_tƒ‰ˆ d¡ˆ ¡ˆ ¡}ˆ d¡ˆ d¡ˆ d¡ˆ d¡g‰‡‡fdd„}g}t	 
d|¡}d	}}	xT|D]J}
|
 d
¡r¼d\}}|
dd
k}|rØd}|
 d¡rèqªqö|
 d¡r| |
||… 
¡¡}
ˆ d|
¡qö|ƒ|
||… 
¡ 
¡}|ddkrŒt|ƒdkr^| d|
¡| d¡ˆ d| |d¡¡ˆ ¡qö|ddkrt|ƒdks¶|ddkrÂ| d|
¡| d¡| |d|j¡ˆ d |d| |d¡¡¡ˆ ¡n²|ddkr&| d¡d}	n”|d d¡rªt|ƒdkrP| d |
¡|ddd!…}|sr| 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)|›d*|›d+¡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.extendz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)ÚbufferedrrrÚ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_{} in {}:éZjoinedTÚendzDon't understand endNz
Too many endszMismatched end tagzDon't understand tagz\s*\n\s*rzUnmatched action tagéÿÿÿÿÚc_z = context[ú]zreturn "".join(result)Zrender_function)ÚcontextÚupdateÚsetÚall_varsZ	loop_varsr
rrrÚreÚsplitÚ
startswithÚ
_expr_codeÚstriprr'Ú
_syntax_errorÚ	_variableÚformatÚpopr!ÚsubÚlstripÚreprr$Ú_render_function)r
ÚtextZcontextsr7Z	vars_coder)Z	ops_stackÚtokensZsquashZ	in_joinedÚtokenÚstartr3ÚexprÚwordsZend_whatZ
start_whatÚvar_namer)r(rrrrsš














zTemplite.__init__cCsÂd|krX| d¡}| |d¡}xœ|dd…D]$}| ||j¡d|›d|›d}q.Wnfd|kr¨| d¡}| |d¡}d	 d
d„|dd…Dƒ¡}d|›d	|›d}n| ||j¡d
|}|S)z(Generate a Python expression for `expr`.ú|rr&Nr5ú(ú)Ú.z, css|]}t|ƒVqdS)N)rF)rÚdrrrrøsz&Templite._expr_code.<locals>.<genexpr>zdo_dots(zc_%s)r<r>rAr:r)r
rLZpipesrÚfuncÚdotsÚargsrrrr>ís

zTemplite._expr_codecCst|›d|›ƒ‚dS)z6Raise a syntax error using `msg`, and showing `thing`.z: N)r)r
ÚmsgÚthingrrrr@ÿ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_setrrrrAs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.

        )Údictr7r8rGÚ_do_dots)r
r7Zrender_contextrrrÚrenders

zTemplite.rendercGsŽxˆ|D]€}yt||ƒ}Wn^tk
rvy||}Wn<ttfk
rp}ztd|›d|›ƒ|‚Wdd}~XYnXYnXt|ƒr|ƒ}qW|S)z(Evaluate dotted expressions at run-time.zCouldn't evaluate rRN)ÚgetattrÚAttributeErrorÚ	TypeErrorÚKeyErrorr	Úcallable)r
ÚvaluerUÚdotÚexcrrrr]s

zTemplite._do_dots)N)
rrrrrr>r@rAr^r]rrrrr%Hs){
r%)rr;Ú
ValueErrorrr	r
r%rrrrÚ<module>	s
.