本文整理匯總了Python中twisted.web.http.HTTPChannel.makeConnection方法的典型用法代碼示例。如果您正苦於以下問題:Python HTTPChannel.makeConnection方法的具體用法?Python HTTPChannel.makeConnection怎麽用?Python HTTPChannel.makeConnection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.web.http.HTTPChannel
的用法示例。
在下文中一共展示了HTTPChannel.makeConnection方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from twisted.web.http import HTTPChannel [as 別名]
# 或者: from twisted.web.http.HTTPChannel import makeConnection [as 別名]
def __init__(self, counter, method, path, headers, content):
channel = HTTPChannel()
host = IPv4Address(b"TCP", b"127.0.0.1", 80)
channel.makeConnection(StringTransport(hostAddress=host))
Request.__init__(self, channel, False)
# An extra attribute for identifying this fake request
self._counter = counter
# Attributes a Request is supposed to have but we have to set ourselves
# because the base class mixes together too much other logic with the
# code that sets them.
self.prepath = []
self.requestHeaders = headers
self.content = BytesIO(content)
self.requestReceived(method, path, b"HTTP/1.1")
# requestReceived initializes the path attribute for us (but not
# postpath).
self.postpath = list(map(unquote, self.path[1:].split(b'/')))
# Our own notifyFinish / finish state because the inherited
# implementation wants to write confusing stuff to the transport when
# the request gets finished.
self._finished = False
self._finishedChannel = EventChannel()
# Our own state for the response body so we don't have to dig it out of
# the transport.
self._responseBody = b""
示例2: test_client_sends_body
# 需要導入模塊: from twisted.web.http import HTTPChannel [as 別名]
# 或者: from twisted.web.http.HTTPChannel import makeConnection [as 別名]
def test_client_sends_body(self):
self.cl.post_json("testserv:8008", "foo/bar", timeout=10000, data={"a": "b"})
self.pump()
clients = self.reactor.tcpClients
self.assertEqual(len(clients), 1)
client = clients[0][2].buildProtocol(None)
server = HTTPChannel()
client.makeConnection(FakeTransport(server, self.reactor))
server.makeConnection(FakeTransport(client, self.reactor))
self.pump(0.1)
self.assertEqual(len(server.requests), 1)
request = server.requests[0]
content = request.content.read()
self.assertEqual(content, b'{"a":"b"}')