
    Evg/4                         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mZ ddlmZ  G d	 d
e          Z G d d          Z G d de          Z G d de          Z G d de          Zd Zd ZdS )    )Iterable)wraps)import_module)getfullargspecunwrap)conditional_escape   )NodeTemplatetoken_kwargs)TemplateSyntaxErrorc                       e Zd ZdS )InvalidTemplateLibraryN)__name__
__module____qualname__     T/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/template/library.pyr   r      s        Dr   r   c                   D    e Zd ZdZd Zd
dZd Zd
dZd ZddZ	dd	Z
dS )Librarya  
    A class for registering template tags and filters. Compiled filter and
    template tag functions are stored in the filters and tags attributes.
    The filter, simple_tag, and inclusion_tag methods provide a convenient
    way to register callables as tags.
    c                 "    i | _         i | _        d S N)filterstags)selfs    r   __init__zLibrary.__init__   s    			r   Nc                      	| j         S .|,t                    r                                S  fd}|S || j        <   |S t          dd|d          )Nc                 0                         |           S r   )tag)funcnamer   s    r   deczLibrary.tag.<locals>.dec&   s    88D$///r   z'Unsupported arguments to Library.tag: (, ))tag_functioncallabler   
ValueError)r   r"   compile_functionr#   s   ``  r   r    zLibrary.tag   s    <,4$$"2":~~ ((...0 0 0 0 0 0 
"2">.DIdO##*44)))+  r   c                 $    || j         |j        <   |S r   )r   r   )r   r!   s     r   r&   zLibrary.tag_function4   s    #'	$- r   c                 N    
| fd}|S (|&t                    r  j        fi S  fd}|S U|S| j        <   dD ]=}|v r7|         }t          |||           t          t	          |          ||           >|_        |S t          dd|d          )z
        Register a callable as a template filter. Example:

        @register.filter
        def lower(value):
            return value.lower()
        Nc                       j         | fi S r   )filter_function)r!   flagsr   s    r   r#   zLibrary.filter.<locals>.decB   s    +t+D::E:::r   c                 "     j         | fi S r   )filter)r!   r.   r"   r   s    r   r#   zLibrary.filter.<locals>.decL   s    &4;tT;;U;;;r   )expects_localtimeis_safeneeds_autoescapez*Unsupported arguments to Library.filter: (r$   r%   )r'   r-   r   setattrr   _filter_namer(   )r   r"   filter_funcr.   r#   attrvalues   `` `   r   r0   zLibrary.filter8   s/    <K/; ; ; ; ; ; J+"5~~ +t+D::E:::< < < < < < < 
+"9!,DLL > >5==!$KEKu555 F;//u==='+K$*44&  r   c                 *     | j         |j        |fi |S r   )r0   r   )r   r!   r.   s      r   r-   zLibrary.filter_functionc   s     t{4=$88%888r   c                 p      fd}||S t          |          r ||          S t          d          )z
        Register a callable as a compiled template tag. Example:

        @register.simple_tag
        def hello(*args, **kwargs):
            return 'world'
        c           
          	 t          t                               \  	}
p j        t                      	f	d            }                    |            S )Nc                    	 |                                 dd          }d }t          |          dk    r|d         dk    r|d         }|d d         }t          | |	

  
        \  }}t          |||          S )Nr	      as)split_contentslen
parse_bits
SimpleNode)parsertokenbits
target_varargskwargsdefaultsr!   function_namekwonlykwonly_defaultsparamstakes_contextvarargsvarkws         r   compile_funcz5Library.simple_tag.<locals>.dec.<locals>.compile_func{   s    ++--abb1!
t99>>d2h$&6&6!%bJ9D)#!!   f "$tVZPPPr   r   r   r   r   r    )r!   _rS   rK   rL   rM   rN   rO   rQ   rR   r"   r   rP   s   `  @@@@@@@r   r#   zLibrary.simple_tag.<locals>.deco   s     vd||,, 1DMM4[[Q Q Q Q Q Q Q Q Q Q Q Q [Q( HH]L111Kr   Nz(Invalid arguments provided to simple_tag)r'   r(   )r   r!   rP   r"   r#   s   ` `` r   
simple_tagzLibrary.simple_tagf   sa    "	 "	 "	 "	 "	 "	 "	H <Jd^^ 	I3t99GHHHr   c                       fd}|S )z
        Register a callable as an inclusion tag:

        @register.inclusion_tag('results.html')
        def show_results(poll):
            choices = poll.choice_set.all()
            return {'choices': choices}
        c                     	 t          t                               \  	}p j        t                     
 	f
