Known subclasses: twisted.web.test.test_web.DummyRequestForLogTest

Represents a dummy or fake request. See twisted.web.server.Request.

Instance Variable requestheaders A Headers instance that stores values for all request headers. (type: Headers)
Instance Variable responseHeaders A Headers instance that stores values for all response headers. (type: Headers)
Instance Variable responseCode The response code which was passed to setResponseCode. (type: int)
Instance Variable written The bytes which have been written to the request. (type: list of bytes)
Method registerProducer Call an IPullProducer's resumeProducing method in a loop until it unregisters itself.
Method unregisterProducer Undocumented
Method __init__ Undocumented
Method getAllHeaders Return dictionary mapping the names of all received headers to the last value received for each.
Method getHeader Retrieve the value of a request header.
Method setHeader TODO: make this assert on write() if the header is content-length
Method getSession Undocumented
Method render Render the given resource as a response to this request.
Method write Undocumented
Method notifyFinish Return a Deferred which is called back with None when the request is finished. This will probably only work if you haven't called finish yet.
Method finish Record that the request is finished and callback and Deferreds waiting for notification of this.
Method processingFailed Errback and Deferreds waiting for finish notification.
Method addArg Undocumented
Method setResponseCode Set the HTTP status response code, but takes care that this is called before any data is written.
Method setLastModified Undocumented
Method setETag Undocumented
Method getClientIP Return the IPv4 address of the client which made this request, if there is one, otherwise None.
Method getClientAddress Return the IAddress of the client that made this request.
Method getRequestHostname Get a dummy hostname associated to the HTTP request.
Method getHost Get a dummy transport's host.
Method setHost Change the host and port the request thinks it's using.
Method redirect Utility function that does a redirect.
Instance Variable _finishedDeferreds None or a list of Deferreds which will be called back with None when finish is called or which will be errbacked if processingFailed is called.
_finishedDeferreds =
None or a list of Deferreds which will be called back with None when finish is called or which will be errbacked if processingFailed is called.
requestheaders =
A Headers instance that stores values for all request headers. (type: Headers)
responseHeaders =
A Headers instance that stores values for all response headers. (type: Headers)
responseCode =
The response code which was passed to setResponseCode. (type: int)
written =
The bytes which have been written to the request. (type: list of bytes)
def registerProducer(self, prod, s):

Call an IPullProducer's resumeProducing method in a loop until it unregisters itself.

ParametersprodThe producer. (type: IPullProducer)
sWhether or not the producer is streaming.
def unregisterProducer(self):
Undocumented
def __init__(self, postpath, session=None, client=None):
Undocumented
def getAllHeaders(self):

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, self.requestHeaders.getAllRawHeaders() may be preferred.

NOTE: This function is a direct copy of twisted.web.http.Request.getAllRawHeaders.

def getHeader(self, name):

Retrieve the value of a request header.

ParametersnameThe name of the request header for which to retrieve the value. Header names are compared case-insensitively. (type: bytes)
ReturnsThe value of the specified request header. (type: bytes or None)
def setHeader(self, name, value):

TODO: make this assert on write() if the header is content-length

def getSession(self):
Undocumented
def render(self, resource):

Render the given resource as a response to this request.

This implementation only handles a few of the most common behaviors of resources. It can handle a render method that returns a string or NOT_DONE_YET. It doesn't know anything about the semantics of request methods (eg HEAD) nor how to set any particular headers. Basically, it's largely broken, but sufficient for some tests at least. It should not be expanded to do all the same stuff Request does. Instead, DummyRequest should be phased out and Request (or some other real code factored in a different way) used.

def write(self, data):
Undocumented
def notifyFinish(self):

Return a Deferred which is called back with None when the request is finished. This will probably only work if you haven't called finish yet.

def finish(self):

Record that the request is finished and callback and Deferreds waiting for notification of this.

def processingFailed(self, reason):

Errback and Deferreds waiting for finish notification.

def addArg(self, name, value):
Undocumented
def setResponseCode(self, code, message=None):

Set the HTTP status response code, but takes care that this is called before any data is written.

def setLastModified(self, when):
Undocumented
def setETag(self, tag):
Undocumented
def getClientIP(self):

Return the IPv4 address of the client which made this request, if there is one, otherwise None.

def getClientAddress(self):

Return the IAddress of the client that made this request.

Returnsan address. (type: an IAddress provider.)
def getRequestHostname(self):

Get a dummy hostname associated to the HTTP request.

Returnsa dummy hostname (type: bytes)
def getHost(self):

Get a dummy transport's host.

Returnsa dummy transport's host (type: IPv4Address)
def setHost(self, host, port, ssl=0):

Change the host and port the request thinks it's using.

ParametershostThe value to which to change the host header. (type: bytes)
sslA flag which, if True, indicates that the request is considered secure (if True, isSecure will return True). (type: bool)
def redirect(self, url):

Utility function that does a redirect.

The request should have finish() called after this.

API Documentation for twisted, generated by pydoctor at 2020-03-25 17:34:30.