本文整理汇总了Python中scrapy.http.Headers.getlist方法的典型用法代码示例。如果您正苦于以下问题:Python Headers.getlist方法的具体用法?Python Headers.getlist怎么用?Python Headers.getlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.http.Headers
的用法示例。
在下文中一共展示了Headers.getlist方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_copy(self):
h1 = Headers({'header1': ['value1', 'value2']})
h2 = copy.copy(h1)
self.assertEqual(h1, h2)
self.assertEqual(h1.getlist('header1'), h2.getlist('header1'))
assert h1.getlist('header1') is not h2.getlist('header1')
assert isinstance(h2, Headers)
示例2: test_multivalue
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_multivalue(self):
h = Headers()
h['X-Forwarded-For'] = hlist = ['ip1', 'ip2']
self.assertEqual(h['X-Forwarded-For'], b'ip2')
self.assertEqual(h.get('X-Forwarded-For'), b'ip2')
self.assertEqual(h.getlist('X-Forwarded-For'), [b'ip1', b'ip2'])
assert h.getlist('X-Forwarded-For') is not hlist
示例3: test_appendlist
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_appendlist(self):
h1 = Headers({'header1': 'value1'})
h1.appendlist('header1', 'value3')
self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])
h1 = Headers()
h1.appendlist('header1', 'value1')
h1.appendlist('header1', 'value3')
self.assertEqual(h1.getlist('header1'), ['value1', 'value3'])
示例4: test_int_value
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_int_value(self):
h1 = Headers({'hey': 5})
h1['foo'] = 1
h1.setdefault('bar', 2)
h1.setlist('buz', [1, 'dos', 3])
self.assertEqual(h1.getlist('foo'), [b'1'])
self.assertEqual(h1.getlist('bar'), [b'2'])
self.assertEqual(h1.getlist('buz'), [b'1', b'dos', b'3'])
self.assertEqual(h1.getlist('hey'), [b'5'])
示例5: test_setdefault
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_setdefault(self):
h = Headers()
hlist = ['ip1', 'ip2']
olist = h.setdefault('X-Forwarded-For', hlist)
assert h.getlist('X-Forwarded-For') is not hlist
assert h.getlist('X-Forwarded-For') is olist
h = Headers()
olist = h.setdefault('X-Forwarded-For', 'ip1')
self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1'])
assert h.getlist('X-Forwarded-For') is olist
示例6: test_basics
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_basics(self):
h = Headers({'Content-Type': 'text/html', 'Content-Length': 1234})
assert h['Content-Type']
assert h['Content-Length']
self.assertRaises(KeyError, h.__getitem__, 'Accept')
self.assertEqual(h.get('Accept'), None)
self.assertEqual(h.getlist('Accept'), [])
self.assertEqual(h.get('Accept', '*/*'), '*/*')
self.assertEqual(h.getlist('Accept', '*/*'), ['*/*'])
self.assertEqual(h.getlist('Accept', ['text/html', 'images/jpeg']), ['text/html','images/jpeg'])
示例7: test_none_value
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_none_value(self):
h1 = Headers()
h1['foo'] = 'bar'
h1['foo'] = None
h1.setdefault('foo', 'bar')
self.assertEqual(h1.get('foo'), None)
self.assertEqual(h1.getlist('foo'), [])
示例8: _test
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def _test(response):
import json
headers = Headers(json.loads(response.text)['headers'])
contentlengths = headers.getlist('Content-Length')
self.assertEqual(len(contentlengths), 1)
self.assertEqual(contentlengths, [b"0"])
示例9: test_update
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_update(self):
h = Headers()
h.update(
{'Content-Type': 'text/html', 'X-Forwarded-For': ['ip1', 'ip2']})
self.assertEqual(h.getlist('Content-Type'), ['text/html'])
self.assertEqual(h.getlist('X-Forwarded-For'), ['ip1', 'ip2'])
示例10: test_single_value
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_single_value(self):
h = Headers()
h['Content-Type'] = 'text/html'
self.assertEqual(h['Content-Type'], 'text/html')
self.assertEqual(h.get('Content-Type'), 'text/html')
self.assertEqual(h.getlist('Content-Type'), ['text/html'])
示例11: test_setlistdefault
# 需要导入模块: from scrapy.http import Headers [as 别名]
# 或者: from scrapy.http.Headers import getlist [as 别名]
def test_setlistdefault(self):
h1 = Headers({'header1': 'value1'})
h1.setlistdefault('header1', ['value2', 'value3'])
h1.setlistdefault('header2', ['value2', 'value3'])
self.assertEqual(h1.getlist('header1'), ['value1'])
self.assertEqual(h1.getlist('header2'), ['value2', 'value3'])