本文整理汇总了Python中twisted.web.client.HTTPClientFactory.protocol方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPClientFactory.protocol方法的具体用法?Python HTTPClientFactory.protocol怎么用?Python HTTPClientFactory.protocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.HTTPClientFactory
的用法示例。
在下文中一共展示了HTTPClientFactory.protocol方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getPage
# 需要导入模块: from twisted.web.client import HTTPClientFactory [as 别名]
# 或者: from twisted.web.client.HTTPClientFactory import protocol [as 别名]
def _getPage(url, host, port):
"""
Fetch the body of the given url via HTTP, connecting to the given host
and port.
@param url: The URL to GET
@type url: C{str}
@param host: The hostname to connect to
@type host: C{str}
@param port: The port number to connect to
@type port: C{int}
@return: A deferred; upon 200 success the body of the response is returned,
otherwise a twisted.web.error.Error is the result.
"""
factory = HTTPClientFactory(url)
factory.protocol = HTTPPageGetter
connect(GAIEndpoint(reactor, host, port), factory)
return factory.deferred
示例2: getPageU
# 需要导入模块: from twisted.web.client import HTTPClientFactory [as 别名]
# 或者: from twisted.web.client.HTTPClientFactory import protocol [as 别名]
def getPageU(url, contextFactory=None, *args, **kwargs):
"""Download a web page as a unicode object.
Download a page. Return a deferred, which will callback with a
page (as a string) or errback with a description of the error.
See HTTPClientFactory to see what extra args can be passed.
"""
scheme, host, port, path = _parse(url)
factory = HTTPClientFactory(url, *args, **kwargs)
factory.protocol = UnicodeHTTPPageGetter
if scheme == 'https':
from twisted.internet import ssl
if contextFactory is None:
contextFactory = ssl.ClientContextFactory()
reactor.connectSSL(host, port, factory, contextFactory)
else:
reactor.connectTCP(host, port, factory)
return factory.deferred