httpbin.structures

This commit is contained in:
Kenneth Reitz
2011-06-12 19:30:13 -04:00
parent 8ae2571fa1
commit 9d3e18ef0d
+29
View File
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""
httpbin.structures
~~~~~~~~~~~~~~~~~~~
Data structures that power httpbin.
"""
class CaseInsensitiveDict(dict):
"""Case-insensitive Dictionary for headers.
For example, ``headers['content-encoding']`` will return the
value of a ``'Content-Encoding'`` response header.
"""
def _lower_keys(self):
return map(str.lower, self.keys())
def __contains__(self, key):
return key.lower() in self._lower_keys()
def __getitem__(self, key):
# We allow fall-through here, so values default to None
if key in self:
return self.items()[self._lower_keys().index(key.lower())][1]