3
g              	   @   sn  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l
mZmZ ddlmZ ddlmZmZ dd	lmZmZmZ dd
lmZ ddlmZmZ ddlmZ dZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)edeje eje!eje"eje#eje$eje%f Z*ej+dZ,G dd deZ-G dd  d e.Z/G d!d" d"Z0G d#d$ d$Z1d%d& Z2G d'd( d(Z3G d)d* d*Z4G d+d, d,e4Z5G d-d. d.Z6d/d0d1ejd2ejd3d4 Z7e7j8d5d6Z7d7e7d8d9ejeejed: Z9ee9ej:Z;G d;d< d<Z<G d=d> d>Z=G d?d@ d@Z>G dAdB dBe?Z@G dCdD dDe>ZAdEdF ZBG dGdH dHe>ZCedIZDdMdKdLZEdS )Na  
This is the Django template system.

How it works:

The Lexer.tokenize() method converts a template string (i.e., a string
containing markup with custom template tags) to tokens, which can be either
plain text (TokenType.TEXT), variables (TokenType.VAR), or block statements
(TokenType.BLOCK).

The Parser() class takes a list of tokens in its constructor, and its parse()
method returns a compiled template -- which is, under the hood, a list of
Node objects.

Each Node is responsible for creating some sort of output -- e.g. simple text
(TextNode), variable values in a given context (VariableNode), results of basic
logic (IfNode), results of looping (ForNode), or anything else. The core Node
types are TextNode, VariableNode, IfNode and ForNode, but plugin modules can
define their own custom node types.

Each Node has a render() method, which takes a Context and returns a string of
the rendered node. For example, the render() method of a Variable Node returns
the variable's value as a string. The render() method of a ForNode returns the
rendered output of whatever was inside the loop, recursively.

The Template class is a convenient wrapper that takes care of template
compilation and rendering.

Usage:

The only thing you should ever use directly in this file is the Template class.
Create a compiled template object with a template_string, then call render()
with a context. In the compilation stage, the TemplateSyntaxError exception
will be raised if the template doesn't have proper syntax.

Sample code:

>>> from django import template
>>> s = '<html>{% if test %}<h1>{{ varvalue }}</h1>{% endif %}</html>'
>>> t = template.Template(s)

(t is now a compiled template, and its render() method can be called multiple
times with multiple contexts)

