B
    ª0H[t#  ã               @   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	   ú[C:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\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||Ž |j | ¡ || _d S )N)ÚsuperÚ__init__ÚdictsÚappendÚcontext)Úselfr   ÚargsÚkwargs)Ú	__class__r	   r
   r      s    zContextDict.__init__c             C   s   | S )Nr	   )r   r	   r	   r
   Ú	__enter__   s    zContextDict.__enter__c             O   s   | j  ¡  d S )N)r   Úpop)r   r   r   r	   r	   r
   Ú__exit__   s    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 )N)Ú_reset_dicts)r   Údict_r	   r	   r
   r      s    zBaseContext.__init__c             C   s,   ddd dœ}|g| _ |d k	r(| j  |¡ 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 )N)r   r   r   )r   Ú	duplicate)r   r	   r
   Ú__copy__%   s    
zBaseContext.__copy__c             C   s
   t | jƒS )N)Úreprr   )r   r	   r	   r
   Ú__repr__*   s    zBaseContext.__repr__c             c   s   t | jƒE d H  d S )N)Úreversedr   )r   r	   r	   r
   Ú__iter__-   s    zBaseContext.__iter__c             O   sJ   g }x4|D ],}t |tƒr,||jdd … 7 }q
| |¡ q
W t| f|ž|Ž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 )Nr'   )Ú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 contextéÿÿÿÿN)r   )r   Úkeyr   r	   r	   r
   Ú__setitem__>   s    zBaseContext.__setitem__c             C   s8   | j d }x t| j ƒD ]}||kr|}P qW |||< dS )z|
        Set a variable in one of the higher contexts if it exists there,
        otherwise in the current context.
        r,   N)r   r%   )r   r-   r   r   r)   r	   r	   r
   Ú
set_upwardB   s    
zBaseContext.set_upwardc             C   s0   x"t | jƒD ]}||kr|| S qW t|ƒ‚dS )zHGet a variable's value, starting at the current context and going upwardN)r%   r   ÚKeyError)r   r-   r)   r	   r	   r
   Ú__getitem__N   s    zBaseContext.__getitem__c             C   s   | j d |= dS )z*Delete a variable from the current contextr,   N)r   )r   r-   r	   r	   r
   Ú__delitem__U   s    zBaseContext.__delitem__c             C   s    x| j D ]}||krdS qW dS )NTF)r   )r   r-   r)   r	   r	   r
   Ú__contains__Y   s    zBaseContext.__contains__c             C   s(   x"t | jƒD ]}||kr|| S qW |S )N)r%   r   )r   r-   Ú	otherwiser)   r	   r	   r
   Úget_   s    zBaseContext.getc             C   s*   y| | S  t k
r$   || |< Y nX |S )N)r0   )r   r-   Údefaultr	   r	   r
   Ú
setdefaulte   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
   Únewl   s    
zBaseContext.newc             C   s"   i }x| j D ]}| |¡ qW |S )z6
        Return self.dicts as one dictionary.
        )r   Úupdate)r   Zflatr)   r	   r	   r
   Úflattenu   s    zBaseContext.flattenc             C   s   t |tƒr|  ¡ | ¡ kS dS )zN
        Compare two contexts by comparing theirs 'dicts' attributes.
        F)r(   r   r<   )r   Úotherr	   r	   r
   Ú__eq__~   s    
zBaseContext.__eq__)N)N)N)N)N)r   r   r   r   r   r"   r$   r&   r*   r   r.   r/   r1   r2   r3   r5   r7   r:   r<   r>   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_tzZtemplate_nameÚRenderContextÚrender_contextÚtemplater   r   )r   r   rA   rB   rC   )r   r	   r
   r   �   s    zContext.__init__c             c   s0   | j d k	rtdƒ‚|| _ z
d V  W d d | _ X d S )Nz&Context is already bound to a template)rF   ÚRuntimeError)r   rF   r	   r	   r
   Úbind_template˜   s    

zContext.bind_templatec                s   t ƒ  ¡ }t| jƒ|_|S )N)r   r"   r   rE   )r   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 Contextr1   z6other_dict must be a mapping (dictionary-like) object.r'   N)ÚhasattrÚ	TypeErrorr(   r   r   r   r   )r   Ú
other_dictr	   r	   r
   r;   §   s
    

zContext.update)NTNN)
r   r   r   r   r   r   rH   r"   r;   r   r	   r	   )r   r
   r?   ‹   s
   
r?   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 )rD   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 )Nr,   )r   )r   r	   r	   r
   r&   Á   s    zRenderContext.__iter__c             C   s   || j d kS )Nr,   )r   )r   r-   r	   r	   r
   r3   Ä   s    zRenderContext.__contains__c             C   s   | j d  ||¡S )Nr,   )r   r5   )r   r-   r4   r	   r	   r
   r5   Ç   s    zRenderContext.getc             C   s   | j d | S )Nr,   )r   )r   r-   r	   r	   r
   r1   Ê   s    zRenderContext.__getitem__Tc             c   s<   | j }|| _ |r|  ¡  z
d V  W d || _ |r6|  ¡  X d S )N)rF   r*   r   )r   rF   Zisolated_contextÚinitialr	   r	   r
   Ú
push_stateÍ   s    
zRenderContext.push_state)N)T)r   r   r   r   rF   r&   r3   r5   r1   r   rM   r	   r	   r	   r
   rD   °   s   
rD   c                   s<   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 kr&dnt|ƒ| _t| jƒ| _|  i ¡ |  i ¡ d S )N)rB   rC   rA   r	   )	r   r   ÚrequestÚtupleÚ_processorsr+   r   Ú_processors_indexr;   )r   rO   r   Ú
processorsrB   rC   rA   )r   r	   r
   r   â   s    
zRequestContext.__init__c          	   c   sx   | j d k	rtdƒ‚|| _ |jj| j }i }x|D ]}| || jƒ¡ q0W || j| j< z
d V  W d d | _ i | j| j< X d S )Nz&Context is already bound to a template)	rF   rG   ZengineZtemplate_context_processorsrQ   r;   rO   r   rR   )r   rF   rS   ZupdatesÚ	processorr	   r	   r
   rH   ï   s    


zRequestContext.bind_templatec                s   t ƒ  |¡}t|dƒr|`|S )NrR   )r   r:   rI   rR   )r   r8   r9   )r   r	   r
   r:     s    
zRequestContext.new)NNNNT)N)	r   r   r   r   r   r   rH   r:   r   r	   r	   )r   r
   rN   Û   s   rN   Nc             K   sZ   | dk	r"t | tƒs"td| jj ƒ‚|dkr8t| f|Ž} n| }t|f|Ž} |rV|  |¡ | S )zT
    Create a suitable Context from a plain dict and optionally an HttpRequest.
    Nz&context must be a dict rather than %s.)r(   ÚdictrJ   r   r   r?   rN   r*   )r   rO   r   Zoriginal_contextr	   r	   r
   Úmake_context  s    
rV   )N)Ú
contextlibr   r   Z_builtin_context_processorsÚ	Exceptionr   rU   r   r   r?   rD   rN   rV   r	   r	   r	   r
   Ú<module>   s   p%+2