本文整理汇总了Python中paste.util.multidict.MultiDict.getall方法的典型用法代码示例。如果您正苦于以下问题:Python MultiDict.getall方法的具体用法?Python MultiDict.getall怎么用?Python MultiDict.getall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类paste.util.multidict.MultiDict
的用法示例。
在下文中一共展示了MultiDict.getall方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dict
# 需要导入模块: from paste.util.multidict import MultiDict [as 别名]
# 或者: from paste.util.multidict.MultiDict import getall [as 别名]
def test_dict():
d = MultiDict({'a': 1})
assert list(d.items()) == [('a', 1)]
d['b'] = 2
d['c'] = 3
assert list(d.items()) == [('a', 1), ('b', 2), ('c', 3)]
d['b'] = 4
assert list(d.items()) == [('a', 1), ('c', 3), ('b', 4)]
d.add('b', 5)
assert_raises(KeyError, d.getone, "b")
assert d.getall('b') == [4, 5]
assert list(d.items()) == [('a', 1), ('c', 3), ('b', 4), ('b', 5)]
del d['b']
assert list(d.items()) == [('a', 1), ('c', 3)]
assert d.pop('xxx', 5) == 5
assert d.getone('a') == 1
assert d.popitem() == ('c', 3)
assert list(d.items()) == [('a', 1)]
item = []
assert d.setdefault('z', item) is item
assert list(d.items()) == [('a', 1), ('z', item)]
assert d.setdefault('y', 6) == 6
assert d.mixed() == {'a': 1, 'y': 6, 'z': item}
assert d.dict_of_lists() == {'a': [1], 'y': [6], 'z': [item]}
assert 'a' in d
dcopy = d.copy()
assert dcopy is not d
assert dcopy == d
d['x'] = 'x test'
assert dcopy != d
d[(1, None)] = (None, 1)
assert list(d.items()) == [('a', 1), ('z', []), ('y', 6), ('x', 'x test'),
((1, None), (None, 1))]
示例2: MimeHeaders
# 需要导入模块: from paste.util.multidict import MultiDict [as 别名]
# 或者: from paste.util.multidict.MultiDict import getall [as 别名]
class MimeHeaders(object):
"""Dictionary-like object that preserves the order and
supports multiple values for the same key, knows
whether it has been changed after the creation
"""
def __init__(self, items=()):
self._v = MultiDict([(normalize(key), remove_newlines(val))
for (key, val) in items])
self.changed = False
def __getitem__(self, key):
return self._v.get(normalize(key), None)
def __len__(self):
return len(self._v)
def __iter__(self):
return iter(self._v)
def __contains__(self, key):
return normalize(key) in self._v
def __setitem__(self, key, value):
self._v[normalize(key)] = remove_newlines(value)
self.changed = True
def __delitem__(self, key):
del self._v[normalize(key)]
self.changed = True
def __nonzero__(self):
return len(self._v) > 0
def prepend(self, key, value):
self._v._items.insert(0, (normalize(key), remove_newlines(value)))
self.changed = True
def add(self, key, value):
"""Adds header without changing the
existing headers with same name"""
self._v.add(normalize(key), remove_newlines(value))
self.changed = True
def keys(self):
"""
Returns the keys. (message header names)
It remembers the order in which they were added, what
is really important
"""
return self._v.keys()
def transform(self, fn):
"""Accepts a function, getting a key, val and returning
a new pair of key, val and applies the function to all
header, value pairs in the message.
"""
changed = [False]
def tracking_fn(key, val):
new_key, new_val = fn(key, val)
if new_val != val or new_key != key:
changed[0] = True
return new_key, new_val
v = MultiDict(tracking_fn(key, val) for key, val in self._v.iteritems())
if changed[0]:
self._v = v
self.changed = True
def items(self):
"""
Returns header,val pairs in the preserved order.
"""
return list(self.iteritems())
def iteritems(self):
"""
Returns iterator header,val pairs in the preserved order.
"""
return self._v.iteritems()
def get(self, key, default=None):
"""
Returns header value (case-insensitive).
"""
return self._v.get(normalize(key), default)
def getall(self, key):
"""
Returns all header values by the given header name
(case-insensitive)
"""
return self._v.getall(normalize(key))
def have_changed(self):
"""Tells whether someone has altered the headers
after creation"""
#.........这里部分代码省略.........