當前位置: 首頁>>代碼示例>>Python>>正文


Python client.HTTPDownloader方法代碼示例

本文整理匯總了Python中twisted.web.client.HTTPDownloader方法的典型用法代碼示例。如果您正苦於以下問題:Python client.HTTPDownloader方法的具體用法?Python client.HTTPDownloader怎麽用?Python client.HTTPDownloader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.web.client的用法示例。


在下文中一共展示了client.HTTPDownloader方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_downloadTimeout

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def test_downloadTimeout(self):
        """
        If the timeout indicated by the C{timeout} parameter to
        L{client.HTTPDownloader.__init__} elapses without the complete response
        being received, the L{defer.Deferred} returned by
        L{client.downloadPage} fires with a L{Failure} wrapping a
        L{defer.TimeoutError}.
        """
        self.cleanupServerConnections = 2
        # Verify the behavior if no bytes are ever written.
        first = client.downloadPage(
            self.getURL("wait"),
            self.mktemp(), timeout=0.01)

        # Verify the behavior if some bytes are written but then the request
        # never completes.
        second = client.downloadPage(
            self.getURL("write-then-wait"),
            self.mktemp(), timeout=0.01)

        return defer.gatherResults([
            self.assertFailure(first, defer.TimeoutError),
            self.assertFailure(second, defer.TimeoutError)]) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:25,代碼來源:test_webclient.py

示例2: test_downloadTimeoutsWorkWithoutReading

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def test_downloadTimeoutsWorkWithoutReading(self):
        """
        If the timeout indicated by the C{timeout} parameter to
        L{client.HTTPDownloader.__init__} elapses without the complete response
        being received, the L{defer.Deferred} returned by
        L{client.downloadPage} fires with a L{Failure} wrapping a
        L{defer.TimeoutError}, even if the remote peer isn't reading data from
        the socket.
        """
        self.cleanupServerConnections = 1

        # The timeout here needs to be slightly longer to give the resource a
        # change to stop the reading.
        d = client.downloadPage(
            self.getURL("never-read"),
            self.mktemp(), timeout=0.05)
        return self.assertFailure(d, defer.TimeoutError) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_webclient.py

示例3: test_downloadHeaders

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
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:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_webclient.py

示例4: test_downloadCookies

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
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(),
                b"[('foo', 'bar')]")
        factory.deferred.addCallback(cbFinished)
        return factory.deferred 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:20,代碼來源:test_webclient.py

示例5: test_downloadRedirectLimit

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
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:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_webclient.py

示例6: test_downloadHeaders

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
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.assertEquals(factory.status, '200')
            self.assertEquals(factory.response_headers['content-type'][0], 'text/html')
            self.assertEquals(factory.response_headers['content-length'][0], '10')
            os.unlink(factory.fileName)
        factory = client._makeGetterFactory(
            self.getURL('file'),
            client.HTTPDownloader,
            fileOrName=self.mktemp())
        return factory.deferred.addCallback(lambda _: checkHeaders(factory)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:18,代碼來源:test_webclient.py

示例7: test_downloadCookies

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
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={'foo': 'bar'})
        def cbFinished(ignored):
            self.assertEqual(
                FilePath(output).getContent(),
                "[('foo', 'bar')]")
        factory.deferred.addCallback(cbFinished)
        return factory.deferred 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:20,代碼來源:test_webclient.py

示例8: test_downloadRedirectLimit

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def test_downloadRedirectLimit(self):
        """
        When more than C{redirectLimit} HTTP redirects are encountered, the
        page request fails with L{InfiniteRedirection}.
        """
        def checkRedirectCount(*a):
            self.assertEquals(f._redirectCount, 7)
            self.assertEquals(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:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_webclient.py

示例9: attemptRequestWithMaliciousMethod

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def attemptRequestWithMaliciousMethod(self, method):
        """
        Attempt a request with the provided method.

        @param method: L{MethodInjectionTestsMixin}
        """
        client.HTTPDownloader(
            b"https://twisted.invalid",
            io.BytesIO(),
            method=method,
        ) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:13,代碼來源:test_webclient.py

示例10: attemptRequestWithMaliciousURI

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def attemptRequestWithMaliciousURI(self, uri):
        """
        Attempt a request with the provided URI.

        @param uri: L{URIInjectionTestsMixin}
        """
        client.HTTPDownloader(uri, io.BytesIO()) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:9,代碼來源:test_webclient.py

示例11: __init__

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def __init__(self, url, file, progressCallback, *a, **kw):
        client.HTTPDownloader.__init__(self, url, file, *a, **kw)
        self.progressCallback = progressCallback
        self.written = 0 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:6,代碼來源:HTTPDownloader.py

示例12: gotHeaders

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPDownloader [as 別名]
def gotHeaders(self, headers):
        self.response_headers = headers
        client.HTTPDownloader.gotHeaders(self, headers)
        self.contentLength = headers.get("content-length", None)
        if self.contentLength is not None:
            self.contentLength = int(self.contentLength[0]) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:8,代碼來源:HTTPDownloader.py


注:本文中的twisted.web.client.HTTPDownloader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。