本文整理汇总了Python中twisted.web.server.Request.method方法的典型用法代码示例。如果您正苦于以下问题:Python Request.method方法的具体用法?Python Request.method怎么用?Python Request.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.server.Request
的用法示例。
在下文中一共展示了Request.method方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_renderRealRequest
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_renderRealRequest(self):
"""
The request managed by L{WebSocketsResource.render} doesn't contain
unnecessary HTTP headers like I{Content-Type} or I{Transfer-Encoding}.
"""
channel = DummyChannel()
channel.transport = StringTransportWithDisconnection()
channel.transport.protocol = channel
request = Request(channel, False)
headers = {
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"}
for key, value in headers.items():
request.requestHeaders.setRawHeaders(key, [value])
request.method = "GET"
request.clientproto = "HTTP/1.1"
result = self.resource.render(request)
self.assertEqual(NOT_DONE_YET, result)
self.assertEqual(
[("Connection", ["Upgrade"]),
("Upgrade", ["WebSocket"]),
("Sec-Websocket-Accept", ["oYBv54i42V5dw6KnZqOFroecUTc="])],
list(request.responseHeaders.getAllRawHeaders()))
self.assertEqual(
"HTTP/1.1 101 Switching Protocols\r\n"
"Connection: Upgrade\r\n"
"Upgrade: WebSocket\r\n"
"Sec-Websocket-Accept: oYBv54i42V5dw6KnZqOFroecUTc=\r\n\r\n",
channel.transport.value())
self.assertEqual(101, request.code)
self.assertIdentical(None, request.transport)
示例2: test_redirectToUnicodeURL
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_redirectToUnicodeURL(self) :
"""
L{redirectTo} will raise TypeError if unicode object is passed in URL
"""
request = Request(DummyChannel(), True)
request.method = b'GET'
targetURL = u'http://target.example.com/4321'
self.assertRaises(TypeError, redirectTo, targetURL, request)
示例3: makeRequest
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def makeRequest(method, path, post_data=None):
req = Request(FakeChannel(), None)
req.prepath = req.postpath = None
req.method = method
req.path = path
req.content = StringIO(post_data)
resource = site.getChildWithDefault(path, req)
return resource.render(req)
示例4: test_requestFeature
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_requestFeature(self):
self.log.addFeature(request)
req = Request(DummyChannel(), False)
req.method = 'GET'
req.uri = '/foo'
self.log.request(req).info('handling request')
self.assertIn('method=GET', self.out.getvalue())
self.assertIn('uri=/foo', self.out.getvalue())
示例5: test_error_in_read_function
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_error_in_read_function(self):
req = Request(DummyChannel(), 1)
req.setResponseCode(200)
req.method = 'GET'
def error_function(a, b):
raise Exception("boom")
self.api.read_GET = error_function
self.api._handle_error = mock.Mock()
result, body = self.api.resource_renderer('res', req)
self.api._handle_error.assert_called_with(req, 500, "ReadError",
"Error %r in resource reading function." % Exception('boom'))
示例6: get_request
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def get_request(self, method, uri, clientproto, headers, data, response):
self.transport = response.transport
r = Request(self, False)
r.method = method
r.clientproto = clientproto
r.path = uri
r.client = response.client
r.host = self.host
r.prepath = []
r.postpath = map(unquote, string.split(r.path[1:], "/"))
r.content = StringIO.StringIO(data)
r.transport = response.transport
return r
示例7: test_headersAndCode
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_headersAndCode(self):
"""
L{redirectTo} will set the C{Location} and C{Content-Type} headers on
its request, and set the response code to C{FOUND}, so the browser will
be redirected.
"""
request = Request(DummyChannel(), True)
request.method = b'GET'
targetURL = b"http://target.example.com/4321"
redirectTo(targetURL, request)
self.assertEqual(request.code, FOUND)
self.assertEqual(
request.responseHeaders.getRawHeaders(b'location'), [targetURL])
self.assertEqual(
request.responseHeaders.getRawHeaders(b'content-type'),
[b'text/html; charset=utf-8'])
示例8: getRequest
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def getRequest(method, url):
req = Request(FakeChannel(), None)
req.method = method
req.path = url
return req
示例9: test_resource_renderer
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import method [as 别名]
def test_resource_renderer(self):
req = Request(DummyChannel(), 1)
req.method = 'GET'
result, body = self.api.resource_renderer('res', req)
self.assertEqual(result.code, 200)
self.assertEqual(body, 'res::SimpleAPIResource')