
    Yf                     L   d dl Z d dlmZmZmZmZmZmZmZm	Z	 d dl
mZ d dlmZmZmZ d dlmZmZmZ erd dlmZmZ  ed          Z eded	ef         
          Z G d d          Zded	ef         defdZedd            Z ee           G d d                      ZdS )    N)TYPE_CHECKINGAnyCallableListOptionalTypeVarUnionoverload)implementer)MissingRenderMethodMissingTemplateLoaderUnexposedMethodError)IRenderableIRequestITemplateLoader)FlattenableTagT_Tc.)boundc                       e Zd ZdZdededef         defdZ e            Ze	dede
dedef         fd	            Ze	dede
d
edeedef         ef         fd            Zefdede
d
edefdZdS )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.
    ffuncObjs.returnc                    t          j        |g|          D ]9}t          |dg           }|                    |            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)	itertoolschaingetattrappendsetattr)selfr   r   fObjr   s        F/var/www/html/env/lib/python3.11/site-packages/twisted/web/_element.py__call__zExpose.__call__,   sb    8 OQC22 	< 	<D+249I2+N+NN!!$'''D*N;;;;    instance
methodNamec                     d S N )r#   r(   r)   s      r%   getz
Expose.getP   s    r'   defaultc                     d S r+   r,   )r#   r(   r)   r.   s       r%   r-   z
Expose.getT   s	     	r'   c                     t          ||d          }t          |dg           }| |vr|| j        u rt          | |          |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#   r(   r)   r.   methodr   s         r%   r-   z
Expose.getZ   sY     :t44 )92>>~%%$/))*4<<<Nr'   N)__name__
__module____qualname____doc__r   r   objectr&   r1   r
   strr   r-   r   r	   r,   r'   r%   r   r   "   s-         #  Xc6k-B  s        D JF  c8J    X ,/:;	xS!1$	%   X DN ,/:@	     r'   r   thunkr   c                 :    t                      }| j        |_        |S r+   )r   r6   )r9   exposes     r%   exposerr<   o   s    XXF]FNMr'   c                      dS )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%   rendererr>   u   s      r'   c                       e Zd ZU dZdZee         ed<   ddee         fdZde	de
ee         dgdf         fd	Zd
ee         ddfdZdS )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}.
    Nloaderc                     |	|| _         d S d S r+   )rA   )r#   rA   s     r%   __init__zElement.__init__   s     DKKK r'   namer   r   r   c                 b    t                               | |d          }|t          | |          |S )z=
        Look up and return the named render method.
        N)r>   r-   r   )r#   rD   r2   s      r%   lookupRenderMethodzElement.lookupRenderMethod   s3     dD$//>%dD111r'   requestc                 Z    | j         }|t          |           |                                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}.)
        )rA   r   load)r#   rG   rA   s      r%   renderzElement.render   s,     >'---{{}}r'   r+   )r3   r4   r5   r6   rA   r   r   __annotations__rC   r8   r   r   rF   rJ   r,   r'   r%   r@   r@      s          4 )-FH_%,,,! !x8 ! ! ! !			8H%u-}<	=	 	 	 	hx0 ]      r'   r@   )r   N)r   typingr   r   r   r   r   r   r	   r
   zope.interfacer   twisted.web.errorr   r   r   twisted.web.iwebr   r   r   twisted.web.templater   r   r   r7   r   r   r<   r>   r@   r,   r'   r%   <module>rQ      s  
    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ' & & & & &         
 D C C C C C C C C C 655555555 GCLLge8CK0111J J J J J J J JZ8CK( V     	   	. [: : : : : : : : : :r'   