o
    
h2$                     @   s   d dl mZ d dlmZ dZG dd deZG dd deZG dd	 d	ZG d
d deZ	G dd deZ
G dd de	ZdddZdS )    )contextmanager)copy)z'django.template.context_processors.csrfc                   @   s   e Zd ZdZdS )ContextPopExceptionz,pop() has been called more times than push()N)__name__
__module____qualname____doc__ r	   r	   Y/var/www/html/optinet_system/venv/lib/python3.10/site-packages/django/template/context.pyr      s    r   c                       s,   e Zd Z fddZdd Zdd Z  ZS )ContextDictc                    s(   t  j|i | |j|  || _d S N)super__init__dictsappendcontext)selfr   argskwargs	__class__r	   r
   r      s   
zContextDict.__init__c                 C   s   | S r   r	   r   r	   r	   r
   	__enter__   s   zContextDict.__enter__c                 O   s   | j   d S r   )r   pop)r   r   r   r	   r	   r
   __exit__      zContextDict.__exit__)r   r   r   r   r   r   __classcell__r	   r	   r   r
   r      s    r   c                       s   e Zd Zd$ddZd$ddZ fddZdd	 Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd Zd$ddZd$ddZd$ddZd d! Zd"d# Z  ZS )%BaseContextNc                 C   s   |  | d S r   )_reset_dicts)r   dict_r	   r	   r
   r      r   zBaseContext.__init__c                 C   s0   ddd d}|g| _ |d ur| j | d S d S )NTF)TrueFalseNone)r   r   )r   valuebuiltinsr	   r	   r
   r      s
   zBaseContext._reset_dictsc                    s   t t }| jd d  |_|S r   )r   r   r   r   	duplicater   r	   r
   __copy__%   s   
zBaseContext.__copy__c                 C   
   t | jS r   )reprr   r   r	   r	   r
   __repr__*      
zBaseContext.__repr__c                 C   r(   r   reversedr   r   r	   r	   r
   __iter__-   r+   zBaseContext.__iter__c                 O   sL   g }|D ]}t |tr||jdd  7 }q|| qt| g|R i |S N   )
isinstancer   r   r   r   )r   r   r   r   dr	   r	   r
   push0   s   
zBaseContext.pushc                 C   s   t | jdkr	t| j S r/   )lenr   r   r   r   r	   r	   r
   r   9   s   
zBaseContext.popc                 C   s   || j d |< dS )z%Set a variable in the current contextNr   )r   keyr#   r	   r	   r
   __setitem__>   s   zBaseContext.__setitem__c                 C   s6   | j d }t| j D ]
}||v r|} nq
|||< dS )z|
        Set a variable in one of the higher contexts if it exists there,
        otherwise in the current context.
        r5   N)r   r-   )r   r7   r#   r   r2   r	   r	   r
   
set_upwardB   s   
zBaseContext.set_upwardc                 C   s,   t | jD ]}||v r||   S qt|)zHGet a variable's value, starting at the current context and going upward)r-   r   KeyError)r   r7   r2   r	   r	   r
   __getitem__N   s
   zBaseContext.__getitem__c                 C   s   | j d |= dS )z*Delete a variable from the current contextr5   Nr6   r   r7   r	   r	   r
   __delitem__U   s   zBaseContext.__delitem__c                    s   t  fdd| jD S )Nc                 3   s    | ]} |v V  qd S r   r	   ).0r2   r7   r	   r
   	<genexpr>Z   s    z+BaseContext.__contains__.<locals>.<genexpr>)anyr   r<   r	   r?   r
   __contains__Y   s   zBaseContext.__contains__c                 C   s(   t | jD ]}||v r||   S q|S r   r,   )r   r7   	otherwiser2   r	   r	   r
   get\   s
   zBaseContext.getc                 C   s(   z| | W S  t y   || |< Y |S w r   )r:   )r   r7   defaultr	   r	   r
   
setdefaultb   s   

zBaseContext.setdefaultc                 C   s   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_contextr	   r	   r
   newi   s   
zBaseContext.newc                 C   s   i }| j D ]}|| q|S )z6
        Return self.dicts as one dictionary.
        )r   update)r   flatr2   r	   r	   r
   flattenr   s   
