î

_ÝV•%  ã               @   sâ   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z d Z e ƒ  Z Gd d „  d e	 ƒ Z
 Gd d	 „  d	 e ƒ Z Gd
 d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z Gd d „  d e ƒ Z d d d „ Z d S)é    N)Úcontextmanager)Úcopy)ÚRemovedInDjango110Warningú'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   ú9/tmp/pip-build-ghmbqnp_/Django/django/template/context.pyr      s   r   c                   s:   e  Z d  Z ‡  f d d †  Z d d „  Z d d „  Z ‡  S)ÚContextDictc                s6   t  t |  ƒ j | | Ž  | j j |  ƒ | |  _ d  S)N)Úsuperr   Ú__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  j ƒ  d  S)N)r   Úpop)r   r   r   r   r   r   Ú__exit__   s    zContextDict.__exit__)r   r   r	   r   r   r   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 ‡  S)$ÚBaseContextNc             C   s   |  j  | ƒ d  S)N)Ú_reset_dicts)r   Údict_r   r   r   r   !   s    zBaseContext.__init__c             C   sJ   i d d 6d d 6d  d 6} | g |  _  | d  k	 rF |  j  j | ƒ n  d  S)NTÚTrueFÚFalseÚNone)r   r   )r   ÚvalueÚbuiltinsr   r   r   r   $   s    zBaseContext._reset_dictsc                s/   t  t t |  ƒ ƒ } |  j d  d  … | _ | S)N)r   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#   x t  |  j ƒ D] } | Vq Wd  S)N)Úreversedr   )r   Údr   r   r   Ú__iter__2   s    zBaseContext.__iter__c             O   s]   g  } xD | D]< } t  | t ƒ r< | | j d d  … 7} q | j | ƒ q Wt |  | | Ž S)Né   )Ú
isinstancer   r   r   r   )r   r   r   r   r'   r   r   r   Úpush6   s    zBaseContext.pushc             C   s+   t  |  j ƒ d k r t ‚ n  |  j j ƒ  S)Nr)   )Ú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 contextr)   Néÿÿÿÿ)r   )r   Úkeyr    r   r   r   Ú__setitem__D   s    zBaseContext.__setitem__c             C   s>   x+ t  |  j ƒ D] } | | k r | | Sq Wt | ƒ ‚ 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__H   s    zBaseContext.__getitem__c             C   s   |  j  d | =d S)z*Delete a variable from the current contextr)   Nr-   )r   )r   r.   r   r   r   Ú__delitem__O   s    zBaseContext.__delitem__c             C   s(   x! |  j  D] } | | k r
 d Sq
 Wd S)NTF)r   )r   r.   r'   r   r   r   Úhas_keyS   s    zBaseContext.has_keyc             C   s   |  j  | ƒ S)N)r3   )r   r.   r   r   r   Ú__contains__Y   s    zBaseContext.__contains__c             C   s2   x+ t  |  j ƒ D] } | | k r | | Sq W| S)N)r&   r   )r   r.   Ú	otherwiser'   r   r   r   Úget\   s    zBaseContext.getc             C   s/   y |  | SWn t  k
 r* | |  | <Yn X| S)N)r0   )r   r.   Údefaultr   r   r   Ú
setdefaultb   s
    zBaseContext.setdefaultc             C   s   t  |  ƒ } | j | ƒ | S)z|
        Returns 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  } x |  j  D] } | j | ƒ q W| S)z6
        Returns self.dicts as one dictionary
        )r   Úupdate)r   Zflatr'   r   r   r   Úflattenr   s    zBaseContext.flattenc             C   s)   t  | t ƒ r% |  j ƒ  | j ƒ  k Sd S)zO
        Compares two contexts by comparing theirs 'dicts' attributes.
        F)r*   r   r=   )r   Úotherr   r   r   Ú__eq__{   s    zBaseContext.__eq__)r   r   r	   r   r   r#   r%   r(   r+   r   r/   r1   r2   r3   r4   r6   r8   r;   r=   r?   r   r   )r   r   r       s"   			r   c                   s‹   e  Z d  Z d Z d d e d d ‡  f d d † Z e d d „  ƒ Z e d d	 „  ƒ Z e	 d
 d „  ƒ Z
 ‡  f d d †  Z d d „  Z ‡  S)ÚContextz&A stack container for variable contextNTc                s   | t  k	 r% t j d t d d ƒn  | |  _ | |  _ | |  _ | |  _ d |  _ t	 ƒ  |  _
 d  |  _ t t |  ƒ j | ƒ d  S)NzThe current_app argument of Context is deprecated. Use RequestContext and set the current_app attribute of its request instead.Ú
