本文整理汇总了Python中twisted.web.client._makeGetterFactory函数的典型用法代码示例。如果您正苦于以下问题:Python _makeGetterFactory函数的具体用法?Python _makeGetterFactory怎么用?Python _makeGetterFactory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_makeGetterFactory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: downloadFile
def downloadFile(url, file, statusCallback=None, bucketFilter=None, contextFactory=None, *args, **kwargs):
factoryFactory = lambda url, *a, **kw: HTTPManagedDownloader(url, file, statusCallback=statusCallback, bucketFilter=bucketFilter, *a, **kw)
return _makeGetterFactory(
url,
factoryFactory,
contextFactory=contextFactory,
*args, **kwargs).deferred
开发者ID:jjongsma,项目名称:downpour,代码行数:7,代码来源:http.py
示例2: quiet_get_page
def quiet_get_page(url, contextFactory=None, *args, **kwargs):
"""A version of getPage that uses QuietHTTPClientFactory."""
return _makeGetterFactory(
url,
QuietHTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs).deferred
开发者ID:AndrewCvekl,项目名称:vumi,代码行数:7,代码来源:sentry.py
示例3: getPageAndHeaders
def getPageAndHeaders(url, contextFactory=None, *args, **kwargs):
factory = client._makeGetterFactory(
url,
client.HTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs)
return factory.deferred.addCallback(lambda page: (page, factory.response_headers))
开发者ID:forrestv,项目名称:bennu,代码行数:7,代码来源:jsonrpc.py
示例4: makeUpstreamGetter
def makeUpstreamGetter(upstream):
identifier, url, args, kwargs = upstream
subfactory = client._makeGetterFactory(url,
factory,
context_factory,
*args, **kwargs)
subfactory.deferred.addBoth(lambda x: (x, identifier, subfactory))
return subfactory.deferred
开发者ID:bussiere,项目名称:couchdb-lounge,代码行数:8,代码来源:fetcher.py
示例5: fetch
def fetch(url, contextFactory=None, *args, **kwargs):
def wrapper(error):
return Page(error=error.getErrorMessage())
d = client._makeGetterFactory(url, HTTPClientFactory,
contextFactory=contextFactory, *args, **kwargs).deferred
d.addErrback(wrapper)
return d
开发者ID:ddgromit,项目名称:cyclone,代码行数:8,代码来源:httpclient.py
示例6: _request_cookies
def _request_cookies(self, url, method="GET", data=None):
factory = _makeGetterFactory(self.base_url + url, HTTPClientFactory,
method=method, postdata=data,
cookies=self.cookies)
factory.deferred.addErrback(self._log_errback)
def cookie_magic(data):
return (data, factory.cookies)
factory.deferred.addCallback(cookie_magic)
return factory.deferred
开发者ID:minus7,项目名称:oneliner-tui,代码行数:9,代码来源:async.py
示例7: getTwitterStream
def getTwitterStream(url, username, password, contextFactory=None, *args, **kwargs):
encoded_auth = base64.encodestring("%s:%s" % (username, password))
authorization_header = "Basic %s" % encoded_auth
kwargs.update({'headers' : {'authorization': authorization_header}})
return _makeGetterFactory(
url,
StreamingTwitterClientFactory,
contextFactory=contextFactory,
*args, **kwargs).deferred
开发者ID:thatmattbone,项目名称:lab,代码行数:10,代码来源:twitiwt.py
示例8: getPage
def getPage(url, contextFactory=None, *args, **kwargs):
"""Adapted version of twisted.web.client.getPage"""
def _clientfactory(*args, **kwargs):
timeout = kwargs.pop('timeout', 0)
f = client.ScrapyHTTPClientFactory(Request(*args, **kwargs), timeout=timeout)
f.deferred.addCallback(lambda r: r.body)
return f
from twisted.web.client import _makeGetterFactory
return _makeGetterFactory(url, _clientfactory,
contextFactory=contextFactory, *args, **kwargs).deferred
开发者ID:bihicheng,项目名称:scrapy,代码行数:11,代码来源:test_webclient.py
示例9: get_page
def get_page(self, url, contextFactory=None, *args, **kwargs):
'''Adapted version of twisted.web.client.getPage'''
def _clientfactory(*args, **kwargs):
timeout = kwargs.pop('timeout', 0)
download_size = kwargs.pop('download_size', 0)
f = CrawlmiHTPPClientFactory(Request(*args, **kwargs),
timeout=timeout, download_size=download_size)
f.deferred.addCallback(lambda r: r.body)
return f
from twisted.web.client import _makeGetterFactory
return _makeGetterFactory(url, _clientfactory,
contextFactory=contextFactory, *args, **kwargs).deferred
开发者ID:Mimino666,项目名称:crawlmi,代码行数:12,代码来源:test_webclient.py
示例10: start
def start(self):
self.original_mimetype = self.download.mime_type
self.download.status = Status.STARTING
bucketFilter = ThrottledBucketFilter(0, self.manager.get_download_rate_filter())
factoryFactory = lambda url, *a, **kw: HTTPManagedDownloader(str(self.download.url),
os.path.join(self.directory, self.download.filename),
statusCallback=DownloadStatus(self.download),
bucketFilter=bucketFilter, *a, **kw)
self.factory = _makeGetterFactory(str(self.download.url), factoryFactory)
self.factory.deferred.addCallback(self.check_mimetype);
self.factory.deferred.addErrback(self.errback);
return True
开发者ID:jjongsma,项目名称:downpour,代码行数:12,代码来源:http.py
示例11: getPage
def getPage(url, contextFactory=None, response_transform=None, *args, **kwargs):
"""Adapted version of twisted.web.client.getPage"""
def _clientfactory(url, *args, **kwargs):
url = to_unicode(url)
timeout = kwargs.pop('timeout', 0)
f = client.ScrapyHTTPClientFactory(
Request(url, *args, **kwargs), timeout=timeout)
f.deferred.addCallback(response_transform or (lambda r: r.body))
return f
from twisted.web.client import _makeGetterFactory
return _makeGetterFactory(to_bytes(url), _clientfactory,
contextFactory=contextFactory, *args, **kwargs).deferred
开发者ID:01-,项目名称:scrapy,代码行数:13,代码来源:test_webclient.py
示例12: test_infiniteRedirection
def test_infiniteRedirection(self):
"""
When more than C{redirectLimit} HTTP redirects are encountered, the
page request fails with L{InfiniteRedirection}.
"""
def checkRedirectCount(*a):
self.assertEqual(f._redirectCount, 13)
self.assertEqual(self.infiniteRedirectResource.count, 13)
f = client._makeGetterFactory(self.getURL("infiniteRedirect"), client.HTTPClientFactory, redirectLimit=13)
d = self.assertFailure(f.deferred, error.InfiniteRedirection)
d.addCallback(checkRedirectCount)
return d
开发者ID:ragercool,项目名称:twisted,代码行数:14,代码来源:test_webclient.py
示例13: getPage
def getPage(url, contextFactory=None, *args, **kwargs):
"""
Download a web page as a string.
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.
"""
kwargs['agent'] = "Coherence PageGetter"
return client._makeGetterFactory(
url,
HeaderAwareHTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs).deferred
开发者ID:BlackHole,项目名称:coherence,代码行数:15,代码来源:utils.py
示例14: subgen
def subgen():
lastError = None
for (identifier, url, args, kwargs) in upstreams:
subfactory = client._makeGetterFactory(url,
factory,
context_factory,
*args, **kwargs)
wait = defer.waitForDeferred(subfactory.deferred)
yield wait
try:
yield (wait.getResult(), identifier, subfactory)
return
except ConnectError:
lastError = sys.exc_info()[1]
raise lastError and lastError or error.Error(http.INTERNAL_SERVER_ERROR)
开发者ID:bussiere,项目名称:couchdb-lounge,代码行数:15,代码来源:fetcher.py
示例15: getPageAndHeaders
def getPageAndHeaders(url, contextFactory=None, *args, **kwargs):
"""Return deferred with a (body, headers) success result.
This is a small modification to twisted.web.client.getPage that
allows the caller access to the response headers.
"""
factory = txwebclient._makeGetterFactory(
url,
txwebclient.HTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs)
return factory.deferred.addCallback(
lambda page: (page, factory.response_headers))
开发者ID:tomatoXu,项目名称:ZenPacks.zenoss.OpenStackInfrastructure,代码行数:15,代码来源:novaapiclient.py
示例16: test_downloadHeaders
def test_downloadHeaders(self):
"""
After L{client.HTTPDownloader.deferred} fires, the
L{client.HTTPDownloader} instance's C{status} and C{response_headers}
attributes are populated with the values from the response.
"""
def checkHeaders(factory):
self.assertEqual(factory.status, b"200")
self.assertEqual(factory.response_headers[b"content-type"][0], b"text/html")
self.assertEqual(factory.response_headers[b"content-length"][0], b"10")
os.unlink(factory.fileName)
factory = client._makeGetterFactory(self.getURL("file"), client.HTTPDownloader, fileOrName=self.mktemp())
return factory.deferred.addCallback(lambda _: checkHeaders(factory))
开发者ID:ragercool,项目名称:twisted,代码行数:15,代码来源:test_webclient.py
示例17: test_downloadCookies
def test_downloadCookies(self):
"""
The C{cookies} dict passed to the L{client.HTTPDownloader}
initializer is used to populate the I{Cookie} header included in the
request sent to the server.
"""
output = self.mktemp()
factory = client._makeGetterFactory(
self.getURL("cookiemirror"), client.HTTPDownloader, fileOrName=output, cookies={b"foo": b"bar"}
)
def cbFinished(ignored):
self.assertEqual(FilePath(output).getContent(), "[('foo', 'bar')]")
factory.deferred.addCallback(cbFinished)
return factory.deferred
开发者ID:ragercool,项目名称:twisted,代码行数:16,代码来源:test_webclient.py
示例18: test_downloadRedirectLimit
def test_downloadRedirectLimit(self):
"""
When more than C{redirectLimit} HTTP redirects are encountered, the
page request fails with L{InfiniteRedirection}.
"""
def checkRedirectCount(*a):
self.assertEqual(f._redirectCount, 7)
self.assertEqual(self.infiniteRedirectResource.count, 7)
f = client._makeGetterFactory(
self.getURL("infiniteRedirect"), client.HTTPDownloader, fileOrName=self.mktemp(), redirectLimit=7
)
d = self.assertFailure(f.deferred, error.InfiniteRedirection)
d.addCallback(checkRedirectCount)
return d
开发者ID:ragercool,项目名称:twisted,代码行数:16,代码来源:test_webclient.py
示例19: getPageWebClient
def getPageWebClient(self, url, contextFactory=None, *args, **kwargs):
"""
Download a web page as a string.
COPY OF twisted.web.client.getPage to store the factory
Download a page. Return a deferred, which will callback with a
page (as a string) or errback with a description of the error.
See L{HTTPClientFactory} to see what extra arguments can be passed.
"""
self.httpGetterFactory = _makeGetterFactory(
url,
HTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs)
return self.httpGetterFactory.deferred
开发者ID:13K-OMAR,项目名称:enigma2-plugins-sh4,代码行数:17,代码来源:CurlyTx.py
示例20: getPage
def getPage(url, contextFactory=None, *args, **kwargs):
"""
Download a web page as a string.
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.
"""
# This function is like twisted.web.client.getPage, except it uses
# our HeaderAwareHTTPClientFactory instead of HTTPClientFactory
# and sets the user agent.
if 'headers' in kwargs and 'user-agent' in kwargs['headers']:
kwargs['agent'] = kwargs['headers']['user-agent']
elif not 'agent' in kwargs:
kwargs['agent'] = "Coherence PageGetter"
return client._makeGetterFactory(
url,
HeaderAwareHTTPClientFactory,
contextFactory=contextFactory,
*args, **kwargs).deferred
开发者ID:pezam,项目名称:Cohen,代码行数:21,代码来源:utils.py
注:本文中的twisted.web.client._makeGetterFactory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论