o
    ô<âg‰$  ã                   @   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	   úJ/var/www/html/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   sV   ddd dœ}|g| _ t|tƒr|  j |j dd … 7  _ d S |d ur)| j  |¡ d S d S )NTF)ÚTrueÚFalseÚNoneé   )r   Ú
isinstancer   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 ©Nr#   )r$   r   r   r   r   )r   r   r   r   Údr	   r	   r
   Úpush2   s   
zBaseContext.pushc                 C   s   t | jƒdkr	t‚| j ¡ S r1   )Úlenr   r   r   r   r	   r	   r
   r   ;   s   
zBaseContext.popc                 C   s   || j d |< dS )z%Set a variable in the current contextéÿÿÿÿN©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_upwardD   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__P   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__W   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>\   s   € z+BaseContext.__contains__.<locals>.<genexpr>)Úanyr   r<   r	   r?   r
   Ú__contains__[   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
   Ú
setdefaultd   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
   Únewk   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
   Úflattent   s   
zBaseContext.flattenc                 C   s   t |tƒstS |  ¡ | ¡ kS )zN
        Compare two contexts by comparing theirs 'dicts' attributes.
        )r$   r   ÚNotImplementedrM   )r   Úotherr	   r	   r
   Ú__eq__}   s   
zBaseContext.__eq__r   )r   r   r   r   r   r)   r,   r0   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.r#   N)ÚhasattrÚ	TypeErrorr$   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
   r0   ¿   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   r0   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.)r$   Ú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    l&,B