d            }                    |            S )Nc                    
 |                                 dd          }t          | |	

  
        \  }}t          ||          S )Nr	   )rA   rC   InclusionNode)rE   rF   rG   rI   rJ   rK   filenamer!   rL   rM   rN   rO   rP   rQ   rR   s        r   rS   z8Library.inclusion_tag.<locals>.dec.<locals>.compile_func   sq    ++--abb1)#!!   f %!  r   rT   )r!   rU   rS   rK   rL   rM   rN   rO   rQ   rR   r[   r"   r   rP   s   `  @@@@@@@r   r#   z"Library.inclusion_tag.<locals>.dec   s     vd||,, 1DMM4[[             [, HH]L111Kr   r   )r   r[   r!   rP   r"   r#   s   `` `` r   inclusion_tagzLibrary.inclusion_tag   s6    $	 $	 $	 $	 $	 $	 $	 $	L 
r   )NN)NNN)r   r   r   __doc__r   r    r&   r0   r-   rV   r\   r   r   r   r   r      s              0  ) ) ) )V9 9 94I 4I 4I 4Il0 0 0 0 0 0r   r   c                       e Zd ZdZd Zd ZdS )TagHelperNodez
    Base class for tag helper nodes such as SimpleNode and InclusionNode.
    Manages the positional and keyword arguments to be passed to the decorated
    function.
    c                 >    || _         || _        || _        || _        d S r   )r!   rP   rI   rJ   )r   r!   rP   rI   rJ   s        r   r   zTagHelperNode.__init__   s#    	*	r   c                     fd| j         D             }| j        rg|z   }fd| j                                        D             }||fS )Nc                 :    g | ]}|                               S r   resolve).0varcontexts     r   
