本文整理汇总了Python中twisted.web.server.Request.clientproto方法的典型用法代码示例。如果您正苦于以下问题:Python Request.clientproto方法的具体用法?Python Request.clientproto怎么用?Python Request.clientproto使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.server.Request
的用法示例。
在下文中一共展示了Request.clientproto方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_renderRealRequest
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import clientproto [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: get_request
# 需要导入模块: from twisted.web.server import Request [as 别名]
# 或者: from twisted.web.server.Request import clientproto [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