CaseInsensitiveDict Class — requests Architecture
Architecture documentation for the CaseInsensitiveDict class in structures.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 1d1b9a9a_928e_82bc_295f_cc28d17d2e85["CaseInsensitiveDict"] 989bc203_d602_fe82_ab02_7d12fb621eee["structures.py"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|defined in| 989bc203_d602_fe82_ab02_7d12fb621eee 2b9162fc_1803_aaf9_c3b6_b8f54b0923d3["__init__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 2b9162fc_1803_aaf9_c3b6_b8f54b0923d3 9ecf8010_5260_5396_f650_7aa64971f9d3["__setitem__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 9ecf8010_5260_5396_f650_7aa64971f9d3 a101c018_c5a1_b8d2_14ac_98240726cd67["__getitem__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| a101c018_c5a1_b8d2_14ac_98240726cd67 4738db02_33dd_1049_6e10_0803894ff1aa["__delitem__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 4738db02_33dd_1049_6e10_0803894ff1aa 6b99bdc0_105f_71fa_87f1_a45e07b659a3["__iter__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 6b99bdc0_105f_71fa_87f1_a45e07b659a3 77608b8f_7114_4f91_5dcc_cf67c2a0ebbf["__len__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 77608b8f_7114_4f91_5dcc_cf67c2a0ebbf 3423d00d_57c6_a65a_f5e3_2d61ccf6df5b["lower_items()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 3423d00d_57c6_a65a_f5e3_2d61ccf6df5b ad837ca9_2104_7038_f2ad_7c800a5fc37e["__eq__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| ad837ca9_2104_7038_f2ad_7c800a5fc37e 5753d29d_693d_5a68_687e_60c24e80e953["copy()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| 5753d29d_693d_5a68_687e_60c24e80e953 a4829c1f_9d53_3eb7_ddef_b529b344bad6["__repr__()"] 1d1b9a9a_928e_82bc_295f_cc28d17d2e85 -->|method| a4829c1f_9d53_3eb7_ddef_b529b344bad6
Relationship Graph
Source Code
src/requests/structures.py lines 13–80
class CaseInsensitiveDict(MutableMapping):
"""A case-insensitive ``dict``-like object.
Implements all methods and operations of
``MutableMapping`` as well as dict's ``copy``. Also
provides ``lower_items``.
All keys are expected to be strings. The structure remembers the
case of the last key to be set, and ``iter(instance)``,
``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
will contain case-sensitive keys. However, querying and contains
testing is case insensitive::
cid = CaseInsensitiveDict()
cid['Accept'] = 'application/json'
cid['aCCEPT'] == 'application/json' # True
list(cid) == ['Accept'] # True
For example, ``headers['content-encoding']`` will return the
value of a ``'Content-Encoding'`` response header, regardless
of how the header name was originally stored.
If the constructor, ``.update``, or equality comparison
operations are given keys that have equal ``.lower()``s, the
behavior is undefined.
"""
def __init__(self, data=None, **kwargs):
self._store = OrderedDict()
if data is None:
data = {}
self.update(data, **kwargs)
def __setitem__(self, key, value):
# Use the lowercased key for lookups, but store the actual
# key alongside the value.
self._store[key.lower()] = (key, value)
def __getitem__(self, key):
return self._store[key.lower()][1]
def __delitem__(self, key):
del self._store[key.lower()]
def __iter__(self):
return (casedkey for casedkey, mappedvalue in self._store.values())
def __len__(self):
return len(self._store)
def lower_items(self):
"""Like iteritems(), but with all lowercase keys."""
return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())
def __eq__(self, other):
if isinstance(other, Mapping):
other = CaseInsensitiveDict(other)
else:
return NotImplemented
# Compare insensitively
return dict(self.lower_items()) == dict(other.lower_items())
# Copy is required
def copy(self):
return CaseInsensitiveDict(self._store.values())
def __repr__(self):
return str(dict(self.items()))
Domain
Defined In
Source
Frequently Asked Questions
What is the CaseInsensitiveDict class?
CaseInsensitiveDict is a class in the requests codebase, defined in src/requests/structures.py.
Where is CaseInsensitiveDict defined?
CaseInsensitiveDict is defined in src/requests/structures.py at line 13.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free