From 9d3e18ef0d1d6b50c31a15d26f37552ee418486d Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sun, 12 Jun 2011 19:30:13 -0400 Subject: [PATCH] httpbin.structures --- httpbin/structures.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 httpbin/structures.py diff --git a/httpbin/structures.py b/httpbin/structures.py new file mode 100644 index 0000000..996b159 --- /dev/null +++ b/httpbin/structures.py @@ -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] \ No newline at end of file