annotate MoinMoin/support/werkzeug/datastructures.py @ 6132:df65dcf7daea

upgrade werkzeug to 0.12.2
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 17:49:42 +0200
parents 7f12cf241d5e
children
rev   line source
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 werkzeug.datastructures
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 This module provides mixins and classes with an immutable interface.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
8 :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 :license: BSD, see LICENSE for more details.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 import re
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 import codecs
4627
c404a1295318 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4614
diff changeset
13 import mimetypes
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
14 from copy import deepcopy
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
15 from itertools import repeat
6132
df65dcf7daea upgrade werkzeug to 0.12.2
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6129
diff changeset
16 from collections import Container, Iterable, MutableSet
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
17
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
18 from werkzeug._internal import _missing, _empty_stream
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
19 from werkzeug._compat import iterkeys, itervalues, iteritems, iterlists, \
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
20 PY2, text_type, integer_types, string_types, make_literal_wrapper, \
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
21 to_native
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
22 from werkzeug.filesystem import get_filesystem_encoding
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 _locale_delim_re = re.compile(r'[_-]')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 def is_immutable(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 raise TypeError('%r objects are immutable' % self.__class__.__name__)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
32 def iter_multi_items(mapping):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
33 """Iterates over the items of a mapping yielding keys and values
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
34 without dropping any from more complex structures.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
35 """
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
36 if isinstance(mapping, MultiDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
37 for item in iteritems(mapping, multi=True):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
38 yield item
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
39 elif isinstance(mapping, dict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
40 for key, value in iteritems(mapping):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
41 if isinstance(value, (tuple, list)):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
42 for value in value:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
43 yield key, value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
44 else:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
45 yield key, value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
46 else:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
47 for item in mapping:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
48 yield item
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
49
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
50
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
51 def native_itermethods(names):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
52 if not PY2:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
53 return lambda x: x
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
54
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
55 def setviewmethod(cls, name):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
56 viewmethod_name = 'view%s' % name
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
57 viewmethod = lambda self, *a, **kw: ViewItems(self, name, 'view_%s' % name, *a, **kw)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
58 viewmethod.__doc__ = \
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
59 '"""`%s()` object providing a view on %s"""' % (viewmethod_name, name)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
60 setattr(cls, viewmethod_name, viewmethod)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
61
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
62 def setitermethod(cls, name):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
63 itermethod = getattr(cls, name)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
64 setattr(cls, 'iter%s' % name, itermethod)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
65 listmethod = lambda self, *a, **kw: list(itermethod(self, *a, **kw))
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
66 listmethod.__doc__ = \
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
67 'Like :py:meth:`iter%s`, but returns a list.' % name
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
68 setattr(cls, name, listmethod)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
69
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
70 def wrap(cls):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
71 for name in names:
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
72 setitermethod(cls, name)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
73 setviewmethod(cls, name)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
74 return cls
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
75 return wrap
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
76
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
77
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78 class ImmutableListMixin(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
79
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 """Makes a :class:`list` immutable.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84 :private:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
87 _hash_cache = None
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
88
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
89 def __hash__(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
90 if self._hash_cache is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
91 return self._hash_cache
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
92 rv = self._hash_cache = hash(tuple(self))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
93 return rv
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
94
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
95 def __reduce_ex__(self, protocol):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
96 return type(self), (list(self),)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
97
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 def __delitem__(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 def __iadd__(self, other):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 __imul__ = __iadd__
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 def __setitem__(self, key, value):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 def append(self, item):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
109 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 remove = append
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 def extend(self, iterable):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 def insert(self, pos, value):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 def pop(self, index=-1):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 def reverse(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 def sort(self, cmp=None, key=None, reverse=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 class ImmutableList(ImmutableListMixin, list):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
129
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 """An immutable :class:`list`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 :private:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
137 def __repr__(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
138 return '%s(%s)' % (
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
139 self.__class__.__name__,
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
140 list.__repr__(self),
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
141 )
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 class ImmutableDictMixin(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
145
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
146 """Makes a :class:`dict` immutable.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
147
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
149
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150 :private:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
151 """
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
152 _hash_cache = None
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
153
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
154 @classmethod
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
155 def fromkeys(cls, keys, value=None):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
156 instance = super(cls, cls).__new__(cls)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
157 instance.__init__(zip(keys, repeat(value)))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
158 return instance
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
159
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
160 def __reduce_ex__(self, protocol):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
161 return type(self), (dict(self),)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
162
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
163 def _iter_hashitems(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
164 return iteritems(self)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
165
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
166 def __hash__(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
167 if self._hash_cache is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
168 return self._hash_cache
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
169 rv = self._hash_cache = hash(frozenset(self._iter_hashitems()))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
170 return rv
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
171
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
172 def setdefault(self, key, default=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
173 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
174
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
175 def update(self, *args, **kwargs):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
176 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 def pop(self, key, default=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181 def popitem(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
183
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 def __setitem__(self, key, value):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
186
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 def __delitem__(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190 def clear(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
191 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
192
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
193
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
194 class ImmutableMultiDictMixin(ImmutableDictMixin):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
195
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
196 """Makes a :class:`MultiDict` immutable.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
197
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
198 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
199
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
200 :private:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
201 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
202
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
203 def __reduce_ex__(self, protocol):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
204 return type(self), (list(iteritems(self, multi=True)),)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
205
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
206 def _iter_hashitems(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
207 return iteritems(self, multi=True)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
208
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
209 def add(self, key, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
210 is_immutable(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
211
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
212 def popitemlist(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
213 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
214
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
215 def poplist(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
216 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
217
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
218 def setlist(self, key, new_list):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
219 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
220
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
221 def setlistdefault(self, key, default_list=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
222 is_immutable(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
223
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
224
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
225 class UpdateDictMixin(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
226
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
227 """Makes dicts call `self.on_update` on modifications.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
228
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
229 .. versionadded:: 0.5
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
230
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
231 :private:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
232 """
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
233
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
234 on_update = None
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
235
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
236 def calls_update(name):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
237 def oncall(self, *args, **kw):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
238 rv = getattr(super(UpdateDictMixin, self), name)(*args, **kw)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
239 if self.on_update is not None:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
240 self.on_update(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
241 return rv
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
242 oncall.__name__ = name
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
243 return oncall
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
244
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
245 def setdefault(self, key, default=None):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
246 modified = key not in self
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
247 rv = super(UpdateDictMixin, self).setdefault(key, default)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
248 if modified and self.on_update is not None:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
249 self.on_update(self)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
250 return rv
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
251
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
252 def pop(self, key, default=_missing):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
253 modified = key in self
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
254 if default is _missing:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
255 rv = super(UpdateDictMixin, self).pop(key)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
256 else:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
257 rv = super(UpdateDictMixin, self).pop(key, default)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
258 if modified and self.on_update is not None:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
259 self.on_update(self)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
260 return rv
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
261
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
262 __setitem__ = calls_update('__setitem__')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
263 __delitem__ = calls_update('__delitem__')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
264 clear = calls_update('clear')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
265 popitem = calls_update('popitem')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
266 update = calls_update('update')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
267 del calls_update
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
268
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
269
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
270 class TypeConversionDict(dict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
271
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
272 """Works like a regular dict but the :meth:`get` method can perform
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
273 type conversions. :class:`MultiDict` and :class:`CombinedMultiDict`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
274 are subclasses of this class and provide the same feature.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
275
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
276 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
277 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
278
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
279 def get(self, key, default=None, type=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
280 """Return the default value if the requested data doesn't exist.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
281 If `type` is provided and is a callable it should convert the value,
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
282 return it or raise a :exc:`ValueError` if that is not possible. In
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
283 this case the function will return the default as if the value was not
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
284 found:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
285
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
286 >>> d = TypeConversionDict(foo='42', bar='blub')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
287 >>> d.get('foo', type=int)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
288 42
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
289 >>> d.get('bar', -1, type=int)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
290 -1
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
291
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
292 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
293 :param default: The default value to be returned if the key can't
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
294 be looked up. If not further specified `None` is
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
295 returned.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
296 :param type: A callable that is used to cast the value in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
297 :class:`MultiDict`. If a :exc:`ValueError` is raised
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
298 by this callable the default value is returned.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
299 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
300 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
301 rv = self[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
302 if type is not None:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
303 rv = type(rv)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
304 except (KeyError, ValueError):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
305 rv = default
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
306 return rv
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
307
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
308
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
309 class ImmutableTypeConversionDict(ImmutableDictMixin, TypeConversionDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
310
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
311 """Works like a :class:`TypeConversionDict` but does not support
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
312 modifications.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
313
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
314 .. versionadded:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
315 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316
4754
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
317 def copy(self):
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
318 """Return a shallow mutable copy of this object. Keep in mind that
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
319 the standard library's :func:`copy` function is a no-op for this class
4754
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
320 like for any other python immutable type (eg: :class:`tuple`).
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
321 """
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
322 return TypeConversionDict(self)
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
323
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
324 def __copy__(self):
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
325 return self
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
326
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
327
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
328 class ViewItems(object):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
329
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
330 def __init__(self, multi_dict, method, repr_name, *a, **kw):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
331 self.__multi_dict = multi_dict
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
332 self.__method = method
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
333 self.__repr_name = repr_name
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
334 self.__a = a
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
335 self.__kw = kw
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
336
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
337 def __get_items(self):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
338 return getattr(self.__multi_dict, self.__method)(*self.__a, **self.__kw)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
339
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
340 def __repr__(self):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
341 return '%s(%r)' % (self.__repr_name, list(self.__get_items()))
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
342
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
343 def __iter__(self):
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
344 return iter(self.__get_items())
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
345
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
346
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
347 @native_itermethods(['keys', 'values', 'items', 'lists', 'listvalues'])
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
348 class MultiDict(TypeConversionDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
349
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
350 """A :class:`MultiDict` is a dictionary subclass customized to deal with
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
351 multiple values for the same key which is for example used by the parsing
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
352 functions in the wrappers. This is necessary because some HTML form
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
353 elements pass multiple values for the same key.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
354
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
355 :class:`MultiDict` implements all standard dictionary methods.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 Internally, it saves all values for a key as a list, but the standard dict
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357 access methods will only return the first value for a key. If you want to
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358 gain access to the other values, too, you have to use the `list` methods as
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
359 explained below.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
360
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
361 Basic Usage:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
362
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
363 >>> d = MultiDict([('a', 'b'), ('a', 'c')])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
364 >>> d
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365 MultiDict([('a', 'b'), ('a', 'c')])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
366 >>> d['a']
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
367 'b'
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
368 >>> d.getlist('a')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
369 ['b', 'c']
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370 >>> 'a' in d
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
371 True
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
373 It behaves like a normal dict thus all dict functions will only return the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374 first value when multiple values for one key are found.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
378 render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
379 exceptions.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
380
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
381 A :class:`MultiDict` can be constructed from an iterable of
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
382 ``(key, value)`` tuples, a dict, a :class:`MultiDict` or from Werkzeug 0.2
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
383 onwards some keyword parameters.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
384
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385 :param mapping: the initial value for the :class:`MultiDict`. Either a
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
386 regular dict, an iterable of ``(key, value)`` tuples
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
387 or `None`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
388 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
389
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
390 def __init__(self, mapping=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
391 if isinstance(mapping, MultiDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
392 dict.__init__(self, ((k, l[:]) for k, l in iterlists(mapping)))
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
393 elif isinstance(mapping, dict):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
394 tmp = {}
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
395 for key, value in iteritems(mapping):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
396 if isinstance(value, (tuple, list)):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
397 if len(value) == 0:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
398 continue
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
399 value = list(value)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
400 else:
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
401 value = [value]
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402 tmp[key] = value
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403 dict.__init__(self, tmp)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
404 else:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 tmp = {}
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
406 for key, value in mapping or ():
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
407 tmp.setdefault(key, []).append(value)
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
408 dict.__init__(self, tmp)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
409
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
410 def __getstate__(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
411 return dict(self.lists())
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
412
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
413 def __setstate__(self, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
414 dict.clear(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
415 dict.update(self, value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
416
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
417 def __getitem__(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
418 """Return the first data value for this key;
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
419 raises KeyError if not found.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
420
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
422 :raise KeyError: if the key does not exist.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
423 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
424 if key in self:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
425 lst = dict.__getitem__(self, key)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
426 if len(lst) > 0:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
427 return lst[0]
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
428 raise exceptions.BadRequestKeyError(key)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
430 def __setitem__(self, key, value):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
431 """Like :meth:`add` but removes an existing key first.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
432
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
433 :param key: the key for the value.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
434 :param value: the value to set.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
435 """
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
436 dict.__setitem__(self, key, [value])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
437
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
438 def add(self, key, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
439 """Adds a new value for the key.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
440
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
441 .. versionadded:: 0.6
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
442
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
443 :param key: the key for the value.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
444 :param value: the value to add.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
445 """
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
446 dict.setdefault(self, key, []).append(value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
447
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
448 def getlist(self, key, type=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
449 """Return the list of items for a given key. If that key is not in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
450 `MultiDict`, the return value will be an empty list. Just as `get`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
451 `getlist` accepts a `type` parameter. All items will be converted
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
452 with the callable defined there.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
455 :param type: A callable that is used to cast the value in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
456 :class:`MultiDict`. If a :exc:`ValueError` is raised
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
457 by this callable the value will be removed from the list.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
458 :return: a :class:`list` of all the values for the key.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
459 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
461 rv = dict.__getitem__(self, key)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
462 except KeyError:
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
463 return []
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
464 if type is None:
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
465 return list(rv)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
466 result = []
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467 for item in rv:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
468 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469 result.append(type(item))
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 except ValueError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
471 pass
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
472 return result
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
474 def setlist(self, key, new_list):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475 """Remove the old values for a key and add new ones. Note that the list
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 you pass the values in will be shallow-copied before it is inserted in
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
477 the dictionary.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
478
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
479 >>> d = MultiDict()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
480 >>> d.setlist('foo', ['1', '2'])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
481 >>> d['foo']
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
482 '1'
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
483 >>> d.getlist('foo')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
484 ['1', '2']
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
485
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
486 :param key: The key for which the values are set.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487 :param new_list: An iterable with the new values for the key. Old values
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 are removed first.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
489 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
490 dict.__setitem__(self, key, list(new_list))
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
491
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492 def setdefault(self, key, default=None):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493 """Returns the value for the key if it is in the dict, otherwise it
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494 returns `default` and sets that value for `key`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 :param default: The default value to be returned if the key is not
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
498 in the dict. If not further specified it's `None`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
499 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500 if key not in self:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
501 self[key] = default
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
502 else:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
503 default = self[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
504 return default
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
506 def setlistdefault(self, key, default_list=None):
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
507 """Like `setdefault` but sets multiple values. The list returned
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
508 is not a copy, but the list that is actually used internally. This
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
509 means that you can put new values into the dict by appending items
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
510 to the list:
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
511
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
512 >>> d = MultiDict({"foo": 1})
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
513 >>> d.setlistdefault("foo").extend([2, 3])
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
514 >>> d.getlist("foo")
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
515 [1, 2, 3]
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
516
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
517 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518 :param default: An iterable of default values. It is either copied
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
519 (in case it was a list) or converted into a list
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
520 before returned.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
521 :return: a :class:`list`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
522 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
523 if key not in self:
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
524 default_list = list(default_list or ())
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
525 dict.__setitem__(self, key, default_list)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
526 else:
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
527 default_list = dict.__getitem__(self, key)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
528 return default_list
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
529
4754
7cb92118a93e updated werkzeug to 0.5.1
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4689
diff changeset
530 def items(self, multi=False):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
531 """Return an iterator of ``(key, value)`` pairs.
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
532
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
533 :param multi: If set to `True` the iterator returned will have a pair
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
534 for each value of each key. Otherwise it will only
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
535 contain pairs for the first value of each key.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
536 """
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
537
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
538 for key, values in iteritems(dict, self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
539 if multi:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
540 for value in values:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
541 yield key, value
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
542 else:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
543 yield key, values[0]
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
544
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
545 def lists(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
546 """Return a list of ``(key, values)`` pairs, where values is the list
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
547 of all values associated with the key."""
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
548
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
549 for key, values in iteritems(dict, self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
550 yield key, list(values)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
551
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
552 def keys(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
553 return iterkeys(dict, self)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
554
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
555 __iter__ = keys
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
556
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
557 def values(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
558 """Returns an iterator of the first value on every key's value list."""
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
559 for values in itervalues(dict, self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
560 yield values[0]
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
561
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
562 def listvalues(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
563 """Return an iterator of all values associated with a key. Zipping
4689
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
564 :meth:`keys` and this is the same as calling :meth:`lists`:
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
565
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
566 >>> d = MultiDict({"foo": [1, 2, 3]})
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
567 >>> zip(d.keys(), d.listvalues()) == d.lists()
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
568 True
bd3f5ccf6fb6 updated werkzeug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4627
diff changeset
569 """
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
570
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
571 return itervalues(dict, self)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
572
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
573 def copy(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
574 """Return a shallow copy of this object."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
575 return self.__class__(self)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
576
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
577 def deepcopy(self, memo=None):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
578 """Return a deep copy of this object."""
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
579 return self.__class__(deepcopy(self.to_dict(flat=False), memo))
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
580
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
581 def to_dict(self, flat=True):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
582 """Return the contents as regular dict. If `flat` is `True` the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
583 returned dict will only have the first item present, if `flat` is
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
584 `False` all values will be returned as lists.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
585
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
586 :param flat: If set to `False` the dict returned will have lists
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
587 with all the values in it. Otherwise it will only
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
588 contain the first value for each key.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
589 :return: a :class:`dict`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
590 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
591 if flat:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
592 return dict(iteritems(self))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
593 return dict(self.lists())
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
594
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
595 def update(self, other_dict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
596 """update() extends rather than replaces existing key lists:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
597
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
598 >>> a = MultiDict({'x': 1})
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
599 >>> b = MultiDict({'x': 2, 'y': 3})
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
600 >>> a.update(b)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
601 >>> a
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
602 MultiDict([('y', 3), ('x', 1), ('x', 2)])
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
603
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
604 If the value list for a key in ``other_dict`` is empty, no new values
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
605 will be added to the dict and the key will not be created:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
606
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
607 >>> x = {'empty_list': []}
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
608 >>> y = MultiDict()
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
609 >>> y.update(x)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
610 >>> y
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
611 MultiDict([])
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
612 """
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
613 for key, value in iter_multi_items(other_dict):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
614 MultiDict.add(self, key, value)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
615
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
616 def pop(self, key, default=_missing):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
617 """Pop the first item for a list on the dict. Afterwards the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
618 key is removed from the dict, so additional values are discarded:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
619
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
620 >>> d = MultiDict({"foo": [1, 2, 3]})
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
621 >>> d.pop("foo")
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
622 1
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
623 >>> "foo" in d
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
624 False
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
625
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
626 :param key: the key to pop.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
627 :param default: if provided the value to return if the key was
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
628 not in the dictionary.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
629 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
630 try:
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
631 lst = dict.pop(self, key)
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
632
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
633 if len(lst) == 0:
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
634 raise exceptions.BadRequestKeyError()
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
635
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
636 return lst[0]
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
637 except KeyError as e:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
638 if default is not _missing:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
639 return default
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
640 raise exceptions.BadRequestKeyError(str(e))
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
641
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
642 def popitem(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
643 """Pop an item from the dict."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
644 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
645 item = dict.popitem(self)
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
646
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
647 if len(item[1]) == 0:
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
648 raise exceptions.BadRequestKeyError()
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
649
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
650 return (item[0], item[1][0])
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
651 except KeyError as e:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
652 raise exceptions.BadRequestKeyError(str(e))
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
653
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
654 def poplist(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
655 """Pop the list for a key from the dict. If the key is not in the dict
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
656 an empty list is returned.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
657
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
658 .. versionchanged:: 0.5
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
659 If the key does no longer exist a list is returned instead of
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
660 raising an error.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
661 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
662 return dict.pop(self, key, [])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
663
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
664 def popitemlist(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
665 """Pop a ``(key, list)`` tuple from the dict."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
666 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
667 return dict.popitem(self)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
668 except KeyError as e:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
669 raise exceptions.BadRequestKeyError(str(e))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
670
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
671 def __copy__(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
672 return self.copy()
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
673
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
674 def __deepcopy__(self, memo):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
675 return self.deepcopy(memo=memo)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
676
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
677 def __repr__(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
678 return '%s(%r)' % (self.__class__.__name__, list(iteritems(self, multi=True)))
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
679
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
680
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
681 class _omd_bucket(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
682
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
683 """Wraps values in the :class:`OrderedMultiDict`. This makes it
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
684 possible to keep an order over multiple different keys. It requires
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
685 a lot of extra memory and slows down access a lot, but makes it
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
686 possible to access elements in O(1) and iterate in O(n).
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
687 """
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
688 __slots__ = ('prev', 'key', 'value', 'next')
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
689
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
690 def __init__(self, omd, key, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
691 self.prev = omd._last_bucket
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
692 self.key = key
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
693 self.value = value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
694 self.next = None
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
695
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
696 if omd._first_bucket is None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
697 omd._first_bucket = self
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
698 if omd._last_bucket is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
699 omd._last_bucket.next = self
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
700 omd._last_bucket = self
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
701
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
702 def unlink(self, omd):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
703 if self.prev:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
704 self.prev.next = self.next
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
705 if self.next:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
706 self.next.prev = self.prev
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
707 if omd._first_bucket is self:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
708 omd._first_bucket = self.next
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
709 if omd._last_bucket is self:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
710 omd._last_bucket = self.prev
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
711
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
712
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
713 @native_itermethods(['keys', 'values', 'items', 'lists', 'listvalues'])
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
714 class OrderedMultiDict(MultiDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
715
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
716 """Works like a regular :class:`MultiDict` but preserves the
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
717 order of the fields. To convert the ordered multi dict into a
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
718 list you can use the :meth:`items` method and pass it ``multi=True``.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
719
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
720 In general an :class:`OrderedMultiDict` is an order of magnitude
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
721 slower than a :class:`MultiDict`.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
722
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
723 .. admonition:: note
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
724
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
725 Due to a limitation in Python you cannot convert an ordered
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
726 multi dict into a regular dict by using ``dict(multidict)``.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
727 Instead you have to use the :meth:`to_dict` method, otherwise
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
728 the internal bucket objects are exposed.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
729 """
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
730
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
731 def __init__(self, mapping=None):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
732 dict.__init__(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
733 self._first_bucket = self._last_bucket = None
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
734 if mapping is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
735 OrderedMultiDict.update(self, mapping)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
736
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
737 def __eq__(self, other):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
738 if not isinstance(other, MultiDict):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
739 return NotImplemented
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
740 if isinstance(other, OrderedMultiDict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
741 iter1 = iteritems(self, multi=True)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
742 iter2 = iteritems(other, multi=True)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
743 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
744 for k1, v1 in iter1:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
745 k2, v2 = next(iter2)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
746 if k1 != k2 or v1 != v2:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
747 return False
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
748 except StopIteration:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
749 return False
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
750 try:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
751 next(iter2)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
752 except StopIteration:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
753 return True
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
754 return False
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
755 if len(self) != len(other):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
756 return False
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
757 for key, values in iterlists(self):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
758 if other.getlist(key) != values:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
759 return False
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
760 return True
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
761
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
762 __hash__ = None
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
763
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
764 def __ne__(self, other):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
765 return not self.__eq__(other)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
766
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
767 def __reduce_ex__(self, protocol):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
768 return type(self), (list(iteritems(self, multi=True)),)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
769
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
770 def __getstate__(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
771 return list(iteritems(self, multi=True))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
772
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
773 def __setstate__(self, values):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
774 dict.clear(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
775 for key, value in values:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
776 self.add(key, value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
777
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
778 def __getitem__(self, key):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
779 if key in self:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
780 return dict.__getitem__(self, key)[0].value
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
781 raise exceptions.BadRequestKeyError(key)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
782
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
783 def __setitem__(self, key, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
784 self.poplist(key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
785 self.add(key, value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
786
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
787 def __delitem__(self, key):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
788 self.pop(key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
789
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
790 def keys(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
791 return (key for key, value in iteritems(self))
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
792
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
793 __iter__ = keys
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
794
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
795 def values(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
796 return (value for key, value in iteritems(self))
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
797
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
798 def items(self, multi=False):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
799 ptr = self._first_bucket
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
800 if multi:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
801 while ptr is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
802 yield ptr.key, ptr.value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
803 ptr = ptr.next
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
804 else:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
805 returned_keys = set()
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
806 while ptr is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
807 if ptr.key not in returned_keys:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
808 returned_keys.add(ptr.key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
809 yield ptr.key, ptr.value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
810 ptr = ptr.next
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
811
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
812 def lists(self):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
813 returned_keys = set()
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
814 ptr = self._first_bucket
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
815 while ptr is not None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
816 if ptr.key not in returned_keys:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
817 yield ptr.key, self.getlist(ptr.key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
818 returned_keys.add(ptr.key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
819 ptr = ptr.next
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
820
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
821 def listvalues(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
822 for key, values in iterlists(self):
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
823 yield values
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
824
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
825 def add(self, key, value):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
826 dict.setdefault(self, key, []).append(_omd_bucket(self, key, value))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
827
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
828 def getlist(self, key, type=None):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
829 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
830 rv = dict.__getitem__(self, key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
831 except KeyError:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
832 return []
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
833 if type is None:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
834 return [x.value for x in rv]
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
835 result = []
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
836 for item in rv:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
837 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
838 result.append(type(item.value))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
839 except ValueError:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
840 pass
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
841 return result
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
842
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
843 def setlist(self, key, new_list):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
844 self.poplist(key)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
845 for value in new_list:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
846 self.add(key, value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
847
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
848 def setlistdefault(self, key, default_list=None):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
849 raise TypeError('setlistdefault is unsupported for '
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
850 'ordered multi dicts')
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
851
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
852 def update(self, mapping):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
853 for key, value in iter_multi_items(mapping):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
854 OrderedMultiDict.add(self, key, value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
855
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
856 def poplist(self, key):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
857 buckets = dict.pop(self, key, ())
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
858 for bucket in buckets:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
859 bucket.unlink(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
860 return [x.value for x in buckets]
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
861
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
862 def pop(self, key, default=_missing):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
863 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
864 buckets = dict.pop(self, key)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
865 except KeyError as e:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
866 if default is not _missing:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
867 return default
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
868 raise exceptions.BadRequestKeyError(str(e))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
869 for bucket in buckets:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
870 bucket.unlink(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
871 return buckets[0].value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
872
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
873 def popitem(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
874 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
875 key, buckets = dict.popitem(self)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
876 except KeyError as e:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
877 raise exceptions.BadRequestKeyError(str(e))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
878 for bucket in buckets:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
879 bucket.unlink(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
880 return key, buckets[0].value
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
881
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
882 def popitemlist(self):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
883 try:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
884 key, buckets = dict.popitem(self)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
885 except KeyError as e:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
886 raise exceptions.BadRequestKeyError(str(e))
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
887 for bucket in buckets:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
888 bucket.unlink(self)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
889 return key, [x.value for x in buckets]
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
890
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
891
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
892 def _options_header_vkw(value, kw):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
893 return dump_options_header(value, dict((k.replace('_', '-'), v)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
894 for k, v in kw.items()))
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
895
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
896
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
897 def _unicodify_header_value(value):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
898 if isinstance(value, bytes):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
899 value = value.decode('latin-1')
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
900 if not isinstance(value, text_type):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
901 value = text_type(value)
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
902 return value
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
903
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
904
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
905 @native_itermethods(['keys', 'values', 'items'])
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
906 class Headers(object):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
907
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
908 """An object that stores some headers. It has a dict-like interface
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
909 but is ordered and can store the same keys multiple times.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
910
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
911 This data structure is useful if you want a nicer way to handle WSGI
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
912 headers which are stored as tuples in a list.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
913
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
914 From Werkzeug 0.3 onwards, the :exc:`KeyError` raised by this class is
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
915 also a subclass of the :class:`~exceptions.BadRequest` HTTP exception
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
916 and will render a page for a ``400 BAD REQUEST`` if caught in a
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
917 catch-all for HTTP exceptions.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
918
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
919 Headers is mostly compatible with the Python :class:`wsgiref.headers.Headers`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
920 class, with the exception of `__getitem__`. :mod:`wsgiref` will return
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
921 `None` for ``headers['missing']``, whereas :class:`Headers` will raise
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
922 a :class:`KeyError`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
923
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
924 To create a new :class:`Headers` object pass it a list or dict of headers
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
925 which are used as default values. This does not reuse the list passed
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
926 to the constructor for internal usage.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
927
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
928 :param defaults: The list of default values for the :class:`Headers`.
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
929
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
930 .. versionchanged:: 0.9
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
931 This data structure now stores unicode values similar to how the
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
932 multi dicts do it. The main difference is that bytes can be set as
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
933 well which will automatically be latin1 decoded.
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
934
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
935 .. versionchanged:: 0.9
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
936 The :meth:`linked` function was removed without replacement as it
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
937 was an API that does not support the changes to the encoding model.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
938 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
939
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
940 def __init__(self, defaults=None):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
941 self._list = []
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
942 if defaults is not None:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
943 if isinstance(defaults, (list, Headers)):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
944 self._list.extend(defaults)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
945 else:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
946 self.extend(defaults)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
947
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
948 def __getitem__(self, key, _get_mode=False):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
949 if not _get_mode:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
950 if isinstance(key, integer_types):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
951 return self._list[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
952 elif isinstance(key, slice):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
953 return self.__class__(self._list[key])
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
954 if not isinstance(key, string_types):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
955 raise exceptions.BadRequestKeyError(key)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
956 ikey = key.lower()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
957 for k, v in self._list:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
958 if k.lower() == ikey:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
959 return v
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
960 # micro optimization: if we are in get mode we will catch that
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
961 # exception one stack level down so we can raise a standard
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
962 # key error instead of our special one.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
963 if _get_mode:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
964 raise KeyError()
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
965 raise exceptions.BadRequestKeyError(key)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
966
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
967 def __eq__(self, other):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
968 return other.__class__ is self.__class__ and \
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
969 set(other._list) == set(self._list)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
970
6129
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
971 __hash__ = None
7f12cf241d5e update werkzeug to 0.12.1, update CHANGES
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 6094
diff changeset
972
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
973 def __ne__(self, other):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
974 return not self.__eq__(other)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
975
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
976 def get(self, key, default=None, type=None, as_bytes=False):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
977 """Return the default value if the requested data doesn't exist.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
978 If `type` is provided and is a callable it should convert the value,
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
979 return it or raise a :exc:`ValueError` if that is not possible. In
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
980 this case the function will return the default as if the value was not
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
981 found:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
982
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
983 >>> d = Headers([('Content-Length', '42')])
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
984 >>> d.get('Content-Length', type=int)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
985 42
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
986
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
987 If a headers object is bound you must not add unicode strings
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
988 because no encoding takes place.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
989
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
990 .. versionadded:: 0.9
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
991 Added support for `as_bytes`.
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
992
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
993 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
994 :param default: The default value to be returned if the key can't
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
995 be looked up. If not further specified `None` is
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
996 returned.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
997 :param type: A callable that is used to cast the value in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
998 :class:`Headers`. If a :exc:`ValueError` is raised
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
999 by this callable the default value is returned.
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1000 :param as_bytes: return bytes instead of unicode strings.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1001 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1002 try:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1003 rv = self.__getitem__(key, _get_mode=True)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1004 except KeyError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1005 return default
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1006 if as_bytes:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1007 rv = rv.encode('latin1')
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1008 if type is None:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1009 return rv
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1010 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1011 return type(rv)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1012 except ValueError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1013 return default
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1014
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1015 def getlist(self, key, type=None, as_bytes=False):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1016 """Return the list of items for a given key. If that key is not in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1017 :class:`Headers`, the return value will be an empty list. Just as
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1018 :meth:`get` :meth:`getlist` accepts a `type` parameter. All items will
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1019 be converted with the callable defined there.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1020
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1021 .. versionadded:: 0.9
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1022 Added support for `as_bytes`.
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1023
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1024 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1025 :param type: A callable that is used to cast the value in the
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1026 :class:`Headers`. If a :exc:`ValueError` is raised
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1027 by this callable the value will be removed from the list.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1028 :return: a :class:`list` of all the values for the key.
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1029 :param as_bytes: return bytes instead of unicode strings.
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1030 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1031 ikey = key.lower()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1032 result = []
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1033 for k, v in self:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1034 if k.lower() == ikey:
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1035 if as_bytes:
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1036 v = v.encode('latin1')
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1037 if type is not None:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1038 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1039 v = type(v)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1040 except ValueError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1041 continue
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1042 result.append(v)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1043 return result
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1044
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1045 def get_all(self, name):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1046 """Return a list of all the values for the named field.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1047
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1048 This method is compatible with the :mod:`wsgiref`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1049 :meth:`~wsgiref.headers.Headers.get_all` method.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1050 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1051 return self.getlist(name)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1052
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1053 def items(self, lower=False):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1054 for key, value in self:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1055 if lower:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1056 key = key.lower()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1057 yield key, value
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1058
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1059 def keys(self, lower=False):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1060 for key, _ in iteritems(self, lower):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1061 yield key
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1062
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1063 def values(self):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1064 for _, value in iteritems(self):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1065 yield value
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1066
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1067 def extend(self, iterable):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1068 """Extend the headers with a dict or an iterable yielding keys and
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1069 values.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1070 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1071 if isinstance(iterable, dict):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1072 for key, value in iteritems(iterable):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1073 if isinstance(value, (tuple, list)):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1074 for v in value:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1075 self.add(key, v)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1076 else:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1077 self.add(key, value)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1078 else:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1079 for key, value in iterable:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1080 self.add(key, value)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1081
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1082 def __delitem__(self, key, _index_operation=True):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1083 if _index_operation and isinstance(key, (integer_types, slice)):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1084 del self._list[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1085 return
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1086 key = key.lower()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1087 new = []
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1088 for k, v in self._list:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1089 if k.lower() != key:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1090 new.append((k, v))
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1091 self._list[:] = new
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1092
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1093 def remove(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1094 """Remove a key.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1095
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1096 :param key: The key to be removed.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1097 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1098 return self.__delitem__(key, _index_operation=False)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1099
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1100 def pop(self, key=None, default=_missing):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1101 """Removes and returns a key or index.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1102
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1103 :param key: The key to be popped. If this is an integer the item at
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1104 that position is removed, if it's a string the value for
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1105 that key is. If the key is omitted or `None` the last
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1106 item is removed.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1107 :return: an item.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1108 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1109 if key is None:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1110 return self._list.pop()
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1111 if isinstance(key, integer_types):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1112 return self._list.pop(key)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1113 try:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1114 rv = self[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1115 self.remove(key)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1116 except KeyError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1117 if default is not _missing:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1118 return default
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1119 raise
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1120 return rv
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1121
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1122 def popitem(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1123 """Removes a key or index and returns a (key, value) item."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1124 return self.pop()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1125
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1126 def __contains__(self, key):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1127 """Check if a key is present."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1128 try:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1129 self.__getitem__(key, _get_mode=True)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1130 except KeyError:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1131 return False
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1132 return True
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1133
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1134 has_key = __contains__
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1135
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1136 def __iter__(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1137 """Yield ``(key, value)`` tuples."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1138 return iter(self._list)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1139
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1140 def __len__(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1141 return len(self._list)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1142
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1143 def add(self, _key, _value, **kw):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1144 """Add a new header tuple to the list.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1145
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1146 Keyword arguments can specify additional parameters for the header
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1147 value, with underscores converted to dashes::
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1148
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1149 >>> d = Headers()
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1150 >>> d.add('Content-Type', 'text/plain')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1151 >>> d.add('Content-Disposition', 'attachment', filename='foo.png')
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1152
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1153 The keyword argument dumping uses :func:`dump_options_header`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1154 behind the scenes.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1155
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1156 .. versionadded:: 0.4.1
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1157 keyword arguments were added for :mod:`wsgiref` compatibility.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1158 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1159 if kw:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1160 _value = _options_header_vkw(_value, kw)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1161 _value = _unicodify_header_value(_value)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1162 self._validate_value(_value)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1163 self._list.append((_key, _value))
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1164
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1165 def _validate_value(self, value):
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1166 if not isinstance(value, text_type):
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1167 raise TypeError('Value should be unicode.')
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1168 if u'\n' in value or u'\r' in value:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1169 raise ValueError('Detected newline in header value. This is '
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1170 'a potential security problem')
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1171
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1172 def add_header(self, _key, _value, **_kw):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1173 """Add a new header tuple to the list.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1174
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1175 An alias for :meth:`add` for compatibility with the :mod:`wsgiref`
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1176 :meth:`~wsgiref.headers.Headers.add_header` method.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1177 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1178 self.add(_key, _value, **_kw)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1179
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1180 def clear(self):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1181 """Clears all headers."""
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1182 del self._list[:]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1183
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1184 def set(self, _key, _value, **kw):
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1185 """Remove all header tuples for `key` and add a new one. The newly
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1186 added key either appears at the end of the list if there was no
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1187 entry or replaces the first one.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1188
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1189 Keyword arguments can specify additional parameters for the header
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1190 value, with underscores converted to dashes. See :meth:`add` for
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1191 more information.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1192
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1193 .. versionchanged:: 0.6.1
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1194 :meth:`set` now accepts the same arguments as :meth:`add`.
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1195
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1196 :param key: The key to be inserted.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1197 :param value: The value to be inserted.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1198 """
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1199 if kw:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1200 _value = _options_header_vkw(_value, kw)
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5801
diff changeset
1201 _value = _unicodify_header_value(_value)
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1202 self._validate_value(_value)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1203 if not self._list:
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1204 self._list.append((_key, _value))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1205 return
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1206 listiter = iter(self._list)
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1207 ikey = _key.lower()
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1208 for idx, (old_key, old_value) in enumerate(listiter):
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1209 if old_key.lower() == ikey:
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1210 # replace first ocurrence
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1211 self._list[idx] = (_key, _value)
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1212 break
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1213 else:
5801
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1214 self._list.append((_key, _value))
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1215 return
8de563c487be upgrade werkzeug to 0.8.1, document current bundled version and current minimum requirement (0.6, for py 2.7 compatibility)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4754
diff changeset
1216 self._list[idx + 1:] = [t for t in listiter if t[0].lower() != ikey]
4609
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1217
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1218 def setdefault(self, key, value):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1219 """Returns the value for the key if it is in the dict, otherwise it
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1220 returns `default` and sets that value for `key`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1221
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1222 :param key: The key to be looked up.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1223 :param default: The default value to be returned if the key is not
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1224 in the dict. If not further specified it's `None`.
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1225 """
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1226 if key in self:
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1227 return self[key]
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1228 self.set(key, value)
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1229 return value
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1230
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1231 def __setitem__(self, key, value):
246ba4eecab2 updated werkzeug to 0.5.pre20090228
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1232 """Like :meth:`set` but also supports index/slice based setting."""
6094
9f12f41504fc upgrade werkzeug from 0.8.3 to 0.11.11
Thomas Waldmann <tw AT waldmann-edv DOT de