当前位置: 首页>>代码示例>>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;未经允许,请勿转载。