>>> c = template.Context({'test':True, 'varvalue': 'Hello'})
>>> t.render(c)
'<html><h1>Hello</h1></html>'
>>> c = template.Context({'test':False, 'varvalue': 'Hello'})
>>> t.render(c)
'<html></html>'
    N)Enum)BaseContext)localize)conditional_escapeescape)_lazy_re_compile)SafeData	mark_safe)get_text_listsmart_splitunescape_string_literal)template_localtime)gettext_lazypgettext_lazy   )TemplateSyntaxError|:.z{%z%}z{{z}}z{#z#}ZTranslators{}z<unknown source>z(%s.*?%s|%s.*?%s|%s.*?%s)zdjango.templatec               @   s   e Zd ZdZdZdZdZdS )	TokenTyper   r         N)__name__
__module____qualname__TEXTVARBLOCKCOMMENT r!   r!   R/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/template/base.pyr   c   s   r   c               @   s    e Zd Zf fddZdd ZdS )VariableDoesNotExistc             C   s   || _ || _d S )N)msgparams)selfr$   r%   r!   r!   r"   __init__l   s    zVariableDoesNotExist.__init__c             C   s   | j | j S )N)r$   r%   )r&   r!   r!   r"   __str__p   s    zVariableDoesNotExist.__str__N)r   r   r   r'   r(   r!   r!   r!   r"   r#   j   s   r#   c               @   s2   e Zd Zd
ddZdd Zdd Zedd	 ZdS )OriginNc             C   s   || _ || _|| _d S )N)nametemplate_nameloader)r&   r*   r+   r,   r!   r!   r"   r'   u   s    zOrigin.__init__c             C   s   | j S )N)r*   )r&   r!   r!   r"   r(   z   s    zOrigin.__str__c             C   s"   t |to | j|jko | j|jkS )N)
isinstancer)   r*   r,   )r&   otherr!   r!   r"   __eq__}   s    
zOrigin.__eq__c             C   s    | j rd| j j| j jjf S d S )Nz%s.%s)r,   r   	__class__r   )r&   r!   r!   r"   loader_name   s    zOrigin.loader_name)NN)r   r   r   r'   r(   r/   propertyr1   r!   r!   r!   r"   r)   t   s   
r)   c               @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )TemplateNc             C   sV   |d krddl m} |j }|d kr,tt}|| _|| _|| _ t|| _| j	 | _
d S )Nr   )Engine)enginer4   get_defaultr)   UNKNOWN_SOURCEr*   originstrsourcecompile_nodelistnodelist)r&   template_stringr8   r*   r5   r4   r!   r!   r"   r'      s    
zTemplate.__init__c             c   s   x| j D ]}|E d H  qW d S )N)r<   )r&   noder!   r!   r"   __iter__   s    zTemplate.__iter__c             C   s   | j j|S )N)r<   render)r&   contextr!   r!   r"   _render   s    zTemplate._renderc             C   sV   |j j| @ |jdkr>|j|  | j|_| j|S Q R X n
| j|S W dQ R X dS )z)Display stage -- can be called many timesN)render_contextZ
push_statetemplateZbind_templater*   r+   rB   )r&   rA   r!   r!   r"   r@      s    
zTemplate.renderc             C   s   | j jrt| j}n
t| j}|j }t|| j j| j j| j	}y|j
 S  tk
r } z | j jrp| j||j|_ W Y dd}~X nX dS )z
        Parse and compile the template source into a nodelist. If debug
        is True and an exception occurs during parsing, the exception is
        annotated with contextual line information where it occurred in the
        template source.
        N)r5   debug
DebugLexerr:   LexertokenizeParserZtemplate_librariesZtemplate_builtinsr8   parse	Exceptionget_exception_infotokentemplate_debug)r&   lexertokensparserer!   r!   r"   r;      s    
zTemplate.compile_nodelistc             C   s0  |j \}}d}d}d}g }d }	 }
}xtt| jD ]r\}}||kr||kr|}t| j|| }	t| j|| }
t| j|| }|j|t| j|| f |}q6W t|}td|| }t||d | }yt	|j
d }W n ttfk
r   d}Y nX |||| |	|
|||||| jj||dS )a:  
        Return a dictionary containing contextual line information of where
        the exception occurred in the template. The following information is
        provided:

        message
            The message of the exception raised.

        source_lines
            The lines before, after, and including the line the exception
            occurred on.

        line
            The line number the exception occurred on.

        before, during, after
            The line the exception occurred on split into three parts:
            1. The content before the token that raised the error.
            2. The token that raised the error.
            3. The content after the token that raised the error.

        total
            The number of lines in source_lines.

        top
            The line number where source_lines starts.

        bottom
            The line number where source_lines ends.

        start
            The start position of the token in the template source.

        end
            The end position of the token in the template source.
        
   r    r   z!(Could not get exception message))messagesource_linesbeforeduringaftertopbottomtotalliner*   startend)position	enumeratelinebreak_iterr:   r   appendlenmaxminr9   args
IndexErrorUnicodeDecodeErrorr8   r*   )r&   	exceptionrM   r^   r_   Zcontext_linesr]   uptorV   rW   rX   rY   numnextr\   rZ   r[   rU   r!   r!   r"   rL      sB    %


zTemplate.get_exception_info)NNN)	r   r   r   r'   r?   rB   r@   r;   rL   r!   r!   r!   r"   r3      s   

r3   c             c   sJ   dV  | j d}x&|dkr6|d V  | j d|d }qW t| d V  d S )Nr   
r   )findrd   )Ztemplate_sourcepr!   r!   r"   rb     s    


