
    h                     f   S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJr  SSKJr  SSKJrJrJr  SS	KJrJrJr  SS
KJr  SSKJrJr  SSKJr  SrSrSr Sr!Sr"Sr#Sr$Sr%Sr&Sr'Sr(Sr)\RT                  " S5      r+\RX                  " S5      r- " S S\5      r. " S S\/5      r0 " S  S!5      r1 " S" S#5      r2S$ r3 " S% S&5      r4 " S' S(5      r5 " S) S*\55      r6 " S+ S,5      r7S-S.S/\R                  " S05      \R                  " S15      S2.-  r8\8Rs                  S3S45      r8S5\8S6S7\R                  " \5      \R                  " \5      S8.-  r:\" \:\Rv                  5      r< " S9 S:5      r= " S; S<5      r> " S= S>5      r? " S? S@\@5      rA " SA SB\?5      rBSC rC " SD SE\?5      rD\" SF5      rESHSG jrFg)Ia  
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
SafeString	mark_safe)get_text_listsmart_splitunescape_string_literal)template_localtime)gettext_lazypgettext_lazy   )TemplateSyntaxError|:.z{%z%}z{{z}}z{#z#}{}z<unknown source>z({%.*?%}|{{.*?}}|{#.*?#})zdjango.templatec                   $    \ rS rSrSrSrSrSrSrg)	TokenType^   r   r          N)	__name__
__module____qualname____firstlineno__TEXTVARBLOCKCOMMENT__static_attributes__r       F/var/www/html/env/lib/python3.13/site-packages/django/template/base.pyr   r   ^   s    D
CEGr(   r   c                   $    \ rS rSrSS jrS rSrg)VariableDoesNotExiste   c                     Xl         X l        g Nmsgparams)selfr0   r1   s      r)   __init__VariableDoesNotExist.__init__f   s    r(   c                 4    U R                   U R                  -  $ r.   r/   r2   s    r)   __str__VariableDoesNotExist.__str__j   s    xx$++%%r(   r/   N)r   )r   r    r!   r"   r3   r7   r'   r   r(   r)   r+   r+   e   s    &r(   r+   c                   @    \ rS rSrS	S jrS rS rS r\S 5       r	Sr
g)
Originn   Nc                 (    Xl         X l        X0l        g r.   )nametemplate_nameloader)r2   r=   r>   r?   s       r)   r3   Origin.__init__o   s    	*r(   c                     U R                   $ r.   )r=   r6   s    r)   r7   Origin.__str__t   s    yyr(   c                 T    SU R                   R                  < SU R                  < S3$ )N<z name=>)	__class__r!   r=   r6   s    r)   __repr__Origin.__repr__w   s    !%!<!<diiHHr(   c                     [        U[        5      =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r.   )
isinstancer:   r=   r?   )r2   others     r)   __eq__Origin.__eq__z   s;    uf% ,		UZZ',u||+	
r(   c                     U R                   (       a;  U R                   R                  < SU R                   R                  R                  < 3$ g )Nr   )r?   r    rF   r   r6   s    r)   loader_nameOrigin.loader_name   s8    ;;&&%%..  r(   )r?   r=   r>   NN)r   r    r!   r"   r3   r7   rG   rL   propertyrO   r'   r   r(   r)   r:   r:   n   s+    
I
  r(   r:   c                   <    \ rS rSrS
S jrS rS rS rS rS r	S	r
g)Template   Nc                     Uc  SSK Jn  UR                  5       nUc  [        [        5      nX0l        X l        X@l         [        U5      U l        U R                  5       U l
        g )Nr   )Engine)enginerW   get_defaultr:   UNKNOWN_SOURCEr=   originstrsourcecompile_nodelistnodelist)r2   template_stringr[   r=   rX   rW   s         r)   r3   Template.__init__   sT    
 >&'')F>N+F	/*--/r(   c                 z    SU R                   R                  < SU R                  S S R                  SS5      < S3$ )NrD    template_string="   
 ...">)rF   r!   r]   replacer6   s    r)   rG   Template.__repr__   s4    NN''KK$$T2.
 	
r(   c                 8    U R                   R                  U5      $ r.   )r_   renderr2   contexts     r)   _renderTemplate._render   s    }}##G,,r(   c                 l   UR                   R                  U 5         UR                  cF  UR                  U 5         U R                  Ul        U R                  U5      sSSS5        sSSS5        $ U R                  U5      sSSS5        $ ! , (       d  f       O= f SSS5        g! , (       d  f       g= f)z)Display stage -- can be called many timesN)render_context
push_statetemplatebind_templater=   r>   rn   rl   s     r)   rk   Template.render   s    ##..t4'**40,0IIG)<<0 10 54 ||G, 54000 544s(   B%"B
	B%0B%

B	B%%
B3c                    U R                   R                  (       a  [        U R                  5      nO[	        U R                  5      nUR                  5       n[        UU R                   R                  U R                   R                  U R                  5      n UR                  5       nUR                  U l        U$ ! [         aA  nU R                   R                  (       a   U R                  XUR                  5      Ul        e SnAff = f)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)rX   debug
DebugLexerr]   LexertokenizeParsertemplate_librariestemplate_builtinsr[   parse
extra_data	Exceptionget_exception_infotokentemplate_debug)r2   lexertokensparserr_   es         r)   r^   Template.compile_nodelist   s     ;;t{{+E$++&E!KK**KK))KK	
	||~H$//DOO 	{{  #'#:#:1gg#F 	s   "B; ;
D<DDc                 |   UR                   u  p4SnSnSn/ nS=n	=p[        [        U R                  5      5       H  u  pX7:  aL  XM::  aG  Un[	        U R                  Xs 5      n	[	        U R                  X4 5      n
[	        U R                  XM 5      nUR                  U[	        U R                  X} 5      45        UnM     [        U5      n[        SXe-
  5      n[        XS-   U-   5      n [        UR                  S   5      nUXU U	U
UUUUUU R                  R                  UUS.$ ! [        [        4 a    Sn N9f = f)aj  
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   rf   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minr\   args
IndexErrorUnicodeDecodeErrorr[   r=   )r2   	exceptionr   r   r   context_linesr   uptor   r   r   r   numnextr   r   r   r   s                     r)   r   Template.get_exception_info   sZ   J ^^
"$$$">$++#>?IC}D 78E 67t{{345fT[[-C&D EFD @ L!!T)*U1H}45	:)..+,G
 (V4KK$$
 	
 ./ 	:9G	:s   )D& &D;:D;)rX   r   r=   r_   r[   r]   NNN)r   r    r!   r"   r3   rG   rn   rk   r^   r   r'   r   r(   r)   rT   rT      s!    0"
--:L
r(   rT   c              #      #    Sv   U R                  S5      nUS:  a$  US-   v   U R                  SUS-   5      nUS:  a  M$  [        U 5      S-   v   g 7f)Nr   re   r   )findr   )template_sourceps     r)   r   r     s[     
GT"A
q&!e  q1u- q& o

""s   >AAc                   *    \ rS rSrSS jrS rS rSrg)Tokeni$  Nc                 4    Xl         X l        X@l        X0l        g)a  
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   )r2   r   r   r   r   s        r)   r3   Token.__init__%  s    & %  r(   c                     U R                   R                  R                  5       nSU< SU R                  S S R	                  SS5      < S3$ )NrD   z	 token: "rd   re   rf   rg   )r   r=   
capitalizer   rh   )r2   
token_names     r)   rG   Token.__repr__=  sB    __))446
MM#2&&tR0
 	
r(   c                 `   / n[        U R                  5      nU H  nUR                  S5      (       af  US   S-   nU/nUR                  U5      (       d4  [	        U5      nUR                  U5        UR                  U5      (       d  M4  SR                  U5      nUR                  U5        M     U$ )N)z_("z_('r   ) )r   r   
startswithendswithr   r   join)r2   splitbitsbitsentinel	trans_bits         r)   split_contentsToken.split_contentsD  s    4==)C~~n--q6C< E	,,x00t*C$$S) ,,x00 hhy)LL  r(   )r   r   r   r   rQ   )r   r    r!   r"   r3   rG   r   r'   r   r(   r)   r   r   $  s    !0
r(   r   c                   ,    \ rS rSrS rS rS rS rSrg)ry   iT  c                     Xl         SU l        g )NFr`   verbatim)r2   r`   s     r)   r3   Lexer.__init__U  s    .r(   c                     SU R                   R                  < SU R                  S S R                  SS5      < SU R                  < S3$ )NrD   rc   rd   re   rf   z...", verbatim=rE   )rF   r!   r`   rh   r   r6   s    r)   rG   Lexer.__repr__Y  s=    NN''  "%--dB7MM
 	
r(   c           	          SnSn/ n[         R                  U R                  5       HF  nU(       a5  UR                  U R	                  USX!5      5        X$R                  S5      -  nU(       + nMH     U$ )z7
Return a list of tokens from a given template_string.
Fr   Nre   )tag_rer   r`   r   create_tokencount)r2   in_tagr   resulttoken_strings        r)   rz   Lexer.tokenize`  sk     "LL)=)=>Ld//dFST,,T22ZF	 ?
 r(   c                 N   U(       Ga  USS nU[         :X  a  USS R                  5       nU R                  (       a2  X`R                  :w  a  [        [        R
                  XU5      $ SU l        OUSS S;   a
  SU-  U l        [        [        R                  XbU5      $ U R                  (       d_  USS R                  5       nU[        :X  a  [        [        R                  XbU5      $ U[        :X  d   e[        [        R                  XbU5      $ [        [        R
                  XU5      $ )	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   r   FN	   )r   z	verbatim zend%s)BLOCK_TAG_STARTstripr   r   r   r#   r%   VARIABLE_TAG_STARTr$   COMMENT_TAG_STARTr&   )r2   r   r   r   r   token_startcontents          r)   r   Lexer.create_tokenn  s      'q+Ko-&q,224==--/$Y^^\VTT$)DMRa[$==$+g$5DMY__gHH==&q,224"44 6JJ"&7777Y..6JJY^^\VDDr(   r   N)	r   r    r!   r"   r3   rG   rz   r   r'   r   r(   r)   ry   ry   T  s    
 Er(   ry   c                   &    \ rS rSrS rS rS rSrg)rx   i  c              #      #    Sn[         R                  U R                  5       H!  nUR                  5       u  p4X4v   X44v   UnM#     U[	        U R                  5      4v   g 7f)Nr   )r   finditerr`   spanr   )r2   lastmatchr   r   s        r)   _tag_re_split_positions"DebugLexer._tag_re_split_positions  s]     __T%9%9:EJE+*D	 ;
 C,,---s   A!A#c              #   l   #    U R                  5        H  nU R                  [        U6    U4v   M     g 7fr.   )r   r`   slice)r2   r   s     r)   _tag_re_splitDebugLexer._tag_re_split  s3     446H&&uh'78(BB 7s   24c           	          SnSn/ nU R                  5        HG  u  pEU(       a4  UR                  U R                  XEX!5      5        X$R                  S5      -  nU(       + nMI     U$ )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.
Fr   re   )r   r   r   r   )r2   r   r   r   r   r   s         r)   rz   DebugLexer.tokenize  sf     &*&8&8&:"Ld//WX,,T22ZF	 ';
 r(   r   N)r   r    r!   r"   r   r   rz   r'   r   r(   r)   rx   rx     s    .Cr(   rx   c                   t    \ rS rSrSS jrS rSS jrS rS rS r	SS	 jr
S
 rS rS rS rS rS rS rSrg)r{   i  Nc                     [        [        U5      5      U l        0 U l        0 U l        / U l        0 U l        Uc  0 nUc  / nX l        U H  nU R                  U5        M     X@l	        g r.   )
listreversedr   tagsfilterscommand_stackr   	librariesadd_libraryr[   )r2   r   r   builtinsr[   builtins         r)   r3   Parser.__init__  sl     8F+,	 IH"GW%  r(   c                 T    SU R                   R                  < SU R                  < S3$ )NrD   z tokens=rE   )rF   r!   r   r6   s    r)   rG   Parser.__repr__  s    #'>>#>#>LLr(   c                    Uc  / n[        5       nU R                  (       Gau  U R                  5       nUR                  R                  nUS:X  a(  U R                  U[        UR                  5      U5        GOUS:X  aj  UR                  (       d  U R                  USUR                  -  5      e U R                  UR                  5      n[        U5      nU R                  X'U5        OUS:X  a   UR                  R                  5       S   nX;   a  U R                  U5        U$ U R                   R#                  X45         U R$                  U   n	 W	" X5      n
U R                  X*U5        U R                   R-                  5         U R                  (       a  GMu  U(       a  U R/                  U5        U$ ! [         a  nU R                  X65      eSnAff = f! [         a     U R                  USUR                  -  5      ef = f! [&         a    U R)                  X8U5         Nf = f! [*         a  nU R                  X65      eSnAff = f)aH  
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)NodeListr   
next_tokenr   valueextend_nodelistTextNoder   errorr   compile_filterr   VariableNoder   r   prepend_tokenr   r   r   KeyErrorinvalid_block_tagr   popunclosed_block_tag)r2   parse_untilr_   r   r   filter_expressionr   var_nodecommandcompile_funccompiled_results              r)   r~   Parser.parse  s    K:kkkOO%E))//JQ$$Xx/GOq~~**>M /(,(;(;ENN(K% ((9:$$X?qY#nn224Q7G ) &&u-#O ""))7*:;H#'99W#5L
/&24&?O $$XF""&&(] kkk^ ##K0I + /**U../ " Y**U,H5<<,WXXY    H**5;GH ! /**U../sN   -F1 -G ?H H# 1
G;GG*G>H H #
I-H>>Ic                     U R                   (       aR  U R                  5       nUR                  [        R                  :X  a  UR
                  U:X  a  g U R                   (       a  MR  U R                  U/5        g r.   )r   r   r   r   r%   r   r  )r2   endtagr   s      r)   	skip_pastParser.skip_past  sR    kkOO%E9??2u~~7O kkk 	)r(   c                     UR                   (       a&  UR                  (       a  U R                  USU-  5      e[        U[        5      (       d  SUl        X2l        U R                  Ul        UR                  U5        g )Nz)%r must be the first tag in the template.T)must_be_firstcontains_nontextr   rJ   r   r   r[   r   )r2   r_   noder   s       r)   r   Parser.extend_nodelist  sd    (";";**;dB  $))(,H% 
kkr(   c                 t    [        U[        5      (       d  [        U5      n[        US5      (       d  Xl        U$ )a	  
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.
r   )rJ   r   r   hasattrr   )r2   r   r   s      r)   r   Parser.error$  s2     !Y''#A&Aq'""Gr(   c                     U(       a@  U R                  USUR                  U[        U Vs/ s H  nSU-  PM
     snS5      4-  5      eU R                  USUR                  U4-  5      es  snf )Nz]Invalid block tag on line %d: '%s', expected %s. Did you forget to register or load this tag?z'%s'orzPInvalid block tag on line %d: '%s'. Did you forget to register or load this tag?)r   r   r   )r2   r   r	  r  r   s        r)   r  Parser.invalid_block_tag1  s    **7 LL!{"C{!6A:{"CTJ	 	 jj #(<<"9:
 	
 #Ds   A)c                     U R                   R                  5       u  p#SUR                  USR                  U5      4-  nU R	                  X45      e)Nz6Unclosed tag on line %d: '%s'. Looking for one of: %s.z, )r   r  r   r   r   )r2   r  r	  r   r0   s        r)   r  Parser.unclosed_block_tagC  sO    ++//1FLLIIk"J
 

 jj$$r(   c                 6    U R                   R                  5       $ r.   )r   r  r6   s    r)   r   Parser.next_tokenL  s    {{  r(   c                 :    U R                   R                  U5        g r.   )r   r   r2   r   s     r)   r  Parser.prepend_tokenO  s    5!r(   c                     U R                   S	 g )N)r   r6   s    r)   delete_first_tokenParser.delete_first_tokenR  s    KKOr(   c                     U R                   R                  UR                   5        U R                  R                  UR                  5        g r.   )r   updater   )r2   libs     r)   r   Parser.add_libraryU  s.    		"CKK(r(   c                     [        X5      $ )z)
Convenient wrapper for FilterExpression
)FilterExpressionr!  s     r)   r   Parser.compile_filterY  s      ,,r(   c                 Z    XR                   ;   a  U R                   U   $ [        SU-  5      e)NzInvalid filter: '%s')r   r   )r2   filter_names     r)   find_filterParser.find_filter_  s,    ,,&<<,,%&<{&JKKr(   )r   r   r   r   r[   r   r   r   r.   )r   r    r!   r"   r3   rG   r~   r  r   r   r  r  r   r  r%  r   r   r0  r'   r   r(   r)   r{   r{     sK    0M=~*
$%!")-Lr(   r{   zf
(?:%(i18n_open)s%(strdq)s%(i18n_close)s|
%(i18n_open)s%(strsq)s%(i18n_close)s|
%(strdq)s|
%(strsq)s)
z"[^"\\]*(?:\\.[^"\\]*)*"z'[^'\\]*(?:\\.[^'\\]*)*'_(r   )strdqstrsq	i18n_open
i18n_closere   rf   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\.)constantr   	var_chars
filter_separg_sepc                   N    \ rS rSrSrSrS rSS jrS r\	" \5      rS r
S rS	rg
)r,  i  aZ  
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'>
)r   r   varis_varc                 d   Xl         [        R                  U5      nS n/ nSnU GH0  nUR                  5       nXh:w  a  [	        SUS U < SXU < SXS  < 35      eUcJ  US   =n	(       a   [        U	5      R                  0 5      nOUS   =n
c  [	        SU-  5      e[        U
5      nOUS   n/ nUS   =n(       a,  UR                  S	[        U5      R                  0 5      45        O(US
   =n(       a  UR                  S[        U5      45        UR                  U5      nU R                  XU5        UR                  X45        UR                  5       nGM3     U[        U5      :w  a  [	        SXS  < SU< S35      eXPl        X@l        [        U[
        5      U l        g ! [         a    S n Njf = f)Nr   z!Could not parse some characters: r   r7  r<  z'Could not find variable at start of %s.r/  constant_argFvar_argTz Could not parse the remainder: 'z' from '')r   	filter_rer   r   r   Variableresolver+   r   r0  
args_checkr   r   r   r<  rJ   r=  )r2   r   r   matchesvar_objr   r   r   r   r7  r<  r/  r   r?  r@  filter_funcs                   r)   r3   FilterExpression.__init__  s   
$$U+EKKME})"',50A5=R  $Z0080'"*8"4"<"<R"@ #5\)c2-AEI  'smG#M2#(#88<8KK(>(F(Fr(J KL %i 00W0KKx'8 9:$00=$?2399;D; < 3u:%$U|U4 
  (37 0 '"&'s   +F  F/.F/c                 "   U R                   (       a   U R                  R                  U5      nOU R                  nU R                   H  u  pV/ nU HH  u  pU(       d  UR                  [        U	5      5        M(  UR                  U	R                  U5      5        MJ     [        USS5      (       a  [        X1R                  5      n[        USS5      (       a  U" U/UQ7SUR                  06n
O	U" U/UQ76 n
[        USS5      (       a"  [        U[        5      (       a  [        U
5      nM  U
nM     U$ ! [         aS    U(       a  S n GNUR                  R
                  R                  nU(       a  SU;   a  X@R                  -  s $ Us $ Un GNRf = f)Nz%sexpects_localtimeFneeds_autoescape
autoescapeis_safe)r=  r<  rD  r+   rs   rX   string_if_invalidr   r   r   getattrr   use_tzrM  rJ   r	   )r2   rm   ignore_failuresobjrO  funcr   arg_valslookupargnew_objs              r)   rD  FilterExpression.resolve  sU   ;;0hh&&w/ ((C,,JDH#OOIcN3OOCKK$89	  $
 t0%88(nn=t/77sMHMw/A/AMs.X.tY..:c83L3L(! '" 
? ( 0"C(/(8(8(?(?(Q(Q%(#44#4xx#??#44/0s#   D1 1F;FFFFc                    [        U5      n[        U5      S-   n[        R                  " U5      n[        R                  " U5      u  n  pV    n[        U5      n[        U=(       d    / 5      nX7U-
  :  d  X7:  a  [        SXU-
  U4-  5      eg)Nr   z%%s requires %d arguments, %d providedT)r   r   inspectunwrapgetfullargspecr   )	r=   rT  providedplenr   _defaultsalendlens	            r)   rE  FilterExpression.args_check  s    >8}q ~~d#(/(>(>t(D%aaA4y8>r"$;4;%74d:SS  r(   c                     U R                   $ r.   )r   r6   s    r)   r7   FilterExpression.__str__  s    zzr(   c                 T    SU R                   R                  < SU R                  < S3$ )NrD   r   rE   )rF   r!   r   r6   s    r)   rG   FilterExpression.__repr__  s     NN77DDr(   )r   r=  r   r<  NF)r   r    r!   r"   __doc__	__slots__r3   rD  rE  staticmethodr7   rG   r'   r   r(   r)   r,  r,    s6     6I,4\#J$ j)JEr(   r,  c                   :    \ rS rSrSrSrS rS rS rS r	S r
S	rg
)rC  i  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 '.')
)r<  literallookups	translatemessage_contextc                 v   Xl         S U l        S U l        SU l        S U l        [        U[        5      (       d  [        S[        U5      -  5      e SU;   d  SUR                  5       ;   a   [        U5      U l        US   S:X  a  [        eg [        U5      U l        g ! [         a    USS S:X  a  US   S	:X  a  S
U l        USS n [        [        U5      5      U l         g ! [         aK    [        S-   U;   d	  US   S:X  a  [!        SU-  5      e[#        UR%                  [        5      5      U l          g f = ff = f)NFz+Variable must be a string or number, got %sr   r   r$  r   r   r2  r   Tr`  z=Variables and attributes may not begin with underscores: '%s')r<  rn  ro  rp  rq  rJ   r\   	TypeErrortypelowerfloat
ValueErrorintr   r   VARIABLE_ATTRIBUTE_SEPARATORr   tupler   )r2   r<  s     r)   r3   Variable.__init__   sC   ##s##IDQTIUVV#	N czSCIIK/$Szr7c>$$ "  #3x 	N1Qx4CGsN "&!Bi
N()@)EF N 0#5<A#-;=@A   %SYY/K%LMN	Ns1   9B 
B (D8CAD40D83D44D8c                 N   U R                   b  U R                  U5      nOU R                  nU R                  (       ah  [	        U[
        5      nUR                  SS5      nU(       a  [        U5      OUnU R                  (       a  [        U R                  U5      $ [        U5      $ U$ )z.Resolve this variable against a given context.%z%%)ro  _resolve_lookuprn  rp  rJ   r	   rh   r   rq  r   r   )r2   rm   r   rN  msgids        r)   rD  Variable.resolveN  s    <<#((1E LLE>> 1GMM#t,E(/Ie$UE##$T%9%95AA#E**r(   c                 T    SU R                   R                  < SU R                  < S3$ )NrD   : rE   )rF   r   r<  r6   s    r)   rG   Variable.__repr__`  s    !^^44dhh??r(   c                     U R                   $ r.   )r<  r6   s    r)   r7   Variable.__str__c  s    xxr(   c           	         Un U R                    Hj  n X#   n[        U5      (       d  M  [        USS5      (       a  M.  [        USS5      (       a"  UR                  R                  R                   nMb   U" 5       nMl     U$ ! [        [        [        [        [
        4 a     [        U[        5      (       a   [        [        U5      U5      (       a  [        e[        X#5      n N! [        [        4 ad    [        U[        5      (       d  U[        U5      ;   a  e  U[        U5         n  GN! [
        [        [        [        4 a    [        SX245      ef = ff = ff = f! [         a     ["        R$                  " U5      n UR'                  5         e ! [         a&    UR                  R                  R                   n  GM  f = f! [         a&    UR                  R                  R                   n  GM  f = ff = f! [(         aj  n[        USS5      =(       d    Sn[*        R-                  SWUS	S
9  [        USS5      (       a&  UR                  R                  R                   n SnAU$ e SnAff = f)z
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 %rdo_not_call_in_templatesFalters_datar>   Nunknownz9Exception while resolving variable '%s' in template '%s'.T)exc_infosilent_variable_failure)ro  rs  AttributeErrorr  rw  r   rJ   r   rP  rt  dirrx  r+   callablers   rX   rO  r[  	signaturebindr   loggerrw   )r2   rm   currentr   r  r   r>   s          r)   r~  Variable._resolve_lookupf  sT    ?	||%lG6 G$$w(BEJJ -??")"2"2"9"9"K"K*&-iGI $@ w ">8ZT %g{;; M3A A #10")'"7%~6 )';??C3w<DW!&-c#h&7G&&$%	  	 #7 B!$# 	@  ) **,3,=,=g,F	!*$-NN$4
 %*	 (1 !X.5.>.>.E.E.W.WG!X $. T*1*:*:*A*A*S*ST*  	#G_dCPyMLLK	   q3U;;!**11CC  	s   G: B G: AG: 3E:G:  E A C" G: "5ED*&E'G: *(E	EEG: 
G7(G?FG7*G :G7;G: ?G  G7*G3-G7.G: 2G33G77G: :
I.AI)(I))I.)rn  ro  rq  rp  r<  N)r   r    r!   r"   rj  rk  r3   rD  rG   r7   r~  r'   r   r(   r)   rC  rC    s,    $ NI,N\$@Kr(   rC  c                   2    \ rS rSrSrSrSrS rS rS r	Sr
g)	Nodei  F)r_   Nc                     g)z'
Return the node rendered as a string.
Nr   rl   s     r)   rk   Node.render  s     	r(   c                     U R                  U5      $ ! [         a  nUR                  R                  R                  (       a  [        US5      (       d  Xl        [        US5      (       dw  UR                  R                  R                  UR                  R                  :X  a?  UR                  R                  R                  UUR                  R                  5      Ul        e SnAff = f)z
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.
_culprit_noder   N)rk   r   rs   rX   rw   r  r  rq   r[   r   r   r   )r2   rm   r   s      r)   render_annotatedNode.render_annotated  s    	;;w'' 	&&,,q/22&*O#344..77>>!//BXBXX  ..77JJOO11 $ 	s    
C'CC""C'c                     / n[        X5      (       a  UR                  U 5        U R                   H8  n[        XS5      nU(       d  M  UR	                  UR                  U5      5        M:     U$ )zR
Return a list of all nodes (within this node and its nodelist)
of the given type
N)rJ   r   child_nodelistsrP  extendget_nodes_by_type)r2   nodetypenodesattrr_   s        r)   r  Node.get_nodes_by_type  s_    
 d%%LL((Dt40HxX77AB ) r(   r   )r   r    r!   r"   r  r  r   rk   r  r  r'   r   r(   r)   r  r    s"     M#OE4r(   r  c                   $    \ rS rSrSrS rS rSrg)r   i  Fc           
      ~    [        SR                  U  Vs/ s H  o"R                  U5      PM     sn5      5      $ s  snf Nrf   )r
   r   r  )r2   rm   r  s      r)   rk   NodeList.render  s1    "''d"Sdd#8#8#Ad"STUU"Ss   :c                 \    / nU  H#  nUR                  UR                  U5      5        M%     U$ )z,Return a list of all nodes of the given type)r  r  )r2   r  r  r  s       r)   r  NodeList.get_nodes_by_type  s-    DLL//9: r(   r   N)r   r    r!   r"   r  rk   r  r'   r   r(   r)   r   r     s     Vr(   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   i  r   c                     Xl         g r.   s)r2   r  s     r)   r3   TextNode.__init__  s    r(   c                 Z    SU R                   R                  < SU R                  S S < S3$ )NrD   r     rE   )rF   r   r  r6   s    r)   rG   TextNode.__repr__   s!    !^^44dffSbkBBr(   c                     U R                   $ r.   r  rl   s     r)   rk   TextNode.render  s    vvr(   c                     U R                   $ )z
Return the given value.

The default implementation of this method handles exceptions raised
during rendering, which is not necessary for text nodes.
r  rl   s     r)   r  TextNode.render_annotated  s     vvr(   r  N)
r   r    r!   r"   r  r3   rG   rk   r  r'   r   r(   r)   r   r     s    OCr(   r   c                     [        XR                  S9n [        XR                  S9n UR                  (       a4  [        [        U 5      [        5      (       d  [        U 5      n [        U 5      $ [        U 5      $ )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.
)rQ  )use_l10n)	r   rQ  r   r  rM  
issubclassrt  r\   r   )r   rm   s     r)   render_value_in_contextr    sZ     u^^<EU%5%56E$u+s++JE!%((5zr(   c                   *    \ rS rSrSrS rS rS rSrg)r   i   r   c                     Xl         g r.   r  )r2   r  s     r)   r3   VariableNode.__init__#  s    !2r(   c                      SU R                   -  $ )Nz<Variable Node: %s>r  r6   s    r)   rG   VariableNode.__repr__&  s    $t'='===r(   c                 p     U R                   R                  U5      n[        X!5      $ ! [         a     gf = fr  )r  rD  r   r  )r2   rm   outputs      r)   rk   VariableNode.render)  s@    	++33G<F 'v77 " 	 		s   ( 
55r  N)	r   r    r!   r"   r  r3   rG   rk   r'   r   r(   r)   r   r      s    O3>8r(   r   z(?:(\w+)=)?(.+)c                 "   U (       d  0 $ [         R                  U S   5      nU=(       a    US   nU(       d#  U(       d  0 $ [        U 5      S:  d	  U S   S:w  a  0 $ 0 nU (       a  U(       aC  [         R                  U S   5      nU(       a
  US   (       d  U$ UR                  5       u  pgU SS2	 O([        U 5      S:  d	  U S   S:w  a  U$ U S   U S   pvU SS2	 UR	                  U5      XV'   U (       a  U(       d  U S   S:w  a  U$ U SS2	 U (       a  M  U$ )a,  
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   r   groupsr   )r   r   support_legacyr   kwarg_formatkwargskeyr   s           r)   token_kwargsr  8  s	     	NN47#E%U1XLIt9q=DGtOIF
NN47+EaJCRaR4y1}Q4a$q'RaR++E2Aw%RaR! $" Mr(   ri  )Grj  r[  loggingreenumr   django.template.contextr   django.utils.formatsr   django.utils.htmlr   r   django.utils.regex_helperr   django.utils.safestringr	   r
   r   django.utils.textr   r   r   django.utils.timezoner   django.utils.translationr   r   
exceptionsr   FILTER_SEPARATORFILTER_ARGUMENT_SEPARATORry  r   BLOCK_TAG_ENDr   VARIABLE_TAG_ENDr   COMMENT_TAG_ENDSINGLE_BRACE_STARTSINGLE_BRACE_ENDrZ   compiler   	getLoggerr  r   r   r+   r:   rT   r   r   ry   rx   r{   constant_stringrh   filter_raw_stringVERBOSErB  r,  rC  r  r   r   r   r  r   r  r  r   r(   r)   <module>r     s  2h   	  / ) 8 6 C C Q Q 4 @ +   "       $
 
0	1			,	- &9 & 8N
 N
b#- -`:E :Ez DpL pLl )(4))C.	
 "))$3  )),-yy23	 & .

;	|E |E~f fR3 3lt  t , 84 8* ./,r(   