ϪfddlZddlmZmZmZmZmZmZmZm Z ddl m Z ddl m Z mZmZddlmZmZmZerddlmZmZedZeded ef ZGd d Zd ed efdefdZeddZe eGddZy)N) TYPE_CHECKINGAnyCallableListOptionalTypeVarUnionoverload) implementer)MissingRenderMethodMissingTemplateLoaderUnexposedMethodError) IRenderableIRequestITemplateLoader) FlattenableTagT_Tc.)boundc eZdZdZdededefdefdZeZe dede dede ffd Z e dede d e deede fe ffd Z efdede d edefd Z y )Exposea/ Helper for exposing methods for various uses using a simple decorator-style callable. Instances of this class can be called with one or more functions as positional arguments. The names of these functions will be added to a list on the class object of which they are methods. ffuncObjs.returnctj|g|D]-}t|dg}|j|t |d|/|S)a; Add one or more functions to the set of exposed functions. This is a way to declare something about a class definition, similar to L{zope.interface.implementer}. Use it like this:: magic = Expose('perform extra magic') class Foo(Bar): def twiddle(self, x, y): ... def frob(self, a, b): ... magic(twiddle, frob) Later you can query the object:: aFoo = Foo() magic.get(aFoo, 'twiddle')(x=1, y=2) The call to C{get} will fail if the name it is given has not been exposed using C{magic}. @param funcObjs: One or more function objects which will be exposed to the client. @return: The first of C{funcObjs}. exposedThrough) itertoolschaingetattrappendsetattr)selfrrfObjrs 6/usr/lib/python3/dist-packages/twisted/web/_element.py__call__zExpose.__call__,sQ8OOQC2  ~ %$//)*4<<N r'N)__name__ __module__ __qualname____doc__rrobjectr&r1r strrr-rr r,r'r%rr"s # Xc6k-B s DJ  F  c8J    ,/ :; xS!1$ %  DN,/:@ r'rthunkrc<t}|j|_|Sr+)rr6)r9exposes r%exposerr<os XF]]FN Mr'cy)a Decorate with L{renderer} to use methods as template render directives. For example:: class Foo(Element): @renderer def twiddle(self, request, tag): return tag('Hello, world.')
Will result in this final output::
Hello, world.
Nr,r,r'r%rendererr>usr'cteZdZUdZdZeeed<d deefdZde de ee dgdffd Z d ee ddfd Z y) Elementa Base for classes which can render part of a page. An Element is a renderer that can be embedded in a stan document and can hook its template (from the loader) up to render methods. An Element might be used to encapsulate the rendering of a complex piece of data which is to be displayed in multiple different contexts. The Element allows the rendering logic to be easily re-used in different ways. Element returns render methods which are registered using L{twisted.web._element.renderer}. For example:: class Menu(Element): @renderer def items(self, request, tag): .... Render methods are invoked with two arguments: first, the L{twisted.web.http.Request} being served and second, the tag object which "invoked" the render method. @ivar loader: The factory which will be used to load documents to return from C{render}. Nloaderc|||_yyr+)rA)r#rAs r%__init__zElement.__init__s   DK r'namerrrcPtj||d}| t|||S)z= Look up and return the named render method. N)r>r-r )r#rDr2s r%lookupRenderMethodzElement.lookupRenderMethods- dD$/ >%dD1 1 r'requestcT|j}| t||jS)a Implement L{IRenderable} to allow one L{Element} to be embedded in another's template or rendering output. (This will simply load the template from the C{loader}; when used in a template, the flattening engine will keep track of this object separately as the object to lookup renderers on and call L{Element.renderer} to look them up. The resulting object from this method is not directly associated with this L{Element}.) )rAr load)r#rGrAs r%renderzElement.renders) >'- -{{}r'r+)r3r4r5r6rArr__annotations__rCr8rrrFrJr,r'r%r@r@sj4)-FH_ %,!x8!   8H%u-}< = hx0]r'r@)rN)rtypingrrrrrrr r zope.interfacer twisted.web.errorr r rtwisted.web.iwebrrrtwisted.web.templaterrrr7rrr<r>r@r,r'r%rQs    ' DC5 CL e8CK01JJZ8CK(V   . [:::r'