Spamworldpro Mini Shell
Spamworldpro


Server : Apache/2.4.52 (Ubuntu)
System : Linux webserver 6.8.0-49-generic #49~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Nov 6 17:42:15 UTC 2 x86_64
User : www-data ( 33)
PHP Version : 8.1.2-1ubuntu2.21
Disable Function : NONE
Directory :  /lib/python3/dist-packages/twisted/web/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/twisted/web/__pycache__/resource.cpython-310.pyc
o

�b5�@s�dZgd�ZddlZddlmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZdd	lmZGd
d�de�Zdd
�Zee�Gdd�d��Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zee�Gdd�de
e���ZdS)z4
Implementation of the lowest-level Resource class.
)�	IResource�getChildForRequest�Resource�	ErrorPage�
NoResource�ForbiddenResource�EncodingResourceWrapper�N)�	Attribute�	Interface�implementer)�nativeString)�proxyForInterface)�prefixedMethodNames)�	FORBIDDEN�	NOT_FOUND)�UnsupportedMethodc@s0eZdZdZed�Zdd�Zdd�Zdd�Zd	S)
rz
    A web resource.
    z�
        Signal if this IResource implementor is a "leaf node" or not. If True,
        getChildWithDefault will not be called on this Resource.
        cC�dS)a
        Return a child with the given name for the given request.
        This is the external interface used by the Resource publishing
        machinery. If implementing IResource without subclassing
        Resource, it must be provided. However, if subclassing Resource,
        getChild overridden instead.

        @param name: A single path component from a requested URL.  For example,
            a request for I{http://example.com/foo/bar} will result in calls to
            this method with C{b"foo"} and C{b"bar"} as values for this
            argument.
        @type name: C{bytes}

        @param request: A representation of all of the information about the
            request that is being made for this child.
        @type request: L{twisted.web.server.Request}
        N�)�name�requestrr�6/usr/lib/python3/dist-packages/twisted/web/resource.py�getChildWithDefault+�zIResource.getChildWithDefaultcCr)a�
        Put a child IResource implementor at the given path.

        @param path: A single path component, to be interpreted relative to the
            path this resource is found at, at which to put the given child.
            For example, if resource A can be found at I{http://example.com/foo}
            then a call like C{A.putChild(b"bar", B)} will make resource B
            available at I{http://example.com/foo/bar}.
        @type path: C{bytes}
        Nr)�path�childrrr�putChild>rzIResource.putChildcCr)ap
        Render a request. This is called on the leaf resource for a request.

        @return: Either C{server.NOT_DONE_YET} to indicate an asynchronous or a
            C{bytes} instance to write as the response to the request.  If
            C{NOT_DONE_YET} is returned, at some point later (for example, in a
            Deferred callback) call C{request.write(b"<html>")} to write data to
            the request, and C{request.finish()} to send the data to the
            browser.

        @raise twisted.web.error.UnsupportedMethod: If the HTTP verb
            requested is not supported by this resource.
        Nr�rrrr�renderJrzIResource.renderN)	�__name__�
__module__�__qualname__�__doc__r	�isLeafrrrrrrrrs�rcCs@|jr|js|j�d�}|j�|�|�||�}|jr|jr|S)zE
    Traverse resource tree to find who will handle the request.
    r)�postpathr"�pop�prepath�appendr)�resourcer�pathElementrrrrZs�rc@s�eZdZdZeZdZdd�ZdZdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
d&dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdS)'rz�
    Define a web-accessible resource.

    This serves 2 main purposes; one is to provide a standard representation
    for what HTTP specification calls an 'entity', and the other is to provide
    an abstract directory structure for URL retrieval.
    NcCs
i|_dS)z
        Initialize.
        N��children��selfrrr�__init__ss