rb   c               @   s&   e Zd ZdddZdd Zdd ZdS )	TokenNc             C   s   || | _ | _|| _|| _dS )a7  
        A token representing a string from the template.

        token_type
            A TokenType, either .TEXT, .VAR, .BLOCK, or .COMMENT.

        contents
            The token source string.

        position
            An optional tuple containing the start and end index of the token
            in the template source. This is used for traceback information
            when debug is on.

        lineno
            The line number the token appears on in the template source.
            This is used for traceback information and gettext files.
        N)
token_typecontentslinenor`   )r&   rr   rs   r`   rt   r!   r!   r"   r'      s    zToken.__init__c             C   s*   | j jj }d|| jd d jddf S )Nz<%s token: "%s...">   rn   rT   )rr   r*   
capitalizers   replace)r&   Z
token_namer!   r!   r"   r(   7  s    zToken.__str__c             C   sr   g }t | j}x^|D ]V}|jdr`|d d }|g}x |j|sTt|}|j| q6W dj|}|j| qW |S )N_("_('r   ) )rx   ry   )r   rs   
startswithendswithrm   rc   join)r&   splitbitsbitsentinelZ	trans_bitr!   r!   r"   split_contents<  s    



zToken.split_contents)NN)r   r   r   r'   r(   r   r!   r!   r!   r"   rq     s   
rq   c               @   s$   e Zd Zdd Zdd Zdd ZdS )rG   c             C   s   || _ d| _d S )NF)r=   verbatim)r&   r=   r!   r!   r"   r'   M  s    zLexer.__init__c             C   sT   d}d}g }xBt j| jD ]2}|r8|j| j|d|| | }||jd7 }qW |S )zG
        Return a list of tokens from a given template_string.
        Fr   Nrn   )tag_rer   r=   rc   create_tokencount)r&   in_tagrt   resultr   r!   r!   r"   rH   Q  s    zLexer.tokenizec             C   s   |r4|j tr4|dd	 j }| jr4|| jkr4d| _|r| j r|j trfttj|dd
 j ||S |j tr|dd dkrd| | _ttj|||S |j t	rd}|j
tr|dd j }ttj|||S nttj|||S dS )z
        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.
        r   FN	   r   	verbatim zend%srT   r   )r   r   r   )r|   BLOCK_TAG_STARTstripr   VARIABLE_TAG_STARTrq   r   r   r   COMMENT_TAG_STARTro   TRANSLATOR_COMMENT_MARKr    r   )r&   token_stringr`   rt   r   Zblock_contentcontentr!   r!   r"   r   _  s"    




zLexer.create_tokenN)r   r   r   r'   rH   r   r!   r!   r!   r"   rG   L  s   rG   c               @   s   e Zd Zdd ZdS )rF   c       	      C   s   d}g }d}xt j| jD ]}|j \}}||krj| j|| }|j| j|||f|dd ||jd7 }| j|| }|j| j|||f|dd ||jd7 }|}qW | j|d }|r|j| j|||t| f|dd |S )z
        Split a template string into tokens and annotates each token with its
        start and end position in the source. This is slower than the default
        lexer so only use it when debug is True.
        r   r   F)r   rn   TN)r   finditerr=   spanrc   r   r   rd   )	r&   rt   r   rk   matchr^   r_   r   Zlast_bitr!   r!   r"   rH   ~  s"    $zDebugLexer.tokenizeN)r   r   r   rH   r!   r!   r!   r"   rF   }  s   rF   c               @   sz   e Zd ZdddZdddZdd Zdd	 Zd
d ZdddZdd Z	dd Z
dd Zdd Zdd Zdd Zdd ZdS )rI   Nc             C   s`   t t|| _i | _i | _g | _|d kr,i }|d kr8g }|| _x|D ]}| j| qDW || _d S )N)	listreversedrP   tagsfilterscommand_stack	librariesadd_libraryr8   )r&   rP   r   builtinsr8   builtinr!   r!   r"   r'     s    
zParser.__init__c       
   "   C   s  |dkrg }t  }x| jr| j }|jjdkrH| j|t|j| q|jjdkr|jsl| j|d|j	 y| j
