Case-insensitive Dictionary for headers. For example, ``headers['content-encoding']`` will return the value of a ``'Content-Encoding'`` response header.
| 9 | |
| 10 | |
| 11 | class CaseInsensitiveDict(dict): |
| 12 | """Case-insensitive Dictionary for headers. |
| 13 | |
| 14 | For example, ``headers['content-encoding']`` will return the |
| 15 | value of a ``'Content-Encoding'`` response header. |
| 16 | """ |
| 17 | |
| 18 | def _lower_keys(self): |
| 19 | return [k.lower() for k in self.keys()] |
| 20 | |
| 21 | def __contains__(self, key): |
| 22 | return key.lower() in self._lower_keys() |
| 23 | |
| 24 | def __getitem__(self, key): |
| 25 | # We allow fall-through here, so values default to None |
| 26 | if key in self: |
| 27 | return list(self.items())[self._lower_keys().index(key.lower())][1] |
no outgoing calls
no test coverage detected
searching dependent graphs…