structures.py — requests Source File
Architecture documentation for structures.py, a python file in the requests codebase. 2 imports, 5 dependents.
Entity Profile
Dependency Diagram
graph LR 989bc203_d602_fe82_ab02_7d12fb621eee["structures.py"] 655589d9_9504_8132_6277_d047dcd65486["compat.py"] 989bc203_d602_fe82_ab02_7d12fb621eee --> 655589d9_9504_8132_6277_d047dcd65486 ccaec2dd_688f_da13_1759_2748abf12131["collections"] 989bc203_d602_fe82_ab02_7d12fb621eee --> ccaec2dd_688f_da13_1759_2748abf12131 8cafec3a_816a_3b74_357a_0167321e5d19["adapters.py"] 8cafec3a_816a_3b74_357a_0167321e5d19 --> 989bc203_d602_fe82_ab02_7d12fb621eee 461bc6e0_32e7_8eab_ec87_7226e7be0d13["models.py"] 461bc6e0_32e7_8eab_ec87_7226e7be0d13 --> 989bc203_d602_fe82_ab02_7d12fb621eee ea1101aa_233b_1206_7b38_a38f0fe92a52["sessions.py"] ea1101aa_233b_1206_7b38_a38f0fe92a52 --> 989bc203_d602_fe82_ab02_7d12fb621eee 49a0c53c_80e1_9458_74b1_35d844ac4420["status_codes.py"] 49a0c53c_80e1_9458_74b1_35d844ac4420 --> 989bc203_d602_fe82_ab02_7d12fb621eee 2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"] 2c39b9da_e317_5e6c_bbac_8362bac2110c --> 989bc203_d602_fe82_ab02_7d12fb621eee style 989bc203_d602_fe82_ab02_7d12fb621eee fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""
requests.structures
~~~~~~~~~~~~~~~~~~~
Data structures that power Requests.
"""
from collections import OrderedDict
from .compat import Mapping, MutableMapping
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()))
class LookupDict(dict):
"""Dictionary lookup object."""
def __init__(self, name=None):
self.name = name
super().__init__()
def __repr__(self):
return f"<lookup '{self.name}'>"
def __getitem__(self, key):
# We allow fall-through here, so values default to None
return self.__dict__.get(key, None)
def get(self, key, default=None):
return self.__dict__.get(key, default)
Domain
Subdomains
Classes
Dependencies
- collections
- compat.py
Imported By
Source
Frequently Asked Questions
What does structures.py do?
structures.py is a source file in the requests codebase, written in python. It belongs to the CoreAPI domain, VerbHandlers subdomain.
What does structures.py depend on?
structures.py imports 2 module(s): collections, compat.py.
What files import structures.py?
structures.py is imported by 5 file(s): adapters.py, models.py, sessions.py, status_codes.py, utils.py.
Where is structures.py in the architecture?
structures.py is located at src/requests/structures.py (domain: CoreAPI, subdomain: VerbHandlers, directory: src/requests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free