�
Ϫ�fKl � � � d Z ddlmZmZmZmZ ddlmZmZ ddl m
Z
ddlmZ ddl
mZ ddlmZ erddlmZmZ G d � d
e� Z G d� de� Z G d
� de� Z G d� de� Z G d� de� Z G d� de� Z G d� de� Z G d� de� Z G d� de� Z G d� de� Z G d� de� Z G d� d e� Z G d!� d"e� Z G d#� d$e� Z!d%Z"g d&�Z#y')(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_CHECKING�Callable�List�Optional)� Attribute� Interface)�IUsernameDigestHash)�Deferred)�
IPushProducer)�Headers)�Flattenable�Tagc �D � e Zd ZdZ ed� Z ed� Z ed� Z ed� Z ed� Z ed� Z
ed� Z ed � Z ed
� Z
d� Zd� Zd
� Zd� Zd� Zd� Zd� Zd� Zd� Zd� Zd$d�Zd� Zd� Zd� Zd� Zd� Zd� Z d%d�Zd$d�Z d� Z!d � Z"d!� Z#d"� Z$d&d#�Z%y)'�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.z�A 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 � � y)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� ��keys �2/usr/lib/python3/dist-packages/twisted/web/iweb.py� getHeaderzIRequest.getHeaderK � � � c � � y)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 s r � getCookiezIRequest.getCookieX r r c � � y)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 �
getAllHeaderszIRequest.getAllHeadersd r r c � � y)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 �getRequestHostnamezIRequest.getRequestHostnamem r r c � � y)z�
Get my originally requesting transport's host.
@return: An L{IAddress<twisted.internet.interfaces.IAddress>}.
Nr r r r �getHostzIRequest.getHost� r r c � � y)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 �getClientAddresszIRequest.getClientAddress� r r c � � y)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 �getClientIPzIRequest.getClientIP� r r c � � y)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 �getUserzIRequest.getUser� r r c � � y)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 �getPasswordzIRequest.getPassword� r r c � � y)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 �isSecurezIRequest.isSecure� r r Nc � � y)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 )�sessionInterfaces r �
getSessionzIRequest.getSession� r r c � � y)z�
@return: A L{URLPath<twisted.python.urlpath.URLPath>} instance
which identifies the URL for which this request is.
Nr r r r �URLPathzIRequest.URLPath� r r c � � y)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 �
prePathURLzIRequest.prePathURL� r r c � � y)z_
Remember the currently-processed part of the URL for later
recalling.
Nr r r r �rememberRootURLzIRequest.rememberRootURL� r r c � � y)zn
Get a previously-remembered URL.
@return: An absolute URL.
@rtype: L{bytes}
Nr r r r �
getRootURLzIRequest.getRootURL� r r c � � y)zI
Indicate that the response to this request is complete.
Nr r r r �finishzIRequest.finish� r r c � � y)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 ��datas r �writezIRequest.write� r r c � � y)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 )�k�v�expires�domain�path�max_age�comment�secures r � addCookiezIRequest.addCookie r r c � � y)zi
Set the HTTP response code.
@type code: L{int}
@type message: L{bytes}
Nr )�code�messages r �setResponseCodezIRequest.setResponseCode r r c � � y)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> |