
    k"g$                         d dl mZ d dlmZ dZ G d de      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dZy)    )contextmanager)copy)z'django.template.context_processors.csrfc                       e Zd ZdZy)ContextPopExceptionz,pop() has been called more times than push()N)__name__
__module____qualname____doc__     P/var/www/html/djangosite/lib/python3.12/site-packages/django/template/context.pyr   r      s    2r   r   c                   *     e Zd Z fdZd Zd Z xZS )ContextDictc                 h    t        |   |i | |j                  j                  |        || _        y N)super__init__dictsappendcontext)selfr   argskwargs	__class__s       r   r   zContextDict.__init__   s.    $)&)T"r   c                     | S r   r   r   s    r   	__enter__zContextDict.__enter__   s    r   c                 8    | j                   j                          y r   )r   pop)r   r   r   s      r   __exit__zContextDict.__exit__   s    r   )r   r   r	   r   r   r    __classcell__r   s   @r   r   r      s    r   r   c                        e Zd ZddZddZ fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZddZddZddZd Zd Z xZS )BaseContextc                 &    | j                  |       y r   )_reset_dicts)r   dict_s     r   r   zBaseContext.__init__   s    % r   c                     ddd d}|g| _         t        |t              r#| xj                   |j                   dd  z  c_         y || j                   j                  |       y y )NTF)TrueFalseNone   )r   
isinstancer$   r   )r   valuebuiltinss      r   r&   zBaseContext._reset_dicts   sV     5$?Z
e[)JJ%++ab/)JJJe$ r   c                 V    t        t                     }| j                  d d  |_        |S r   )r   r   r   r   	duplicater   s     r   __copy__zBaseContext.__copy__'   s#    M	**Q-	r   c                 ,    t        | j                        S r   )reprr   r   s    r   __repr__zBaseContext.__repr__,   s    DJJr   c                 ,    t        | j                        S r   reversedr   r   s    r   __iter__zBaseContext.__iter__/   s    

##r   c                     g }|D ]6  }t        |t              r||j                  dd  z  }&|j                  |       8 t	        | g|i |S Nr,   )r-   r$   r   r   r   )r   r   r   r   ds        r   pushzBaseContext.push2   sV     	 A![)$Q		 
 42%2622r   c                 r    t        | j                        dk(  rt        | j                  j                         S r<   )lenr   r   r   r   s    r   r   zBaseContext.pop;   s)    tzz?a%%zz~~r   c                 (    || j                   d   |<   y)z%Set a variable in the current contextNr   )r   keyr.   s      r   __setitem__zBaseContext.__setitem__@   s    #

2sr   c                 p    | j                   d   }t        | j                         D ]
  }||v s|} n |||<   y)z|
        Set a variable in one of the higher contexts if it exists there,
        otherwise in the current context.
        rB   N)r   r9   )r   rD   r.   r   r=   s        r   
