ó
ú2ec           @   sS  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d d d	 d
 d d g Z
 e j d ƒ Z e j d ƒ Z e j d e j ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d d „ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d	 e f d „  ƒ  YZ d „  Z d e  d „ Z! e j d  ƒ Z" d! d" d# d$ g Z# e j d% ƒ Z$ e j d& ƒ Z% d' „  Z& d( „  Z' d d) „ Z( d3 d* „ Z) d+ „  Z* d, „  Z+ d- „  Z, d. „  Z- d/ Z. d d0 „ Z/ e0 d1 k rOd d2 l1 m/ Z/ e/ ƒ  n  d S(4   sð  
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(   t   escape(   t   quote(   t   loopert   TemplateErrort   Templatet   subt   HTMLTemplatet   sub_htmlt   htmlt   bunchs	   \{\{|\}\}s   \s+in\s+s   ^[a-z_][a-z0-9_]*$c           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s.   Exception raised while parsing a template
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   t   messaget   positiont   name(   t   selfR
   R   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   __init__3   s    		c         C   sE   d |  j  |  j d |  j d f } |  j rA | d |  j 7} n  | S(   Ns   %s at line %s column %si    i   s    in %s(   R
   R   R   (   R   t   msg(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   __str__8   s
    !	N(   t   __name__t
   __module__t   __doc__t   NoneR   R   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   /   s   t   _TemplateContinuec           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   ?   s   t   _TemplateBreakc           B   s   e  Z RS(    (   R   R   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   B   s   c           B   s¶   e  Z i d  d 6d d 6e d 6Z d Z d d d „ Z d d d „ Z e e ƒ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s   {{t   start_bracess   }}t
   end_bracesR   t   utf8c         C   s^   | |  _  t | t j ƒ |  _ | |  _ t | d | ƒ|  _ | d  k rQ i  } n  | |  _	 d  S(   NR   (
   t   contentt
   isinstancet   sixt	   text_typet   _unicodeR   t   parset   _parsedR   t	   namespace(   R   R   R   R!   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   O   s    			c         C   sV   t  | d ƒ } | j ƒ  } | j ƒ  | r= | j | ƒ } n  |  d | d | d | ƒ S(   Nt   rbR   R   R!   (   t   opent   readt   closet   decode(   t   clst   filenameR!   t   encodingt   ft   c(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   from_filenameX   s    
c         C   s*   d |  j  j t t |  ƒ ƒ d |  j f S(   Ns   <%s %s name=%r>i   (   t	   __class__R   t   hext   idR   (   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   __repr__b   s    	c         O   sˆ   | rI | r t  d ƒ ‚ n  t | ƒ d k r< t  d ƒ ‚ n  | d } n  |  j j ƒ  } | j |  j ƒ | j | ƒ |  j | ƒ } | S(   Ns3   You can only give positional *or* keyword argumentsi   s(   You can only give on positional argumenti    (   t	   TypeErrort   lent   default_namespacet   copyt   updateR!   t
   _interpret(   R   t   argst   kwt   nst   result(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt
   substituteg   s    c         C   s2   t  } g  } |  j |  j | d | ƒd j | ƒ S(   Nt   outt    (   t   Truet   _interpret_codesR    t   join(   R   R9   t   __traceback_hide__t   parts(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR6   v   s    c         C   sP   t  } xC | D]; } t | t j ƒ r5 | j | ƒ q |  j | | | ƒ q Wd  S(   N(   R>   R   R   t   string_typest   appendt   _interpret_code(   R   t   codesR9   R<   RA   t   item(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR?   |   s
    c         C   s   t  } | d | d } } | d k rA |  j | d | | ƒ n»| d k rY t ƒ  ‚ n£| d k rq t ƒ  ‚ n‹| d k rÎ | d | d | d	 } } }	 |  j | | | ƒ } |  j | | |	 | | ƒ n.| d
 k rú | d }
 |  j |
 | | ƒ n| d k r„| d j d ƒ }
 |  j |
 d | | ƒ } x3 |
 d D]' } |  j | | | ƒ } | | ƒ } q=W| j |  j	 | | ƒ ƒ nx | d k rÖ| d | d } } | | k rü|  j | | | ƒ } | | | <qün& | d k ræd  Sd süt
 d | ƒ ‚ d  S(   Ni    i   t   pyi   t   continuet   breakt   fori   i   t   condt   exprt   |t   defaultt   comments   Unknown code: %r(   R>   t   _execR   R   t   _evalt   _interpret_fort   _interpret_ift   splitRD   t   _reprt   AssertionError(   R   t   codeR9   R<   RA   R   t   post   varsRM   R   RB   t   baset   partt   funct   varR:   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRE   „   s<     
c   
      C   sä   t  } x× | D]Ï } t | ƒ d k r6 | | | d <ng t | ƒ t | ƒ k rs t d t | ƒ t | ƒ f ƒ ‚ n  x' t | | ƒ D] \ } }	 |	 | | <qƒ Wy |  j | | | ƒ Wq t k
 rÊ q q t k
 rÛ Pq Xq Wd  S(   Ni   i    s&   Need %i items to unpack (got %i items)(   R>   R2   t
   ValueErrort   zipR?   R   R   (
   R   RZ   RM   R   R9   R<   RA   RG   R   t   value(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRS   ¥   s     c   	      C   s˜   t  } x‹ | D]ƒ } t | t j ƒ s, t ‚ | d | d } } | d k rV t  } n |  j | d | | ƒ } | r |  j | d | | ƒ Pq q Wd  S(   Ni    i   t   elsei   i   (   R>   R   R   RC   RW   RR   R?   (	   R   RB   R9   R<   RA   R\   R   RY   R:   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRT   ¸   s    	c   	      C   sŸ   t  } y t | | ƒ } | SWn{ t j ƒ  } | d } t | d ƒ rX | j d } n t | ƒ } |  j | | ƒ f | _ t j	 | d | | d ƒ n Xd  S(   Ni   R7   i    i   (
   R>   t   evalt   syst   exc_infot   getattrR7   t   strt   _add_line_infoR   t   reraise(	   R   RX   R9   RY   RA   Ra   Re   t   et   arg0(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRR   Æ   s    
c         C   sx   t  } y t j | | ƒ WnW t j ƒ  } | d } |  j | j d | ƒ f | _ t j | d | | d ƒ n Xd  S(   Ni   i    i   (   R>   R   t   exec_Rd   Re   Rh   R7   Ri   (   R   RX   R9   RY   RA   Re   Rj   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRQ   Õ   s    
c         C   s`  t  } y_ | d  k r d S|  j rX y t j | ƒ } Wqd t k
 rT t | ƒ } qd Xn t | ƒ } WnW t j ƒ  } | d } |  j	 | j
 d | ƒ f | _
 t j | d | | d ƒ nž X|  j rt | t j ƒ r|  j sö t d | ƒ ‚ n  | j |  j ƒ } nM |  j rXt | t j ƒ rX|  j sCt d | ƒ ‚ n  | j |  j ƒ } n  | Sd  S(   NR=   i   i    i   sF   Cannot decode str value %r into unicode (no default_encoding provided)sF   Cannot encode unicode value %r into str (no default_encoding provided)(   R>   R   R   R   R   t   UnicodeDecodeErrorRg   Rd   Re   Rh   R7   Ri   R   t   binary_typet   decode_encodingR&   t   default_encodingt   UnicodeEncodeErrort   encode(   R   Ra   RY   RA   Re   Rj   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRV   ß   s8    	
		c         C   s<   d | | d | d f } |  j  r8 | d |  j  7} n  | S(   Ns   %s at line %s column %si    i   s    in file %s(   R   (   R   R   RY   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRh      s
    	N(   R   R   R   R3   Rp   R   R   R,   t   classmethodR0   R;   R6   R?   RE   RS   RT   RR   RQ   RV   Rh   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   E   s&   
						!				
	!c         K   s.   | j  d ƒ } t |  d | ƒ} | j | ƒ S(   Nt   __nameR   (   t   getR   R;   (   R   R8   R   t   tmpl(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR     s    c         C   s   t  |  d | ƒ} | j | ƒ S(   NR   (   R   R;   (   R   RZ   R(   Rv   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   paste_script_template_renderer  s    c           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         K   s1   x* | j  ƒ  D] \ } } t |  | | ƒ q Wd  S(   N(   t   itemst   setattr(   R   R8   R   Ra   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR     s    c         C   s   | |  | <d  S(   N(    (   R   R   Ra   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   __setattr__  s    c         C   s0   y |  | SWn t  k
 r+ t | ƒ ‚ n Xd  S(   N(   t   KeyErrort   AttributeError(   R   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   __getattr__  s    c         C   sX   d |  k rD y t  j |  | ƒ SWqT t k
 r@ t  j |  d ƒ SXn t  j |  | ƒ Sd  S(   NRO   (   t   dictt   __getitem__R{   (   R   t   key(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR     s    c         C   su   g  |  j  ƒ  D] \ } } | | f ^ q } | j ƒ  d |  j j d j g  | D] \ } } d | | f ^ qN ƒ f S(   Ns   <%s %s>t    s   %s=%r(   Rx   t   sortR-   R   R@   (   R   t   kt   vRx   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR0   (  s
    +
	(   R   R   R   Rz   R}   R   R0   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR	     s
   					c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   Ra   (   R   Ra   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   5  s    c         C   s   |  j  S(   N(   Ra   (   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   7  s    c         C   s   d |  j  j |  j f S(   Ns   <%s %r>(   R-   R   Ra   (   R   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR0   9  s    (   R   R   R   R   R0   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   4  s   		c         C   s˜   |  d  k r d St |  t j ƒ sX t j rI t |  d ƒ rI t |  ƒ }  qX t |  ƒ }  n  t |  d ƒ }  t j r” t |  t ƒ r” |  j	 d d ƒ }  n  |  S(   NR=   t   __unicode__i   t   asciit   xmlcharrefreplace(
   R   R   R   RC   t   PY2t   hasattrt   unicodeRg   R    Rr   (   Ra   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt
   html_quote=  s    c         C   s|   t  |  t j ƒ sH t j r9 t |  d ƒ r9 t |  ƒ }  qH t |  ƒ }  n  t j rr t  |  t ƒ rr |  j d ƒ }  n  t |  ƒ S(   NR…   R   (	   R   R   RC   Rˆ   R‰   RŠ   Rg   Rr   R   (   R„   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   urlJ  s    c          K   s“   t  |  j ƒ  ƒ }  g  } xe |  D]] \ } } | d  k r= q n  | j d ƒ rY | d  } n  | j d t | ƒ t | ƒ f ƒ q Wt d j | ƒ ƒ S(   Nt   _iÿÿÿÿs   %s="%s"R   (   t   sortedRx   R   t   endswithRD   R‹   R   R@   (   R8   RB   R   Ra   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   attrT  s    'c           B   sB   e  Z e j j ƒ  Z e j e d  e d e d e	 ƒ ƒ d „  Z
 RS(   R   R   RŒ   c         C   s6   t  j |  | | ƒ } t | t ƒ r( | St | ƒ Sd  S(   N(   R   RV   R   R   R‹   (   R   Ra   RY   t   plain(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRV   h  s    (   R   R   R   R3   R4   R5   R~   R   R   RŒ   RV   (    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   _  s   
c         K   s.   | j  d ƒ } t |  d | ƒ} | j | ƒ S(   NRt   R   (   Ru   R   R;   (   R   R8   R   Rv   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   o  s    c         C   s  t  } g  } d } d
 } xt j |  ƒ D]û } | j d ƒ } t |  | j ƒ  ƒ }	 | d k r | r t d d |	 d | ƒ‚ n. | d k r­ | r­ t d d |	 d | ƒ‚ n  | d k rë |  | | j ƒ  !}
 |
 râ | j |
 ƒ n  t	 } n& | j |  | | j ƒ  !| f ƒ t  } | j ƒ  } |	 } q( W| rHt d	 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

    i    i   s   {{s   {{ inside expressionR   R   s   }}s   }} outside expressions   No }} to finish last expression(   i   i   (   t   Falset   token_ret   finditert   groupt   find_positiont   endR   t   startRD   R>   t   trim_lex(   t   sR   t   trim_whitespacet   in_exprt   chunkst   lastt   last_post   matchRM   RY   R\   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   lexy  s>    	 
	
s   ^(?:if |elif |else |for |py:)t   endift   endforRI   RJ   s	   \n[\t ]*$s	   ^[\t ]*\nc         C   sˆ  xt  t |  ƒ ƒ D]m} |  | } t |  | t j ƒ r? q n  | d } t j | ƒ rk | t k rk q n  | sz d } n |  | d } | d t |  ƒ k r§ d } n |  | d } t | t j ƒ s t | t j ƒ rá q n  | s÷ t j | ƒ r | st	 j | ƒ r | rGt j | ƒ } | | j
 ƒ  d  } | |  | d <n  | r€t	 j | ƒ } | | j ƒ  } | |  | d <q€q q W|  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']
    i    R=   i   (   t   rangeR2   R   R   RC   t   statement_ret   searcht   single_statementst   trail_whitespace_ret   lead_whitespace_reR˜   R—   (   t   tokenst   it   currentRG   t   prevt   nextt   m(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR™   µ  s6    

		c         C   s.   |  |  j  ƒ  } t | ƒ t | d ƒ d f S(   s/   Given a string and index, return (line, column)iÿÿÿÿi   (   t
   splitlinesR2   (   t   stringt   indext   leading(    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR–   á  s    c         C   sK   t  |  d | ƒ} g  } x, | rF t | | ƒ \ } } | j | ƒ q W| 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_exprRD   (   Rš   R   Rª   R:   R®   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR   æ  s    2	c         C   sK  t  |  d t j ƒ r( |  d |  d f S|  d \ } } | j ƒ  } | j d ƒ rÀ | d j d ƒ } | j d ƒ r‚ | d } n' d | k r© t d d | d	 | ƒ‚ n  d
 | | f |  d f S| d k rd | k ró t d d | d	 | ƒ‚ n  | | f |  d f S| j d ƒ r&t |  | | ƒ S| j d ƒ sA| d k rjt d | j ƒ  d d | d	 | ƒ‚ nÂ | d k r•t d | d | d	 | ƒ‚ n— | d  k rÀt d | d | d	 | ƒ‚ nl | j d ƒ rßt	 |  | | ƒ S| j d ƒ rþt
 |  | | ƒ S| j d ƒ r,d | |  d d f |  d f Sd | |  d d f |  d f S(!   Ni    i   s   py:i   s    	s   
s.   Multi-line py blocks must start with a newlineR   R   RH   RI   RJ   RK   s   continue outside of for loops   if s   elif Rb   s   %s outside of an if blockt   ift   elifs   %s with no expressionR¢   R£   s   Unexpected %ss   for s   default t   #RP   RM   (   RI   RJ   (   Rµ   R¶   RK   (   R¢   R£   (   R   R   RC   t   stript
   startswitht   lstripR   t
   parse_condRU   t	   parse_fort   parse_default(   Rª   R   t   contextRM   RY   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR´     sR    

c         C   s´   |  d d } g  } | d	 } x |  sB t  d d | d | ƒ‚ n  t |  d t ƒ r‡ |  d d d k r‡ d | f t | ƒ |  d f St |  | | ƒ \ } }  | j | ƒ q! Wd  S(
   Ni    i   Rµ   s   Missing {{endif}}R   R   R¢   RL   (   Rµ   (   R   R   t   tuplet   parse_one_condRD   (   Rª   R   R¾   R˜   t   piecesR®   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR»   K  s    
c         C   sƒ  |  d |  d \ } } }  g  } | j  d ƒ r= | d  } n  | j d ƒ rk d | | d j ƒ  | f } nk | j d ƒ r™ d	 | | d
 j ƒ  | f } n= | d k rº d | d  | f } n d sÖ t d | | f ƒ ‚ x¦ |  sú t d d | d | ƒ‚ n  t |  d t ƒ rV|  d d d k sL|  d d j d ƒ sL|  d d d k rV| |  f St |  | | ƒ \ } }  | j	 | ƒ qÙ Wd  S(   Ni    i   t   :iÿÿÿÿs   if Rµ   i   s   elif R¶   i   Rb   s   Unexpected token %r at %ss   No {{endif}}R   R   R¢   (
   R   R¹   Rº   R   RW   R   R   R¿   R´   RD   (   Rª   R   R¾   t   firstRY   R   R\   R®   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyRÀ   Z  s.    
c         C   sÃ  |  d \ } } |  d }  d | } g  } | j  d ƒ s? t ‚ | j d ƒ r[ | d  } n  | d j ƒ  } t j | ƒ } | sŸ t d | d	 | d
 | ƒ‚ n  | | j ƒ   } d | k rÚ t d | d	 | d
 | ƒ‚ n  t g  | | j ƒ   j	 d ƒ D] } | j ƒ  r÷ | j ƒ  ^ q÷ ƒ } | | j
 ƒ  }	 xŽ |  sRt d d	 | d
 | ƒ‚ n  t |  d t ƒ r–|  d d d k r–d | | |	 | f |  d f St |  | | ƒ \ }
 }  | j |
 ƒ q1Wd  S(   Ni    i   RK   s   for RÂ   iÿÿÿÿi   s   Bad 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£   (   RK   (   R¹   RW   R   R¸   t   in_reR¦   R   R˜   R¿   RU   R—   R   R´   RD   (   Rª   R   R¾   RÃ   RY   R   R    RZ   R„   RM   R®   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR¼   t  s@    


 !c         C   s  |  d \ } } | j  d ƒ s% t ‚ | j d  d ƒ d } | j d d ƒ } t | ƒ d k r~ t d | d | d | ƒ‚ n  | d j ƒ  } d | k rµ t d	 d | d | ƒ‚ n  t j | ƒ sã t d
 | d | d | ƒ‚ n  | d j ƒ  } d | | | f |  d f S(   Ni    s   default i   t   =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}}: %rRO   (	   R¹   RW   RU   R   R2   R   R¸   t   var_reR¦   (   Rª   R   R¾   RÃ   RY   RB   R^   RM   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyR½   –  s&    
sn   %prog [OPTIONS] TEMPLATE arg=value

Use py:arg=value to set a Python value; otherwise all values are
strings.
c      	   C   s   d d  l  } d d  l } d d  l } d d  l } |  d  k rL | j d }  n  | j d ƒ } | j d t | ƒ d t	 ƒ } | j
 d d d d	 d
 d d d ƒ| j
 d d d d d d d ƒ| j
 d d d d d d d ƒ| j |  ƒ \ } }  t |  ƒ d k  rd GHt | ƒ GHd st ‚ n  |  d } |  d }  i  }	 | j rU|	 j | j ƒ n  x} |  D]u }
 d |
 k r‡d |
 GH| j d ƒ n  |
 j d d ƒ \ } }
 | j d ƒ rÇ| d  } t |
 ƒ }
 n  |
 |	 | <q\W| d k rù| j j ƒ  } d } n% t | d ƒ } | j ƒ  } | j ƒ  | j r0t } n t } | | d  | ƒ} | j |	 ƒ } | j rŒt | j d! ƒ } | j | ƒ | j ƒ  n | j  j | ƒ d  S("   Niÿÿÿÿi   t   Pastet   versiont   usages   -os   --outputt   destt   outputt   metavart   FILENAMEt   helps(   File to write output to (default stdout)s   --htmlt   use_htmlt   actiont
   store_trues9   Use HTML style filling (including automatic HTML quoting)s   --envt   use_envs-   Put the environment in as top-level variabless!   You must give a template filenamei    RÇ   s   Bad argument: %ri   s   py:i   t   -s   <stdin>R"   R   t   wb(!   Rd   t   optparset   pkg_resourcest   osR   t   argvt   get_distributiont   OptionParserRg   t   _fill_command_usaget
   add_optiont
   parse_argsR2   t   dirRW   RÔ   R5   t   environt   exitRU   R¹   Rc   t   stdinR$   R#   R%   RÑ   R   R   R;   RÍ   t   writet   stdout(   R7   Rd   R×   RØ   RÙ   t   distt   parsert   optionst   template_nameRZ   Ra   R   t   template_contentR*   t   TemplateClasst   templateR:   (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   fill_command²  sr    0			

		
	
			t   __main__(   Rí   (    (2   R   t   reR   Rd   R   R    t   six.moves.urllib.parseR   t   paste.util.looperR   t   __all__t   compileR“   RÆ   t   IRÈ   t	   ExceptionR   R   R   t   objectR   R   R   Rw   R~   R	   R‹   RŒ   R   R   R   R>   R¡   R¥   R§   R¨   R©   R™   R–   R   R´   R»   RÀ   R¼   R½   RÝ   Rí   R   t   paste.util.template(    (    (    s=   /usr/local/lib/python2.7/dist-packages/paste/util/template.pyt   <module>   sT   Â	$			
		
7	,	9,			"	>