m &Ec@sMdZdkZdklZdklZdklZdkl Z l Z dk l Z l Z lZdk lZlZlZdklZd klZd klZd klZdkZdkZd klZd kl Z dk!l"Z"l#Z#dk$l%Z%dk&l'Z'dk(l)Z)dk*l+Z+dk,l-Z-e'i.Z/ei0dZ1dk2Zdk2l3Z3ei4i5d-dee"e#fZ6dZ7dZ8de fdYZ9d efd!YZ:d"e fd#YZ;d$ei<i=i>i?fd%YZ?d&e fd'YZ@d(e@fd)YZAd*ZBd+ZCeBZDd,ZEdS(.sPage Template Expression Engine Page Template-specific implementation of TALES, with handlers for Python expressions, string literals, and paths. $Id: Expressions.py 71799 2007-01-08 13:18:19Z philikon $ N(s getUtility(sComponentLookupError(s implements(sContextsIterator(sPathExprs StringExprsNotExpr(s DeferExprs SubPathExprsUndefs(s PythonExpr(s ITraversable(straversePathElement(sremoveAllProxies(s MultiMapping(saq_base(sNotFounds Unauthorized(sZ2ProviderExpression(s ZRPythonExpr(sLazyExpr(sgetGlobalTranslationService(s IUnicodeEncodingConflictResolvert Expressions(s deprecatet StringExprtNotExprtPathExprt SubPathExprtUndefsseZope 2 uses the Zope 3 ZPT engine now. Expression types can be imported from zope.tales.expressions.cCst|dd}t|}|ixY|oQ|i}t i i i |o|i|}q+t|||d|}q+W|S(sTraverses a sequence of names, first trying attributes then items. This uses Zope 3 path traversal where possible and interacts correctly with objects providing OFS.interface.ITraversable when necessary (bobo-awareness). trequestN(tgetattrtecontexttNoneRtlistt path_itemstreversetpoptnametOFSt interfacest ITraversablet providedBytobjecttrestrictedTraversettraversePathElement(RR RRR((tA/data/zmath/zope/lib/python/Products/PageTemplates/Expressions.pytboboAwareZopeTraverseBs    cCst|doti|i|}nt|}t|}t |ooy9t |ddoti||d}n |}Wqt j o#}t |djoqqXn|S(soCalls the object, possibly a document template, or just returns it if not callable. (From DT_Util.py) t__render_with_namespace__t isDocTempiit__call__N(thasattrtobt ZRPythonExprt call_with_nsRtnstaq_basetbasetremoveAllProxiestcallableRtAttributeErrortntstr(RRR%R!((RtrenderVs    t ZopePathExprcBs#tZdZdZdZRS(NcCs:|ip d}ntt|i|||tdS(Ntnothing( texprtstriptsuperR(tselft__init__RtengineR(R-RR*R/((RR.os  cCsxa|id D]-}y||}Wntj oqXPqW|id|}|io|Sn|idjo|Snt||i S(Nitnocall( R-t _subexprsR*RRt ZopeUndefst_hybridt_nameR'tvars(R-RR*R((Rt_evalxs cCs@x9|iD].}y||Wntj oq XdSq WdS(Nii(R-R1R*RR2(R-RR*((Rt_existss (t__name__t __module__R.R6R7(((RR(ms t SafeMappingcBs0tZdZeZeZZeiZ eiZ RS(s3Mapping with security declarations and limited method exposure. Since it subclasses MultiMapping, this class can be used to wrap one or more mapping objects. Restricted Python code will not be able to mutate the SafeMapping or the wrapped mappings, but will be able to read any value. ( R8R9t__doc__tTruet*__allow_access_to_unprotected_subobjects__R tpushR t MultiMappingt_pusht_pop(((RR:s   t ZopeContextcBs5tZdZddddZdZdZRS(NcCsUtt|i|||idt|i|i |_ }|g|_ dS(Ntrepeat( R,RBR-R.R/tcontextst setContextR:t repeat_varstcopyR5t _vars_stack(R-R/RDR5((RR.sc Cs7|iid}ti||d|d|d|S(Ntcontexttmappingtdefault( R-RDtgetRItgetGlobalTranslationServicet translatetdomaintmsgidRJRK(R-RPRORJRKRI((RRNscCs4|i|}||ijo|Snt|S(N(R-tevaluateR*tvaluet getDefaulttbool(R-R*RR((RtevaluateBooleanscCs |i|}||ijp |djo|Snt|to|Snt|toyt t }Wnt j ot|SnXy|i |id||SWq tj o?}tid||i||idid|fq Xn t|SdS(s_ customized version in order to get rid of unicode errors for all and ever RIstUnicodeDecodeError detected for expression "%s" Resolver class: %s Exception text: %s Template: %s Rendered text: %rttemplateiN(R-RQR*ttextRSR t isinstancetunicodeR&t getUtilityt IUnicodeEncodingConflictResolvertresolvertComponentLookupErrortresolveRDtUnicodeDecodeErrortetLOGterrort __class__t absolute_url(R-R*R`R\RW((Rt evaluateTexts" 3 (R8R9R.R RNRURe(((RRBs  t ZopeEnginecBstZeZRS(N(R8R9RBt_create_context(((RRfst ZopeIteratorcBstZeZedZedZedZedZee ddZ ddZ ddZ d Zd ZRS( NcCstt|iS(N(R,RhR-tindex(R-((RRiscCstt|iS(N(R,RhR-tstart(R-((RRjscCstt|iS(N(R,RhR-tend(R-((RRkscCstt|iS(N(R,RhR-titem(R-((RRl sslThe 'nextIndex' method has been deprecated and will disappear in Zope 2.12. Use 'iterator.index+1' instead.cCs |idS(Ni(R-Ri(R-((Rt nextIndexscCs,|iotSn|i||i|i S(N(R-RjR<t same_partRt _last_itemRl(R-R((Rtfirsts cCs,|iotSn|i||i|i S(N(R-RkR<RnRRlt_next(R-R((Rtlast!s cCsW|djo||jSnt}t|||t|||jo |j nS(N(RR tob1tob2RtnoR(R-RRsRtRu((RRn&s  cCs3|idjo|i|_ntt|iS(Ni(R-t _nextIndexRlRoR,Rhtnext(R-((RRw-s(R8R9R<R=tpropertyRiRjRkRlt deprecateRmR RpRrRnRw(((RRhs    t PathIteratorcBs*tZdZeedZdZRS(sXA TALES Iterator with the ability to use first() and last() on subpaths of elements.cCsV|djo<t||}|}|p d}ng|(||Snt||S(NRpRr(sfirstslast(RRR-tmethodt furtherPathR (R-RR|R{((Rttraverse9s  cCs|djo||jSnt|to|id}ny(t||d}t||d}Wntj o t SnX||jS(Nt/( RR RsRtRXt basestringtsplitRR2tFalse(R-RRsRt((RRnFs  (R8R9R;t implementsRR}Rn(((RRz2s   cCst}t|_x!tiD]}|i|tqW|idt|idt i |idt |idt |idt |idt|idt|S(Ntstringtpythontnottdefertlazytprovidertmodules(RfR`RztiteratorFactoryR(t_default_type_namestptt registerTypeRRt PythonExprRt DeferExprtLazyExprtZ2ProviderExpressiontregisterBaseNametSecureModuleImporter(RR`((RtcreateZopeEngineRs   cCst}t|id<|S(NR(RR`Rttypes(R`((RtcreateTrustedZopeEngine`s  cCstS(N(t_engine(((Rt getEnginehs(s StringExprsNotExprsPathExprs SubPathExprsUndefs(FR;tloggingtzope.componentRZtzope.component.interfacesR]tzope.interfaceRtzope.tales.talestContexttIteratortzope.tales.expressionsRRRRRRtzope.tales.pythonexprRtzope.traversing.interfacesRtzope.traversing.adaptersRt zope.proxyR"tzope.app.pagetemplate.enginetzopetOFS.interfacesRR?t AcquisitionR t zExceptionstNotFoundt Unauthorizedt(Products.Five.browser.providerexpressionRtProducts.PageTemplatesRt Products.PageTemplates.DeferExprRt/Products.PageTemplates.GlobalTranslationServiceRMt!Products.PageTemplates.interfacesR[t_SecureModuleImporterRt getLoggerRatzope.deprecationRyt deprecationt deprecatedR2RR'R(R:RBtappt pagetemplateR/RfRhRzRRRR(+R:RaR'RR[R?RZRRRhRfR(RRRRRBRRRRRR]R RRRRRRRyRRR"RRRRRRRzRMR2((Rt?sP                        ,H"?