本文整理匯總了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