
    h<                       S r SSKJr  / SQrSSKrSSKJr  SSKJrJ	r	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr   " S S\	5      rS r\
" \5       " S S5      5       rS r " S S\5      r " S S\5      r " S S\5      r  " S S\5      r!\r"\ r#\!r$ " S S\	5      r%\
" \%5       " S S\" \5      5      5       r&g) zp
Implementation of the lowest-level Resource class.

See L{twisted.web.pages} for some utility implementations.
    )annotations)	IResourcegetChildForRequestResource	ErrorPage
NoResourceForbiddenResourceEncodingResourceWrapperN)Sequence)	Attribute	Interfaceimplementer)Version)nativeString)proxyForInterface)
deprecated)prefixedMethodNames)	FORBIDDEN	NOT_FOUND)UnsupportedMethodc                  >    \ rS rSrSr\" S5      rS rS	S jrS r	Sr
g)
r   %   z
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.
        c                    g)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requests     [/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/web/resource.pygetChildWithDefaultIResource.getChildWithDefault1           c                    g)a  
Put a child L{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}.

    The path component is I{not} URL-encoded -- pass C{b'foo bar'}
    rather than C{b'foo%20bar'}.
Nr   )pathchilds     r   putChildIResource.putChildD   r    r!   c                    g)a   
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   r   s    r   renderIResource.renderR   r    r!   r   N)r#   bytesr$   z'IResource'returnNone)__name__
__module____qualname____firstlineno____doc__r   isLeafr   r%   r)   __static_attributes__r   r!   r   r   r   %   s'     	F&r!   r   c                    UR                   (       a|  U R                  (       dk  UR                   R                  S5      nUR                  R	                  U5        U R                  X!5      n UR                   (       a  U R                  (       d  Mk  U $ )z=
Traverse resource tree to find who will handle the request.
r   )postpathr3   popprepathappendr   )resourcer   pathElements      r   r   r   b   se     

8??&&**1-{+//E 

8??? Or!   c                      \ rS rSr% Sr\rS\S'   SrS r	Sr
S rS	 rS
 rS rS rSS jrS rS rS rS rS rS rS rSS jrS rS rSrg)r   m   z
Define a web-accessible resource.

This serves two 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.
zSequence[bytes]allowedMethodsNc                    0 U l         g)z
Initialize.
Nchildrenselfs    r   __init__Resource.__init__|   s     r!   r   c                H    [        U R                  R                  5       5      $ N)listrA   keysrB   s    r   listStaticNamesResource.listStaticNames   s    DMM&&())r!   c                H    [        U R                  R                  5       5      $ rG   )rH   rA   itemsrB   s    r   listStaticEntitiesResource.listStaticEntities   s    DMM'')**r!   c                V    [        U R                  5       5      U R                  5       -   $ rG   )rH   rJ   listDynamicNamesrB   s    r   	listNamesResource.listNames   s$    D((*+d.C.C.EEEr!   c                V    [        U R                  5       5      U R                  5       -   $ rG   )rH   rN   listDynamicEntitiesrB   s    r   listEntitiesResource.listEntities   s$    D++-.1I1I1KKKr!   c                    / $ rG   r   rB   s    r   rQ   Resource.listDynamicNames       	r!   c                    / $ rG   r   rC   r   s     r   rU   Resource.listDynamicEntities   rZ   r!   c                8    U R                   R                  U5      $ rG   )rA   getrC   r   s     r   getStaticEntityResource.getStaticEntity   s    }}  &&r!   c                D    XR                   ;  a  U R                  X5      $ g rG   rA   getChild)rC   r   r   s      r   getDynamicEntityResource.getDynamicEntity   s    }}$==//r!   c                    U R                   U	 g rG   r@   r`   s     r   	delEntityResource.delEntity   s    MM$r!   c                     X R                   U'   g rG   r@   )rC   r   entitys      r   reallyPutEntityResource.reallyPutEntity   s    $dr!   c                    [        5       $ )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}.
)_UnsafeNoResourcerC   r#   r   s      r   re   Resource.getChild   s    * !""r!   c                `    XR                   ;   a  U R                   U   $ U R                  X5      $ )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}
rd   rq   s      r   r   Resource.getChildWithDefault   s,     == ==&&}}T++r!   c                P    [         R                  " S[        S5        [        X5      $ )zb
Deprecated in favor of L{getChildForRequest}.

@see: L{twisted.web.resource.getChildForRequest}.
z+Please use module level getChildForRequest.   )warningswarnDeprecationWarningr   r\   s     r   r   Resource.getChildForRequest   s%     	9;Mq	
 "$00r!   c                    [        U[        5      (       d  [        SU< S[        U5       35      eX R                  U'   U R
                  Ul        g)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.