zBaseContext.flattenc                 C   s   t |tstS |  | kS )zN
        Compare two contexts by comparing theirs 'dicts' attributes.
        )r1   r   NotImplementedrM   )r   otherr	   r	   r
   __eq__{   s   
zBaseContext.__eq__r   )r   r   r   r   r   r'   r*   r.   r3   r   r8   r9   r;   r=   rB   rD   rF   rJ   rM   rP   r   r	   r	   r   r
   r      s$    

	


		r   c                       sB   e Zd ZdZd fdd	Zedd Z fdd	Zd
d Z  Z	S )Contextz&A stack container for variable contextNTc                    s6   || _ || _|| _d| _t | _d | _t | d S )Nunknown)	
autoescapeuse_l10nuse_tztemplate_nameRenderContextrender_contexttemplater   r   )r   r   rS   rT   rU   r   r	   r
   r      s   zContext.__init__c                 c   s6    | j d ur
td|| _ z	d V  W d | _ d S d | _ w )N&Context is already bound to a template)rY   RuntimeError)r   rY   r	   r	   r
   bind_template   s   
zContext.bind_templatec                    s   t   }t| j|_|S r   )r   r'   r   rX   r%   r   r	   r
   r'      s   
zContext.__copy__c                 C   s8   t |ds	tdt|tr|jdd  }t| |S )z;Push other_dict to the stack of dictionaries in the Contextr;   z6other_dict must be a mapping (dictionary-like) object.r0   N)hasattr	TypeErrorr1   r   r   r   r   )r   
other_dictr	   r	   r
   rK      s
   


zContext.update)NTNN)
r   r   r   r   r   r   r\   r'   rK   r   r	   r	   r   r
   rQ      s    
	rQ   c                   @   sD   e Zd ZdZdZdd Zdd ZdddZd	d
 Ze	dddZ
dS )rW   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                 c   s    | j d E d H  d S Nr5   r6   r   r	   r	   r
   r.      s   zRenderContext.__iter__c                 C   s   || j d v S r`   r6   r<   r	   r	   r
   rB      r   zRenderContext.__contains__c                 C   s   | j d ||S r`   )r   rD   )r   r7   rC   r	   r	   r
   rD      s   zRenderContext.getc                 C   s   | j d | S r`   r6   r<   r	   r	   r
   r;      r   zRenderContext.__getitem__Tc                 c   sT    | j }|| _ |r|   zd V  W || _ |r|   d S d S || _ |r)|   w w r   )rY   r3   r   )r   rY   isolated_contextinitialr	   r	   r
   
push_state   s   
zRenderContext.push_stater   )T)r   r   r   r   rY   r.   rB   rD   r;   r   rc   r	   r	   r	   r
   rW      s    
rW   c                       sF   e Zd ZdZ					d
 fdd	Zedd Zd fdd		Z  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                    sT   t  j||||d || _|d u rdnt|| _t| j| _| i  | i  d S )N)rT   rU   rS   r	   )	r   r   requesttuple_processorsr4   r   _processors_indexrK   )r   re   r   
processorsrT   rU   rS   r   r	   r
   r      s   	
zRequestContext.__init__c                 c   s    | j d ur
td|| _ |jj| j }i }|D ]$}|| j}z|| W q ty< } z
td|j d|d }~ww || j	| j
< zd V  W d | _ i | j	| j
< d S d | _ i | j	| j
< w )NrZ   zContext processor z didn't return a dictionary.)rY   r[   enginetemplate_context_processorsrg   re   rK   r^   r   r   rh   )r   rY   ri   updates	processorr   er	   r	   r
   r\      s2   

zRequestContext.bind_templatec                    s   t  |}t|dr|`|S )Nrh   )r   rJ   r]   rh   rG   r   r	   r
   rJ     s   
zRequestContext.new)NNNNTr   )	r   r   r   r   r   r   r\   rJ   r   r	   r	   r   r
   rd      s    

rd   Nc                 K   sd   | durt | tstd| jj |du rt| fi |} | S | }t|fi |} |r0| | | S )zT
    Create a suitable Context from a plain dict and optionally an HttpRequest.
    Nz&context must be a dict rather than %s.)r1   dictr^   r   r   rQ   rd   r3   )r   re   r   original_contextr	   r	   r
   make_context  s   

rq   r   )
contextlibr   r   _builtin_context_processors	Exceptionr   ro   r   r   rQ   rW   rd   rq   r	   r	   r	   r
   <module>   s    j&,B