Python twisted.web.client.HTTPPageGetter() Examples

The following are 8 code examples of twisted.web.client.HTTPPageGetter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.web.client , or try the search function .
Example #1
Source File: test_webclient.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #2
Source File: test_webclient.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_httpPageGetterDeprecated(self):
        """
        L{client.HTTPPageGetter} is deprecated.
        """
        self._testDeprecatedClass("HTTPPageGetter") 
Example #3
Source File: test_webclient.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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) 
Example #4
Source File: test_webclient.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_httpPageGetterDeprecated(self):
        """
        L{client.HTTPPageGetter} is deprecated.
        """
        self._testDeprecatedClass("HTTPPageGetter") 
Example #5
Source File: test_webclient.py    From learn_python3_spider with MIT License 5 votes vote down vote up
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 
Example #6
Source File: test_webclient.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
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") 
Example #7
Source File: HTTPDownloader.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #8
Source File: HTTPDownloader.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def lineReceived(self, line):
        return client.HTTPPageGetter.lineReceived(self, line.rstrip('\r'))