@param child: The child resource to register.

@see: L{IResource.putChild}
z Path segment must be bytes, but z is N)
isinstancer+   	TypeErrortyperA   server)rC   r#   r$   s      r   r%   Resource.putChild   sH     $&&>thd4PT:,WXX#d {{r!   c                    [        U S[        UR                  5      -   S5      nU(       d   U R                  n[        U5      eU" U5      $ ! [         a    [        U 5      n N*f = f)a  
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   methodr>   AttributeError_computeAllowedMethodsr   )rC   r   mr>   s       r   r)   Resource.render   se    ( D)l7>>&BBDI>!%!4!4 $N33z " >!7!=>s   A A#"A#c                $    U R                  U5      $ )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\   s     r   render_HEADResource.render_HEAD  s     w''r!   r@   rG   )r#   r+   r$   r   r,   r-   )r.   r/   r0   r1   r2   r   
entityType__annotations__r   rD   r3   rJ   rN   rR   rV   rQ   rU   ra   rf   ri   rm   re   r   r   r%   r)   r   r4   r   r!   r   r   r   m   sw     J##F F*+FL' %
#.,$	1#,:(r!   r   c                    / n[        U R                  S5       H#  nUR                  UR                  S5      5        M%     U$ )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.
r   ascii)r   	__class__r9   encode)r:   r>   r   s      r   r   r     sB     N#H$6$6	B 	dkk'23	 C
 r!   c                  .    \ rS rSrSrSrS rS rS rSr	g)	_UnsafeErrorPageBasei)  a  
Base class for deprecated error page resources.

