本文整理匯總了Python中scrapy.utils.datatypes.CaselessDict類的典型用法代碼示例。如果您正苦於以下問題:Python CaselessDict類的具體用法?Python CaselessDict怎麽用?Python CaselessDict使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CaselessDict類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: make_headers
def make_headers(self, headers):
headers = CaselessDict(headers)
if 'user-agent' in headers:
self.user_agent = headers.pop('user-agent')
self.cookies = self.make_cookies(headers.pop('cookie', {}))
self.headers = headers
示例2: test_caseless
def test_caseless(self):
d = CaselessDict()
d['key_Lower'] = 1
self.assertEqual(d['KEy_loWer'], 1)
self.assertEqual(d.get('KEy_loWer'), 1)
d['KEY_LOWER'] = 3
self.assertEqual(d['key_Lower'], 3)
self.assertEqual(d.get('key_Lower'), 3)
示例3: test_setdefault
def test_setdefault(self):
d = CaselessDict({'a': 1, 'b': 2})
r = d.setdefault('A', 5)
self.assertEqual(r, 1)
self.assertEqual(d['A'], 1)
r = d.setdefault('c', 5)
self.assertEqual(r, 5)
self.assertEqual(d['C'], 5)
示例4: test_fromkeys
def test_fromkeys(self):
keys = ('a', 'b')
d = CaselessDict.fromkeys(keys)
self.assertEqual(d['A'], None)
self.assertEqual(d['B'], None)
d = CaselessDict.fromkeys(keys, 1)
self.assertEqual(d['A'], 1)
self.assertEqual(d['B'], 1)
instance = CaselessDict()
d = instance.fromkeys(keys)
self.assertEqual(d['A'], None)
self.assertEqual(d['B'], None)
d = instance.fromkeys(keys, 1)
self.assertEqual(d['A'], 1)
self.assertEqual(d['B'], 1)
示例5: test_pop
def test_pop(self):
d = CaselessDict()
d['a'] = 1
self.assertEqual(d.pop('A'), 1)
self.assertRaises(KeyError, d.pop, 'A')
示例6: test_getdefault
def test_getdefault(self):
d = CaselessDict()
self.assertEqual(d.get('c', 5), 5)
d['c'] = 10
self.assertEqual(d.get('c', 5), 10)
示例7: test_copy
def test_copy(self):
h1 = CaselessDict({'header1': 'value'})
h2 = copy.copy(h1)
self.assertEqual(h1, h2)
self.assertEqual(h1.get('header1'), h2.get('header1'))
assert isinstance(h2, CaselessDict)
示例8: test_contains
def test_contains(self):
d = CaselessDict()
d['a'] = 1
assert 'a' in d
assert d.has_key('a')