本文整理汇总了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)
示例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")
示例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
示例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")
示例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)
示例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'))