set_upwardzBaseContext.set_upwardD   sC    
 **R.$**% 	Aax	 r   c                 b    t        | j                        D ]  }||v s||   c S  t        |      )zHGet a variable's value, starting at the current context and going upward)r9   r   KeyError)r   rD   r=   s      r   __getitem__zBaseContext.__getitem__P   s6    $**% 	Aaxv	 smr   c                 $    | j                   d   |= y)z*Delete a variable from the current contextrB   NrC   r   rD   s     r   __delitem__zBaseContext.__delitem__W   s    JJrN3r   c                 @    t        fd| j                  D              S )Nc              3   &   K   | ]  }|v  
 y wr   r   ).0r=   rD   s     r   	<genexpr>z+BaseContext.__contains__.<locals>.<genexpr>\   s     03!80s   )anyr   rL   s    `r   __contains__zBaseContext.__contains__[   s    0TZZ000r   c                 P    t        | j                        D ]  }||v s||   c S  |S r   r8   )r   rD   	otherwiser=   s       r   getzBaseContext.get^   s2    $**% 	Aaxv	 r   c                 8    	 | |   S # t         $ r	 || |<   Y |S w xY wr   )rI   )r   rD   defaults      r   
setdefaultzBaseContext.setdefaultd   s.    	 9 	 DI	 s    c                 >    t        |       }|j                  |       |S )z{
        Return a new context with the same properties, but with only the
        values given in 'values' stored.
        )r   r&   )r   valuesnew_contexts      r   newzBaseContext.newk   s!    
 4j  (r   c                 N    i }| j                   D ]  }|j                  |        |S )z6
        Return self.dicts as one dictionary.
        )r   update)r   flatr=   s      r   flattenzBaseContext.flattent   s,      	AKKN	r   c                 p    t        |t              st        S | j                         |j                         k(  S )zN
        Compare two contexts by comparing theirs 'dicts' attributes.
        )r-   r$   NotImplementedra   )r   others     r   __eq__zBaseContext.__eq__}   s+     %-!!||~00r   r   )r   r   r	   r   r&   r3   r6   r:   r>   r   rE   rG   rJ   rM   rS   rV   rY   r]   ra   re   r!   r"   s   @r   r$   r$      sX    !%
 $3 
$
 11r   r$   c                   D     e Zd ZdZd fd	Zed        Z fdZd Z xZ	S )Contextz&A stack container for variable contextc                     || _         || _        || _        d| _        t	               | _        d | _        t        | !  |       y )Nunknown)	
autoescapeuse_l10nuse_tztemplate_nameRenderContextrender_contexttemplater   r   )r   r'   rj   rk   rl   r   s        r   r   zContext.__init__   s@    $ &+o r   c              #   x   K   | j                   t        d      || _         	 d  d | _         y # d | _         w xY ww)N&Context is already bound to a template)rp   RuntimeError)r   rp   s     r   bind_templatezContext.bind_template   s9     ==$GHH 	! DMDDMs   :. :	7:c                 X    t         |          }t        | j                        |_        |S r   )r   r3   r   ro   r1   s     r   r3   zContext.__copy__   s)    G$&	#'(;(;#<	 r   c                     t        |d      st        d      t        |t              r|j                  dd j                         }t        | |      S )z;Push other_dict to the stack of dictionaries in the ContextrJ   z6other_dict must be a mapping (dictionary-like) object.r,   N)hasattr	TypeErrorr-   r$   r   r   r   )r   
other_dicts     r   r_   zContext.update   sJ    z=1TUUj+.#))!"-113J4,,r   )NTNN)
r   r   r	   r
   r   r   rt   r3   r_   r!   r"   s   @r   rg   rg      s)    ,	  ! !
-r   rg   c                   @    e Zd ZdZdZd Zd ZddZd Ze	d	d       Z
y)
rn   a  
    A stack container for storing Template state.

    RenderContext simplifies the implementation of template Nodes by providing a
    safe place to store state between invocations of a node's `render` method.

    The RenderContext also provides scoping rules that are more sensible for
    'template local' variables. The render context stack is pushed before each
    template is rendered, creating a fresh scope with nothing in it. Name
    resolution fails if a variable is not found at the top of the RequestContext
    stack. Thus, variables are local to a specific template and don't affect the
    rendering of other templates as they would if they were stored in the normal
    template context.
    Nc              #   >   K   | j                   d   E d {    y 7 wNrB   rC   r   s    r   r:   zRenderContext.__iter__   s     ::b>!!s   c                 $    || j                   d   v S r|   rC   rL   s     r   rS   zRenderContext.__contains__   s    djjn$$r   c                 @    | j                   d   j                  ||      S r|   )r   rV   )r   rD   rU   s      r   rV   zRenderContext.get   s    zz"~!!#y11r   c                 &    | j                   d   |   S r|   rC   rL   s     r   rJ   zRenderContext.__getitem__   s    zz"~c""r   c              #      K   | j                   }|| _         |r| j                          	 d  || _         |r| j                          y y # || _         |r| j                          w w xY wwr   )rp   r>   r   )r   rp   isolated_contextinitials       r   
push_statezRenderContext.push_state   s]     -- IIK	#DM
   $DM
  s   &A'A A'A$$A'r   )T)r   r   r	   r
   rp   r:   rS   rV   rJ   r   r   r   r   r   rn   rn      s6     H"%2# 
 
r   rn   c                   J     e Zd ZdZ	 	 	 	 	 d fd	Zed        Zd fd	Z xZS )RequestContextz
    This subclass of template.Context automatically populates itself using
    the processors defined in the engine's configuration.
    Additional processors can be specified as a list of callables
    using the "processors" keyword argument.
    c                     t         |   ||||       || _        |dn
t        |      | _        t        | j                        | _        | j                  i        | j                  i        y )N)rk   rl   rj   r   )	r   r   requesttuple_processorsr@   r   _processors_indexr_   )r   r   r'   
processorsrk   rl   rj   r   s          r   r   zRequestContext.__init__   s`     	&ZX!+!32z9J!$TZZ 	B 	Br   c              #     K   | j                   t        d      || _         |j                  j                  | j                  z   }i }|D ]&  } || j
                        }	 |j                  |       ( || j                  | j                  <   	 d  d | _         i | j                  | j                  <   y # t        $ r}t        d|j                   d      |d }~ww xY w# d | _         i | j                  | j                  <   w xY ww)Nrr   zContext processor z didn't return a dictionary.)rp   rs   enginetemplate_context_processorsr   r   r_   rx   r	   r   r   )r   rp   r   updates	processorr   es          r   rt   zRequestContext.bind_template   s    ==$GHH __@@4CSCSS
# 	I-Gw'	 .5

4))*	4 DM13DJJt--.  ()?)?(@ A" "  !DM13DJJt--.sB   AD B0/D C !D 0	C9CCD "C==D c                 B    t         |   |      }t        |d      r|`|S )Nr   )r   r]   rw   r   )r   r[   r\   r   s      r   r]   zRequestContext.new  s*    gk&) ; 34-r   )NNNNTr   )	r   r   r	   r
   r   r   rt   r]   r!   r"   s   @r   r   r      s<     * 4 46 r   r   Nc                     | 2t        | t              s"t        d| j                  j                  z        |t        | fi |} | S | }t        |fi |} |r| j                  |       | S )zT
    Create a suitable Context from a plain dict and optionally an HttpRequest.
    z&context must be a dict rather than %s.)r-   dictrx   r   r   rg   r   r>   )r   r   r   original_contexts       r   make_contextr     s}     :gt#<4w7H7H7Q7QQ
 	
 ',V, N	 # 3F3LL)*Nr   r   )
contextlibr   r   _builtin_context_processors	Exceptionr   r   r   r$   rg   rn   r   r   r   r   r   <module>r      se    %  K 	) 	
$ i1 i1X#-k #-L)K )X?W ?Dr   