本文整理汇总了Python中twisted.internet.protocol.Factory.response_body方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.response_body方法的具体用法?Python Factory.response_body怎么用?Python Factory.response_body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.response_body方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_http_request_potential_data_loss
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import response_body [as 别名]
def test_http_request_potential_data_loss(self):
self.webserver.loseConnection()
factory = Factory()
factory.protocol = FakeHTTP10
factory.response_body = (
"HTTP/1.0 201 CREATED\r\n"
"Date: Mon, 23 Jan 2012 15:08:47 GMT\r\n"
"Server: Fake HTTP 1.0\r\n"
"Content-Type: text/html; charset=utf-8\r\n"
"\r\n"
"Yay")
self.webserver = yield reactor.listenTCP(0, factory)
addr = self.webserver.getHost()
self.url = "http://%s:%s/" % (addr.host, addr.port)
data = yield http_request(self.url, '')
self.assertEqual(data, "Yay")
示例2: test_http_request_potential_data_loss
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import response_body [as 别名]
def test_http_request_potential_data_loss(self):
"""
In the absence of a Content-Length header or chunked transfer encoding,
we need to swallow a PotentialDataLoss exception.
"""
# We can't use Twisted's HTTP server, because that always does the
# sensible thing. We also pretend to be HTTP 1.0 for simplicity.
factory = Factory()
factory.protocol = FakeHTTP10
factory.response_body = (
"HTTP/1.0 201 CREATED\r\n"
"Date: Mon, 23 Jan 2012 15:08:47 GMT\r\n"
"Server: Fake HTTP 1.0\r\n"
"Content-Type: text/html; charset=utf-8\r\n"
"\r\n"
"Yay")
fake_server = FakeServer(factory)
agent_factory = lambda *a, **kw: ProxyAgentWithContext(
fake_server.endpoint, *a, **kw)
data = yield http_request(self.url, '', agent_class=agent_factory)
self.assertEqual(data, "Yay")