
    j_C                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  SSKJrJrJr  SS	KJr   " S
 S\5      r " S S5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rS rg)    )Iterable)wraps)import_module)unwrap)conditional_escape)getfullargspec   )NodeTemplatetoken_kwargs)TemplateSyntaxErrorc                       \ rS rSrSrg)InvalidTemplateLibrary    N)__name__
__module____qualname____firstlineno____static_attributes__r       O/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/template/library.pyr   r      s    r   r   c                   \    \ rS rSrSrS rSS jrS rSS jrS r	SS	 jr
SS
 jrSS jrSrg)Library   z
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                      0 U l         0 U l        g Nfilterstags)selfs    r   __init__Library.__init__   s    	r   Nc                    ^ ^ Tc  Uc  T R                   $ Tb-  Uc*  [        T5      (       a  T R                  T5      $ UU 4S jnU$ Tb  Ub  UT R                  T'   U$ [        ST< SU< S35      e)Nc                 (   > TR                  TU 5      $ r   )tag)funcnamer!   s    r   decLibrary.tag.<locals>.dec'   s    88D$//r   z'Unsupported arguments to Library.tag: (, ))tag_functioncallabler    
ValueError)r!   r(   compile_functionr)   s   ``  r   r&   Library.tag   s    <,4$$$"2":~~((..0 
"2">.DIIdO##)+ r   c                 6    XR                   UR                  '   U$ r   )r    r   )r!   r'   s     r   r-   Library.tag_function5   s    #'		$-- r   c                 ^  ^ ^^ Tc  Uc	  UU 4S jnU$ Tb0  Uc-  [        T5      (       a  T R                  " T40 TD6$ UUU 4S jnU$ TbR  UbO  UT R                  T'   S H1  nUT;   d  M  TU   n[        X%U5        [        [	        U5      XV5        M3     TUl        U$ [        ST< SU< S35      e)zq
Register a callable as a template filter. Example:

@register.filter
def lower(value):
    return value.lower()
c                 *   > TR                   " U 40 TD6$ r   )filter_function)r'   flagsr!   s    r   r)   Library.filter.<locals>.decC   s    ++D:E::r   c                 ,   > TR                   " TU 40 TD6$ r   )filter)r'   r7   r(   r!   s    r   r)   r8   N   s    ;;tT;U;;r   )expects_localtimeis_safeneeds_autoescapez*Unsupported arguments to Library.filter: (r+   r,   )r.   r6   r   setattrr   _filter_namer/   )r!   r(   filter_funcr7   r)   attrvalues   `` `   r   r:   Library.filter9   s     <K/; J+"5~~++D:E::< 
+"9!,DLLL5=!$KEKu5 F;/= M (,K$& r   c                 >    U R                   " UR                  U40 UD6$ r   )r:   r   )r!   r'   r7   s      r   r6   Library.filter_functione   s    {{4==$8%88r   c                 h   ^ ^^ UU U4S jnUc  U$ [        U5      (       a  U" U5      $ [        S5      e)z
Register a callable as a compiled template tag. Example:

@register.simple_tag
def hello(*args, **kwargs):
    return 'world'
