本文整理汇总了Python中werkzeug.datastructures.CombinedMultiDict.lists方法的典型用法代码示例。如果您正苦于以下问题:Python CombinedMultiDict.lists方法的具体用法?Python CombinedMultiDict.lists怎么用?Python CombinedMultiDict.lists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.datastructures.CombinedMultiDict
的用法示例。
在下文中一共展示了CombinedMultiDict.lists方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_combined_multidict
# 需要导入模块: from werkzeug.datastructures import CombinedMultiDict [as 别名]
# 或者: from werkzeug.datastructures.CombinedMultiDict import lists [as 别名]
def test_combined_multidict():
"""Combined multidict behavior"""
d1 = MultiDict([('foo', '1')])
d2 = MultiDict([('bar', '2'), ('bar', '3')])
d = CombinedMultiDict([d1, d2])
# lookup
assert d['foo'] == '1'
assert d['bar'] == '2'
assert d.getlist('bar') == ['2', '3']
assert sorted(d.items()) == [('bar', '2'), ('foo', '1')], d.items()
assert sorted(d.items(multi=True)) == [('bar', '2'), ('bar', '3'), ('foo', '1')]
assert 'missingkey' not in d
assert 'foo' in d
# type lookup
assert d.get('foo', type=int) == 1
assert d.getlist('bar', type=int) == [2, 3]
# get key errors for missing stuff
assert_raises(KeyError, lambda: d["missing"])
# make sure that they are immutable
def test_assign():
d['foo'] = 'blub'
assert_raises(TypeError, test_assign)
# copies are immutable
d = d.copy()
assert_raises(TypeError, test_assign)
# make sure lists merges
md1 = MultiDict((("foo", "bar"),))
md2 = MultiDict((("foo", "blafasel"),))
x = CombinedMultiDict((md1, md2))
assert x.lists() == [('foo', ['bar', 'blafasel'])]