zResource.__init__rcC�t|j���S�N)�listr*�keysr+rrr�listStaticNames}�zResource.listStaticNamescCr.r/)r0r*�itemsr+rrr�listStaticEntities�r3zResource.listStaticEntitiescC�t|���|��Sr/)r0r2�listDynamicNamesr+rrr�	listNames��zResource.listNamescCr6r/)r0r5�listDynamicEntitiesr+rrr�listEntities�r9zResource.listEntitiescC�gSr/rr+rrrr7��zResource.listDynamicNamescCr<r/r�r,rrrrr:�r=zResource.listDynamicEntitiescCs|j�|�Sr/)r*�get�r,rrrr�getStaticEntity��zResource.getStaticEntitycCs||jvr|�||�SdSr/�r*�getChild)r,rrrrr�getDynamicEntity�s
zResource.getDynamicEntitycCs|j|=dSr/r)r@rrr�	delEntity�rBzResource.delEntitycCs||j|<dSr/r))r,r�entityrrr�reallyPutEntity�r3zResource.reallyPutEntitycCstd�S)a<
        Retrieve a 'child' resource from me.

        Implement this to create dynamic resource generation -- resources which
        are always available may be registered with self.putChild().

        This will not be called if the class-level variable 'isLeaf' is set in
        your subclass; instead, the 'postpath' attribute of the request will be
        left as a list of the remaining path elements.

        For example, the URL /foo/bar/baz will normally be::

          | site.resource.getChild('foo').getChild('bar').getChild('baz').

        However, if the resource returned by 'bar' has isLeaf set to true, then
        the getChild call will never be made on it.

        Parameters and return value have the same meaning and requirements as
        those defined by L{IResource.getChildWithDefault}.
        zNo such child resource.)r�r,rrrrrrD�szResource.getChildcCs ||jvr
|j|S|�||�S)a�
        Retrieve a static or dynamically generated child resource from me.

        First checks if a resource was added manually by putChild, and then
        call getChild to check for dynamic resources. Only override if you want
        to affect behaviour of all child lookups, rather than just dynamic
        ones.

        This will check to see if I have a pre-registered child resource of the
        given name, and call getChild if I do not.

        @see: L{IResource.getChildWithDefault}
        rCrIrrrr�s

zResource.getChildWithDefaultcCst�dtd�t||�S)Nz+Please use module level getChildForRequest.�)�warnings�warn�DeprecationWarningrr>rrrr�s�
zResource.getChildForRequestcCs:t|t�stjd�t|��tdd�||j|<|j|_dS)a�
        Register a static child.

        You almost certainly don't want '/' in your path. If you
        intended to have the root of a folder, e.g. /foo/, you want
        path to be ''.

        @param path: A single path component.
        @type path: L{bytes}

        @param child: The child resource to register.
        @type child: L{IResource}

        @see: L{IResource.putChild}
        zcPath segment must be bytes; passing {} has never worked, and will raise an exception in the future.rJ)�category�
stacklevelN)	�
isinstance�bytesrKrL�format�typerMr*�server)r,rrrrrr�s

�
zResource.putChildcCsTt|dt|j�d�}|s&z|j}Wt|��ty%t|�}Yt|��w||�S)aF
        Render a given resource. See L{IResource}'s render method.

        I delegate to methods of self with the form 'render_METHOD'
        where METHOD is the HTTP that was used to make the
        request. Examples: render_GET, render_HEAD, render_POST, and
        so on. Generally you should implement those methods instead of
        overriding this one.

        render_METHOD methods are expected to return a byte string which will be
        the rendered page, unless the return value is C{server.NOT_DONE_YET}, in
        which case it is this class's responsibility to write the results using
        C{request.write(data)} and then call C{request.finish()}.

        Old code that overrides render() directly is likewise expected
        to return a byte string or NOT_DONE_YET.

        @see: L{IResource.render}
        �render_N)�getattrr�method�allowedMethods�AttributeError�_computeAllowedMethodsr)r,r�mrXrrrr�s�
�zResource.rendercCs
|�|�S)z�
        Default handling of HEAD method.

        I just return self.render_GET(request). When method is HEAD,
        the framework will handle this correctly.
        )�
render_GETr>rrr�render_HEADs
zResource.render_HEADr/)rrr r!r�
entityTyperTr-r"r2r5r8r;r7r:rArErFrHrDrrrrr]rrrrres,
rcCs*g}t|jd�D]
}|�|�d��q|S)z�
    Compute the allowed methods on a C{Resource} based on defined render_FOO
    methods. Used when raising C{UnsupportedMethod} but C{Resource} does
    not define C{allowedMethods} attribute.
    rU�ascii)r�	__class__r&�encode)r'rXrrrrrZsrZc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
