Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request.header objects don't support the standard keys() method of dicts #46

Merged
merged 1 commit into from
May 27, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 4 additions & 40 deletions requests/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,21 @@

"""

from UserDict import DictMixin


class CaseInsensitiveDict(DictMixin):
class CaseInsensitiveDict(dict):
"""Case-insensitive Dictionary for :class:`Response <models.Response>` Headers.

For example, ``headers['content-encoding']`` will return the
value of a ``'Content-Encoding'`` response header."""

def __init__(self, *args, **kwargs):
# super(CaseInsensitiveDict, self).__init__()
self.data = dict(*args, **kwargs)

def __repr__(self):
return self.data.__repr__()

def __getstate__(self):
return self.data.copy()

def __setstate__(self, d):
self.data = d

def _lower_keys(self):
return map(str.lower, self.data.keys())
return map(str.lower, self.keys())


def __contains__(self, key):
return key.lower() in self._lower_keys()


def __getitem__(self, key):

if key.lower() in self:
# We allow fall-through here, so values default to None
if key in self:
return self.items()[self._lower_keys().index(key.lower())][1]


def __setitem__(self, key, value):
return self.data.__setitem__(key, value)


def __delitem__(self, key):
return self.data.__delitem__(key)


def __keys__(self):
return self.data.__keys__()


def __iter__(self):
return self.data.__iter__()


def iteritems(self):
return self.data.iteritems()