
    Evg$                         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dS )    )contextmanager)copy)z'django.template.context_processors.csrfc                       e Zd ZdZdS )ContextPopExceptionz,pop() has been called more times than push()N)__name__
__module____qualname____doc__     T/var/www/pixelcanvas.ch/venv/lib/python3.11/site-packages/django/template/context.pyr   r      s        22Dr   r   c                   *     e Zd Z fdZd Zd Z xZS )ContextDictc                 |     t                      j        |i | |j                            |            || _        d S 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                                          d S 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      sV                    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 )BaseContextNc                 0    |                      |           d S 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_         d S || j                             |           d S d S )NTF)TrueFalseNone   )r   
isinstancer$   r   )r   valuebuiltinss      r   r&   zBaseContext._reset_dicts   st     5$??Z
e[)) 	%JJ%+abb/)JJJJJe$$$$$ r   c                 f    t          t                                }| j        d d          |_        |S r   )r   r   r   r   	duplicater   s     r   __copy__zBaseContext.__copy__'   s)    MM	*QQQ-	r   c                 *    t          | j                  S r   )reprr   r   s    r   __repr__zBaseContext.__repr__,   s    DJr   c                 *    t          | j                  S r   reversedr   r   s    r   __iter__zBaseContext.__iter__/   s    
###r   c                     g }|D ]?}t          |t                    r||j        dd          z  }*|                    |           @t	          | g|R i |S Nr,   )r-   r$   r   r   r   )r   r   r   r   ds        r   pushzBaseContext.push2   sm     	  	 A![))  $Q42%2226222r   c                 r    t          | j                  dk    rt          | j                                        S r<   )lenr   r   r   r   s    r   r   zBaseContext.pop;   s-    tz??a%%z~~r   c                 &    || j         d         |<   dS )z%Set a variable in the current contextNr   )r   keyr.   s      r   __setitem__zBaseContext.__setitem__@   s    #
2sr   c                 h    | j         d         }t          | j                   D ]
}||v r|} n|||<   dS )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   sO    
 *R.$*%% 	 	Aaxx  r   c                 j    t          | j                  D ]}||v r
||         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   sB    $*%% 	 	Aaxxv smmr   c                 "    | j         d         |= dS )z*Delete a variable from the current contextrB   NrC   r   rD   s     r   __delitem__zBaseContext.__delitem__W   s    JrN3r   c                 D    t          fd| j        D                       S )Nc              3       K   | ]}|v V  	d S r   r   ).0r=   rD   s     r   	<genexpr>z+BaseContext.__contains__.<locals>.<genexpr>\   s'      003!8000000r   )anyr   rL   s    `r   __contains__zBaseContext.__contains__[   s(    0000TZ000000r   c                 P    t          | j                  D ]}||v r
||         c S |S r   r8   )r   rD   	otherwiser=   s       r   getzBaseContext.get^   s<    $*%% 	 	Aaxxv r   c                 B    	 | |         S # t           $ r || |<   Y nw xY w|S r   )rI   )r   rD   defaults      r   
setdefaultzBaseContext.setdefaultd   s>    	 9 	  	  	 DIII	 s   
 c                 N    t          |           }|                    |           |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)    
 4jj  (((r   c                 H    i }| j         D ]}|                    |           |S )z6
        Return self.dicts as one dictionary.
        )r   update)r   flatr=   s      r   flattenzBaseContext.flattent   s0      	 	AKKNNNNr   c                     t          |t                    st          S |                                 |                                k    S )zN
        Compare two contexts by comparing theirs 'dicts' attributes.
        )r-   r$   NotImplementedra   )r   others     r   __eq__zBaseContext.__eq__}   s7     %-- 	"!!||~~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$      sA       ! ! ! !% % % %    
     $ $ $3 3 3     