ra�
    L{ErrorPage} is a resource which responds with a particular
    (parameterized) status and a body consisting of HTML containing some
    descriptive text.  This is useful for rendering simple error pages.

    @ivar template: A native string which will have a dictionary interpolated
        into it to generate the response body.  The dictionary has the following
        keys:

          - C{"code"}: The status code passed to L{ErrorPage.__init__}.
          - C{"brief"}: The brief description passed to L{ErrorPage.__init__}.
          - C{"detail"}: The detailed description passed to
            L{ErrorPage.__init__}.

    @ivar code: An integer status code which will be used for the response.
    @type code: C{int}

    @ivar brief: A short string which will be included in the response body as
        the page title.
    @type brief: C{str}

    @ivar detail: A longer string which will be included in the response body.
    @type detail: C{str}
    z�
<html>
  <head><title>%(code)s - %(brief)s</title></head>
  <body>
    <h1>%(brief)s</h1>
    <p>%(detail)s</p>
  </body>
</html>
cCs t�|�||_||_||_dSr/)rr-�code�brief�detail)r,�statusrcrdrrrr-Es

zErrorPage.__init__cCsJ|�|j�|�dd�|jt|j|j|jd�}t|t�r#|�	d�S|S)Nscontent-typestext/html; charset=utf-8)rbrcrdzutf-8)
�setResponseCoderb�	setHeader�template�dictrcrdrP�strra)r,r�interpolatedrrrrKs�

zErrorPage.rendercCs|Sr/r)r,�chnamrrrrrDUr=zErrorPage.getChildN)rrr r!rhr-rrDrrrrr!s

rc@�eZdZdZddd�ZdS)rzr
    L{NoResource} is a specialization of L{ErrorPage} which returns the HTTP
    response code I{NOT FOUND}.
    �%Sorry. No luck finding that resource.cC�t�|td|�dS)NzNo Such Resource)rr-r�r,�messagerrrr-_r9zNoResource.__init__N)rn�rrr r!r-rrrrrY�rc@rm)rzy
    L{ForbiddenResource} is a specialization of L{ErrorPage} which returns the
    I{FORBIDDEN} HTTP response code.
    �Sorry, resource is forbidden.cCro)NzForbidden Resource)rr-rrprrrr-ir9zForbiddenResource.__init__N)rtrrrrrrrcrsrc@seZdZdZdd�ZdS)�_IEncodingResourcezT
    A resource which knows about L{_IRequestEncoderFactory}.

    @since: 12.3
    cCr)z�
        Parse the request and return an encoder if applicable, using
        L{_IRequestEncoderFactory.encoderForRequest}.

        @return: A L{_IRequestEncoder}, or L{None}.
        Nrrrrr�
getEncodertrz_IEncodingResource.getEncoderN)rrr r!rvrrrrrumsrucs(eZdZdZ�fdd�Zdd�Z�ZS)ra�
    Wrap a L{IResource}, potentially applying an encoding to the response body
    generated.

    Note that the returned children resources won't be wrapped, so you have to
    explicitly wrap them if you want the encoding to be applied.

    @ivar encoders: A list of
        L{_IRequestEncoderFactory<twisted.web.iweb._IRequestEncoderFactory>}
        returning L{_IRequestEncoder<twisted.web.iweb._IRequestEncoder>} that
        may transform the data passed to C{Request.write}. The list must be
        sorted in order of priority: the first encoder factory handling the
        request will prevent the others from doing the same.
    @type encoders: C{list}.

    @since: 12.3
    cst��|�||_dSr/)�superr-�	_encoders)r,�original�encoders�r`rrr-�s
z EncodingResourceWrapper.__init__cCs*|jD]}|�|�}|dur|SqdS)zR
        Browser the list of encoders looking for one applicable encoder.
        N)rx�encoderForRequest)r,r�encoderFactory�encoderrrrrv�s

��z"EncodingResourceWrapper.getEncoder)rrr r!r-rv�
__classcell__rrr{rr}sr)r!�__all__rK�zope.interfacer	r
r�twisted.python.compatr�twisted.python.componentsr
�twisted.python.reflectr�twisted.web._responsesrr�twisted.web.errorrrrrrZrrrrurrrrr�<module>s*
;-8



Spamworldpro Mini