%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/
Upload File :
Create Path :
Current File : //proc/self/root/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyo

�
|��Wc@s?dZddlZddlZddlZddlZddlmZdddddd	d
gZejd�Z	ejd�Z
ejd
ej�Zde
fd��YZde
fd��YZde
fd��YZdefd��YZd�Zdd�Zd
efd��YZd	efd��YZd�Zd�Zd�Zdefd��YZd�Zded�Zejd�Z dd d!d"gZ!ejd#�Z"ejd$�Z#d%�Z$d&�Z%dd'�Z&d1d(�Z'd)�Z(d*�Z)d+�Z*d,�Z+d-Z,dd.�Z-e.d/kr;dd0l/m-Z-e-�ndS(2s�
A small templating language

This implements a small templating language for use internally in
Paste and Paste Script.  This language implements if/elif/else,
for/continue/break, expressions, and blocks of Python code.  The
syntax is::

  {{any expression (function calls etc)}}
  {{any expression | filter}}
  {{for x in y}}...{{endfor}}
  {{if x}}x{{elif y}}y{{else}}z{{endif}}
  {{py:x=1}}
  {{py:
  def foo(bar):
      return 'baz'
  }}
  {{default var = default_value}}
  {{# comment}}

You use this with the ``Template`` class or the ``sub`` shortcut.
The ``Template`` class takes the template string and the name of
the template (for errors) and a default namespace.  Then (like
``string.Template``) you can call the ``tmpl.substitute(**kw)``
method to make a substitution (or ``tmpl.substitute(a_dict)``).

``sub(content, **kw)`` substitutes the template immediately.  You
can use ``__name='tmpl.html'`` to set the name of the template.

If there are syntax errors ``TemplateError`` will be raised.
i����N(tloopert
TemplateErrortTemplatetsubtHTMLTemplatetsub_htmlthtmltbunchs	\{\{|\}\}s\s+in\s+s^[a-z_][a-z0-9_]*$cBs#eZdZdd�Zd�ZRS(s.Exception raised while parsing a template
    cCs||_||_||_dS(N(tmessagetpositiontname(tselfRR	R
((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__init__2s		cCsEd|j|jd|jdf}|jrA|d|j7}n|S(Ns%s at line %s column %siis in %s(RR	R
(Rtmsg((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__str__7s
!	N(t__name__t
__module__t__doc__tNoneRR(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR.st_TemplateContinuecBseZRS((RR(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR>st_TemplateBreakcBseZRS((RR(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRAscBs�eZidd6dd6ed6ZdZddd�Zddd�Zee�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�ZRS(s{{tstart_bracess}}t
end_bracesRtutf8cCs[||_t|t�|_||_t|d|�|_|dkrNi}n||_dS(NR
(	tcontentt
isinstancetunicodet_unicodeR
tparset_parsedRt	namespace(RRR
R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRNs			cCsVt|d�}|j�}|j�|r=|j|�}n|d|d|d|�S(NtrbRR
R(topentreadtclosetdecode(tclstfilenameRtencodingtftc((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt
from_filenameWs
cCs*d|jjtt|��d|jfS(Ns<%s %s name=%r>i(t	__class__RthextidR
(R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__repr__as	cOs�|rI|rtd��nt|�dkr<td��n|d}n|jj�}|j|j�|j|�|j|�}|S(Ns3You can only give positional *or* keyword argumentsis(You can only give on positional argumenti(t	TypeErrortlentdefault_namespacetcopytupdateRt
_interpret(Rtargstkwtnstresult((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt
substitutefs

cCs2t}g}|j|j|d|�dj|�S(Ntoutt(tTruet_interpret_codesRtjoin(RR6t__traceback_hide__tparts((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR3uscCsMt}x@|D]8}t|t�r2|j|�q
|j|||�q
WdS(N(R;Rt
basestringtappendt_interpret_code(RtcodesR6R9R>titem((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR<{s

cCs�t}|d|d}}|dkrA|j|d||�n�|dkrYt��n�|dkrqt��nu|dkr�|d|d|d	}}}	|j|||�}|j|||	||�n|d
kr�|d}
|j|
||�n�|dkr�|djd�}
|j|
d||�}x3|
dD]'}|j|||�}
|
|�}q=W|j|j	||��nb|d
kr�|d|d}}||kr�|j|||�}|||<q�n|dkr�dSdS(Niitpyitcontinuetbreaktforiitcondtexprt|tdefaulttcomment(
R;t_execRRt_evalt_interpret_fort
_interpret_iftsplitRAt_repr(RtcodeR6R9R>R
tpostvarsRJRR?tbasetparttfunctvarR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRB�s< 
c
Cs�t}x�|D]�}t|�dkr6|||d<ngt|�t|�krstdt|�t|�f��nx't||�D]\}}	|	||<q�Wy|j|||�Wq
tk
r�q
q
tk
r�Pq
Xq
WdS(Niis&Need %i items to unpack (got %i items)(R;R/t
ValueErrortzipR<RR(
RRVRJRR6R9R>RDR
tvalue((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRP�s 


c	Cst}xr|D]j}|d|d}}|dkr=t}n|j|d||�}|r
|j|d||�Pq
q
WdS(Niitelseii(R;ROR<(	RR?R6R9R>RXR
RUR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRQ�s
	c	Cs�t}yt||�}|SWnttj�}|d}t|d�rX|jd}nt|�}|j||�f|_|d||d�nXdS(NiR4ii(R;tevaltsystexc_infotgetattrR4tstrt_add_line_info(	RRTR6RUR>R]Ratetarg0((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRO�s
cBsie}y||UWnPej�}|d}|j|jd|�f|_|d||d�nXdS(Niii(R;R`RaRdR4(RRTR6RUR>RaRe((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRN�s
cCsPt}y\|dkrdS|jrUyt|�}Wqatk
rQt|�}qaXnt|�}WnPtj�}|d}|j|j	d|�f|_	|d||d�n�X|jr�t
|t�r�|js�td|��n|j|j
�}nJ|jrHt
|t�rH|js3td|��n|j|j
�}n|SdS(NR:iiisFCannot decode str value %r into unicode (no default_encoding provided)sFCannot encode unicode value %r into str (no default_encoding provided)(R;RRRtUnicodeDecodeErrorRcR`RaRdR4Rtdecode_encodingR#tdefault_encodingtUnicodeEncodeErrortencode(RR]RUR>RaRe((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRS�s8	

	
	
cCs<d||d|df}|jr8|d|j7}n|S(Ns%s at line %s column %siis in file %s(R
(RR
RU((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRd�s
	N(RRRR0RiRRR)tclassmethodR-R8R3R<RBRPRQRORNRSRd(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRDs&
						!				
	!cKs.|jd�}t|d|�}|j|�S(Nt__nameR
(tgetRR8R7(RR5R
ttmpl((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs
cCst|d|�}|j|�S(NR
(RR8(RRVR%Ro((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytpaste_script_template_rendererscBs5eZd�Zd�Zd�Zd�Zd�ZRS(cKs1x*|j�D]\}}t|||�q
WdS(N(titemstsetattr(RR5R
R]((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRscCs|||<dS(N((RR
R]((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__setattr__scCs0y||SWntk
r+t|��nXdS(N(tKeyErrortAttributeError(RR
((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt__getattr__s
cCsXd|krDytj||�SWqTtk
r@tj|d�SXntj||�SdS(NRL(tdictt__getitem__Rt(Rtkey((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRxs
cCsug|j�D]\}}||f^q
}|j�d|jjdjg|D]\}}d||f^qN�fS(Ns<%s %s>t s%s=%r(RqtsortR*RR=(RtktvRq((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR-(s
+
	(RRRRsRvRxR-(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRs
					cBs#eZd�Zd�Zd�ZRS(cCs
||_dS(N(R](RR]((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR5scCs|jS(N(R](R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR7scCsd|jj|jfS(Ns<%s %r>(R*RR](R((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR-9s(RRRRR-(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR4s		cCs�|dkrdSt|t�sLt|d�r=t|�}qLt|�}ntj|d�}t|t�r�|jdd�}n|S(NR:t__unicode__itasciitxmlcharrefreplace(	RRR@thasattrRRctcgitescapeRk(R]((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt
html_quote=scCsjt|t�s<t|d�r-t|�}q<t|�}nt|t�r]|jd�}ntj|�S(NR~R(RR@R�RRcRkturllibtquote(R}((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyturlJscKs�|j�}|j�g}xe|D]]\}}|dkrAq#n|jd�r]|d }n|jdt|�t|�f�q#Wtdj|��S(Nt_i����s%s="%s"Rz(RqR{RtendswithRAR�RR=(R5R?R
R]((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytattrTs

'cBsBeZejj�Zejededede	��d�Z
RS(RR�R�cCs6tj|||�}t|t�r(|St|�SdS(N(RRSRRR�(RR]RUtplain((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRSis(RRRR0R1R2RwRR�R�RS(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR`s
cKs.|jd�}t|d|�}|j|�S(NRmR
(RnRR8R7(RR5R
Ro((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyRps
c	Cs�t}g}d}d
}xtj|�D]�}|jd�}t||j��}	|dkr|rtdd|	d|��n.|dkr�|r�tdd|	d|��n|dkr�|||j�!}
|
r�|j|
�nt	}n&|j|||j�!|f�t}|j�}|	}q(W|rHtd	d|d|��n||}
|
rh|j|
�n|r}t
|�}n|S(sY
    Lex a string into chunks:

        >>> lex('hey')
        ['hey']
        >>> lex('hey {{you}}')
        ['hey ', ('you', (1, 7))]
        >>> lex('hey {{')
        Traceback (most recent call last):
            ...
        TemplateError: No }} to finish last expression at line 1 column 7
        >>> lex('hey }}')
        Traceback (most recent call last):
            ...
        TemplateError: }} outside expression at line 1 column 7
        >>> lex('hey {{ {{')
        Traceback (most recent call last):
            ...
        TemplateError: {{ inside expression at line 1 column 10

    iis{{s{{ inside expressionR	R
s}}s}} outside expressionsNo }} to finish last expression(ii(tFalsettoken_retfinditertgroupt
find_positiontendRtstartRAR;ttrim_lex(tsR
ttrim_whitespacetin_exprtchunkstlasttlast_postmatchRJRURX((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytlex{s>	 
	
s^(?:if |elif |else |for |py:)tendiftendforRFRGs	\n[\t ]*$s	^[\t ]*\nc
Csxxtt|��D]d}||}t||t�r<qn|d}tj|�rh|tkrhqn|swd}n||d}|dt|�kr�d}n||d}t|t�st|t�r�qn|s�tj|�r|stj|�r|r>tj|�}||j	�d }|||d<n|rwtj|�}||j
�}|||d<qwqqW|S(sa
    Takes a lexed set of tokens, and removes whitespace when there is
    a directive on a line by itself:

       >>> tokens = lex('{{if x}}\nx\n{{endif}}\ny', trim_whitespace=False)
       >>> tokens
       [('if x', (1, 3)), '\nx\n', ('endif', (3, 3)), '\ny']
       >>> trim_lex(tokens)
       [('if x', (1, 3)), 'x\n', ('endif', (3, 3)), 'y']
    iR:i(trangeR/RR@tstatement_retsearchtsingle_statementsttrail_whitespace_retlead_whitespace_reR�R�(ttokenstitcurrentRDtprevtnexttm((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR��s6

		cCs.|| j�}t|�t|d�dfS(s/Given a string and index, return (line, column)i����i(t
splitlinesR/(tstringtindextleading((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR��scCsKt|d|�}g}x,|rFt||�\}}|j|�qW|S(s�
    Parses a string into a kind of AST

        >>> parse('{{x}}')
        [('expr', (1, 3), 'x')]
        >>> parse('foo')
        ['foo']
        >>> parse('{{if x}}test{{endif}}')
        [('cond', (1, 3), ('if', (1, 3), 'x', ['test']))]
        >>> parse('series->{{for x in y}}x={{x}}{{endfor}}')
        ['series->', ('for', (1, 11), ('x',), 'y', ['x=', ('expr', (1, 27), 'x')])]
        >>> parse('{{for x, y in z:}}{{continue}}{{endfor}}')
        [('for', (1, 3), ('x', 'y'), 'z', [('continue', (1, 21))])]
        >>> parse('{{py:x=1}}')
        [('py', (1, 3), 'x=1')]
        >>> parse('{{if x}}a{{elif y}}b{{else}}c{{endif}}')
        [('cond', (1, 3), ('if', (1, 3), 'x', ['a']), ('elif', (1, 12), 'y', ['b']), ('else', (1, 23), None, ['c']))]

    Some exceptions::
        
        >>> parse('{{continue}}')
        Traceback (most recent call last):
            ...
        TemplateError: continue outside of for loop at line 1 column 3
        >>> parse('{{if x}}foo')
        Traceback (most recent call last):
            ...
        TemplateError: No {{endif}} at line 1 column 3
        >>> parse('{{else}}')
        Traceback (most recent call last):
            ...
        TemplateError: else outside of an if block at line 1 column 3
        >>> parse('{{if x}}{{for x in y}}{{endif}}{{endfor}}')
        Traceback (most recent call last):
            ...
        TemplateError: Unexpected endif at line 1 column 25
        >>> parse('{{if}}{{endif}}')
        Traceback (most recent call last):
            ...
        TemplateError: if with no expression at line 1 column 3
        >>> parse('{{for x y}}{{endfor}}')
        Traceback (most recent call last):
            ...
        TemplateError: Bad for (no "in") in 'x y' at line 1 column 3
        >>> parse('{{py:x=1\ny=2}}')
        Traceback (most recent call last):
            ...
        TemplateError: Multi-line py blocks must start with a newline at line 1 column 3
    R
(R�t
parse_exprRA(R�R
R�R7R�((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR�s2	cCsHt|dt�r%|d|dfS|d\}}|j�}|jd�r�|djd�}|jd�r|d}n'd|kr�tdd|d	|��nd
||f|dfS|dkrd
|kr�tdd|d	|��n||f|dfS|jd�r#t|||�S|jd�s>|dkrgtd|j�dd|d	|��n�|dkr�td|d|d	|��n�|d kr�td|d|d	|��nl|jd�r�t|||�S|jd�r�t	|||�S|jd�r)d||ddf|dfSd||ddf|dfS(!Niispy:is 	s
s.Multi-line py blocks must start with a newlineR	R
RERFRGRHscontinue outside of for loopsif selif R^s%s outside of an if blocktiftelifs%s with no expressionR�R�s
Unexpected %ssfor sdefault t#RMRJ(scontinuesbreak(R�R�sfor(R�R�(
RR@tstript
startswithtlstripRt
parse_condRRt	parse_fort
parse_default(R�R
tcontextRJRU((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR�!sR


cCs�|dd}g}|d	}x�|sBtdd|d|��nt|dt�r�|dddkr�d|ft|�|dfSt|||�\}}|j|�q!dS(
NiiR�sMissing {{endif}}R	R
R�RI(sif(RRttupletparse_one_condRA(R�R
R�R�tpiecesR�((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR�Ms
cCsf|d|d\}}}g}|jd�r=|d }n|jd�rkd||dj�|f}nO|jd�r�d	||d
j�|f}n!|dkr�d|d|f}nx�|s�tdd
|d|��nt|dt�r:|dddks0|ddjd�s0|dddkr:||fSt|||�\}}|j|�q�dS(Niit:i����sif R�iselif R�iR^sNo {{endif}}R	R
R�(	R�R�R�RRRR�R�RA(R�R
R�tfirstRURRXR�((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR�\s,

cCs�|d\}}|d}d|}g}|jd�rF|d }n|dj�}tj|�}|s�td|d|d	|��n||j� }d
|kr�td|d|d	|��ntg||j� jd�D]}|j�r�|j�^q��}||j�}	x�|s=td
d|d	|��nt	|dt�r�|dddkr�d|||	|f|dfSt
|||�\}
}|j|
�qdS(NiiRHR�i����isBad for (no "in") in %rR	R
t(s=You cannot have () in the variable section of a for loop (%r)t,s
No {{endfor}}R�(sfor(R�R�tin_reR�RR�R�RRR�RR�RA(R�R
R�R�RURR�RVR}RJR�((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR�vs>



 !cCs�|d\}}|jdd�d}|jdd�}t|�dkritd|d|d|��n|dj�}d|kr�tdd|d|��ntj|�s�td	|d|d|��n|dj�}d
|||f|dfS(Niit=s:Expression must be {{default var=value}}; no = found in %rR	R
R�s'{{default x, y = ...}} is not supporteds-Not a valid variable name for {{default}}: %rRL(RRRR/RR�tvar_reR�(R�R
R�R�RUR?RZRJ((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyR��s$
sn%prog [OPTIONS] TEMPLATE arg=value

Use py:arg=value to set a Python value; otherwise all values are
strings.
c	Cs�ddl}ddl}ddl}ddl}|dkrL|jd}n|jd�}|jdt|�dt	�}|j
dddd	d
ddd
�|j
ddddddd�|j
ddddddd�|j|�\}}t|�dkrdGHt
|�GHn|d}|d}i}	|jrI|	j|j�nx}|D]u}
d|
kr{d|
GH|jd�n|
jdd�\}}
|jd�r�|d }t|
�}
n|
|	|<qPW|dkr�|jj�}d}n%t|d�}
|
j�}|
j�|jr$t}nt}||d |�}|j|	�}|jr�t|jd!�}
|
j|�|
j�n|jj|�dS("Ni����itPastetversiontusages-os--outputtdesttoutputtmetavartFILENAMEthelps(File to write output to (default stdout)s--htmltuse_htmltactiont
store_trues9Use HTML style filling (including automatic HTML quoting)s--envtuse_envs-Put the environment in as top-level variabless!You must give a template filenameiR�sBad argument: %rispy:it-s<stdin>RR
twb( R`toptparset
pkg_resourcestosRtargvtget_distributiontOptionParserRct_fill_command_usaget
add_optiont
parse_argsR/tdirR�R2tenvirontexitRRR�R_tstdinR!R R"R�RRR8R�twritetstdout(R4R`R�R�R�tdisttparsertoptionst
template_nameRVR]R
ttemplate_contentR't
TemplateClassttemplateR7((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pytfill_command�sr0			

	
	
	
			

t__main__(R�((0RtreR`R�R�tpaste.util.looperRt__all__tcompileR�R�tIR�t	ExceptionRRRtobjectRRRRpRwRRR�R�R�RRR;R�R�R�R�R�R�R�RR�R�R�R�R�R�R�Rtpaste.util.template(((sN/opt/alt/python27/lib/python2.7/site-packages/paste/util/template/_template.pyt<module>sR�	$		
	
		7	,	9,			"	>

Zerion Mini Shell 1.0