o Úøaì"ã@sˆddlmZddlmZdZGdd„deƒZGdd„deƒZGdd „d ƒZGd d „d eƒZ Gd d „d eƒZ Gdd„de ƒZ ddd„Z dS)é)Úcontextmanager)Úcopy)z'django.template.context_processors.csrfc@seZdZdZdS)ÚContextPopExceptionz,pop() has been called more times than push()N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©r r ú9/usr/lib/python3/dist-packages/django/template/context.pyrsrcs,eZdZ‡fdd„Zdd„Zdd„Z‡ZS)Ú ContextDictcs(tƒj|i|¤Ž|j |¡||_dS©N)ÚsuperÚ__init__ÚdictsÚappendÚcontext)ÚselfrÚargsÚkwargs©Ú __class__r r rs  zContextDict.__init__cCs|Sr r ©rr r r Ú __enter__szContextDict.__enter__cOs|j ¡dSr )rÚpop)rrrr r r Ú__exit__ózContextDict.__exit__)rrrrrrÚ __classcell__r r rr r s r cs¦eZdZd$dd„Zd$dd„Z‡fdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zd$dd„Zd$dd„Zd$dd„Zd d!„Zd"d#„Z‡ZS)%Ú BaseContextNcCs| |¡dSr )Ú _reset_dicts)rÚdict_r r r rrzBaseContext.__init__cCs0ddddœ}|g|_|dur|j |¡dSdS)NTF)ÚTrueÚFalseÚNone)rr)rÚvalueÚbuiltinsr r r rs ÿzBaseContext._reset_dictscsttƒƒ}|jdd…|_|Sr )rr r©rÚ duplicaterr r Ú__copy__%s zBaseContext.__copy__cCó t|jƒSr )Úreprrrr r r Ú__repr__*ó zBaseContext.__repr__cCr(r ©Úreversedrrr r r Ú__iter__-r+zBaseContext.__iter__cOsLg}|D]}t|tƒr||jdd…7}q| |¡qt|g|¢Ri|¤ŽS©Né)Ú isinstancerrrr )rrrrÚdr r r Úpush0s   zBaseContext.pushcCst|jƒdkr t‚|j ¡Sr/)Úlenrrrrr r r r9s zBaseContext.popcCs||jd|<dS)z%Set a variable in the current contextéÿÿÿÿN©r)rÚkeyr#r r r Ú __setitem__>szBaseContext.__setitem__cCs6|jd}t|jƒD] }||vr|}nq |||<dS)z| Set a variable in one of the higher contexts if it exists there, otherwise in the current context. r5N)rr-)rr7r#rr2r r r Ú set_upwardBs þ zBaseContext.set_upwardcCs,t|jƒD] }||vr||Sqt|ƒ‚)zHGet a variable's value, starting at the current context and going upward)r-rÚKeyError)rr7r2r r r Ú __getitem__Ns  ÿzBaseContext.__getitem__cCs|jd|=dS)z*Delete a variable from the current contextr5Nr6©rr7r r r Ú __delitem__UszBaseContext.__delitem__cst‡fdd„|jDƒƒS)Nc3s|]}ˆ|vVqdSr r )Ú.0r2©r7r r Ú Zs€z+BaseContext.__contains__..)Úanyrr<r r?r Ú __contains__YszBaseContext.__contains__cCs(t|jƒD] }||vr||Sq|Sr r,)rr7Ú otherwiser2r r r Úget\s  ÿzBaseContext.getcCs(z||WSty|||<Y|Swr )r:)rr7Údefaultr r r Ú setdefaultbs    þzBaseContext.setdefaultcCst|ƒ}| |¡|S)z{ Return a new context with the same properties, but with only the values given in 'values' stored. )rr©rÚvaluesÚ new_contextr r r Únewis zBaseContext.newcCsi}|jD]}| |¡q|S)z6 Return self.dicts as one dictionary. )rÚupdate)rÚflatr2r r r Úflattenrs  zBaseContext.flattencCst|tƒstS| ¡| ¡kS)zN Compare two contexts by comparing theirs 'dicts' attributes. )r1rÚNotImplementedrM)rÚotherr r r Ú__eq__{s zBaseContext.__eq__r )rrrrrr'r*r.r3rr8r9r;r=rBrDrFrJrMrPrr r rr rs$          rcsBeZdZdZd ‡fdd„ Zedd„ƒZ‡fdd „Zd d „Z‡Z S) ÚContextz&A stack container for variable contextNTcs6||_||_||_d|_tƒ|_d|_tƒ |¡dS)NÚunknown) Ú autoescapeÚuse_l10nÚuse_tzÚ template_nameÚ RenderContextÚrender_contextÚtemplater r)rrrSrTrUrr r r‡szContext.__init__ccs6|jdur tdƒ‚||_z dVWd|_dSd|_w©Nz&Context is already bound to a template)rYÚ RuntimeError)rrYr r r Ú bind_template’s€ zContext.bind_templatecstƒ ¡}t|jƒ|_|Sr )r r'rrXr%rr r r'œs  zContext.__copy__cCs8t|dƒs tdƒ‚t|tƒr|jdd… ¡}t||ƒS)z;Push other_dict to the stack of dictionaries in the Contextr;z6other_dict must be a mapping (dictionary-like) object.r0N)ÚhasattrÚ TypeErrorr1rrrr )rÚ other_dictr r r rK¡s   zContext.update)NTNN) rrrrrrr\r'rKrr r rr rQ…s  rQc@sDeZdZdZdZdd„Zdd„Zddd„Zd d „Ze dd d „ƒZ dS)rWaÈ 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. Nccs|jdEdHdS©Nr5r6rr r r r.»s€zRenderContext.__iter__cCs||jdvSr`r6r<r r r rB¾rzRenderContext.__contains__cCs|jd ||¡Sr`)rrD)rr7rCr r r rDÁszRenderContext.getcCs|jd|Sr`r6r<r r r r;ÄrzRenderContext.__getitem__TccsT|j}||_|r | ¡zdVW||_|r| ¡dSdS||_|r)| ¡wwr )rYr3r)rrYÚisolated_contextÚinitialr r r Ú push_stateÇs€ ÿÿ ÿzRenderContext.push_stater )T) rrrrrYr.rBrDr;rrcr r r r rWªs rWcs<eZdZdZd ‡fdd„ Zedd„ƒZd ‡fdd „ Z‡ZS) Ú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. NTcsTtƒj||||d||_|durdnt|ƒ|_t|jƒ|_| i¡| i¡dS)N)rTrUrSr ) r rÚrequestÚtupleÚ _processorsr4rÚ_processors_indexrK)rrerÚ processorsrTrUrSrr r rÜs   zRequestContext.__init__c cs†|jdur tdƒ‚||_|jj|j}i}|D] }| ||jƒ¡q||j|j<zdVWd|_i|j|j<dSd|_i|j|j<wrZ) rYr[ÚengineÚtemplate_context_processorsrgrKrerrh)rrYriÚupdatesÚ processorr r r r\és"€ ÿ þzRequestContext.bind_templatecstƒ |¡}t|dƒr |`|S)Nrh)r rJr]rhrGrr r rJþs  zRequestContext.new)NNNNTr ) rrrrrrr\rJrr r rr rdÕs  rdNcKsd|durt|tƒstd|jjƒ‚|durt|fi|¤Ž}|S|}t|fi|¤Ž}|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^rrrQrdr3)rrerÚoriginal_contextr r r Ú make_contextsü rpr ) Ú contextlibrrÚ_builtin_context_processorsÚ Exceptionrrnr rrQrWrdrpr r r r Ús j%+2