stacklevelé   Úunknown)Ú_current_app_undefinedÚwarningsÚwarnr   Ú
autoescapeÚ_current_appÚuse_l10nÚuse_tzZtemplate_nameÚRenderContextÚrender_contextÚtemplater   r@   r   )r   r   rG   Úcurrent_apprI   rJ   )r   r   r   r   Š   s    						zContext.__init__c             C   s   |  j  t k r d  S|  j  S)N)rH   rD   )r   r   r   r   rN      s    zContext.current_appc             C   s   |  j  t k	 S)N)rH   rD   )r   r   r   r   Úis_current_app_set¡   s    zContext.is_current_app_setc             c   sA   |  j  d  k	 r t d ƒ ‚ n  | |  _  z	 d  VWd  d  |  _  Xd  S)Nz&Context is already bound to a template)rM   ÚRuntimeError)r   rM   r   r   r   Úbind_template¥   s    		zContext.bind_templatec                s+   t  t |  ƒ j ƒ  } t |  j ƒ | _ | S)N)r   r@   r#   r   rL   )r   r"   )r   r   r   r#   ¯   s    zContext.__copy__c             C   sV   t  | d ƒ s t d ƒ ‚ n  t | t ƒ rI | j d d … j ƒ  } n  t |  | ƒ S)z=Pushes 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)r   r   r	   r
   rD   r   ÚpropertyrN   rO   r   rQ   r#   r<   r   r   )r   r   r@   ˆ   s   
r@   c               @   sI   e  Z d  Z d Z d d „  Z d d „  Z d d d „ Z d	 d
 „  Z d S)rK   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.
    c             c   s!   x |  j  d D] } | Vq Wd  S)Nr)   r-   )r   )r   r'   r   r   r   r(   Ì   s    zRenderContext.__iter__c             C   s   | |  j  d k S)Nr)   r-   )r   )r   r.   r   r   r   r3   Ð   s    zRenderContext.has_keyNc             C   s   |  j  d j | | ƒ S)Nr)   r-   )r   r6   )r   r.   r5   r   r   r   r6   Ó   s    zRenderContext.getc             C   s   |  j  d | S)Nr)   r-   )r   )r   r.   r   r   r   r1   Ö   s    zRenderContext.__getitem__)r   r   r	   r
   r(   r3   r6   r1   r   r   r   r   rK   ½   s
   rK   c                   s^   e  Z d  Z d Z d d e d d ‡  f d d † Z e d d „  ƒ Z d ‡  f d d † 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.
    Nc                sª   t  t |  ƒ j | d | d | ƒ| t k	 rG t j d t d d ƒn  | |  _ | |  _ | d  k rk f  n	 t	 | ƒ |  _
 t |  j ƒ |  _ |  j i  ƒ |  j i  ƒ d  S)NrI   rJ   zoThe current_app argument of RequestContext is deprecated. Set the current_app attribute of its request instead.rA   rB   )r   rV   r   rD   rE   rF   r   rH   ÚrequestÚtupleÚ_processorsr,   r   Ú_processors_indexr<   )r   rW   r   Ú
processorsrN   rI   rJ   )r   r   r   r   á   s    		!zRequestContext.__init__c             c   s¡   |  j  d  k	 r t d ƒ ‚ n  | |  _  | j j |  j } i  } x$ | D] } | j | |  j ƒ ƒ qG W| |  j |  j <z	 d  VWd  d  |  _  i  |  j |  j <Xd  S)Nz&Context is already bound to a template)	rM   rP   ZengineZtemplate_context_processorsrY   r<   rW   r   rZ   )r   rM   r[   ZupdatesÚ	processorr   r   r   rQ   ù   s    		
		zRequestContext.bind_templatec                s4   t  t |  ƒ j | ƒ } t | d ƒ r0 | ` n  | S)NrZ   )r   rV   r;   rR   rZ   )r   r9   r:   )r   r   r   r;     s    	zRequestContext.new)	r   r   r	   r
   rD   r   r   rQ   r;   r   r   )r   r   rV   Ú   s   rV   c             C   sG   | d k r t  |  ƒ }  n( |  } t | ƒ }  | rC |  j | ƒ n  |  S)zT
    Create a suitable Context from a plain dict and optionally an HttpRequest.
    N)r@   rV   r+   )r   rW   Zoriginal_contextr   r   r   Úmake_context  s    r]   )r   )rE   Ú
contextlibr   r   Zdjango.utils.deprecationr   Z_builtin_context_processorsÚobjectrD   Ú	Exceptionr   Údictr   r   r@   rK   rV   r]   r   r   r   r   Ú<module>   s   	h5=