HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/web/__pycache__/_element.cpython-38.pyc
U


W[;�@s�ddlmZmZddlmZddlmZddlmZm	Z	ddlm
Z
Gdd�de�Zej
Zedd	��Zee�Gd
d�de��ZdS)
�)�division�absolute_import)�implementer)�IRenderable)�MissingRenderMethod�UnexposedMethodError)�MissingTemplateLoaderc@s@eZdZdZddd�Zdd�Ze�Zefdd�Ze	d	d
��Z
dS)�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.

    @ivar attributeName: The attribute with which exposed methods will be
    tracked.
    NcCs
||_dS�N)�doc)�selfr�r
�6/usr/lib/python3/dist-packages/twisted/web/_element.py�__init__szExpose.__init__cGs8|std��|D]}t|dg�|_|j�|�q|dS)aH
        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.declarations.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}.
        z,expose() takes at least 1 argument (0 given)�exposedThroughr)�	TypeError�getattrr�append)rZfuncObjsZfObjr
r
r�__call__szExpose.__call__cCs<t||d�}t|dg�}||kr8||jkr4t||��|S|S)aB
        Retrieve an exposed method with the given name from the given instance.

        @raise UnexposedMethodError: Raised if C{default} is not specified and
        there is no exposed method with the given name.

        @return: A callable object for the named method assigned to the given
        instance.
        Nr)r�
_nodefaultr)r�instanceZ
methodName�default�methodrr
r
r�getCs


z
Expose.getcCs
||j�S)a
        Slight hack to make users of this class appear to have a docstring to
        documentation generators, by defining them with a decorator.  (This hack
        should be removed when epydoc can be convinced to use some other method
        for documenting.)
        )�__doc__)�clsZthunkr
r
r�_withDocumentationVszExpose._withDocumentation)N)�__name__�
__module__�__qualname__rrr�objectrr�classmethodrr
r
r
rr	s
$r	cCsdS)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.')

        <div xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">
            <span t:render="twiddle" />
        </div>

    Will result in this final output::

        <div>
            <span>Hello, world.</span>
        </div>
    Nr
r
r
r
r�rendereresr"c@s.eZdZdZdZd	dd�Zdd�Zdd�ZdS)
�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.

    @type loader: L{ITemplateLoader} provider
    @ivar loader: The factory which will be used to load documents to
        return from C{render}.
    NcCs|dk	r||_dSr
)�loader)rr$r
r
rr�szElement.__init__cCs$t�||d�}|dkr t||��|S)z=
        Look up and return the named render method.
        N)r"rr)r�namerr
r
r�lookupRenderMethod�s
zElement.lookupRenderMethodcCs|j}|dkrt|��|��S)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}.)
        N)r$r�load)rZrequestr$r
r
r�render�szElement.render)N)rrrrr$rr&r(r
r
r
rr#~s


r#N)Z
__future__rrZzope.interfacerZtwisted.web.iwebrZtwisted.web.errorrrrr r	rZexposerr"r#r
r
r
r�<module>sU