/usr/lib/python3/dist-packages/twisted/web/__pycache__
Edit: /usr/lib/python3/dist-packages/twisted/web/__pycache__/iweb.cpython-310.pyc (31351B)
o
bKl @ s` d Z ddlmZmZmZmZ ddlmZmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ er8ddlmZmZ G d d
d
eZG dd deZG d
d deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd d eZG d!d" d"eZ G d#d$ d$eZ!d%Z"g d&Z#d'S )(z
Interface definitions for L{twisted.web}.
@var UNKNOWN_LENGTH: An opaque object which may be used as the value of
L{IBodyProducer.length} to indicate that the length of the entity
body is not known in advance.
)
TYPE_CHECKINGCallableListOptional) Attribute Interface)IUsernameDigestHash)Deferred)
IPushProducer)Headers)FlattenableTagc @ s, e Zd ZdZedZedZedZedZedZ edZ
edZed Zed
Z
dd Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd=d d!Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Z d>d.d/Zd=d0d1Z d2d3 Z!d4d5 Z"d6d7 Z#d8d9 Z$d?d;d<Z%dS )@IRequestz+
An HTTP request.
@since: 9.0
z0A L{bytes} giving the HTTP method that was used.zWA L{bytes} giving the full encoded URI which was requested (including query arguments).z\A L{bytes} giving the encoded query path of the request URI (not including query arguments).a A mapping of decoded query argument names as L{bytes} to corresponding query argument values as L{list}s of L{bytes}. For example, for a URI with C{foo=bar&foo=baz&quux=spam} for its query part, C{args} will be C{{b'foo': [b'bar', b'baz'], b'quux': [b'spam']}}.zaThe URL path segments which have been processed during resource traversal, as a list of L{bytes}.zkThe URL path segments which have not (yet) been processed during resource traversal, as a list of L{bytes}.zLA L{http_headers.Headers} instance giving all received HTTP request headers.zA file-like object giving the request body. This may be a file on disk, an L{io.BytesIO}, or some other type. The implementation is free to decide on a per-request basis.zPA L{http_headers.Headers} instance holding all HTTP response headers to be sent.c C dS )a
Get an HTTP request header.
@type key: L{bytes} or L{str}
@param key: The name of the header to get the value of.
@rtype: L{bytes} or L{str} or L{None}
@return: The value of the specified header, or L{None} if that header
was not present in the request. The string type of the result
matches the type of C{key}.
N keyr r 2/usr/lib/python3/dist-packages/twisted/web/iweb.py getHeaderK zIRequest.getHeaderc C r )a.
Get a cookie that was sent from the network.
@type key: L{bytes}
@param key: The name of the cookie to get.
@rtype: L{bytes} or L{None}
@returns: The value of the specified cookie, or L{None} if that cookie
was not present in the request.
Nr r r r r getCookieX r zIRequest.getCookiec C r )z
Return dictionary mapping the names of all received headers to the last
value received for each.
Since this method does not return all header information,
C{requestHeaders.getAllRawHeaders()} may be preferred.
Nr r r r r
getAllHeadersd r zIRequest.getAllHeadersc C r )a
Get the hostname that the HTTP client passed in to the request.
This will either use the C{Host:} header (if it is available; which,
for a spec-compliant request, it will be) or the IP address of the host
we are listening on if the header is unavailable.
@note: This is the I{host portion} of the requested resource, which
means that:
1. it might be an IPv4 or IPv6 address, not just a DNS host
name,
2. there's no guarantee it's even a I{valid} host name or IP
address, since the C{Host:} header may be malformed,
3. it does not include the port number.
@returns: the requested hostname
@rtype: L{bytes}
Nr r r r r getRequestHostnamem r zIRequest.getRequestHostnamec C r )z
Get my originally requesting transport's host.
@return: An L{IAddress
}.
Nr r r r r getHost r zIRequest.getHostc C r )a
Return the address of the client who submitted this request.
The address may not be a network address. Callers must check
its type before using it.
@since: 18.4
@return: the client's address.
@rtype: an L{IAddress} provider.
Nr r r r r getClientAddress r zIRequest.getClientAddressc C r )aP
Return the IP address of the client who submitted this request.
This method is B{deprecated}. See L{getClientAddress} instead.
@returns: the client IP address or L{None} if the request was submitted
over a transport where IP addresses do not make sense.
@rtype: L{str} or L{None}
Nr r r r r getClientIP r zIRequest.getClientIPc C r )z
Return the HTTP user sent with this request, if any.
If no user was supplied, return the empty string.
@returns: the HTTP user, if any
@rtype: L{str}
Nr r r r r getUser r zIRequest.getUserc C r )z
Return the HTTP password sent with this request, if any.
If no password was supplied, return the empty string.
@returns: the HTTP password, if any
@rtype: L{str}
Nr r r r r getPassword r zIRequest.getPasswordc C r )az
Return True if this request is using a secure transport.
Normally this method returns True if this request's HTTPChannel
instance is using a transport that implements ISSLTransport.
This will also return True if setHost() has been called
with ssl=True.
@returns: True if this request is secure
@rtype: C{bool}
Nr r r r r isSecure r zIRequest.isSecureNc C r )a@
Look up the session associated with this request or create a new one if
there is not one.
@return: The L{Session} instance identified by the session cookie in
the request, or the C{sessionInterface} component of that session
if C{sessionInterface} is specified.
Nr )sessionInterfacer r r
getSession r zIRequest.getSessionc C r )z
@return: A L{URLPath} instance
which identifies the URL for which this request is.
Nr r r r r URLPath r zIRequest.URLPathc C r )a
At any time during resource traversal or resource rendering,
returns an absolute URL to the most nested resource which has
yet been reached.
@see: {twisted.web.server.Request.prepath}
@return: An absolute URL.
@rtype: L{bytes}
Nr r r r r
prePathURL r zIRequest.prePathURLc C r )z_
Remember the currently-processed part of the URL for later
recalling.
Nr r r r r rememberRootURL r zIRequest.rememberRootURLc C r )zn
Get a previously-remembered URL.
@return: An absolute URL.
@rtype: L{bytes}
Nr r r r r
getRootURL r zIRequest.getRootURLc C r )zI
Indicate that the response to this request is complete.
Nr r r r r finish r zIRequest.finishc C r )a$
Write some data to the body of the response to this request. Response
headers are written the first time this method is called, after which
new response headers may not be added.
@param data: Bytes of the response body.
@type data: L{bytes}
Nr datar r r write r zIRequest.writec C r )z
Set an outgoing HTTP cookie.
In general, you should consider using sessions instead of cookies, see
L{twisted.web.server.Request.getSession} and the
L{twisted.web.server.Session} class for details.
Nr )kvexpiresdomainpathmax_agecommentsecurer r r addCookie r zIRequest.addCookiec C r )zi
Set the HTTP response code.
@type code: L{int}
@type message: L{bytes}
Nr )codemessager r r setResponseCode r zIRequest.setResponseCodec C r )a
Set an HTTP response header. Overrides any previously set values for
this header.
@type k: L{bytes} or L{str}
@param k: The name of the header for which to set the value.
@type v: L{bytes} or L{str}
@param v: The value to set for the named header. A L{str} will be
UTF-8 encoded, which may not interoperable with other
implementations. Avoid passing non-ASCII characters if possible.
Nr )r) r* r r r setHeader r zIRequest.setHeaderc C r )zu
Utility function that does a redirect.
The request should have finish() called after this.
Nr )urlr r r redirect( r zIRequest.redirectc C r )a9
Set the C{Last-Modified} time for the response to this request.
If I am called more than once, I ignore attempts to set Last-Modified
earlier, only replacing the Last-Modified time if it is to a later
value.
If I am a conditional request, I may modify my response code to
L{NOT_MODIFIED} if appropriate for the time given.
@param when: The last time the resource being returned was modified, in
seconds since the epoch.
@type when: L{int} or L{float}
@return: If I am a C{If-Modified-Since} conditional request and the time
given is not newer than the condition, I return
L{CACHED} to indicate that you should write no body.
Otherwise, I return a false value.
Nr )whenr r r setLastModified/ r zIRequest.setLastModifiedc C r )a
Set an C{entity tag} for the outgoing response.
That's "entity tag" as in the HTTP/1.1 I{ETag} header, "used for
comparing two or more entities from the same requested resource."
If I am a conditional request, I may modify my response code to
L{NOT_MODIFIED} or
L{PRECONDITION_FAILED}, if appropriate for the
tag given.
@param etag: The entity tag for the resource being returned.
@type etag: L{str}
@return: If I am a C{If-None-Match} conditional request and the tag
matches one in the request, I return L{CACHED} to
indicate that you should write no body. Otherwise, I return a
false value.
Nr )etagr r r setETagD r zIRequest.setETagr c C r )a
Change the host and port the request thinks it's using.
This method is useful for working with reverse HTTP proxies (e.g. both
Squid and Apache's mod_proxy can do this), when the address the HTTP
client is using is different than the one we're listening on.
For example, Apache may be listening on https://www.example.com, and
then forwarding requests to http://localhost:8080, but we don't want
HTML produced by Twisted to say 'http://localhost:8080', they should
say 'https://www.example.com', so we do::
request.setHost('www.example.com', 443, ssl=1)
Nr )hostportsslr r r setHostY r zIRequest.setHost)N)NNNNNN)r )&__name__
__module____qualname____doc__r methodurir- argsprepathpostpathrequestHeaderscontentresponseHeadersr r r r r r r r r r r r! r" r# r$ r% r( r1 r4 r5 r7 r9 r; r? r r r r r sr
r c @ e Zd ZdZdd ZdS )INonQueuedRequestFactoryzU
A factory of L{IRequest} objects that does not take a ``queued`` parameter.
c C r )an
Create an L{IRequest} that is operating on the given channel. There
must only be one L{IRequest} object processing at any given time on a
channel.
@param channel: A L{twisted.web.http.HTTPChannel} object.
@type channel: L{twisted.web.http.HTTPChannel}
@return: A request object.
@rtype: L{IRequest}
Nr )channelr r r __call__o r z!INonQueuedRequestFactory.__call__Nr@ rA rB rC rO r r r r rM j s rM c @ rL )IAccessLogFormatterzr
An object which can represent an HTTP request as a line of text for
inclusion in an access log file.
c C r )a
Generate a line for the access log.
@param timestamp: The time at which the request was completed in the
standard format for access logs.
@type timestamp: L{unicode}
@param request: The request object about which to log.
@type request: L{twisted.web.server.Request}
@return: One line describing the request without a trailing newline.
@rtype: L{unicode}
Nr ) timestamprequestr r r rO r zIAccessLogFormatter.__call__NrP r r r r rQ } s rQ c @ ( e Zd ZdZedZdd Zdd ZdS )ICredentialFactoryai
A credential factory defines a way to generate a particular kind of
authentication challenge and a way to interpret the responses to these
challenges. It creates
L{ICredentials} providers from
responses. These objects will be used with L{twisted.cred} to authenticate
an authorize requests.
zA L{str} giving the name of the authentication scheme with which this factory is associated. For example, C{'basic'} or C{'digest'}.c C r )aW
Generate a new challenge to be sent to a client.
@type request: L{twisted.web.http.Request}
@param request: The request the response to which this challenge will
be included.
@rtype: L{dict}
@return: A mapping from L{str} challenge fields to associated L{str}
values.
Nr rS r r r getChallenge r zICredentialFactory.getChallengec C r )a
Create a credentials object from the given response.
@type response: L{str}
@param response: scheme specific response string
@type request: L{twisted.web.http.Request}
@param request: The request being processed (from which the response
was taken).
@raise twisted.cred.error.LoginFailed: If the response is invalid.
@rtype: L{twisted.cred.credentials.ICredentials} provider
@return: The credentials represented by the given response.
Nr )responserS r r r decode r zICredentialFactory.decodeN)r@ rA rB rC r schemerW rY r r r r rU s
rU c @ rT )
IBodyProducera
Objects which provide L{IBodyProducer} write bytes to an object which
provides L{IConsumer} by calling its
C{write} method repeatedly.
L{IBodyProducer} providers may start producing as soon as they have an
L{IConsumer} provider. That is, they
should not wait for a C{resumeProducing} call to begin writing data.
L{IConsumer.unregisterProducer}
must not be called. Instead, the
L{Deferred} returned from C{startProducing}
must be fired when all bytes have been written.
L{IConsumer.write} may
synchronously invoke any of C{pauseProducing}, C{resumeProducing}, or
C{stopProducing}. These methods must be implemented with this in mind.
@since: 9.0
z
C{length} is a L{int} indicating how many bytes in total this
L{IBodyProducer} will write to the consumer or L{UNKNOWN_LENGTH}
if this is not known in advance.
c C r )a
Start producing to the given
L{IConsumer} provider.
@return: A L{Deferred} which stops
production of data when L{Deferred.cancel} is called, and which
fires with L{None} when all bytes have been produced or with a
L{Failure} if there is any problem
before all bytes have been produced.
Nr )consumerr r r startProducing r zIBodyProducer.startProducingc C r )a)
In addition to the standard behavior of
L{IProducer.stopProducing}
(stop producing data), make sure the
L{Deferred} returned by
C{startProducing} is never fired.
Nr r r r r
stopProducing r zIBodyProducer.stopProducingN)r@ rA rB rC r lengthr] r^ r r r r r[ s r[ c @ sH e Zd ZdZdedeee dgdf fddZdee ddfd d
Z dS )IRenderablezs
An L{IRenderable} is an object that may be rendered by the
L{twisted.web.template} templating system.
namereturnr
r c C r )a
Look up and return the render method associated with the given name.
@param name: The value of a render directive encountered in the
document returned by a call to L{IRenderable.render}.
@return: A two-argument callable which will be invoked with the request
being responded to and the tag object on which the render directive
was encountered.
Nr )ra r r r lookupRenderMethod r zIRenderable.lookupRenderMethodrS c C r )z
Get the document for this L{IRenderable}.
@param request: The request in response to which this method is being
invoked.
@return: An object which can be flattened.
Nr rV r r r render r zIRenderable.renderN)
r@ rA rB rC strr r r rc rd r r r r r` s
r` c @ s" e Zd ZdZded fddZdS )ITemplateLoaderz|
A loader for templates; something usable as a value for
L{twisted.web.template.Element}'s C{loader} attribute.
rb r c C r )z
Load a template suitable for rendering.
@return: a L{list} of flattenable objects, such as byte and unicode
strings, L{twisted.web.template.Element}s and L{IRenderable} providers.
Nr r r r r load! r zITemplateLoader.loadN)r@ rA rB rC r rg r r r r rf s rf c @ sX e Zd ZdZedZedZedZedZedZ edZ
edZd d
Zdd Z
d
S ) IResponseza
An object representing an HTTP response received from an HTTP server.
@since: 11.1
zA three-tuple describing the protocol and protocol version of the response. The first element is of type L{str}, the second and third are of type L{int}. For example, C{(b'HTTP', 1, 1)}.z3The HTTP status code of this response, as a L{int}.z5The HTTP reason phrase of this response, as a L{str}.z.The HTTP response L{Headers} of this response.a The L{int} number of bytes expected to be in the body of this response or L{UNKNOWN_LENGTH} if the server did not indicate how many bytes to expect. For I{HEAD} responses, this will be 0; if the response includes a I{Content-Length} header, it will be available in C{headers}.z5The L{IClientRequest} that resulted in this response.zThe previous L{IResponse} from a redirect, or L{None} if there was no previous response. This can be used to walk the response or request history for redirections.c C r )a
Register an L{IProtocol} provider
to receive the response body.
The protocol will be connected to a transport which provides
L{IPushProducer}. The protocol's C{connectionLost} method will be
called with:
- ResponseDone, which indicates that all bytes from the response
have been successfully delivered.
- PotentialDataLoss, which indicates that it cannot be determined
if the entire response body has been delivered. This only occurs
when making requests to HTTP servers which do not set
I{Content-Length} or a I{Transfer-Encoding} in the response.
- ResponseFailed, which indicates that some bytes from the response
were lost. The C{reasons} attribute of the exception may provide
more specific indications as to why.
Nr )protocolr r r deliverBodyM r zIResponse.deliverBodyc C r )z
Set the reference to the previous L{IResponse}.
The value of the previous response can be read via
L{IResponse.previousResponse}.
Nr )rX r r r setPreviousResponsec r zIResponse.setPreviousResponseN)r@ rA rB rC r versionr2 phraseheadersr_ rS previousResponserj rk r r r r rh * s" rh c @ s e Zd ZdZdd Zdd ZdS )_IRequestEncoderzy
An object encoding data passed to L{IRequest.write}, for example for
compression purpose.
@since: 12.3
c C r )z
Encode the data given and return the result.
@param data: The content to encode.
@type data: L{str}
@return: The encoded data.
@rtype: L{str}
Nr r&