Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
structures.py
Go to the documentation of this file.
1
"""
2
requests.structures
3
~~~~~~~~~~~~~~~~~~~
4
5
Data structures that power Requests.
6
"""
7
8
from
collections
import
OrderedDict
9
10
from
.compat
import
Mapping, MutableMapping
11
12
13
class
CaseInsensitiveDict
(MutableMapping):
14
"""A case-insensitive ``dict``-like object.
15
16
Implements all methods and operations of
17
``MutableMapping`` as well as dict's ``copy``. Also
18
provides ``lower_items``.
19
20
All keys are expected to be strings. The structure remembers the
21
case of the last key to be set, and ``iter(instance)``,
22
``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
23
will contain case-sensitive keys. However, querying and contains
24
testing is case insensitive::
25
26
cid = CaseInsensitiveDict()
27
cid['Accept'] = 'application/json'
28
cid['aCCEPT'] == 'application/json' # True
29
list(cid) == ['Accept'] # True
30
31
For example, ``headers['content-encoding']`` will return the
32
value of a ``'Content-Encoding'`` response header, regardless
33
of how the header name was originally stored.
34
35
If the constructor, ``.update``, or equality comparison
36
operations are given keys that have equal ``.lower()``s, the
37
behavior is undefined.
38
"""
39
40
def
__init__
(self, data=None, **kwargs):
41
self.
_store
= OrderedDict()
42
if
data
is
None
:
43
data = {}
44
self.update(data, **kwargs)
45
46
def
__setitem__
(self, key, value):
47
# Use the lowercased key for lookups, but store the actual
48
# key alongside the value.
49
self.
_store
[
key.lower
()] = (key, value)
50
51
def
__getitem__
(self, key):
52
return
self.
_store
[
key.lower
()][1]
53
54
def
__delitem__
(self, key):
55
del self.
_store
[
key.lower
()]
56
57
def
__iter__
(self):
58
return
(casedkey
for
casedkey, mappedvalue
in
self.
_store
.values())
59
60
def
__len__
(self):
61
return
len
(self.
_store
)
62
63
def
lower_items
(self):
64
"""Like iteritems(), but with all lowercase keys."""
65
return
((lowerkey, keyval[1])
for
(lowerkey, keyval)
in
self.
_store
.items())
66
67
def
__eq__
(self, other):
68
if
isinstance
(other, Mapping):
69
other =
CaseInsensitiveDict
(other)
70
else
:
71
return
NotImplemented
72
# Compare insensitively
73
return
dict(self.
lower_items
()) == dict(
other.lower_items
())
74
75
# Copy is required
76
def
copy(self):
77
return
CaseInsensitiveDict
(self.
_store
.values())
78
79
def
__repr__
(self):
80
return
str(dict(self.items()))
81
82
83
class
LookupDict
(dict):
84
"""Dictionary lookup object."""
85
86
def
__init__
(self, name=None):
87
self.
name
= name
88
super
().
__init__
()
89
90
def
__repr__
(self):
91
return
f
"<lookup '{self.name}'>"
92
93
def
__getitem__
(self, key):
94
# We allow fall-through here, so values default to None
95
96
return
self.__dict__.get(key,
None
)
97
98
def
get(self, key, default=None):
99
return
self.__dict__.get(key, default)
pip._vendor.requests.structures.CaseInsensitiveDict
Definition
structures.py:13
pip._vendor.requests.structures.CaseInsensitiveDict.__setitem__
__setitem__(self, key, value)
Definition
structures.py:46
pip._vendor.requests.structures.CaseInsensitiveDict.__iter__
__iter__(self)
Definition
structures.py:57
pip._vendor.requests.structures.CaseInsensitiveDict.__repr__
__repr__(self)
Definition
structures.py:79
pip._vendor.requests.structures.CaseInsensitiveDict.__len__
__len__(self)
Definition
structures.py:60
pip._vendor.requests.structures.CaseInsensitiveDict._store
_store
Definition
structures.py:41
pip._vendor.requests.structures.CaseInsensitiveDict.__delitem__
__delitem__(self, key)
Definition
structures.py:54
pip._vendor.requests.structures.CaseInsensitiveDict.__eq__
__eq__(self, other)
Definition
structures.py:67
pip._vendor.requests.structures.CaseInsensitiveDict.__init__
__init__(self, data=None, **kwargs)
Definition
structures.py:40
pip._vendor.requests.structures.CaseInsensitiveDict.__getitem__
__getitem__(self, key)
Definition
structures.py:51
pip._vendor.requests.structures.CaseInsensitiveDict.lower_items
lower_items(self)
Definition
structures.py:63
pip._vendor.requests.structures.LookupDict
Definition
structures.py:83
pip._vendor.requests.structures.LookupDict.__init__
__init__(self, name=None)
Definition
structures.py:86
pip._vendor.requests.structures.LookupDict.__repr__
__repr__(self)
Definition
structures.py:90
pip._vendor.requests.structures.LookupDict.name
name
Definition
structures.py:87
pip._vendor.requests.structures.LookupDict.__getitem__
__getitem__(self, key)
Definition
structures.py:93
i
for i
Definition
prime_search.m:10
venv
lib
python3.12
site-packages
pip
_vendor
requests
structures.py
Generated by
1.9.8