|j}W n. tk
r } z| j||W Y dd}~X nX t|}| j||| q|jjdkry|jj d }W n( tk
r
   | j|d|j	 Y nX ||kr$| j| |S | jj||f y| j| }W n$ tk
rf   | j||| Y nX y|| |}	W n0 tk
r } z| j||W Y dd}~X nX | j||	| | jj  qW |r| j| |S )ax  
        Iterate through the parser tokens and compiles each one into a node.

        If parse_until is provided, parsing will stop once one of the
        specified tokens has been reached. This is formatted as a list of
        tokens, e.g. ['elif', 'else', 'endif']. If no matching token is
        reached, raise an exception with the unclosed block tag details.
        Nr   r   zEmpty variable tag on line %dr   zEmpty block tag on line %d)NodeListrP   
next_tokenrr   valueextend_nodelistTextNoders   errorrt   compile_filterr   VariableNoder   rh   prepend_tokenr   rc   r   KeyErrorinvalid_block_tagrK   popunclosed_block_tag)
r&   parse_untilr<   rM   filter_expressionrR   Zvar_nodecommandZcompile_funcZcompiled_resultr!   r!   r"   rJ     sL    	


zParser.parsec             C   s>   x,| j r,| j }|jtjkr|j|krd S qW | j|g d S )N)rP   r   rr   r   r   rs   r   )r&   ZendtagrM   r!   r!   r"   	skip_past  s
    zParser.skip_pastc             C   sT   |j r|jr| j|d| t|tr8t|t r8d|_||_| j|_|j| d S )Nz)%r must be the first tag in the template.T)	must_be_firstcontains_nontextr   r-   r   r   rM   r8   rc   )r&   r<   r>   rM   r!   r!   r"   r     s    zParser.extend_nodelistc             C   s&   t |tst|}t|ds"||_|S )a1  
        Return an exception annotated with the originating token. Since the
        parser can be called recursively, check if a token is already set. This
        ensures the innermost token is highlighted if an exception occurs,
        e.g. a compile error within the body of an if statement.
        rM   )r-   rK   r   hasattrrM   )r&   rM   rR   r!   r!   r"   r     s
    

zParser.errorc             C   sF   |r,| j |d|j|tdd |D df | j |d|j|f d S )Nz]Invalid block tag on line %d: '%s', expected %s. Did you forget to register or load this tag?c             S   s   g | ]}d | qS )z'%s'r!   ).0rp   r!   r!   r"   
<listcomp>  s    z,Parser.invalid_block_tag.<locals>.<listcomp>orzPInvalid block tag on line %d: '%s'. Did you forget to register or load this tag?)r   rt   r
   )r&   rM   r   r   r!   r!   r"   r     s    zParser.invalid_block_tagc             C   s4   | j j \}}d|j|dj|f }| j||d S )Nz6Unclosed tag on line %d: '%s'. Looking for one of: %s.z, )r   r   rt   r~   r   )r&   r   r   rM   r$   r!   r!   r"   r     s    zParser.unclosed_block_tagc             C   s
   | j j S )N)rP   r   )r&   r!   r!   r"   r   "  s    zParser.next_tokenc             C   s   | j j| d S )N)rP   rc   )r&   rM   r!   r!   r"   r   %  s    zParser.prepend_tokenc             C   s   | j d= d S )Nr   )rP   )r&   r!   r!   r"   delete_first_token(  s    zParser.delete_first_tokenc             C   s    | j j|j  | jj|j d S )N)r   updater   )r&   libr!   r!   r"   r   +  s    zParser.add_libraryc             C   s
   t || S )z9
        Convenient wrapper for FilterExpression
        )FilterExpression)r&   rM   r!   r!   r"   r   /  s    zParser.compile_filterc             C   s$   || j kr| j | S td| d S )NzInvalid filter: '%s')r   r   )r&   filter_namer!   r!   r"   find_filter5  s    

