o a"@sddlmZddlmZdZGdddeZGdddeZGdd d ZGd d d eZ Gd d d eZ Gddde Z dddZ 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,eZdZfddZddZddZZS) ContextDictcs(tj|i||j|||_dSN)super__init__dictsappendcontext)selfrargskwargs __class__r r rs  zContextDict.__init__cCs|Sr r rr r r __enter__szContextDict.__enter__cOs|jdSr )rpop)rrrr r r __exit__zContextDict.__exit__)rrrrrr __classcell__r r rr r s r cseZdZd$ddZd$ddZfddZdd Zd d Zd d ZddZ ddZ ddZ ddZ ddZ ddZd$ddZd$ddZd$ddZd d!Zd"d#ZZS)% BaseContextNcCs||dSr ) _reset_dicts)rdict_r r r rrzBaseContext.__init__cCs0dddd}|g|_|dur|j|dSdS)NTF)TrueFalseNone)rr)rvaluebuiltinsr r r rs zBaseContext._reset_dictscstt}|jdd|_|Sr )rr rr duplicaterr r __copy__%s zBaseContext.__copy__cC t|jSr )reprrrr r r __repr__* zBaseContext.__repr__cCr(r reversedrrr r r __iter__-r+zBaseContext.__iter__cOsLg}|D]}t|tr||jdd7}q||qt|g|Ri|SN) isinstancerrrr )rrrrdr r r push0s   zBaseContext.pushcCst|jdkr t|jSr/)lenrrrrr r r r9s zBaseContext.popcCs||jd|<dS)z%Set a variable in the current contextNr)rkeyr#r r r __setitem__>szBaseContext.__setitem__cCs6|jd}t|jD] }||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|jD] }||vr||Sqt|)zHGet a variable's value, starting at the current context and going upward)r-rKeyError)rr7r2r r r __getitem__Ns  zBaseContext.__getitem__cCs|jd|=dS)z*Delete a variable from the current contextr5Nr6rr7r r r __delitem__UszBaseContext.__delitem__cstfdd|jDS)Nc3s|]}|vVqdSr r ).0r2r7r r Zsz+BaseContext.__contains__..)anyrr<r r?r __contains__YszBaseContext.__contains__cCs(t|jD] }||vr||Sq|Sr r,)rr7 otherwiser2r r r get\s  zBaseContext.getcCs(z||WSty|||<Y|Swr )r:)rr7defaultr r r setdefaultbs    zBaseContext.setdefaultcCst|}|||S)z{ Return a new context with the same properties, but with only the values given in 'values' stored. )rrrvalues new_contextr r r newis zBaseContext.newcCsi}|jD]}||q|S)z6 Return self.dicts as one dictionary. )rupdate)rflatr2r r r flattenrs  zBaseContext.flattencCst|tstS||kS)zN Compare two contexts by comparing theirs 'dicts' attributes. )r1rNotImplementedrM)rotherr r r __eq__{s zBaseContext.__eq__r )rrrrrr'r*r.r3rr8r9r;r=rBrDrFrJrMrPrr r rr rs$          rcsBeZdZdZd fdd ZeddZfdd Zd d ZZ S) Contextz&A stack container for variable contextNTcs6||_||_||_d|_t|_d|_t|dS)Nunknown) autoescapeuse_l10nuse_tz template_name RenderContextrender_contexttemplater r)rrrSrTrUrr r rszContext.__init__ccs6|jdur td||_z dVWd|_dSd|_wNz&Context is already bound to a template)rY RuntimeError)rrYr r r bind_templates zContext.bind_templatecst}t|j|_|Sr )r r'rrXr%rr r r's  zContext.__copy__cCs8t|ds tdt|tr|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 rKs   zContext.update)NTNN) rrrrrrr\r'rKrr r rr rQs  rQc@sDeZdZdZdZddZddZdddZd 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|jdEdHdSNr5r6rr r r r.szRenderContext.__iter__cCs||jdvSr`r6r<r r r rBrzRenderContext.__contains__cCs|jd||Sr`)rrD)rr7rCr r r rDszRenderContext.getcCs|jd|Sr`r6r<r r r r;rzRenderContext.__getitem__TccsT|j}||_|r |zdVW||_|r|dSdS||_|r)|wwr )rYr3r)rrYisolated_contextinitialr r r push_states  zRenderContext.push_stater )T) rrrrrYr.rBrDr;rrcr r r r rWs rWcs<eZdZdZd fdd ZeddZd fdd ZZS) 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. NTcsTtj||||d||_|durdnt||_t|j|_|i|idS)N)rTrUrSr ) r rrequesttuple _processorsr4r_processors_indexrK)rrer processorsrTrUrSrr r rs   zRequestContext.__init__c cs|jdur td||_|jj|j}i}|D] }|||jq||j|j<zdVWd|_i|j|j<dSd|_i|j|j<wrZ) rYr[enginetemplate_context_processorsrgrKrerrh)rrYriupdates processorr r r r\s"  zRequestContext.bind_templatecst|}t|dr |`|S)Nrh)r rJr]rhrGrr r rJs  zRequestContext.new)NNNNTr ) rrrrrrr\rJrr r rr rds  rdNcKsd|durt|tstd|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.)r1dictr^rrrQrdr3)rreroriginal_contextr r r make_contexts rpr ) contextlibrr_builtin_context_processors Exceptionrrnr rrQrWrdrpr r r r s j%+2