c           
      *  >^ ^^^^^^^	 [        [        T 5      5      u  mmm	mmmnT
=(       d    T R                  mT(       a#  T(       a  TS   S:X  a  TS	 O[        T< S35      e[	        T 5      UU UUUUUUU	4	S j5       nTR                  TU5        T $ )Nr   contextS is decorated with takes_context=True so it must have a first argument of 'context'c                    >	 UR                  5       SS  nS n[        U5      S:  a  US   S:X  a
  US   nUS S n[        U UTTTTT	T
T5	      u  pE[        TTXEU5      $ 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_func5Library.simple_tag.<locals>.dec.<locals>.compile_func   s    ++-ab1!
t9>d2h$&6!%bJ9D)#!
  "$tZPPr   r   r   r   r   r   r&   )r'   _rb   rZ   r[   r\   r]   r^   r`   ra   r(   r!   r_   s   `  @@@@@@@r   r)   Library.simple_tag.<locals>.decq   s     vd|, 1DMMMfQi94q	-(+ ,B B 
 4[Q Q Q& HH]L1Kr   z(Invalid arguments provided to simple_tagr.   r/   )r!   r'   r_   r(   r)   s   ` `` r   
simple_tagLibrary.simple_tagh   s4    *	X <Jd^^t9GHHr   c                 l   ^ ^^^ UUU U4S jnUc  U$ [        U5      (       a  U" U5      $ [        S5      e)z
Register a callable as a compiled block template tag. Example:

@register.simple_block_tag
def hello(content):
    return 'world'
c                   >^ ^^^^^^^	 [        [        T 5      5      u  mmm	mmmnT=(       d    T R                  mT
c  ST 3m
T(       aN  [        T5      S:  a  TS   S:X  a  TS	 O[	        T< S35      eT(       a  TS   S:X  a  TS	 O2[	        T< S35      eT(       a  TS   S:X  a  TS	 O[	        T< S	35      e[        T 5      UU
U UUUUUUU	4
S
 j5       nTR                  TU5        T $ )NendrL   r	   contentzv is decorated with takes_context=True so it must have a first argument of 'context' and a second argument of 'content'r   rH   rI   z( must have a first argument of 'content'c                    >
 UR                  5       SS  nS n[        U5      S:  a  US   S:X  a
  US   nUS S nU R                  T45      nU R                  5         [	        U UTTTTTTT
5	      u  pV[        UT	TXVU5      $ rK   )rP   rQ   parsedelete_first_tokenrR   SimpleBlockNode)rT   rU   rV   rW   nodelistrX   rY   rZ   end_namer'   r[   r\   r]   r^   r_   r`   ra   s          r   rb   ;Library.simple_block_tag.<locals>.dec.<locals>.compile_func   s    ++-ab1!
t9>d2h$&6!%bJ9D!<<4))+)#!
  'dM4 r   )r   r   r   rQ   r   r   r&   )r'   re   rb   rZ   r[   r\   r]   r^   r`   ra   rs   r(   r!   r_   s   `  @@@@@@@r   r)   %Library.simple_block_tag.<locals>.dec   s"    vd|, 1DMMM 0v;!#q	Y(>q	-(+ ,0 0  fQi94q	-(+ ,B B  F1I21I)$''OP  4[  4 HH]L1Kr   z.Invalid arguments provided to simple_block_tagrg   )r!   r'   r_   r(   rs   r)   s   ` ``` r   simple_block_tagLibrary.simple_block_tag   s;    D	 D	L <Jd^^t9MNNr   c                     ^ ^^^ UUU U4S jnU$ )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                 0  >^ ^^^^^^^	 [        [        T 5      5      u  mmm	mmmnT=(       d    T R                  mT(       a%  T(       a  TS   S:X  a  TSS  mO[        T< S35      e[	        T 5      UU
U UUUUUUU	4
S j5       nTR                  TU5        T $ )Nr   rH   r	   rI   c                 r   >
 UR                  5       SS  n[        U UTTTTT	T
T5	      u  p4[        TTUUT5      $ )Nr	   )rP   rR   InclusionNode)rT   rU   rV   rX   rY   rZ   filenamer'   r[   r\   r]   r^   r_   r`   ra   s        r   rb   8Library.inclusion_tag.<locals>.dec.<locals>.compile_func  s]    ++-ab1)#!
  %! r   rd   )r'   re   rb   rZ   r[   r\   r]   r^   r`   ra   r|   r(   r!   r_   s   `  @@@@@@@r   r)   "Library.inclusion_tag.<locals>.dec  s     vd|, 1DMMMfQi94#ABZF-(+ ,B B 
 4[  * HH]L1Kr   r   )r!   r|   r'   r_   r(   r)   s   `` `` r   inclusion_tagLibrary.inclusion_tag   s    ,	 ,	\ 
r   r   )NN)NNN)NNNN)r   r   r   r   __doc__r"   r&   r-   r:   r6   rh   rv   r   r   r   r   r   r   r      s5    0*X9<I|VOp8r   r   c                   $    \ rS rSrSrS rS rSrg)TagHelperNodei9  z
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                 4    Xl         X l        X0l        X@l        g r   )r'   r_   rX   rY   )r!   r'   r_   rX   rY   s        r   r"   TagHelperNode.__init__@  s    	*	r   c                    U R                    Vs/ s H  o"R                  U5      PM     nnU R                  (       a  U/UQnU R                  R	                  5        VVs0 s H  u  pEXER                  U5      _M     nnnX64$ s  snf s  snnf r   )rX   resolver_   rY   items)r!   rH   varresolved_argskvresolved_kwargss          r   get_resolved_arguments$TagHelperNode.get_resolved_argumentsF  s}    9=C#W-C$5}5M=A[[=N=N=PQ=PTQ1ii00=PQ--	 D Rs   BB)rX   r'   rY   r_   N)r   r   r   r   r   r"   r   r   r   r   r   r   r   9  s    .r   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )rS   iN  r   c                 2   > [         TU ]  XX45        XPl        g r   )superr"   rW   )r!   r'   r_   rX   rY   rW   	__class__s         r   r"   SimpleNode.__init__Q  s    d;$r   c                     U R                  U5      u  p#U R                  " U0 UD6nU R                  b  XAU R                  '   gUR                  (       a  [	        U5      nU$ )N )r   r'   rW   
autoescaper   )r!   rH   r   r   outputs        r   renderSimpleNode.renderU  sY    )-)D)DW)M&M=_=??&'-DOO$'/Fr   )rW   )	r   r   r   r   child_nodelistsr"   r   r   __classcell__r   s   @r   rS   rS   N  s    O% r   rS   c                   4   ^  \ rS rSrU 4S jrU 4S jrSrU =r$ )rq   i`  c                 2   > [         TU ]  " U0 UD6  Xl        g r   )r   r"   rr   )r!   rr   rX   rY   r   s       r   r"   SimpleBlockNode.__init__a  s    $)&) r   c                    > [         TU ]  U5      u  p#UR                  U R                  (       a  SOSU R                  R                  U5      5        X#4$ )Nr	   r   )r   r   insertr_   rr   r   )r!   rH   r   r   r   s       r   r   &SimpleBlockNode.get_resolved_argumentse  sN    ).)G)P& 	##ADMM,@,@,I	
 --r   )rr   )r   r   r   r   r"   r   r   r   r   s   @r   rq   rq   `  s    !	. 	.r   rq   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )r{   iq  c                 2   > [         TU ]  XX45        XPl        g r   )r   r"   r|   )r!   r'   r_   rX   rY   r|   r   s         r   r"   InclusionNode.__init__r  s    d; r   c                 .   U R                  U5      u  p#U R                  " U0 UD6nUR                  R                  U 5      nUGc  [	        U R
                  [        5      (       a  U R
                  nO[	        [        U R
                  SS5      [        5      (       a  U R
                  R                  nO[	        U R
                  [        5      (       dO  [	        U R
                  [        5      (       a0  UR                  R                  R                  U R
                  5      nO/UR                  R                  R                  U R
                  5      nXQR                  U '   UR                  U5      nUR                  S5      nUb  XvS'   UR                  U5      $ )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)r   r'   render_contextget
isinstancer|   r   getattrr   strr   engineselect_templateget_templatenewr   )r!   rH   r   r   _dicttnew_contextr   s           r   r   InclusionNode.renderv  s9    *.)D)DW)M&		=<O<""&&t,9$--22MMGDMM:tDhOOMM**s33
x9 9 $$++;;DMMJ$$++88G+,""4(kk%( [[.
!(2%xx$$r   )r|   )r   r   r   r   r"   r   r   r   r   s   @r   r{   r{   q  s    !% %r   r{   c	           
      ,   / n	0 n
[        U5      nU Vs/ s H  o(       a  X;  d  M  UPM     nnU H  n[        U/U 5      nU(       a  UR                  5       u  nnX;  a  X;  a  Uc  [        SU< SU< S35      eX;   a  [        SU< SU< S35      eUU
[	        U5      '   X;   a  UR                  U5        M  X;   a  UR                  U5        M  M  U
(       a  [        SU-  5      eU	R                  U R                  U5      5         UR                  S5        M     Ub  US[        U5      *  nU(       d  U(       a+  [        SU< SS	R                  S
 X-    5       5      < 35      eX4$ s  snf ! [         a    Uc  [        SU-  5      e GMa  f = f)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.
N'z(' received unexpected keyword argument 'z1' received multiple values for keyword argument 'zH'%s' received some positional argument(s) after some keyword argument(s)r   z+'%s' received too many positional argumentsz0' did not receive value(s) for the argument(s): r+   c              3   ,   #    U  H
  nS U-  v   M     g7f)z'%s'Nr   ).0ps     r   	<genexpr>parse_bits.<locals>.<genexpr>  s     W3Vavz3Vs   )listr   popitemr   r   removeappendcompile_filterpop
IndexErrorrQ   join)rT   rV   r^   r`   ra   rZ   r\   r]   r(   rX   rY   unhandled_paramskwargunhandled_kwargsbitparamrB   s                    r   rR   rR     s     DFF|!!%E<X6   cUF+ ==?LE5"u':u})HLeT  )U$  &+s5z", %++E2.$++E2 / )*,01  F11#67$((+M X  ,,<s8}n=+!TYYW3C3VWWY
 	
 <sT " 1IDP  's   E.E.E33FFc                      [        U 5      n UR                  $ ! [         a  n[        SU < SU< 35      eSnAff = f! [         a    [        SU -  5      ef = f)z3
Load a Library object from a template tag module.
zLInvalid template library specified. ImportError raised when trying to load 'z': Nz3Module %s does not have a variable named 'register')r   ImportErrorr   registerAttributeError)r(   modulees      r   import_libraryr     sn    
t$
  
$)-q2
 	

  
$ADH
 	

s    ? 
<7<AN)collections.abcr   	functoolsr   	importlibr   inspectr   django.utils.htmlr   django.utils.inspectr   baser
   r   r   
exceptionsr   	Exceptionr   r   r   rS   rq   r{   rR   r   r   r   r   <module>r      sv    $  #  0 / . . +	Y 	e eP	.D .* $.j .""%M "%JL^
r   