
TQc        	   @@ sI  d  d l  m Z m Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z m Z d  d l m Z d  d l m Z d  d	 l m Z m Z m Z d  d
 l m Z m Z d  d l m Z m Z d  d l m Z m Z m Z m  Z  d  d l! m" Z" d  d l# m$ Z$ d  d l% m& Z& d  d l' m( Z( d  d l) m* Z* d  d l m+ Z+ d  Z, d Z- d Z. d Z/ i d e, 6d e- 6d e. 6d e/ 6Z0 d Z1 d Z2 d Z3 d Z4 d Z5 d Z6 d  Z7 d! Z8 d" Z9 d# Z: d$ Z; d% Z< d& Z= d' Z> e j? d( e j$ e4  e j$ e5  e j$ e6  e j$ e7  e j$ e8  e j$ e9  f  Z@ i  ZA g  ZB d aD d) eE f d*     YZF d+ eE f d,     YZG d- eE f d.     YZH e+ d/ eE f d0     Y ZI d1 eE f d2     YZJ d3 eK f d4     YZL d5 eL f d6     YZM d7 eK f d8     YZN d9   ZO d: eK f d;     YZP d< eK f d=     YZQ d> eK f d?     YZR d@ eK f dA     YZS dB i dC dD 6dE dF 6e j$ dG  dH 6e j$ dI  dJ 6ZT eT jU dK dL  ZT dM i eT dN 6dO dP 6dQ dR 6e j$ e1  dS 6e j$ e2  dT 6ZV e j? eV e jW e jX B ZY dU eK f dV     YZZ dW   Z[ dX eK f dY     YZ\ dZ eK f d[     YZ] d\ e^ f d]     YZ_ d^ e] f d_     YZ` d`   Za da e] f db     YZb e j? dc  Zc ed dd  Ze de   Zf df   Zg dg e] f dh     YZh di eK f dj     YZi dk   Zj dl   Zk g  al dm   Zm dn   Zn do   Zo eo dp  eo dq  d S(r   i    (   t   absolute_importt   unicode_literalsN(   t   partial(   t
   getargspec(   t   settings(   t   Contextt   RequestContextt   ContextPopException(   t   import_module(   t   is_iterable(   t   smart_splitt   unescape_string_literalt   get_text_list(   t	   force_strt
   force_text(   t   ugettext_lazyt   pgettext_lazy(   t   SafeDatat
   EscapeDatat	   mark_safet   mark_for_escaping(   t   localize(   t   escape(   t   module_has_submodule(   t   six(   t   template_localtime(   t   python_2_unicode_compatiblei   i   i   u   Textu   Varu   Blocku   Commentu   |u   :u   .u   {%u   %}u   {{u   }}u   {#u   #}u   Translatorsu   {u   }u@   abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.u   <unknown source>u   (%s.*?%s|%s.*?%s|%s.*?%s)t   TemplateSyntaxErrorc           B@ s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s-   ../Django//lib/python/django/template/base.pyR   J   s   t   TemplateDoesNotExistc           B@ s   e  Z RS(    (   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   M   s   t   TemplateEncodingErrorc           B@ s   e  Z RS(    (   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   P   s   t   VariableDoesNotExistc           B@ s   e  Z d d   Z d   Z RS(   c         C@ s   | |  _  | |  _ d  S(   N(   t   msgt   params(   t   selfR!   R"   (    (    s-   ../Django//lib/python/django/template/base.pyt   __init__V   s    	c         C@ s3   |  j  t g  |  j D] } t | d d ^ q  S(   Nt   errorsu   replace(   R!   t   tupleR"   R   (   R#   t   p(    (    s-   ../Django//lib/python/django/template/base.pyt   __str__Z   s    (    (   R   R   R$   R(   (    (    (    s-   ../Django//lib/python/django/template/base.pyR    S   s   t   InvalidTemplateLibraryc           B@ s   e  Z RS(    (   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR)   ^   s   t   Originc           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s   | |  _  d  S(   N(   t   name(   R#   R+   (    (    s-   ../Django//lib/python/django/template/base.pyR$   b   s    c         C@ s
   t   d  S(   N(   t   NotImplementedError(   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   reloade   s    c         C@ s   |  j  S(   N(   R+   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR(   h   s    (   R   R   R$   R-   R(   (    (    (    s-   ../Django//lib/python/django/template/base.pyR*   a   s   		t   StringOriginc           B@ s   e  Z d    Z d   Z RS(   c         C@ s#   t  t |   j t  | |  _ d  S(   N(   t   superR.   R$   t   UNKNOWN_SOURCEt   source(   R#   R1   (    (    s-   ../Django//lib/python/django/template/base.pyR$   l   s    c         C@ s   |  j  S(   N(   R1   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR-   p   s    (   R   R   R$   R-   (    (    (    s-   ../Django//lib/python/django/template/base.pyR.   k   s   	t   Templatec           B@ s2   e  Z d d  d  Z d   Z d   Z d   Z RS(   u   <Unknown Template>c         C@ ss   y t  |  } Wn t k
 r/ t d   n Xt j rT | d  k rT t |  } n  t | |  |  _ | |  _	 d  S(   Nu@   Templates can only be constructed from unicode or UTF-8 strings.(
   R   t   UnicodeDecodeErrorR   R   t   TEMPLATE_DEBUGt   NoneR.   t   compile_stringt   nodelistR+   (   R#   t   template_stringt   originR+   (    (    s-   ../Django//lib/python/django/template/base.pyR$   t   s    c         c@ s.   x' |  j  D] } x | D] } | Vq Wq
 Wd  S(   N(   R7   (   R#   t   nodet   subnode(    (    s-   ../Django//lib/python/django/template/base.pyt   __iter__   s    c         C@ s   |  j  j |  S(   N(   R7   t   render(   R#   t   context(    (    s-   ../Django//lib/python/django/template/base.pyt   _render   s    c         C@ s3   | j  j   z |  j |  SWd | j  j   Xd S(   u)   Display stage -- can be called many timesN(   t   render_contextt   pushR?   t   pop(   R#   R>   (    (    s-   ../Django//lib/python/django/template/base.pyR=      s    N(   R   R   R5   R$   R<   R?   R=   (    (    (    s-   ../Django//lib/python/django/template/base.pyR2   s   s
   		c         C@ sg   t  j r/ d d l m } m } | | } } n t t } } | |  |  } | | j    } | j   S(   u:   Compiles template_string into NodeList ready for renderingi    (   t
   DebugLexert   DebugParser(	   R   R4   t   django.template.debugRC   RD   t   Lexert   Parsert   tokenizet   parse(   R8   R9   RC   RD   t   lexer_classt   parser_classt   lexert   parser(    (    s-   ../Django//lib/python/django/template/base.pyR6      s    	t   Tokenc           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s    | | |  _  |  _ d  |  _ d  S(   N(   t
   token_typet   contentsR5   t   lineno(   R#   RO   RP   (    (    s-   ../Django//lib/python/django/template/base.pyR$      s    c         C@ s.   t  |  j } d | |  j d  j d d  f S(   Nu   <%s token: "%s...">i   u   
u    (   t   TOKEN_MAPPINGRO   RP   t   replace(   R#   t
   token_name(    (    s-   ../Django//lib/python/django/template/base.pyR(      s    c         C@ s   g  } t  t |  j   } x | D] } | j d  sF | j d  r | d d } | g } x, | j |  s t |  } | j |  q` Wd j |  } n  | j |  q" W| S(   Nu   _("u   _('i   u   )u    (   t   iterR
   RP   t
   startswitht   endswitht   nextt   appendt   join(   R#   t   splitt   bitst   bitt   sentinalt	   trans_bit(    (    s-   ../Django//lib/python/django/template/base.pyt   split_contents   s    	(   R   R   R$   R(   R`   (    (    (    s-   ../Django//lib/python/django/template/base.pyRN      s   		RF   c           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s(   | |  _  | |  _ d |  _ t |  _ d  S(   Ni   (   R8   R9   RQ   t   Falset   verbatim(   R#   R8   R9   (    (    s-   ../Django//lib/python/django/template/base.pyR$      s    			c         C@ sV   t  } g  } xC t j |  j  D]/ } | rG | j |  j | |   n  | } q W| S(   uG   
        Return a list of tokens from a given template_string.
        (   Ra   t   tag_reR[   R8   RY   t   create_token(   R#   t   in_tagt   resultR]   (    (    s-   ../Django//lib/python/django/template/base.pyRH      s    c         C@ sT  | rO | j  t  rO | d d !j   } |  j rO | |  j k rO t |  _ qO n  | r|  j r| j  t  r t t | d d !j    } q,| j  t  r | d  d	 k r d | |  _ n  t t |  } q,| j  t	  r,d } | j
 t  r| d d !j   } n  t t |  } q,n t t |  } |  j | _ |  j | j d  7_ | S(
   u   
        Convert the given token string into a new Token object and return it.
        If in_tag is True, we are processing something that matched a tag,
        otherwise it should be treated as a literal string.
        i   ii	   u   verbatimu	   verbatim u   end%su    u   
(   u   verbatimu	   verbatim (   RV   t   BLOCK_TAG_STARTt   stripRb   Ra   t   VARIABLE_TAG_STARTRN   t	   TOKEN_VARt   TOKEN_BLOCKt   COMMENT_TAG_STARTt   findt   TRANSLATOR_COMMENT_MARKt   TOKEN_COMMENTt
   TOKEN_TEXTRQ   t   count(   R#   t   token_stringRe   t   block_contentt   tokent   content(    (    s-   ../Django//lib/python/django/template/base.pyRd      s(    (   R   R   R$   RH   Rd   (    (    (    s-   ../Django//lib/python/django/template/base.pyRF      s   		RG   c           B@ s   e  Z d    Z d d  Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C@ s=   | |  _  i  |  _ i  |  _ x t D] } |  j |  q" Wd  S(   N(   t   tokenst   tagst   filterst   builtinst   add_library(   R#   Rv   t   lib(    (    s-   ../Django//lib/python/django/template/base.pyR$      s
    			c   
      C@ s  | d  k r g  } n  |  j   } x|  j r|  j   } | j d k rg |  j | t | j  |  q$ | j d k r | j s |  j |  n  |  j	 | j  } |  j
 |  } |  j | | |  q$ | j d k r$ y | j j   d } Wn t k
 r|  j |  n X| | k r*|  j |  | S|  j | |  y |  j | } Wn$ t k
 rq|  j | | |  n Xy | |  |  } Wn+ t k
 r}	 |  j | |	  s  qn X|  j | | |  |  j   q$ q$ W| r|  j |  n  | S(   Ni    i   i   (   R5   t   create_nodelistRv   t
   next_tokenRO   t   extend_nodelistt   TextNodeRP   t   empty_variablet   compile_filtert   create_variable_nodeR[   t
   IndexErrort   empty_block_tagt   prepend_tokent   enter_commandRw   t   KeyErrort   invalid_block_tagR   t   compile_function_errort   exit_commandt   unclosed_block_tag(
   R#   t   parse_untilR7   Rt   t   filter_expressiont   var_nodet   commandt   compile_funct   compiled_resultt   e(    (    s-   ../Django//lib/python/django/template/base.pyRI      sH    		
c         C@ sR   x; |  j  r= |  j   } | j t k r | j | k r d  Sq W|  j | g  d  S(   N(   Rv   R}   RO   Rk   RP   R   (   R#   t   endtagRt   (    (    s-   ../Django//lib/python/django/template/base.pyt	   skip_past  s
    c         C@ s
   t  |  S(   N(   t   VariableNode(   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR   #  s    c         C@ s   t    S(   N(   t   NodeList(   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR|   &  s    c         C@ s   | j  rL | rL y | j r$ t  n  WqL t k
 rH t d |   qL Xn  t | t  rw t | t  rw t | _ n  | j |  d  S(   Nu)   %r must be the first tag in the template.(	   t   must_be_firstt   contains_nontextt   AttributeErrorR   t
   isinstanceR   R   t   TrueRY   (   R#   R7   R:   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR~   )  s    	c         C@ s   d  S(   N(    (   R#   R   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR   5  s    c         C@ s   d  S(   N(    (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR   8  s    c         C@ s
   t  |  S(   N(   R   (   R#   Rt   R!   (    (    s-   ../Django//lib/python/django/template/base.pyt   error;  s    c         C@ s   |  j  | d   d  S(   Nu   Empty variable tag(   R   (   R#   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR   >  s    c         C@ s   |  j  | d   d  S(   Nu   Empty block tag(   R   (   R#   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR   A  s    c      	   C@ s\   | rB |  j  | d | t g  | D] } d | ^ q  f   n  |  j  | d |   d  S(   Nu$   Invalid block tag: '%s', expected %su   '%s'u   Invalid block tag: '%s'(   R   R   (   R#   Rt   R   R   R'   (    (    s-   ../Django//lib/python/django/template/base.pyR   D  s    0c         C@ s#   |  j  d  d d j |    d  S(   Nu   Unclosed tags: %s u   , (   R   R5   RZ   (   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR   J  s    c         C@ s   d  S(   N(    (   R#   Rt   R   (    (    s-   ../Django//lib/python/django/template/base.pyR   M  s    c         C@ s   |  j  j d  S(   Ni    (   Rv   RB   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR}   P  s    c         C@ s   |  j  j d |  d  S(   Ni    (   Rv   t   insert(   R#   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR   S  s    c         C@ s   |  j  d =d  S(   Ni    (   Rv   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   delete_first_tokenV  s    c         C@ s*   |  j  j | j   |  j j | j  d  S(   N(   Rw   t   updateRx   (   R#   R{   (    (    s-   ../Django//lib/python/django/template/base.pyRz   Y  s    c         C@ s   t  | |   S(   u9   
        Convenient wrapper for FilterExpression
        (   t   FilterExpression(   R#   Rt   (    (    s-   ../Django//lib/python/django/template/base.pyR   ]  s    c         C@ s.   | |  j  k r |  j  | St d |   d  S(   Nu   Invalid filter: '%s'(   Rx   R   (   R#   t   filter_name(    (    s-   ../Django//lib/python/django/template/base.pyt   find_filterc  s    N(   R   R   R$   R5   RI   R   R   R|   R~   R   R   R   R   R   R   R   R   R}   R   R   Rz   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyRG      s(   	+																t   TokenParserc           B@ sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   u  
    Subclass this and implement the top() method to parse a template line.
    When instantiating the parser, pass in the line from the Django template
    parser.

    The parser's "tagname" instance-variable stores the name of the tag that
    the filter was called with.
    c         C@ s.   | |  _  d |  _ g  |  _ |  j   |  _ d  S(   Ni    (   t   subjectt   pointert   backoutt   tagt   tagname(   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR$   r  s    			c         C@ s   t     d S(   uV   
        Overload this method to do the actual parsing and return the result.
        N(   R,   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   topx  s    c         C@ s   |  j  t |  j  k  S(   uA   
        Returns True if there is more stuff in the tag.
        (   R   t   lenR   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   more~  s    c         C@ s4   t  |  j  s t d   n  |  j j   |  _ d S(   uW   
        Undoes the last microparser. Use this for lookahead and backtracking.
        u)   back called without some previous parsingN(   R   R   R   RB   R   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   back  s    c         C@ s   |  j  } |  j } | t |  k r7 t d |   n  | } x0 | t |  k  ro | | d k ro | d 7} q@ W| | | !} x0 | t |  k  r | | d k r | d 7} q W|  j j |  j  | |  _ | S(   uM   
        A microparser that just returns the next tag from the line.
        u-   expected another tag, found end of string: %su    u   	i   (   u    u   	(   u    u   	(   R   R   R   R   R   RY   (   R#   R   t   iR'   t   s(    (    s-   ../Django//lib/python/django/template/base.pyR     s    		%%	c         C@ s  |  j  } |  j } d   } | t |  k r@ t d |   n  | | d
 k r;| } | d 7} x4 | t |  k  r | | | | k r | d 7} qc W| t |  k r t d | | f   n  | d 7} | | |  } | | | !} x0 | t |  k  r| | d k r| d 7} q W|  j j |  j  | |  _ | S| } | | |  } | | | !} x0 | t |  k  r| | d k r| d 7} q`W|  j j |  j  | |  _ | Sd	 S(   ug   
        A microparser that parses for a value: some string constant or
        variable name.
        c         S@ s   x | t  |   k  r |  | d k r |  | d k r |  | } | d 7} x0 | t  |   k  r{ |  | | k r{ | d 7} qL W| t  |   k r t d | |  f   q n  | d 7} q W| S(	   uz   
            Increment pointer until a real space (i.e. a space not within
            quotes) is encountered
            u    u   	u   "u   'i   u>   Searching for value. Unexpected end of string in column %d: %s(   u    u   	(   u   "u   '(   R   R   (   R   R   t   c(    (    s-   ../Django//lib/python/django/template/base.pyt   next_space_index  s    %

%uG   Searching for value. Expected another value but found end of string: %su   "u   'i   u>   Searching for value. Unexpected end of string in column %d: %su    u   	N(   u   "u   '(   u    u   	(   u    u   	(   R   R   R   R   R   RY   (   R#   R   R   R   R'   t   resR   (    (    s-   ../Django//lib/python/django/template/base.pyt   value  s<    			
)
%	%	(	   R   R   t   __doc__R$   R   R   R   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   i  s   						uf   
(?:%(i18n_open)s%(strdq)s%(i18n_close)s|
%(i18n_open)s%(strsq)s%(i18n_close)s|
%(strdq)s|
%(strsq)s)
u   "[^"\\]*(?:\\.[^"\\]*)*"u   strdqu   '[^'\\]*(?:\\.[^'\\]*)*'u   strsqu   _(u	   i18n_openu   )u
   i18n_closeu   
u    u  
^(?P<constant>%(constant)s)|
^(?P<var>[%(var_chars)s]+|%(num)s)|
 (?:\s*%(filter_sep)s\s*
     (?P<filter_name>\w+)
         (?:%(arg_sep)s
             (?:
              (?P<constant_arg>%(constant)s)|
              (?P<var_arg>[%(var_chars)s]+|%(num)s)
             )
         )?
 )u   constantu   [-+\.]?\d[\d\.e]*u   numu   \w\.u	   var_charsu
   filter_sepu   arg_sepR   c           B@ sA   e  Z d  Z d   Z e d  Z d   Z e e  Z d   Z RS(   u  
    Parses a variable token and its optional filters (all as a single string),
    and return a list of tuples of the filter name and arguments.
    Sample::

        >>> token = 'variable|default:"Default value"|date:"Y-m-d"'
        >>> p = Parser('')
        >>> fe = FilterExpression(token, p)
        >>> len(fe.filters)
        2
        >>> fe.var
        <Variable: 'variable'>

    This class should never be instantiated outside of the
    get_filters_from_token helper function.
    c         C@ s  | |  _  t j |  } d  } g  } d } x| D]} | j   } | | k rz t d | |  | | | !| | f   n  | d  k r| j d d  \ }	 }
 |
 r y t |
  j i   } Wqt	 k
 r d  } qXq|	 d  k r t d |   qt |	  } n | j d  } g  } | j d d  \ } } | r`| j
 t t |  j i   f  n" | r| j
 t t |  f  n  | j |  } |  j | | |  | j
 | | f  | j   } q1 W| t |  k rt d	 | | | f   n  | |  _ | |  _ d  S(
   Ni    u)   Could not parse some characters: %s|%s|%su   varu   constantu'   Could not find variable at start of %s.u   filter_nameu   constant_argu   var_argu-   Could not parse the remainder: '%s' from '%s'(   Rt   t	   filter_ret   finditerR5   t   startR   t   groupt   Variablet   resolveR    RY   Ra   R   R   t
   args_checkt   endR   Rx   t   var(   R#   Rt   RM   t   matchest   var_objRx   t   uptot   matchR   R   t   constantR   t   argst   constant_argt   var_argt   filter_func(    (    s-   ../Django//lib/python/django/template/base.pyR$     sL    	%	c   
      C@ s  t  |  j t  r y |  j j |  } Wq t k
 r | rG d  } q t j r t d  k rn d t j k a n  t r t j |  j St j St j } q Xn	 |  j } x|  j	 D]\ } } g  } xF | D]> \ } } | s | j
 t |   q | j
 | j |   q Wt | d t  r.t | | j  } n  t | d t  r[| | d | j | }	 n | | |  }	 t | d t  rt  | t  rt |	  } q t  | t  rt |	  } q |	 } q W| S(   Nu   %su   expects_localtimeu   needs_autoescapet
   autoescapeu   is_safe(   R   R   R   R   R    R5   R   t   TEMPLATE_STRING_IF_INVALIDt   invalid_var_format_stringRx   RY   R   t   getattrRa   R   t   use_tzR   R   R   R   (
   R#   R>   t   ignore_failurest   objt   funcR   t   arg_valst   lookupt   argt   new_obj(    (    s-   ../Django//lib/python/django/template/base.pyR   ?  s>    			!
c         C@ s5  t  |  } t |  } t | d |  } t |  \ } } } } | j d  | ri | t |   } n | } y" x | D] }	 | j d  qy WWn0 t k
 r t d |  t |  | f   n X| r t  |  p g  } y" x | D] }
 | j d  q WWn0 t k
 r0t d |  t |  | f   n Xt S(   Nu   _decorated_functioni    u%   %s requires %d arguments, %d provided(   t   listR   R   R   RB   R   R   R   (   R+   R   t   providedt   plenR   t   varargst   varkwt   defaultst   nondefsR   t   parg(    (    s-   ../Django//lib/python/django/template/base.pyR   g  s,    c         C@ s   |  j  S(   N(   Rt   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR(     s    (	   R   R   R   R$   Ra   R   R   t   staticmethodR(   (    (    (    s-   ../Django//lib/python/django/template/base.pyR     s   	,(	 c         C@ s   t  |   j |  S(   u   
    Returns the resolved variable, which may contain attribute syntax, within
    the given context.

    Deprecated; use the Variable class instead.
    (   R   R   (   t   pathR>   (    (    s-   ../Django//lib/python/django/template/base.pyt   resolve_variable  s    R   c           B@ s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   u+  
    A template variable, resolvable against a given context. The variable may
    be a hard-coded string (if it begins and ends with single or double quote
    marks)::

        >>> c = {'article': {'section':u'News'}}
        >>> Variable('article.section').resolve(c)
        u'News'
        >>> Variable('article').resolve(c)
        {'section': u'News'}
        >>> class AClass: pass
        >>> c = AClass()
        >>> c.article = AClass()
        >>> c.article.section = u'News'

    (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
    c         C@ s[  | |  _  d  |  _ d  |  _ t |  _ d  |  _ y^ t |  |  _ d | k rr d | j   k rr t	 |  j  |  _ n  | j
 d  r t  n  Wn t k
 rV| j d  r | j
 d  r t |  _ | d d !} n  y t t |   |  _ WqWt k
 rR| j t d  d k s$| d d k r7t d	 |   n  t | j t   |  _ qWXn Xd  S(
   Nu   .u   eu   _(u   )i   iu   _i    u=   Variables and attributes may not begin with underscores: '%s'(   R   R5   t   literalt   lookupsRa   t	   translatet   message_contextt   floatt   lowert   intRW   t
   ValueErrorRV   R   R   R   Rm   t   VARIABLE_ATTRIBUTE_SEPARATORR   R&   R[   (   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR$     s,    						)c         C@ s]   |  j  d k	 r! |  j |  } n	 |  j } |  j rY |  j rL t |  j |  St |  Sn  | S(   u.   Resolve this variable against a given context.N(   R   R5   t   _resolve_lookupR   R   R   R   R   (   R#   R>   R   (    (    s-   ../Django//lib/python/django/template/base.pyR     s    			c         C@ s   d |  j  j |  j f S(   Nu   <%s: %r>(   t	   __class__R   R   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyt   __repr__  s    c         C@ s   |  j  S(   N(   R   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR(     s    c      	   C@ si  | } y(x!|  j  D]} y | | } Wn t t t t f k
 r y t | |  } Wq t t f k
 r y | t |  } Wq t t t t f k
 r t d | | f   q Xq Xn Xt	 |  r t | d t
  r q)t | d t
  r t j } q)y |   } Wq)t k
 r%t j } q)Xq q WWn4 t k
 rd} t | d t
  r^t j } qe  n X| S(   u  
        Performs resolution of a real variable (i.e. not a literal) against the
        given context.

        As indicated by the method's name, this method is an implementation
        detail and shouldn't be called by external code. Use Variable.resolve()
        instead.
        u    Failed lookup for key [%s] in %ru   do_not_call_in_templatesu   alters_datau   silent_variable_failure(   R   t	   TypeErrorR   R   R   R   R   R   R    t   callableRa   R   R   t	   Exception(   R#   R>   t   currentR]   R   (    (    s-   ../Django//lib/python/django/template/base.pyR     s>    	(   R   R   R   R$   R   R   R(   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR     s   	,			t   Nodec           B@ s/   e  Z e Z d Z d   Z d   Z d   Z RS(   u   nodelistc         C@ s   d S(   u7   
        Return the node rendered as a string.
        N(    (   R#   R>   (    (    s-   ../Django//lib/python/django/template/base.pyR=     s    c         c@ s	   |  Vd  S(   N(    (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR<   $  s    c         C@ sn   g  } t  |  |  r% | j |   n  xB |  j D]7 } t |  | d  } | r/ | j | j |   q/ q/ W| S(   uj   
        Return a list of all nodes (within this node and its nodelist)
        of the given type
        N(   R   RY   t   child_nodelistsR   R5   t   extendt   get_nodes_by_type(   R#   t   nodetypet   nodest   attrR7   (    (    s-   ../Django//lib/python/django/template/base.pyR   '  s    (   u   nodelist(   R   R   Ra   R   R   R=   R<   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR     s
   		R   c           B@ s)   e  Z e Z d    Z d   Z d   Z RS(   c         C@ sg   g  } xK |  D]C } t  | t  r7 |  j | |  } n | } | j t |   q Wt d j |   S(   Nu    (   R   R   t   render_nodeRY   R   R   RZ   (   R#   R>   R\   R:   R]   (    (    s-   ../Django//lib/python/django/template/base.pyR=   :  s    c         C@ s1   g  } x$ |  D] } | j  | j |   q W| S(   u,   Return a list of all nodes of the given type(   R   R   (   R#   R   R   R:   (    (    s-   ../Django//lib/python/django/template/base.pyR   D  s    c         C@ s   | j  |  S(   N(   R=   (   R#   R:   R>   (    (    s-   ../Django//lib/python/django/template/base.pyR   K  s    (   R   R   Ra   R   R=   R   R   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   5  s   	
	R   c           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s   | |  _  d  S(   N(   R   (   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR$   O  s    c         C@ s   t  d |  j d  d d d S(   Nu   <Text Node: '%s'>i   u   asciiR%   u   replace(   R   R   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR   R  s    c         C@ s   |  j  S(   N(   R   (   R#   R>   (    (    s-   ../Django//lib/python/django/template/base.pyR=   V  s    (   R   R   R$   R   R=   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   N  s   		c         C@ sp   t  |  d | j }  t |  d | j }  t |   }  | j rO t |  t  s^ t |  t  rh t	 |   S|  Sd S(   u   
    Converts any value to a string to become part of a rendered template. This
    means escaping, if required, and conversion to a unicode object. If value
    is a string, it is expected to have already been translated.
    R   t   use_l10nN(
   R   R   R   R   R   R   R   R   R   R   (   R   R>   (    (    s-   ../Django//lib/python/django/template/base.pyt   _render_value_in_contextY  s    
R   c           B@ s#   e  Z d    Z d   Z d   Z RS(   c         C@ s   | |  _  d  S(   N(   R   (   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR$   i  s    c         C@ s   d |  j  S(   Nu   <Variable Node: %s>(   R   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR   l  s    c         C@ s8   y |  j  j |  } Wn t k
 r* d SXt | |  S(   Nu    (   R   R   R3   R   (   R#   R>   t   output(    (    s-   ../Django//lib/python/django/template/base.pyR=   o  s
    (   R   R   R$   R   R=   (    (    (    s-   ../Django//lib/python/django/template/base.pyR   h  s   		u   (?:(\w+)=)?(.+)c         C@ sR  |  s
 i  St  j |  d  } | o/ | j d  } | sk | sB i  St |   d k  sd |  d d k rk i  Sn  i  } x |  rM| r t  j |  d  } | s | j d  r | S| j   \ } } |  d 4nB t |   d k  s |  d d k r | S|  d |  d } } |  d 4| j |  | | <|  rt | rt |  d d k r@| S|  d 4qt qt W| S(   u  
    A utility method for parsing token keyword arguments.

    :param bits: A list containing remainder of the token (split by spaces)
        that is to be checked for arguments. Valid arguments will be removed
        from this list.

    :param support_legacy: If set to true ``True``, the legacy format
        ``1 as foo`` will be accepted. Otherwise, only the standard ``foo=1``
        format is allowed.

    :returns: A dictionary of the arguments retrieved from the ``bits`` token
        list.

    There is no requirement for all remaining token ``bits`` to be keyword
    arguments, so the dictionary will be returned as soon as an invalid
    argument format is reached.
    i    i   i   u   asi   u   and(   t   kwarg_reR   R   R   t   groupsR   (   R\   RM   t   support_legacyR   t   kwarg_formatt   kwargst   keyR   (    (    s-   ../Django//lib/python/django/template/base.pyt   token_kwargs|  s6    "	
"c         C@ s  | r6 | d d k r# | d } q6 t  d |   n  g  } i  }	 t |  }
 x=| D]5} t | g |   } | rt t j |   d \ } } | | k r | d k r t  d | | f   q| |	 k r t  d | | f   q| |	 t |  <| |
 k r|
 j |  qqU |	 r0t  d |   qU | j |  j	 |   y |
 j
 d  WqU t k
 r| d k rt  d |   qqU XqU W| d k	 r|
 t |   }
 n  |
 rt  d	 | d
 j g  |
 D] } d | ^ q f   n  | |	 f S(   u   
    Parses bits for template tag helpers (simple_tag, include_tag and
    assignment_tag), in particular by detecting syntax errors and by
    extracting positional and keyword arguments.
    i    u   contexti   uW   '%s' is decorated with takes_context=True so it must have a first argument of 'context'u.   '%s' received unexpected keyword argument '%s'u7   '%s' received multiple values for keyword argument '%s'uH   '%s' received some positional argument(s) after some keyword argument(s)u+   '%s' received too many positional argumentsu5   '%s' did not receive value(s) for the argument(s): %su   , u   '%s'N(   R   R   R   R   t	   iteritemsR5   t   strt   removeRY   R   RB   R   R   RZ   (   RM   R\   R"   R   R   R   t   takes_contextR+   R   R   t   unhandled_paramsR]   t   kwargt   paramR   R'   (    (    s-   ../Django//lib/python/django/template/base.pyt
   parse_bits  sV    3c	      	   C@ sG   | j    d }	 t |  |	 | | | | | |  \ }
 } | | |
 |  S(   u+   
    Returns a template.Node subclass.
    i   (   R`   R  (   RM   Rt   R"   R   R   R   R+   R  t
   node_classR\   R   R   (    (    s-   ../Django//lib/python/django/template/base.pyt   generic_tag_compiler  s    t   TagHelperNodec           B@ s    e  Z d  Z d   Z d   Z RS(   u   
    Base class for tag helper nodes such as SimpleNode, InclusionNode and
    AssignmentNode. Manages the positional and keyword arguments to be passed
    to the decorated function.
    c         C@ s   | |  _  | |  _ | |  _ d  S(   N(   R  R   R   (   R#   R  R   R   (    (    s-   ../Django//lib/python/django/template/base.pyR$     s    		c         @ sm   g  |  j  D] } | j    ^ q
 } |  j r>   g | } n  t   f d   |  j j   D  } | | f S(   Nc         3@ s*   |  ]  \ } } | | j     f Vq d  S(   N(   R   (   t   .0t   kt   v(   R>   (    s-   ../Django//lib/python/django/template/base.pys	   <genexpr>
  s   (   R   R   R  t   dictR   t   items(   R#   R>   R   t   resolved_argst   resolved_kwargs(    (   R>   s-   ../Django//lib/python/django/template/base.pyt   get_resolved_arguments  s    %	(   R   R   R   R$   R  (    (    (    s-   ../Django//lib/python/django/template/base.pyR	    s   	t   Libraryc           B@ sw   e  Z d    Z d d d  Z d   Z d d d  Z d   Z d d d d  Z d d d d  Z	 e
 e d d  Z RS(	   c         C@ s   i  |  _  i  |  _ d  S(   N(   Rx   Rw   (   R#   (    (    s-   ../Django//lib/python/django/template/base.pyR$     s    	c         @ s     d  k r | d  k r  j S  d  k	 ri | d  k ri t    rP  j    S   f d   } | Sn>   d  k	 r | d  k	 r |  j   <| St d   | f   d  S(   Nc         @ s     j   |   S(   N(   R   (   R   (   R#   R+   (    s-   ../Django//lib/python/django/template/base.pyt   dec  s    u.   Unsupported arguments to Library.tag: (%r, %r)(   R5   t   tag_functionR   Rw   R)   (   R#   R+   t   compile_functionR  (    (   R+   R#   s-   ../Django//lib/python/django/template/base.pyR     s    c         C@ s    | |  j  t | d |  j <| S(   Nu   _decorated_function(   Rw   R   R   (   R#   R   (    (    s-   ../Django//lib/python/django/template/base.pyR  (  s    c         @ s    d  k r. | d  k r.   f d   } | S  d  k	 r~ | d  k r~ t    rb  j     S    f d   } | Sn   d  k	 r| d  k	 r|  j   <x\ d D]T } |  k r  | } t | | |  t | d  r t | j | |  q q q W| St d   | f   d  S(	   Nc         @ s     j  |    S(   N(   t   filter_function(   R   (   R#   t   flags(    s-   ../Django//lib/python/django/template/base.pyR  /  s    c         @ s     j   |    S(   N(   t   filter(   R   (   R#   R  R+   (    s-   ../Django//lib/python/django/template/base.pyR  9  s    u   expects_localtimeu   is_safeu   needs_autoescapeu   _decorated_functionu1   Unsupported arguments to Library.filter: (%r, %r)(   u   expects_localtimeu   is_safeu   needs_autoescape(   R5   R   R  Rx   t   setattrt   hasattrt   _decorated_functionR)   (   R#   R+   R   R  R  R   R   (    (   R+   R#   R  s-   ../Django//lib/python/django/template/base.pyR  ,  s&    
c         K@ s(   t  | d |  j } |  j | | |  S(   Nu   _decorated_function(   R   R   R  (   R#   R   R  R+   (    (    s-   ../Django//lib/python/django/template/base.pyR  N  s    c         @ sK       f d   } | d  k r% | St |  r; | |  St d   d  S(   Nc         @ s   t     \ } } } } d t f   f d     Y}  pL t   d    j } t t d | d | d | d | d | d	  d
 | }   j | _  j | |    S(   Nt
   SimpleNodec           @ s   e  Z   f d    Z RS(   c         @ s"   |  j  |  \ } }   | |   S(   N(   R  (   R#   R>   R  R  (   R   (    s-   ../Django//lib/python/django/template/base.pyR=   X  s    (   R   R   R=   (    (   R   (    s-   ../Django//lib/python/django/template/base.pyR  V  s   u   _decorated_functionR"   R   R   R   R+   R  R  (   R   R	  R   R   R   R  R   R   (   R   R"   R   R   R   R  t   function_nameR   (   R  R#   R+   (   R   s-   ../Django//lib/python/django/template/base.pyR  S  s    	u(   Invalid arguments provided to simple_tag(   R5   R   R   (   R#   R   R  R+   R  (    (   R  R+   R#   s-   ../Django//lib/python/django/template/base.pyt
   simple_tagR  s    
c         @ sK       f d   } | d  k r% | St |  r; | |  St d   d  S(   Nc         @ s   t     \     d t f    f d     Y 	 pO t   d    j         f d   }   j | _  j  |    S(   Nt   AssignmentNodec           @ s&   e  Z  f d    Z   f d   Z RS(   c         @ s)   t    |   j | | |  | |  _ d  S(   N(   R/   R$   t
   target_var(   R#   R  R   R   R   (   R  (    s-   ../Django//lib/python/django/template/base.pyR$   t  s    c         @ s/   |  j  |  \ } }   | |   | |  j <d S(   Nu    (   R  R   (   R#   R>   R  R  (   R   (    s-   ../Django//lib/python/django/template/base.pyR=   x  s    (   R   R   R$   R=   (    (   R   R  (    s-   ../Django//lib/python/django/template/base.pyR  s  s   u   _decorated_functionc      
   @ s   | j    d } t |  d k  s2 | d d k rE t d    n  | d } | d  } t |  |         \ } }    | | |  S(   Ni   i   iu   asuM   '%s' tag takes at least 2 arguments and the second last argument must be 'as'i(   R`   R   R   R  (   RM   Rt   R\   R   R   R   (   R  R   R   R"   R  R   R  (    s-   ../Django//lib/python/django/template/base.pyR     s    "

(   R   R	  R   R   R   R   (   R   R   (   R  R#   R+   (   R   R"   R  R   R   R   R  s-   ../Django//lib/python/django/template/base.pyR  p  s    
!u,   Invalid arguments provided to assignment_tag(   R5   R   R   (   R#   R   R  R+   R  (    (   R  R+   R#   s-   ../Django//lib/python/django/template/base.pyt   assignment_tago  s     
c         @ s         f d   } | S(   Nc         @ s   t     \ } } } } d t f     f d     Y}  pR t   d    j } t t d | d | d | d | d | d	  d
 | }   j | _  j | |    S(   Nt   InclusionNodec           @ s   e  Z     f d    Z RS(   c   
      @ s  |  j  |  \ } }  | |   } t |  d t  s d d l m } m } t   t  rd   } n: t   t j	  r t
    r |    } n |    } | j |  _ n   | i | j d 6| j d 6| j d 6| j d 6 } | j d d   }	 |	 d  k	 r|	 | d <n  |  j j |  S(	   Nu   nodelisti    (   t   get_templatet   select_templateu
   autoescapeu   current_appu   use_l10nu   use_tzu
   csrf_token(   R  R   Ra   t   django.template.loaderR#  R$  R   R2   R   t   string_typesR	   R7   R   t   current_appR   R   t   getR5   R=   (
   R#   R>   R  R  t   _dictR#  R$  t   tt   new_contextt
   csrf_token(   t	   file_namet   context_classR   (    s-   ../Django//lib/python/django/template/base.pyR=     s&    		


(   R   R   R=   (    (   R-  R   R.  (    s-   ../Django//lib/python/django/template/base.pyR"    s   u   _decorated_functionR"   R   R   R   R+   R  R  (   R   R	  R   R   R   R  R   R   (   R   R"   R   R   R   R"  R  R   (   R  R+   R-  R#   R.  (   R   s-   ../Django//lib/python/django/template/base.pyR    s    "	(    (   R#   R-  R.  R  R+   R  (    (   R  R+   R-  R#   R.  s-   ../Django//lib/python/django/template/base.pyt   inclusion_tag  s    *N(   R   R   R$   R5   R   R  R  R  R  R!  R   Ra   R/  (    (    (    s-   ../Django//lib/python/django/template/base.pyR    s   		"	*c         C@ sU   |  j  d d  \ } } y t |  } t | |  SWn t k
 rP t |  SXd S(   u  Check if library that failed to load cannot be found under any
    templatetags directory or does exist but fails to import.

    Non-existing condition is checked recursively for each subpackage in cases
    like <appdir>/templatetags/subpackage/package/module.py.
    u   .i   N(   t   rsplitR   R   t   ImportErrort   is_library_missing(   R+   R   t   modulet   package(    (    s-   ../Django//lib/python/django/template/base.pyR2    s    	c         C@ s   y t  |   } Wn9 t k
 rK } t |   r2 d St d |  | f   n Xy | j SWn! t k
 rz t d |    n Xd S(   u   
    Load a template tag library module.

    Verifies that the library contains a 'register' attribute, and
    returns that attribute as the representation of the library
    u!   ImportError raised loading %s: %su=   Template library %s does not have a variable named 'register'N(   R   R1  R2  R5   R)   t   registerR   (   t   taglib_modulet   modR   (    (    s-   ../Django//lib/python/django/template/base.pyt   import_library  s    c          C@ sv   t  sr g  }  xZ d g t t j  D]B } y% d | } t |  |  j |  Wq# t k
 rd q# q# Xq# W|  a  n  t  S(   uj   
    Return the list of all available template tag modules.

    Caches the result for faster access.
    u   djangou   %s.templatetags(   t   templatetags_modulesR   R   t   INSTALLED_APPSR   RY   R1  (   t   _templatetags_modulest
   app_modulet   templatetag_module(    (    s-   ../Django//lib/python/django/template/base.pyt   get_templatetags_modules  s    

	c         C@ s   t  j |  d  } | s t   } g  } xK | D]C } d | |  f } | j |  t |  } | r. | t  |  <Pq. q. W| s t d |  d j |  f   q n  | S(   uL  
    Load the template library module with the given name.

    If library is not already loaded loop over all templatetags modules
    to locate it.

    {% load somelib %} and {% load someotherlib %} loops twice.

    Subsequent loads eg. {% load somelib %} in the same process will grab
    the cached module from libraries.
    u   %s.%su'   Template library %s not found, tried %su   ,N(   t	   librariesR(  R5   R>  RY   R8  R)   RZ   (   t   library_nameR{   R9  t   tried_modulesR3  R6  (    (    s-   ../Django//lib/python/django/template/base.pyt   get_library  s     	
c         C@ s   t  j t |    d  S(   N(   Ry   RY   R8  (   R3  (    (    s-   ../Django//lib/python/django/template/base.pyt   add_to_builtins'  s    u   django.template.defaulttagsu   django.template.defaultfilters(p   t
   __future__R    R   t   ret	   functoolsR   t   inspectR   t   django.confR   t   django.template.contextR   R   R   t   django.utils.importlibR   t   django.utils.itercompatR	   t   django.utils.textR
   R   R   t   django.utils.encodingR   R   t   django.utils.translationR   R   t   django.utils.safestringR   R   R   R   t   django.utils.formatsR   t   django.utils.htmlR   t   django.utils.module_loadingR   t   django.utilsR   t   django.utils.timezoneR   R   Rp   Rj   Rk   Ro   RR   t   FILTER_SEPARATORt   FILTER_ARGUMENT_SEPARATORR   Rg   t   BLOCK_TAG_ENDRi   t   VARIABLE_TAG_ENDRl   t   COMMENT_TAG_ENDRn   t   SINGLE_BRACE_STARTt   SINGLE_BRACE_ENDt   ALLOWED_VARIABLE_CHARSR0   t   compileRc   R?  Ry   R5   R   R   R   R   R   R    R)   t   objectR*   R.   R2   R6   RN   RF   RG   R   t   constant_stringRS   t   filter_raw_stringt   UNICODEt   VERBOSER   R   R   R   R   R   R   R   R   R   R   Ra   R   R  R  R	  R  R2  R8  R9  R>  RB  RC  (    (    (    s-   ../Django//lib/python/django/template/base.pyt   <module>   s   "
	"

	3|			1	C	
					