zParser.find_filter)NNN)N)N)r   r   r   r'   rJ   r   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   rI     s   

<
	rI   zf
(?:%(i18n_open)s%(strdq)s%(i18n_close)s|
%(i18n_open)s%(strsq)s%(i18n_close)s|
%(strdq)s|
%(strsq)s)
z"[^"\\]*(?:\\.[^"\\]*)*"z'[^'\\]*(?:\\.[^'\\]*)*'z_(rz   )ZstrdqZstrsqZ	i18n_openZ
i18n_closern   rT   a  
^(?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)
             )
         )?
 )z[-+\.]?\d[\d\.e]*z\w\.)constantrl   Z	var_charsZ
filter_sepZarg_sepc               @   s:   e Zd ZdZdd ZdddZdd ZeeZd	d
 ZdS )r   a  
    Parse 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'>
    c             C   s  || _ tj|}d }g }d}x8|D ].}|j }||krdtd|d | ||| ||d  f |d kr|d |d  }	}
|
ryt|
ji }W q tk
r   d }Y qX n|	d krtd| nt|	}n||d }g }|d |d  }}|r|jd	t|ji f n|r&|jd
t|f |j	|}| j
||| |j||f |j }q$W |t|kr~td||d  |f || _|| _d S )Nr   z)Could not parse some characters: %s|%s|%svarr   z'Could not find variable at start of %s.r   constant_argvar_argFTz-Could not parse the remainder: '%s' from '%s')rM   	filter_rer   r^   r   Variableresolver#   rc   r   
args_checkr_   rd   r   r   )r&   rM   rQ   matchesZvar_objr   rk   r   r^   r   r   r   rg   r   r   Zfilter_funcr!   r!   r"   r'   p  sL    



zFilterExpression.__init__Fc             C   s2  t | jtrhy| jj|}W qn tk
rd   |r6d }n*|jjj}|r\d|krV|| j S |S n|}Y qnX n| j}x| jD ]\}}g }x4|D ],\}}	|s|j	t
|	 q|j	|	j| qW t|ddrt||j}t|ddr||f|d|ji}
n||f| }
t|ddr&t |tr&t
|
}qv|
}qvW |S )Nz%sZexpects_localtimeFZneeds_autoescape
autoescapeis_safe)r-   r   r   r   r#   rD   r5   string_if_invalidr   rc   r	   getattrr   use_tzr   r   )r&   rA   Zignore_failuresobjr   funcrg   arg_valslookupargZnew_objr!   r!   r"   r     s8    


zFilterExpression.resolvec       	      C   sx   t |}t|d }tj|}tj|\}}}}}}}t|}t|pFg }||| k s^||krttd| || |f dS )Nr   z%%s requires %d arguments, %d providedT)r   rd   inspectunwrapgetfullargspecr   )	r*   r   providedplenrg   _defaultsalendlenr!   r!   r"   r     s    
zFilterExpression.args_checkc             C   s   | j S )N)rM   )r&   r!   r!   r"   r(     s    zFilterExpression.__str__N)F)	r   r   r   __doc__r'   r   r   staticmethodr(   r!   r!   r!   r"   r   b  s   ,
%r   c               @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )r   a'  
    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':'News'}}
        >>> Variable('article.section').resolve(c)
        'News'
        >>> Variable('article').resolve(c)
        {'section': 'News'}
        >>> class AClass: pass
        >>> c = AClass()
        >>> c.article = AClass()
        >>> c.article.section = 'News'

    (The example assumes VARIABLE_ATTRIBUTE_SEPARATOR is '.')
    c             C   s  || _ d | _d | _d| _d | _t|ts8tdt| y<d|ksNd|j	 krht
|| _|jdrrtn
t|| _W n tk
r   |jdr|jdrd| _|dd }ytt|| _W nR tk
r   |jtd
 dks|d d