@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{_UnsafeErrorPage.__init__}.
      - C{"brief"}: The brief description passed to
        L{_UnsafeErrorPage.__init__}.
      - C{"detail"}: The detailed description passed to
        L{_UnsafeErrorPage.__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>
c                R    [         R                  U 5        Xl        X l        X0l        g rG   )r   rD   codebriefdetailrC   statusr   r   s       r   rD   _UnsafeErrorPageBase.__init__L  s    $	
r!   c                   UR                  U R                  5        UR                  SS5        U R                  [	        U R                  U R
                  U R                  S9-  n[        U[        5      (       a  UR                  S5      $ U$ )Ns   content-types   text/html; charset=utf-8)r   r   r   zutf-8)
setResponseCoder   	setHeadertemplatedictr   r   r|   strr   )rC   r   interpolateds      r   r)   _UnsafeErrorPageBase.renderR  ss    		*/+FG}}t$**T[[(
 
 lC((&&w//r!   c                    U $ rG   r   )rC   chnamr   s      r   re   _UnsafeErrorPageBase.getChild\  s    r!   )r   r   r   N)
r.   r/   r0   r1   r2   r   rD   r)   re   r4   r   r!   r   r   r   )  s    0Hr!   r   c                  H    \ rS rSrSr\" \" SSSS5      S5      S 5       rS	rg
)_UnsafeErrorPagei`  av  
L{_UnsafeErrorPage}, publicly available via the deprecated alias
C{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.

Deprecated in Twisted 22.10.0 because it permits HTML injection; use
L{twisted.web.pages.errorPage} instead.
Twisted   
   r   zEUse twisted.web.pages.errorPage instead, which properly escapes HTML.c                0    [         R                  XX#5        g rG   )r   rD   r   s       r   rD   _UnsafeErrorPage.__init__k  s    
 	%%dEBr!   r   N	r.   r/   r0   r1   r2   r   r   rD   r4   r   r!   r   r   r   `  s3     	2r1%OC	Cr!   r   c                  L    \ rS rSrSr\" \" SSSS5      S5      SS j5       rS	rg
)rp   is  a  
L{_UnsafeNoResource}, publicly available via the deprecated alias
C{NoResource}, is a specialization of L{_UnsafeErrorPage} which
returns the HTTP response code I{NOT FOUND}.

Deprecated in Twisted 22.10.0 because it permits HTML injection; use
L{twisted.web.pages.notFound} instead.
r   r   r   r   zDUse twisted.web.pages.notFound instead, which properly escapes HTML.c                <    [         R                  U [        SU5        g )NzNo Such Resource)r   rD   r   rC   messages     r   rD   _UnsafeNoResource.__init__}  s    
 	%%dI7I7Sr!   r   N)z%Sorry. No luck finding that resource.r   r   r!   r   rp   rp   s  s3     	2r1%NT	Tr!   rp   c                  L    \ rS rSrSr\" \" SSSS5      S5      SS j5       rS	rg
)_UnsafeForbiddenResourcei  a+  
L{_UnsafeForbiddenResource}, publicly available via the deprecated alias
C{ForbiddenResource} is a specialization of L{_UnsafeErrorPage} which
returns the I{FORBIDDEN} HTTP response code.

Deprecated in Twisted 22.10.0 because it permits HTML injection; use
L{twisted.web.pages.forbidden} instead.
r   r   r   r   zEUse twisted.web.pages.forbidden instead, which properly escapes HTML.c                <    [         R                  U [        SU5        g )NzForbidden Resource)r   rD   r   r   s     r   rD   !_UnsafeForbiddenResource.__init__  s    
 	%%dI7KWUr!   r   N)zSorry, resource is forbidden.r   r   r!   r   r   r     s3     	2r1%OV	Vr!   r   c                      \ rS rSrSrS rSrg)_IEncodingResourcei  zH
A resource which knows about L{_IRequestEncoderFactory}.

@since: 12.3
c                    g)z
Parse the request and return an encoder if applicable, using
L{_IRequestEncoderFactory.encoderForRequest}.

@return: A L{_IRequestEncoder}, or L{None}.
Nr   r(   s    r   
getEncoder_IEncodingResource.getEncoder  r    r!   r   N)r.   r/   r0   r1   r2   r   r4   r   r!   r   r   r     s    r!   r   c                  2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )r
   i  a~  
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
c                0   > [         TU ]  U5        X l        g rG   )superrD   	_encoders)rC   originalencodersr   s      r   rD    EncodingResourceWrapper.__init__  s    "!r!   c                Z    U R                    H  nUR                  U5      nUc  M  Us  $    g)zB
Browser the list of encoders looking for one applicable encoder.
N)r   encoderForRequest)rC   r   encoderFactoryencoders       r   r   "EncodingResourceWrapper.getEncoder  s-     #nnN$66w?G" -r!   )r   )	r.   r/   r0   r1   r2   rD   r   r4   __classcell__)r   s   @r   r
   r
     s    $" r!   r
   )'r2   
__future__r   __all__rw   typingr   zope.interfacer   r   r   incrementalr   twisted.python.compatr   twisted.python.componentsr   twisted.python.deprecater   twisted.python.reflectr   twisted.web._responsesr   r   twisted.web.errorr   r   r   r   r   r   r   rp   r   r   r   r	   r   r
   r   r!   r   <module>r      s   

 #   < <  . 7 / 6 7 /:	 :z Yi( i( i(X48 4nC+ C&T, T$V3 V& 	
,     /	:  !r!   