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


Python client.HTTPPageGetter方法代碼示例

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


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

示例1: test_earlyHeaders

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def test_earlyHeaders(self):
        """
        When a connection is made, L{HTTPPagerGetter} sends the headers from
        its factory's C{headers} dict.  If I{Host} or I{Content-Length} is
        present in this dict, the values are not sent, since they are sent with
        special values before the C{headers} dict is processed.  If
        I{User-Agent} is present in the dict, it overrides the value of the
        C{agent} attribute of the factory.  If I{Cookie} is present in the
        dict, its value is added to the values from the factory's C{cookies}
        attribute.
        """
        factory = client.HTTPClientFactory(
            b'http://foo/bar',
            agent=b"foobar",
            cookies={b'baz': b'quux'},
            postdata=b"some data",
            headers={
                b'Host': b'example.net',
                b'User-Agent': b'fooble',
                b'Cookie': b'blah blah',
                b'Content-Length': b'12981',
                b'Useful': b'value'})
        transport = StringTransport()
        protocol = client.HTTPPageGetter()
        protocol.factory = factory
        protocol.makeConnection(transport)
        result = transport.value()
        for expectedHeader in [
            b"Host: example.net\r\n",
            b"User-Agent: foobar\r\n",
            b"Content-Length: 9\r\n",
            b"Useful: value\r\n",
            b"connection: close\r\n",
            b"Cookie: blah blah; baz=quux\r\n"]:
            self.assertIn(expectedHeader, result) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:37,代碼來源:test_webclient.py

示例2: test_httpPageGetterDeprecated

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def test_httpPageGetterDeprecated(self):
        """
        L{client.HTTPPageGetter} is deprecated.
        """
        self._testDeprecatedClass("HTTPPageGetter") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_webclient.py

示例3: makeHTTPPageGetterFactory

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def makeHTTPPageGetterFactory(protocolClass, method, host, path):
    """
    Make a L{ClientFactory} that can be used with
    L{client.HTTPPageGetter} and its subclasses.

    @param protocolClass: The protocol class
    @type protocolClass: A subclass of L{client.HTTPPageGetter}

    @param method: the HTTP method

    @param host: the host

    @param path: The URI path

    @return: A L{ClientFactory}.
    """
    factory = ClientFactory.forProtocol(protocolClass)

    factory.method = method
    factory.host = host
    factory.path = path

    factory.scheme = b"http"
    factory.port = 0
    factory.headers = {}
    factory.agent = b"User/Agent"
    factory.cookies = {}

    return factory 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:31,代碼來源:test_webclient.py

示例4: test_earlyHeaders

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def test_earlyHeaders(self):
        """
        When a connection is made, L{HTTPPagerGetter} sends the headers from
        its factory's C{headers} dict.  If I{Host} or I{Content-Length} is
        present in this dict, the values are not sent, since they are sent with
        special values before the C{headers} dict is processed.  If
        I{User-Agent} is present in the dict, it overrides the value of the
        C{agent} attribute of the factory.  If I{Cookie} is present in the
        dict, its value is added to the values from the factory's C{cookies}
        attribute.
        """
        factory = client.HTTPClientFactory(
            'http://foo/bar',
            agent="foobar",
            cookies={'baz': 'quux'},
            postdata="some data",
            headers={
                'Host': 'example.net',
                'User-Agent': 'fooble',
                'Cookie': 'blah blah',
                'Content-Length': '12981',
                'Useful': 'value'})
        transport = StringTransport()
        protocol = client.HTTPPageGetter()
        protocol.factory = factory
        protocol.makeConnection(transport)
        self.assertEqual(
            transport.value(),
            "GET /bar HTTP/1.0\r\n"
            "Host: example.net\r\n"
            "User-Agent: foobar\r\n"
            "Content-Length: 9\r\n"
            "Useful: value\r\n"
            "connection: close\r\n"
            "Cookie: blah blah; baz=quux\r\n"
            "\r\n"
            "some data") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:39,代碼來源:test_webclient.py

示例5: handleHeader

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def handleHeader(self, key, value):
        if not self.decode:
            if key.lower() == 'content-encoding' and value.lower() == 'gzip':
                self.decode = True
        return client.HTTPPageGetter.handleHeader(self, key, value) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:7,代碼來源:HTTPDownloader.py

示例6: lineReceived

# 需要導入模塊: from twisted.web import client [as 別名]
# 或者: from twisted.web.client import HTTPPageGetter [as 別名]
def lineReceived(self, line):
        return client.HTTPPageGetter.lineReceived(self, line.rstrip('\r')) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:4,代碼來源:HTTPDownloader.py


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