k rtd| t|jt| _Y nX Y nX d S )NFz+Variable must be a string or number, got %sr   rR   z_(rz   Tr   r   r   r   z=Variables and attributes may not begin with underscores: '%s'r   r   )r   literallookups	translatemessage_contextr-   r9   	TypeErrortypelowerfloatr}   
ValueErrorintr|   r	   r   ro   VARIABLE_ATTRIBUTE_SEPARATORr   tupler   )r&   r   r!   r!   r"   r'     s2    
	

 zVariable.__init__c             C   sf   | j dk	r| j|}n| j}| jrbt|t}|jdd}|rDt|n|}| jrZt	| j|S t
|S |S )z.Resolve this variable against a given context.N%z%%)r   _resolve_lookupr   r   r-   r   rw   r	   r   r   r   )r&   rA   r   r   msgidr!   r!   r"   r     s    

zVariable.resolvec             C   s   d| j j| jf S )Nz<%s: %r>)r0   r   r   )r&   r!   r!   r"   __repr__*  s    zVariable.__repr__c             C   s   | j S )N)r   )r&   r!   r!   r"   r(   -  s    zVariable.__str__c          ,   C   s  |}yjxb| j D ]V}y|| }W n tttttfk
r   y*t|tr\tt	||r\tt||}W nn ttfk
r   t|t r|t
|kr y|t| }W n* ttttfk
r   td||fY nX Y nX Y nX t|rt|ddrqt|ddr|jjj}qy
| }W q tk
rh   tj|}y|j  W n  tk
r`   |jjj}Y nX  Y qX qW W nd tk
r } zFt|ddpd}tjd||d	d
 t|ddr|jjj}n W Y dd}~X nX |S )a  
        Perform 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.
        z Failed lookup for key [%s] in %rZdo_not_call_in_templatesFZalters_datar+   Nunknownz9Exception while resolving variable '%s' in template '%s'.T)exc_infoZsilent_variable_failure)r   r   AttributeErrorr   r   rh   r-   r   r   r   dirr   r#   callablerD   r5   r   r   	signaturebindrK   loggerrE   )r&   rA   currentr   r   rR   r+   r!   r!   r"   r   0  s\    	

zVariable._resolve_lookupN)	r   r   r   r   r'   r   r   r(   r   r!   r!   r!   r"   r     s   .r   c               @   s8   e Zd ZdZdZdZdd Zdd Zdd	 Zd
d Z	dS )NodeFr<   Nc             C   s   dS )z7
        Return the node rendered as a string.
        Nr!   )r&   rA   r!   r!   r"   r@   {  s    zNode.renderc             C   s^   y
| j |S  tk
rX } z2|jjjrFt|d rF|jjj|| j|_	 W Y dd}~X nX dS )a'  
        Render the node. If debug is True and an exception occurs during
        rendering, the exception is annotated with contextual line information
        where it occurred in the template. For internal usage this method is
        preferred over using the render method directly.
        rN   N)
r@   rK   rD   r5   rE   r   rC   rL   rM   rN   )r&   rA   rR   r!   r!   r"   render_annotated  s    
zNode.render_annotatedc             c   s
   | V  d S )Nr!   )r&   r!   r!   r"   r?     s    zNode.__iter__c             C   sL   g }t | |r|j|  x.| jD ]$}t| |d}|r |j|j| q W |S )zj
        Return a list of all nodes (within this node and its nodelist)
        of the given type
        N)r-   rc   child_nodelistsr   extendget_nodes_by_type)r&   nodetypenodesattrr<   r!   r!   r"   r     s    

zNode.get_nodes_by_type)r<   )
r   r   r   r   r   rM   r@   r   r?   r   r!   r!   r!   r"   r   t  s   r   c               @   s    e Zd ZdZdd Zdd ZdS )r   Fc             C   sH   g }x4| D ],}t |tr$|j|}n|}|jt| q
W tdj|S )NrT   )r-   r   r   rc   r9   r	   r~   )r&   rA   r   r>   r   r!   r!   r"   r@     s    

zNodeList.renderc             C   s&   g }x| D ]}|j |j| q
W |S )z,Return a list of all nodes of the given type)r   r   )r&   r   r   r>   r!   r!   r"   r     s    
zNodeList.get_nodes_by_typeN)r   r   r   r   r@   r   r!   r!   r!   r"   r     s   
r   c               @   s$   e Zd Zdd Zdd Zdd ZdS )r   c             C   s
   || _ d S )N)s)r&   r   r!   r!   r"   r'     s    zTextNode.__init__c             C   s   d| j j| jd d f S )Nz<%s: %r>   )r0   r   r   )r&   r!   r!   r"   r     s    zTextNode.__repr__c             C   s   | j S )N)r   )r&   rA   r!   r!   r"   r@     s    zTextNode.renderN)r   r   r   r'   r   r@   r!   r!   r!   r"   r     s   r   c             C   sL   t | |jd} t| |jd} |jr@tt| ts8t| } t| S t| S dS )z
    Convert any value to a string to become part of a rendered template. This
    means escaping, if required, and conversion to a string. If value is a
    string, it's expected to already be translated.
    )r   )use_l10nN)	r   r   r   r   r   
issubclassr   r9   r   )r   rA   r!   r!   r"   render_value_in_context  s    r  c               @   s$   e Zd Zdd Zdd Zdd ZdS )r   c             C   s
   || _ d S )N)r   )r&   r   r!   r!   r"   r'     s    zVariableNode.__init__c             C   s
   d| j  S )Nz<Variable Node: %s>)r   )r&   r!   r!   r"   r     s    zVariableNode.__repr__c             C   s0   y| j j|}W n tk
r$   dS X t||S )NrT   )r   r   ri   r  )r&   rA   outputr!   r!   r"   r@     s
    zVariableNode.renderN)r   r   r   r'   r   r@   r!   r!   r!   r"   r     s   r   z(?:(\w+)=)?(.+)Fc             C   s  | si S t j| d }|o |d }|sJ|s.i S t| dk sF| d dkrJi S i }x| r |rt j| d }| sx|d  r||S |j \}}| dd= n8t| dk s| d dkr|S | d | d  }}| dd= |j|||< | o| rP| d dkr|S | dd= qPW |S )aX  
    Parse token keyword arguments and return a dictionary of the arguments
    retrieved from the ``bits`` token list.

    `bits` is a list containing the remainder of the token (split by spaces)
    that is to be checked for arguments. Valid arguments are removed from this
    list.

    `support_legacy` - if True, the legacy format ``1 as foo`` is accepted.
    Otherwise, only the standard ``foo=1`` format is allowed.

    There is no requirement for all remaining token ``bits`` to be keyword
    arguments, so return the dictionary as soon as an invalid argument format
    is reached.
    r   r   r   asNr   and)kwarg_rer   rd   groupsr   )r   rQ   Zsupport_legacyr   Zkwarg_formatkwargskeyr   r!   r!   r"   token_kwargs  s6    

r	  )F)Fr   r   loggingreenumr   Zdjango.template.contextr   Zdjango.utils.formatsr   Zdjango.utils.htmlr   r   Zdjango.utils.regex_helperr   Zdjango.utils.safestringr   r	   Zdjango.utils.textr
   r   r   Zdjango.utils.timezoner   Zdjango.utils.translationr   r   
exceptionsr   ZFILTER_SEPARATORZFILTER_ARGUMENT_SEPARATORr   r   ZBLOCK_TAG_ENDr   ZVARIABLE_TAG_ENDr   ZCOMMENT_TAG_ENDr   ZSINGLE_BRACE_STARTZSINGLE_BRACE_ENDr7   r   	getLoggerr   r   rK   r#   r)   r3   rb   rq   rG   rF   rI   Zconstant_stringrw   Zfilter_raw_stringVERBOSEr   r   r   r   r   r   r   r  r   r  r	  r!   r!   r!   r"   <module>3   s   

 	-1 .u -