当前位置: 首页>>代码示例>>Python>>正文


Python Headers.getlist方法代码示例

本文整理汇总了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)
开发者ID:pyarnold,项目名称:scrapy,代码行数:9,代码来源:test_http_headers.py

示例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
开发者ID:01-,项目名称:scrapy,代码行数:9,代码来源:test_http_headers.py

示例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'])
开发者ID:pyarnold,项目名称:scrapy,代码行数:11,代码来源:test_http_headers.py

示例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'])
开发者ID:01-,项目名称:scrapy,代码行数:11,代码来源:test_http_headers.py

示例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
开发者ID:pyarnold,项目名称:scrapy,代码行数:13,代码来源:test_http_headers.py

示例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'])
开发者ID:bihicheng,项目名称:scrapy,代码行数:14,代码来源:test_http_headers.py

示例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'), [])
开发者ID:pyarnold,项目名称:scrapy,代码行数:9,代码来源:test_http_headers.py

示例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"])
开发者ID:elacuesta,项目名称:scrapy,代码行数:8,代码来源:test_downloader_handlers.py

示例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'])
开发者ID:pyarnold,项目名称:scrapy,代码行数:8,代码来源:test_http_headers.py

示例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'])
开发者ID:pyarnold,项目名称:scrapy,代码行数:8,代码来源:test_http_headers.py

示例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'])
开发者ID:pyarnold,项目名称:scrapy,代码行数:8,代码来源:test_http_headers.py


注:本文中的scrapy.http.Headers.getlist方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。