当前位置: 首页>>代码示例>>Python>>正文


Python HTTPChannel.makeConnection方法代码示例

本文整理汇总了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""
开发者ID:alex-docker,项目名称:flocker,代码行数:35,代码来源:testtools.py

示例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"}')
开发者ID:matrix-org,项目名称:synapse,代码行数:21,代码来源:test_fedclient.py


注:本文中的twisted.web.http.HTTPChannel.makeConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。