<listcomp>z8TagHelperNode.get_resolved_arguments.<locals>.<listcomp>   s%    CCC#W--CCCr   c                 B    i | ]\  }}||                               S r   rc   )re   kvrg   s      r   
<dictcomp>z8TagHelperNode.get_resolved_arguments.<locals>.<dictcomp>   s+    QQQTQ1aii00QQQr   )rI   rP   rJ   items)r   rg   resolved_argsresolved_kwargss    `  r   get_resolved_argumentsz$TagHelperNode.get_resolved_arguments   sg    CCCCCCC 	6$I5MQQQQT[=N=N=P=PQQQo--r   N)r   r   r   r]   r   rp   r   r   r   r_   r_      s<           . . . . .r   r_   c                   (     e Zd ZdZ fdZd Z xZS )rD   r   c                 ^    t                                          ||||           || _        d S r   )superr   rH   )r   r!   rP   rI   rJ   rH   	__class__s         r   r   zSimpleNode.__init__   s,    }dF;;;$r   c                     |                      |          \  }} | j        |i |}| j        ||| j        <   dS |j        rt	          |          }|S )N )rp   r!   rH   
autoescaper   )r   rg   rn   ro   outputs        r   renderzSimpleNode.render   sf    )-)D)DW)M)M&M=_==?&'-GDO$2 	0'//Fr   )r   r   r   child_nodelistsr   ry   __classcell__rt   s   @r   rD   rD      sL        O% % % % %      r   rD   c                   $     e Zd Z fdZd Z xZS )rZ   c                 ^    t                                          ||||           || _        d S r   )rs   r   r[   )r   r!   rP   rI   rJ   r[   rt   s         r   r   zInclusionNode.__init__   s,    }dF;;; r   c                    |                      |          \  }} | j        |i |}|j                            |           }|t	          | j        t                    r| j        }nt	          t          | j        dd          t                    r| j        j        }n}t	          | j        t                    s?t	          | j        t                    r%|j        j                            | j                  }n$|j        j                            | j                  }||j        | <   |                    |          }|                    d          }|||d<   |                    |          S )z
        Render the specified template and context. Cache the template object
        in render_context to avoid reparsing and loading when used in a for
        loop.
        Ntemplate
csrf_token)rp   r!   render_contextget
isinstancer[   r   getattrr   strr   engineselect_templateget_templatenewry   )r   rg   rn   ro   _dicttnew_contextr   s           r   ry   zInclusionNode.render   sS    *.)D)DW)M)M&	=<O<<"&&t,,9$-22 	HMGDM:tDDhOO HM*s33 H
x9 9 H $+;;DMJJ$+88GG+,G"4(kk%(( [[..
!(2K%xx$$$r   )r   r   r   r   ry   r{   r|   s   @r   rZ   rZ      sG        ! ! ! ! !% % % % % % %r   rZ   c
           
         |r+|r|d         dk    r|dd         }nt          d|	z            g }
i }t          |          }fd|D             }|D ]$}t          |g|           }|r|                                \  }}||vr||vr|t          d|	d|d          ||v rt          d|	d	|d          ||t	          |          <   ||v r|                    |           ||v r|                    |           |rt          d
|	z            |
                    |                     |                     	 |                    d           # t          $ r |t          d|	z            Y "w xY w||dt          |                    }|s|r5t          d|	dd                    d ||z   D                                 |
|fS )z
    Parse bits for template tag helpers simple_tag and inclusion_tag, in
    particular by detecting syntax errors and by extracting positional and
    keyword arguments.
    r   rg   r	   NzW'%s' is decorated with takes_context=True so it must have a first argument of 'context'c                      g | ]
}r|v|S r   r   )re   kwargrN   s     r   rh   zparse_bits.<locals>.<listcomp>7  s2       <A<X<X<X<X<Xr   'z(' received unexpected keyword argument 'z1' received multiple values for keyword argument 'zH'%s' received some positional argument(s) after some keyword argument(s)z+'%s' received too many positional argumentsz0' did not receive value(s) for the argument(s): r$   c              3       K   | ]	}d |z  V  
dS )z'%s'Nr   )re   ps     r   	<genexpr>zparse_bits.<locals>.<genexpr>n  s&      WWavzWWWWWWr   )r   listr   popitemr   removeappendcompile_filterpop
IndexErrorrB   join)rE   rG   rO   rQ   rR   rK   rM   rN   rP   r"   rI   rJ   unhandled_paramsunhandled_kwargsbitr   paramr8   s          `          r   rC   rC     s   "   	fQi9,,ABBZFF%57;<   DFF||   !    + +cUF++ (	 ==??LE5F""uF':':u}))HLeeeT   &))ttUUU$   &+s5zz",,, %++E2222...$++E222 )*,01   F11#66777$((++++!   1IDP   '
  ,,<s8}}n,<= 
+ 
!!ttTYYWW3CFV3VWWWWWWY
 
 	
 <s   <EE54E5c                     	 t          |           }n'# t          $ r}t          d| d|          d}~ww xY w	 |j        S # t          $ r t          d| z            w xY w)z;
    Load a Library object from a template tag module.
    zLInvalid template library specified. ImportError raised when trying to load 'z': Nz4Module  %s does not have a variable named 'register')r   ImportErrorr   registerAttributeError)r"   modulees      r   import_libraryr   s  s    
t$$ 
 
 
$$)-qq2
 
 	



 
 
 
$BTI
 
 	

s    
616A AN)collections.abcr   	functoolsr   	importlibr   inspectr   r   django.utils.htmlr   baser
   r   r   
exceptionsr   	Exceptionr   r   r_   rD   rZ   rC   r   r   r   r   <module>r      s   $ $ $ $ $ $       # # # # # # * * * * * * * * 0 0 0 0 0 0 . . . . . . . . . . + + + + + +	 	 	 	 	Y 	 	 	| | | | | | | |~. . . . .D . . .*       $"% "% "% "% "%M "% "% "%JU U Up
 
 
 
 
r   