This commit is contained in:
Maximilian Hils
2016-05-20 11:04:27 -07:00
parent 560fc756aa
commit b538138ead
5 changed files with 232 additions and 104 deletions

View File

@@ -169,8 +169,8 @@ def parse_set_cookie_headers(headers):
class CookieAttrs(ImmutableMultiDict):
@staticmethod
def _kconv(v):
return v.lower()
def _kconv(key):
return key.lower()
@staticmethod
def _reduce_values(values):

View File

@@ -279,7 +279,7 @@ class MultiDictView(MultiDict):
"""
def __init__(self, attr, message):
if False:
if False: # pragma: no cover
# We do not want to call the parent constructor here as that
# would cause an unnecessary parse/unparse pass.
# This is here to silence linters. Message

View File

@@ -35,12 +35,20 @@ class MultiDict(MutableMapping, Serializable):
@staticmethod
@abstractmethod
def _reduce_values(values):
pass
"""
If a user accesses multidict["foo"], this method
reduces all values for "foo" to a single value that is returned.
For example, HTTP headers are folded, whereas we will just take
the first cookie we found with that name.
"""
@staticmethod
@abstractmethod
def _kconv(v):
pass
def _kconv(key):
"""
This method converts a key to its canonical representation.
For example, HTTP headers are case-insensitive, so this method returns key.lower().
"""
def __getitem__(self, key):
values = self.get_all(key)