$ $ $
 
 
       1 1 1           1 1 1 1 1 1 1r   r$   c                   J     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 contextNTc                     || _         || _        || _        d| _        t	                      | _        d | _        t                                          |           d S )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__   sS    $ &+oo r   c              #   t   K   | j         t          d          || _         	 d V  d | _         d S # d | _         w xY w)N&Context is already bound to a template)rp   RuntimeError)r   rp   s     r   bind_templatezContext.bind_template   sP      =$GHHH 	!EEE DMMMDDM    s   . 	7c                 z    t                                                      }t          | j                  |_        |S r   )r   r3   r   ro   r1   s     r   r3   zContext.__copy__   s1    GG$$&&	#'(;#<#<	 r   c                     t          |d          st          d          t          |t                    r!|j        dd                                         }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   sc    z=11 	VTUUUj+.. 	4#)!""-1133J4,,,r   )NTNN)
r   r   r	   r
   r   r   rt   r3   r_   r!   r"   s   @r   rg   rg      s        ,,	  	  	  	  	  	  ! ! ^!    
- - - - - - -r   rg   c                   H    e Zd ZdZdZd Zd Zd	dZd Ze	d
d            Z
dS )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              #   0   K   | j         d         E d {V  d S NrB   rC   r   s    r   r:   zRenderContext.__iter__   s*      :b>!!!!!!!!!r   c                      || j         d         v S r|   rC   rL   s     r   rS   zRenderContext.__contains__   s    djn$$r   c                 D    | j         d                             ||          S r|   )r   rV   )r   rD   rU   s      r   rV   zRenderContext.get   s    z"~!!#y111r   c                 (    | j         d         |         S r|   rC   rL   s     r   rJ   zRenderContext.__getitem__   s    z"~c""r   Tc              #      K   | j         }|| _         |r|                                  	 d V  || _         |r|                                  d S d S # || _         |r|                                  w w xY wr   )rp   r>   r   )r   rp   isolated_contextinitials       r   
push_statezRenderContext.push_state   s      -  	IIKKK	EEE#DM 




  $DM 



s   A  A-r   )T)r   r   r	   r
   rp   r:   rS   rV   rJ   r   r   r   r   r   rn   rn      s          H" " "% % %2 2 2 2# # # 
 
 
 ^
 
 
r   rn   c                   P     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.
    NTc                    t                                          ||||           || _        |dnt          |          | _        t          | j                  | _        |                     i            |                     i            d S )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XX!+!322z9J9J!$TZ 	B 	Br   c              #     K   | j         t          d          || _         |j        j        | j        z   }i }|D ]S} || j                  }	 |                    |           )# t          $ r}t          d|j         d          |d }~ww xY w|| j	        | j
        <   	 d V  d | _         i | j	        | j
        <   d S # d | _         i | j	        | j
        <   w xY 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H _@4CSS
# 	 	Ii--Gw''''   ")? " " "   .5
4)*	4EEE DM13DJt-... !DM13DJt-.3333s$   A!!
B	+BB	B8 8Cc                 n    t                                          |          }t          |d          r|`|S )Nr   )r   r]   rw   r   )r   r[   r\   r   s      r   r]   zRequestContext.new  s9    ggkk&)) ; 344 	.-r   )NNNNTr   )	r   r   r	   r
   r   r   rt   r]   r!   r"   s   @r   r   r      s               * 4 4 ^46         r   r   Nc                     | 1t          | t                    st          d| j        j        z            |t          | fi |} n&| }t          |fi |} |r|                     |           | S )zT
    Create a suitable Context from a plain dict and optionally an HttpRequest.
    Nz&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#<#<4w7H7QQ
 
 	
 ',,V,, # 33F33 	+LL)***Nr   r   )
contextlibr   r   _builtin_context_processors	Exceptionr   r   r   r$   rg   rn   r   r   r   r   r   <module>r      sV   % % % % % %       K 	 	 	 	 	) 	 	 	
    $   i1 i1 i1 i1 i1 i1 i1 i1X#- #- #- #- #-k #- #- #-L) ) ) ) )K ) ) )X? ? ? ? ?W ? ? ?D     r   