Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/DESCRIPTION.rst +243 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/INSTALLER +1 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/METADATA +275 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/RECORD +44 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/REQUESTED +0 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/WHEEL +6 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/metadata.json +1 -0
- lib/python3.10/site-packages/dill-0.3.4.dist-info/top_level.txt +1 -0
- lib/python3.10/site-packages/libkenlm.so +3 -0
- lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/INSTALLER +1 -0
- lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/LICENSE +202 -0
- lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/METADATA +406 -0
- lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/top_level.txt +1 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/INSTALLER +1 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/LICENSE +27 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/METADATA +233 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/RECORD +94 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/REQUESTED +0 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/WHEEL +5 -0
- lib/python3.10/site-packages/mpmath-1.3.0.dist-info/top_level.txt +1 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc1157.py +126 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc2560.py +225 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc3412.py +53 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc3414.py +28 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc3560.py +74 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc4073.py +59 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc4490.py +113 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc4491.py +44 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc5083.py +52 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc5697.py +70 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc5752.py +49 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc5755.py +398 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc5915.py +32 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc8018.py +260 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc8358.py +50 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc8619.py +45 -0
- lib/python3.10/site-packages/pyasn1_modules/rfc8696.py +104 -0
- lib/python3.10/site-packages/urllib3/__init__.py +102 -0
- lib/python3.10/site-packages/urllib3/_collections.py +355 -0
- lib/python3.10/site-packages/urllib3/_version.py +2 -0
- lib/python3.10/site-packages/urllib3/connection.py +572 -0
- lib/python3.10/site-packages/urllib3/connectionpool.py +1140 -0
- lib/python3.10/site-packages/urllib3/contrib/__init__.py +0 -0
- lib/python3.10/site-packages/urllib3/contrib/_appengine_environ.py +36 -0
- lib/python3.10/site-packages/urllib3/contrib/_securetransport/__init__.py +0 -0
- lib/python3.10/site-packages/urllib3/contrib/_securetransport/bindings.py +519 -0
- lib/python3.10/site-packages/urllib3/contrib/_securetransport/low_level.py +397 -0
- lib/python3.10/site-packages/urllib3/contrib/appengine.py +314 -0
- lib/python3.10/site-packages/urllib3/contrib/ntlmpool.py +130 -0
.gitattributes
CHANGED
|
@@ -59,3 +59,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
lib/python3.10/site-packages/_cffi_backend.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 61 |
lib/python3.10/site-packages/kenlm.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
lib/python3.10/site-packages/_cffi_backend.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 61 |
lib/python3.10/site-packages/kenlm.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
lib/python3.10/site-packages/libkenlm.so filter=lfs diff=lfs merge=lfs -text
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/DESCRIPTION.rst
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----------------------------
|
| 2 |
+
dill: serialize all of python
|
| 3 |
+
-----------------------------
|
| 4 |
+
|
| 5 |
+
About Dill
|
| 6 |
+
==========
|
| 7 |
+
|
| 8 |
+
``dill`` extends python's ``pickle`` module for serializing and de-serializing
|
| 9 |
+
python objects to the majority of the built-in python types. Serialization
|
| 10 |
+
is the process of converting an object to a byte stream, and the inverse
|
| 11 |
+
of which is converting a byte stream back to a python object hierarchy.
|
| 12 |
+
|
| 13 |
+
``dill`` provides the user the same interface as the ``pickle`` module, and
|
| 14 |
+
also includes some additional features. In addition to pickling python
|
| 15 |
+
objects, ``dill`` provides the ability to save the state of an interpreter
|
| 16 |
+
session in a single command. Hence, it would be feasable to save an
|
| 17 |
+
interpreter session, close the interpreter, ship the pickled file to
|
| 18 |
+
another computer, open a new interpreter, unpickle the session and
|
| 19 |
+
thus continue from the 'saved' state of the original interpreter
|
| 20 |
+
session.
|
| 21 |
+
|
| 22 |
+
``dill`` can be used to store python objects to a file, but the primary
|
| 23 |
+
usage is to send python objects across the network as a byte stream.
|
| 24 |
+
``dill`` is quite flexible, and allows arbitrary user defined classes
|
| 25 |
+
and functions to be serialized. Thus ``dill`` is not intended to be
|
| 26 |
+
secure against erroneously or maliciously constructed data. It is
|
| 27 |
+
left to the user to decide whether the data they unpickle is from
|
| 28 |
+
a trustworthy source.
|
| 29 |
+
|
| 30 |
+
``dill`` is part of ``pathos``, a python framework for heterogeneous computing.
|
| 31 |
+
``dill`` is in active development, so any user feedback, bug reports, comments,
|
| 32 |
+
or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/dill/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
Major Features
|
| 36 |
+
==============
|
| 37 |
+
|
| 38 |
+
``dill`` can pickle the following standard types:
|
| 39 |
+
|
| 40 |
+
- none, type, bool, int, long, float, complex, str, unicode,
|
| 41 |
+
- tuple, list, dict, file, buffer, builtin,
|
| 42 |
+
- both old and new style classes,
|
| 43 |
+
- instances of old and new style classes,
|
| 44 |
+
- set, frozenset, array, functions, exceptions
|
| 45 |
+
|
| 46 |
+
``dill`` can also pickle more 'exotic' standard types:
|
| 47 |
+
|
| 48 |
+
- functions with yields, nested functions, lambdas,
|
| 49 |
+
- cell, method, unboundmethod, module, code, methodwrapper,
|
| 50 |
+
- dictproxy, methoddescriptor, getsetdescriptor, memberdescriptor,
|
| 51 |
+
- wrapperdescriptor, xrange, slice,
|
| 52 |
+
- notimplemented, ellipsis, quit
|
| 53 |
+
|
| 54 |
+
``dill`` cannot yet pickle these standard types:
|
| 55 |
+
|
| 56 |
+
- frame, generator, traceback
|
| 57 |
+
|
| 58 |
+
``dill`` also provides the capability to:
|
| 59 |
+
|
| 60 |
+
- save and load python interpreter sessions
|
| 61 |
+
- save and extract the source code from functions and classes
|
| 62 |
+
- interactively diagnose pickling errors
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
Current Release
|
| 66 |
+
===============
|
| 67 |
+
|
| 68 |
+
This documentation is for version ``dill-0.3.4``.
|
| 69 |
+
|
| 70 |
+
The latest released version of ``dill`` is available from:
|
| 71 |
+
|
| 72 |
+
https://pypi.org/project/dill
|
| 73 |
+
|
| 74 |
+
``dill`` is distributed under a 3-clause BSD license.
|
| 75 |
+
|
| 76 |
+
>>> import dill
|
| 77 |
+
>>> dill.license()
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
Development Version
|
| 81 |
+
===================
|
| 82 |
+
|
| 83 |
+
You can get the latest development version with all the shiny new features at:
|
| 84 |
+
|
| 85 |
+
https://github.com/uqfoundation
|
| 86 |
+
|
| 87 |
+
If you have a new contribution, please submit a pull request.
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Installation
|
| 91 |
+
============
|
| 92 |
+
|
| 93 |
+
``dill`` is packaged to install from source, so you must
|
| 94 |
+
download the tarball, unzip, and run the installer::
|
| 95 |
+
|
| 96 |
+
[download]
|
| 97 |
+
$ tar -xvzf dill-0.3.4.tar.gz
|
| 98 |
+
$ cd dill-0.3.4
|
| 99 |
+
$ python setup py build
|
| 100 |
+
$ python setup py install
|
| 101 |
+
|
| 102 |
+
You will be warned of any missing dependencies and/or settings
|
| 103 |
+
after you run the "build" step above.
|
| 104 |
+
|
| 105 |
+
Alternately, ``dill`` can be installed with ``pip`` or ``easy_install``::
|
| 106 |
+
|
| 107 |
+
$ pip install dill
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
Requirements
|
| 111 |
+
============
|
| 112 |
+
|
| 113 |
+
``dill`` requires:
|
| 114 |
+
|
| 115 |
+
- ``python``, **version == 2.7** or **version >= 3.6**, or ``pypy``
|
| 116 |
+
|
| 117 |
+
Optional requirements:
|
| 118 |
+
|
| 119 |
+
- ``setuptools``, **version >= 0.6**
|
| 120 |
+
- ``pyreadline``, **version >= 1.7.1** (on windows)
|
| 121 |
+
- ``objgraph``, **version >= 1.7.2**
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
Basic Usage
|
| 125 |
+
===========
|
| 126 |
+
|
| 127 |
+
``dill`` is a drop-in replacement for ``pickle``. Existing code can be
|
| 128 |
+
updated to allow complete pickling using::
|
| 129 |
+
|
| 130 |
+
>>> import dill as pickle
|
| 131 |
+
|
| 132 |
+
or::
|
| 133 |
+
|
| 134 |
+
>>> from dill import dumps, loads
|
| 135 |
+
|
| 136 |
+
``dumps`` converts the object to a unique byte string, and ``loads`` performs
|
| 137 |
+
the inverse operation::
|
| 138 |
+
|
| 139 |
+
>>> squared = lambda x: x**2
|
| 140 |
+
>>> loads(dumps(squared))(3)
|
| 141 |
+
9
|
| 142 |
+
|
| 143 |
+
There are a number of options to control serialization which are provided
|
| 144 |
+
as keyword arguments to several ``dill`` functions:
|
| 145 |
+
|
| 146 |
+
* with *protocol*, the pickle protocol level can be set. This uses the
|
| 147 |
+
same value as the ``pickle`` module, *HIGHEST_PROTOCOL* or *DEFAULT_PROTOCOL*.
|
| 148 |
+
* with *byref=True*, ``dill`` to behave a lot more like pickle with
|
| 149 |
+
certain objects (like modules) pickled by reference as opposed to
|
| 150 |
+
attempting to pickle the object itself.
|
| 151 |
+
* with *recurse=True*, objects referred to in the global dictionary are
|
| 152 |
+
recursively traced and pickled, instead of the default behavior of
|
| 153 |
+
attempting to store the entire global dictionary.
|
| 154 |
+
* with *fmode*, the contents of the file can be pickled along with the file
|
| 155 |
+
handle, which is useful if the object is being sent over the wire to a
|
| 156 |
+
remote system which does not have the original file on disk. Options are
|
| 157 |
+
*HANDLE_FMODE* for just the handle, *CONTENTS_FMODE* for the file content
|
| 158 |
+
and *FILE_FMODE* for content and handle.
|
| 159 |
+
* with *ignore=False*, objects reconstructed with types defined in the
|
| 160 |
+
top-level script environment use the existing type in the environment
|
| 161 |
+
rather than a possibly different reconstructed type.
|
| 162 |
+
|
| 163 |
+
The default serialization can also be set globally in *dill.settings*.
|
| 164 |
+
Thus, we can modify how ``dill`` handles references to the global dictionary
|
| 165 |
+
locally or globally::
|
| 166 |
+
|
| 167 |
+
>>> import dill.settings
|
| 168 |
+
>>> dumps(absolute) == dumps(absolute, recurse=True)
|
| 169 |
+
False
|
| 170 |
+
>>> dill.settings['recurse'] = True
|
| 171 |
+
>>> dumps(absolute) == dumps(absolute, recurse=True)
|
| 172 |
+
True
|
| 173 |
+
|
| 174 |
+
``dill`` also includes source code inspection, as an alternate to pickling::
|
| 175 |
+
|
| 176 |
+
>>> import dill.source
|
| 177 |
+
>>> print(dill.source.getsource(squared))
|
| 178 |
+
squared = lambda x:x**2
|
| 179 |
+
|
| 180 |
+
To aid in debugging pickling issues, use *dill.detect* which provides
|
| 181 |
+
tools like pickle tracing::
|
| 182 |
+
|
| 183 |
+
>>> import dill.detect
|
| 184 |
+
>>> dill.detect.trace(True)
|
| 185 |
+
>>> f = dumps(squared)
|
| 186 |
+
F1: <function <lambda> at 0x108899e18>
|
| 187 |
+
F2: <function _create_function at 0x108db7488>
|
| 188 |
+
# F2
|
| 189 |
+
Co: <code object <lambda> at 0x10866a270, file "<stdin>", line 1>
|
| 190 |
+
F2: <function _create_code at 0x108db7510>
|
| 191 |
+
# F2
|
| 192 |
+
# Co
|
| 193 |
+
D1: <dict object at 0x10862b3f0>
|
| 194 |
+
# D1
|
| 195 |
+
D2: <dict object at 0x108e42ee8>
|
| 196 |
+
# D2
|
| 197 |
+
# F1
|
| 198 |
+
>>> dill.detect.trace(False)
|
| 199 |
+
|
| 200 |
+
With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
|
| 201 |
+
``_create_function``, the underlying code object (``Co``) and ``_create_code``
|
| 202 |
+
(which is used to handle code objects), then we handle the reference to
|
| 203 |
+
the global dict (``D2``). A ``#`` marks when the object is actually stored.
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
More Information
|
| 207 |
+
================
|
| 208 |
+
|
| 209 |
+
Probably the best way to get started is to look at the documentation at
|
| 210 |
+
http://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that
|
| 211 |
+
demonstrate how ``dill`` can serialize different python objects. You can
|
| 212 |
+
run the test suite with ``python -m dill.tests``. The contents of any
|
| 213 |
+
pickle file can be examined with ``undill``. As ``dill`` conforms to
|
| 214 |
+
the ``pickle`` interface, the examples and documentation found at
|
| 215 |
+
http://docs.python.org/library/pickle.html also apply to ``dill``
|
| 216 |
+
if one will ``import dill as pickle``. The source code is also generally
|
| 217 |
+
well documented, so further questions may be resolved by inspecting the
|
| 218 |
+
code itself. Please feel free to submit a ticket on github, or ask a
|
| 219 |
+
question on stackoverflow (**@Mike McKerns**).
|
| 220 |
+
If you would like to share how you use ``dill`` in your work, please send
|
| 221 |
+
an email (to **mmckerns at uqfoundation dot org**).
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
Citation
|
| 225 |
+
========
|
| 226 |
+
|
| 227 |
+
If you use ``dill`` to do research that leads to publication, we ask that you
|
| 228 |
+
acknowledge use of ``dill`` by citing the following in your publication::
|
| 229 |
+
|
| 230 |
+
M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
|
| 231 |
+
"Building a framework for predictive science", Proceedings of
|
| 232 |
+
the 10th Python in Science Conference, 2011;
|
| 233 |
+
http://arxiv.org/pdf/1202.1056
|
| 234 |
+
|
| 235 |
+
Michael McKerns and Michael Aivazis,
|
| 236 |
+
"pathos: a framework for heterogeneous computing", 2010- ;
|
| 237 |
+
https://uqfoundation.github.io/project/pathos
|
| 238 |
+
|
| 239 |
+
Please see https://uqfoundation.github.io/project/pathos or
|
| 240 |
+
http://arxiv.org/pdf/1202.1056 for further information.
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/METADATA
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.0
|
| 2 |
+
Name: dill
|
| 3 |
+
Version: 0.3.4
|
| 4 |
+
Summary: serialize all of python
|
| 5 |
+
Home-page: https://github.com/uqfoundation/dill
|
| 6 |
+
Author: Mike McKerns
|
| 7 |
+
Maintainer: Mike McKerns
|
| 8 |
+
License: 3-clause BSD
|
| 9 |
+
Download-URL: https://github.com/uqfoundation/dill/releases/download/dill-0.3.4/dill-0.3.4.tar.gz
|
| 10 |
+
Platform: Linux
|
| 11 |
+
Platform: Windows
|
| 12 |
+
Platform: Mac
|
| 13 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 14 |
+
Classifier: Intended Audience :: Developers
|
| 15 |
+
Classifier: Intended Audience :: Science/Research
|
| 16 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 17 |
+
Classifier: Programming Language :: Python :: 2
|
| 18 |
+
Classifier: Programming Language :: Python :: 2.7
|
| 19 |
+
Classifier: Programming Language :: Python :: 3
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.6
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 24 |
+
Classifier: Topic :: Scientific/Engineering
|
| 25 |
+
Classifier: Topic :: Software Development
|
| 26 |
+
Requires-Python: >=2.7, !=3.0.*
|
| 27 |
+
Provides-Extra: readline
|
| 28 |
+
Provides-Extra: graph
|
| 29 |
+
Provides-Extra: graph
|
| 30 |
+
Requires-Dist: objgraph (>=1.7.2); extra == 'graph'
|
| 31 |
+
Provides-Extra: readline
|
| 32 |
+
|
| 33 |
+
-----------------------------
|
| 34 |
+
dill: serialize all of python
|
| 35 |
+
-----------------------------
|
| 36 |
+
|
| 37 |
+
About Dill
|
| 38 |
+
==========
|
| 39 |
+
|
| 40 |
+
``dill`` extends python's ``pickle`` module for serializing and de-serializing
|
| 41 |
+
python objects to the majority of the built-in python types. Serialization
|
| 42 |
+
is the process of converting an object to a byte stream, and the inverse
|
| 43 |
+
of which is converting a byte stream back to a python object hierarchy.
|
| 44 |
+
|
| 45 |
+
``dill`` provides the user the same interface as the ``pickle`` module, and
|
| 46 |
+
also includes some additional features. In addition to pickling python
|
| 47 |
+
objects, ``dill`` provides the ability to save the state of an interpreter
|
| 48 |
+
session in a single command. Hence, it would be feasable to save an
|
| 49 |
+
interpreter session, close the interpreter, ship the pickled file to
|
| 50 |
+
another computer, open a new interpreter, unpickle the session and
|
| 51 |
+
thus continue from the 'saved' state of the original interpreter
|
| 52 |
+
session.
|
| 53 |
+
|
| 54 |
+
``dill`` can be used to store python objects to a file, but the primary
|
| 55 |
+
usage is to send python objects across the network as a byte stream.
|
| 56 |
+
``dill`` is quite flexible, and allows arbitrary user defined classes
|
| 57 |
+
and functions to be serialized. Thus ``dill`` is not intended to be
|
| 58 |
+
secure against erroneously or maliciously constructed data. It is
|
| 59 |
+
left to the user to decide whether the data they unpickle is from
|
| 60 |
+
a trustworthy source.
|
| 61 |
+
|
| 62 |
+
``dill`` is part of ``pathos``, a python framework for heterogeneous computing.
|
| 63 |
+
``dill`` is in active development, so any user feedback, bug reports, comments,
|
| 64 |
+
or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/dill/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
Major Features
|
| 68 |
+
==============
|
| 69 |
+
|
| 70 |
+
``dill`` can pickle the following standard types:
|
| 71 |
+
|
| 72 |
+
- none, type, bool, int, long, float, complex, str, unicode,
|
| 73 |
+
- tuple, list, dict, file, buffer, builtin,
|
| 74 |
+
- both old and new style classes,
|
| 75 |
+
- instances of old and new style classes,
|
| 76 |
+
- set, frozenset, array, functions, exceptions
|
| 77 |
+
|
| 78 |
+
``dill`` can also pickle more 'exotic' standard types:
|
| 79 |
+
|
| 80 |
+
- functions with yields, nested functions, lambdas,
|
| 81 |
+
- cell, method, unboundmethod, module, code, methodwrapper,
|
| 82 |
+
- dictproxy, methoddescriptor, getsetdescriptor, memberdescriptor,
|
| 83 |
+
- wrapperdescriptor, xrange, slice,
|
| 84 |
+
- notimplemented, ellipsis, quit
|
| 85 |
+
|
| 86 |
+
``dill`` cannot yet pickle these standard types:
|
| 87 |
+
|
| 88 |
+
- frame, generator, traceback
|
| 89 |
+
|
| 90 |
+
``dill`` also provides the capability to:
|
| 91 |
+
|
| 92 |
+
- save and load python interpreter sessions
|
| 93 |
+
- save and extract the source code from functions and classes
|
| 94 |
+
- interactively diagnose pickling errors
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
Current Release
|
| 98 |
+
===============
|
| 99 |
+
|
| 100 |
+
This documentation is for version ``dill-0.3.4``.
|
| 101 |
+
|
| 102 |
+
The latest released version of ``dill`` is available from:
|
| 103 |
+
|
| 104 |
+
https://pypi.org/project/dill
|
| 105 |
+
|
| 106 |
+
``dill`` is distributed under a 3-clause BSD license.
|
| 107 |
+
|
| 108 |
+
>>> import dill
|
| 109 |
+
>>> dill.license()
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
Development Version
|
| 113 |
+
===================
|
| 114 |
+
|
| 115 |
+
You can get the latest development version with all the shiny new features at:
|
| 116 |
+
|
| 117 |
+
https://github.com/uqfoundation
|
| 118 |
+
|
| 119 |
+
If you have a new contribution, please submit a pull request.
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
Installation
|
| 123 |
+
============
|
| 124 |
+
|
| 125 |
+
``dill`` is packaged to install from source, so you must
|
| 126 |
+
download the tarball, unzip, and run the installer::
|
| 127 |
+
|
| 128 |
+
[download]
|
| 129 |
+
$ tar -xvzf dill-0.3.4.tar.gz
|
| 130 |
+
$ cd dill-0.3.4
|
| 131 |
+
$ python setup py build
|
| 132 |
+
$ python setup py install
|
| 133 |
+
|
| 134 |
+
You will be warned of any missing dependencies and/or settings
|
| 135 |
+
after you run the "build" step above.
|
| 136 |
+
|
| 137 |
+
Alternately, ``dill`` can be installed with ``pip`` or ``easy_install``::
|
| 138 |
+
|
| 139 |
+
$ pip install dill
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
Requirements
|
| 143 |
+
============
|
| 144 |
+
|
| 145 |
+
``dill`` requires:
|
| 146 |
+
|
| 147 |
+
- ``python``, **version == 2.7** or **version >= 3.6**, or ``pypy``
|
| 148 |
+
|
| 149 |
+
Optional requirements:
|
| 150 |
+
|
| 151 |
+
- ``setuptools``, **version >= 0.6**
|
| 152 |
+
- ``pyreadline``, **version >= 1.7.1** (on windows)
|
| 153 |
+
- ``objgraph``, **version >= 1.7.2**
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
Basic Usage
|
| 157 |
+
===========
|
| 158 |
+
|
| 159 |
+
``dill`` is a drop-in replacement for ``pickle``. Existing code can be
|
| 160 |
+
updated to allow complete pickling using::
|
| 161 |
+
|
| 162 |
+
>>> import dill as pickle
|
| 163 |
+
|
| 164 |
+
or::
|
| 165 |
+
|
| 166 |
+
>>> from dill import dumps, loads
|
| 167 |
+
|
| 168 |
+
``dumps`` converts the object to a unique byte string, and ``loads`` performs
|
| 169 |
+
the inverse operation::
|
| 170 |
+
|
| 171 |
+
>>> squared = lambda x: x**2
|
| 172 |
+
>>> loads(dumps(squared))(3)
|
| 173 |
+
9
|
| 174 |
+
|
| 175 |
+
There are a number of options to control serialization which are provided
|
| 176 |
+
as keyword arguments to several ``dill`` functions:
|
| 177 |
+
|
| 178 |
+
* with *protocol*, the pickle protocol level can be set. This uses the
|
| 179 |
+
same value as the ``pickle`` module, *HIGHEST_PROTOCOL* or *DEFAULT_PROTOCOL*.
|
| 180 |
+
* with *byref=True*, ``dill`` to behave a lot more like pickle with
|
| 181 |
+
certain objects (like modules) pickled by reference as opposed to
|
| 182 |
+
attempting to pickle the object itself.
|
| 183 |
+
* with *recurse=True*, objects referred to in the global dictionary are
|
| 184 |
+
recursively traced and pickled, instead of the default behavior of
|
| 185 |
+
attempting to store the entire global dictionary.
|
| 186 |
+
* with *fmode*, the contents of the file can be pickled along with the file
|
| 187 |
+
handle, which is useful if the object is being sent over the wire to a
|
| 188 |
+
remote system which does not have the original file on disk. Options are
|
| 189 |
+
*HANDLE_FMODE* for just the handle, *CONTENTS_FMODE* for the file content
|
| 190 |
+
and *FILE_FMODE* for content and handle.
|
| 191 |
+
* with *ignore=False*, objects reconstructed with types defined in the
|
| 192 |
+
top-level script environment use the existing type in the environment
|
| 193 |
+
rather than a possibly different reconstructed type.
|
| 194 |
+
|
| 195 |
+
The default serialization can also be set globally in *dill.settings*.
|
| 196 |
+
Thus, we can modify how ``dill`` handles references to the global dictionary
|
| 197 |
+
locally or globally::
|
| 198 |
+
|
| 199 |
+
>>> import dill.settings
|
| 200 |
+
>>> dumps(absolute) == dumps(absolute, recurse=True)
|
| 201 |
+
False
|
| 202 |
+
>>> dill.settings['recurse'] = True
|
| 203 |
+
>>> dumps(absolute) == dumps(absolute, recurse=True)
|
| 204 |
+
True
|
| 205 |
+
|
| 206 |
+
``dill`` also includes source code inspection, as an alternate to pickling::
|
| 207 |
+
|
| 208 |
+
>>> import dill.source
|
| 209 |
+
>>> print(dill.source.getsource(squared))
|
| 210 |
+
squared = lambda x:x**2
|
| 211 |
+
|
| 212 |
+
To aid in debugging pickling issues, use *dill.detect* which provides
|
| 213 |
+
tools like pickle tracing::
|
| 214 |
+
|
| 215 |
+
>>> import dill.detect
|
| 216 |
+
>>> dill.detect.trace(True)
|
| 217 |
+
>>> f = dumps(squared)
|
| 218 |
+
F1: <function <lambda> at 0x108899e18>
|
| 219 |
+
F2: <function _create_function at 0x108db7488>
|
| 220 |
+
# F2
|
| 221 |
+
Co: <code object <lambda> at 0x10866a270, file "<stdin>", line 1>
|
| 222 |
+
F2: <function _create_code at 0x108db7510>
|
| 223 |
+
# F2
|
| 224 |
+
# Co
|
| 225 |
+
D1: <dict object at 0x10862b3f0>
|
| 226 |
+
# D1
|
| 227 |
+
D2: <dict object at 0x108e42ee8>
|
| 228 |
+
# D2
|
| 229 |
+
# F1
|
| 230 |
+
>>> dill.detect.trace(False)
|
| 231 |
+
|
| 232 |
+
With trace, we see how ``dill`` stored the lambda (``F1``) by first storing
|
| 233 |
+
``_create_function``, the underlying code object (``Co``) and ``_create_code``
|
| 234 |
+
(which is used to handle code objects), then we handle the reference to
|
| 235 |
+
the global dict (``D2``). A ``#`` marks when the object is actually stored.
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
More Information
|
| 239 |
+
================
|
| 240 |
+
|
| 241 |
+
Probably the best way to get started is to look at the documentation at
|
| 242 |
+
http://dill.rtfd.io. Also see ``dill.tests`` for a set of scripts that
|
| 243 |
+
demonstrate how ``dill`` can serialize different python objects. You can
|
| 244 |
+
run the test suite with ``python -m dill.tests``. The contents of any
|
| 245 |
+
pickle file can be examined with ``undill``. As ``dill`` conforms to
|
| 246 |
+
the ``pickle`` interface, the examples and documentation found at
|
| 247 |
+
http://docs.python.org/library/pickle.html also apply to ``dill``
|
| 248 |
+
if one will ``import dill as pickle``. The source code is also generally
|
| 249 |
+
well documented, so further questions may be resolved by inspecting the
|
| 250 |
+
code itself. Please feel free to submit a ticket on github, or ask a
|
| 251 |
+
question on stackoverflow (**@Mike McKerns**).
|
| 252 |
+
If you would like to share how you use ``dill`` in your work, please send
|
| 253 |
+
an email (to **mmckerns at uqfoundation dot org**).
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
Citation
|
| 257 |
+
========
|
| 258 |
+
|
| 259 |
+
If you use ``dill`` to do research that leads to publication, we ask that you
|
| 260 |
+
acknowledge use of ``dill`` by citing the following in your publication::
|
| 261 |
+
|
| 262 |
+
M.M. McKerns, L. Strand, T. Sullivan, A. Fang, M.A.G. Aivazis,
|
| 263 |
+
"Building a framework for predictive science", Proceedings of
|
| 264 |
+
the 10th Python in Science Conference, 2011;
|
| 265 |
+
http://arxiv.org/pdf/1202.1056
|
| 266 |
+
|
| 267 |
+
Michael McKerns and Michael Aivazis,
|
| 268 |
+
"pathos: a framework for heterogeneous computing", 2010- ;
|
| 269 |
+
https://uqfoundation.github.io/project/pathos
|
| 270 |
+
|
| 271 |
+
Please see https://uqfoundation.github.io/project/pathos or
|
| 272 |
+
http://arxiv.org/pdf/1202.1056 for further information.
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/RECORD
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
../../../bin/get_objgraph,sha256=WAwCIHmdzvnc9iUZS8p8lVrpM3WckxuA2aBOUpn5OYE,1680
|
| 2 |
+
../../../bin/undill,sha256=-j0SUf2yq6LG0y5DVnIwKeUsw7uI4d1bkNi6CQbNQro,616
|
| 3 |
+
dill-0.3.4.dist-info/DESCRIPTION.rst,sha256=00gLocdQIUPJn9RL8V3W8uSQrlyNE-UKzaiietaS0T0,8491
|
| 4 |
+
dill-0.3.4.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 5 |
+
dill-0.3.4.dist-info/METADATA,sha256=cOye9XYyeDSOuo3Kgiwo9PsgdMA1X6TZxDds_v-TYas,9646
|
| 6 |
+
dill-0.3.4.dist-info/RECORD,,
|
| 7 |
+
dill-0.3.4.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 8 |
+
dill-0.3.4.dist-info/WHEEL,sha256=o2k-Qa-RMNIJmUdIc7KU6VWR_ErNRbWNlxDIpl7lm34,110
|
| 9 |
+
dill-0.3.4.dist-info/metadata.json,sha256=lwZqk2r7HlKyc9QYr8lyAYjYveE2cnruW_A70TVXfeQ,1228
|
| 10 |
+
dill-0.3.4.dist-info/top_level.txt,sha256=HLSIyYIjQzJiBvs3_-16ntezE3j6mWGTW0DT1xDd7X0,5
|
| 11 |
+
dill/__diff.py,sha256=SHKS5x6xTNRlOY_wUN86VvtdVzthwHJYigYUyV3P4ao,7211
|
| 12 |
+
dill/__init__.py,sha256=j9kLcIE53Et8jiTd9eS9QRKmOpXecOKhV3c_EDRlWJo,3634
|
| 13 |
+
dill/_dill.py,sha256=JgLYTLsIBFenphnVNZAdAqdYctpXuv-O1ExktIwfZuQ,61175
|
| 14 |
+
dill/_objects.py,sha256=2SQj3FwxLgWLdoHRpjFgpazkQjP2bhWkcTZBy2D9TgM,20432
|
| 15 |
+
dill/detect.py,sha256=IuuJGD2aDnOMHxCzuIt5Cfibm9Z1Y11SylX0FF_D3lc,11822
|
| 16 |
+
dill/info.py,sha256=7Q_vEQ0Rlzci8lcrFLpobo6pgjB0RaMwnj0SC1mWPss,10396
|
| 17 |
+
dill/objtypes.py,sha256=G4Y_y4iq6fKWPJHwgC336t6frXndOo1hWrLrO37XvEY,736
|
| 18 |
+
dill/pointers.py,sha256=2_BmpXg-onaErn3-DzQqpQEm8nEIgOvi6wabM0nLp2U,4467
|
| 19 |
+
dill/settings.py,sha256=UeJ5UaXMcLqWJUqff_0uqLFRpipfdMcUdYAvWv9FPsI,719
|
| 20 |
+
dill/source.py,sha256=lpbDvv1rb_jBYAo1Y53QRT5YeE-no9Dn0nzmVC9CnR4,44906
|
| 21 |
+
dill/temp.py,sha256=BnPV59leGHaG7_Fsbd_WfsAWEC58fmizUvXTp_zymH8,8242
|
| 22 |
+
dill/tests/__init__.py,sha256=L367MkLXO35T3seLk7O3CD3KP_kTao63cHOV0P5io6o,501
|
| 23 |
+
dill/tests/__main__.py,sha256=9LLFT67dpNrtuaHX3tzpelBkFZ9yGnaFKzlJ_DkVpKE,835
|
| 24 |
+
dill/tests/test_check.py,sha256=lZwdVu6PHPiKdB-HcddOGYZc3IXFaPFGOTsRdwY2xAg,1278
|
| 25 |
+
dill/tests/test_classdef.py,sha256=xns8TGJqBDHlELjlC1T2b6x5kKilMU4p3IFg4c5WYMM,4895
|
| 26 |
+
dill/tests/test_detect.py,sha256=eghRtvWQWrcqGsw-wd-nFkh2SwJcu8QTp-obTu_eQok,4142
|
| 27 |
+
dill/tests/test_diff.py,sha256=_AQZRk5lOgfuU816ar3VsigmZYWfDSx0zkCQE-RNpqI,2761
|
| 28 |
+
dill/tests/test_extendpickle.py,sha256=fJvDNybYMWNnnGG4aOv08qNtjgGodlxp_-OFbftGHh8,1368
|
| 29 |
+
dill/tests/test_fglobals.py,sha256=3m2HbsMfVaXcHQhWYeLDOGm8BgCcinsWG4ovtINFwjY,1297
|
| 30 |
+
dill/tests/test_file.py,sha256=yb1dJN7na1EAxdg67xT0k-PwhEBn8qVL82tiBnZRxSY,13642
|
| 31 |
+
dill/tests/test_functions.py,sha256=Rip47zcn9wr37vpG4WjNImxkTqCxAtWbg_ZibgP6lIo,1653
|
| 32 |
+
dill/tests/test_functors.py,sha256=yKTP9pp3q-wKglWH0jweya4oTLrFPI3vTqZpbBvGzok,930
|
| 33 |
+
dill/tests/test_mixins.py,sha256=CIpVh1g2y35dlbNEh3gDciDz54qnPfKh6wDXgyf9yUo,4007
|
| 34 |
+
dill/tests/test_module.py,sha256=YUfHLoONQddnm3Yau3A-Xkzw2HHrkYHhXCi6F1Yz-Yc,1967
|
| 35 |
+
dill/tests/test_moduledict.py,sha256=AK-LlIVj0kFww5DfDkBdnRIQUzKxuR3y5KVU-cqlzsw,1182
|
| 36 |
+
dill/tests/test_nested.py,sha256=1jR6mLJ1vls4r0DpNx5TRJnNsJTPlFPStOU8kMYzCPg,3134
|
| 37 |
+
dill/tests/test_objects.py,sha256=nK6jgogaho0UhLnLIJO5CpgtF1Ue0nx-Tt-fGSdS-rs,1779
|
| 38 |
+
dill/tests/test_properties.py,sha256=dotptyT8WU3XhNSBPjqqQcAXyYPMK0ZM3wLty8kBZH8,1346
|
| 39 |
+
dill/tests/test_recursive.py,sha256=4t7BZUDqukMhK1iv--zVMjeNwNPB6obD5qV6OA0UFPs,2455
|
| 40 |
+
dill/tests/test_restricted.py,sha256=r1DMKOhq_OCgs-M3EaH7lOHMKoiUvvSj1zW1BwDX6qo,783
|
| 41 |
+
dill/tests/test_selected.py,sha256=xqKReC3nXuOS2qg8KAA4VgX44TfzqKqbfkerG_ug5Ls,2555
|
| 42 |
+
dill/tests/test_source.py,sha256=9mJvi_tDFE3c3b4AIoRSyhFkhm9Qn5W30Z8ei5zB468,6375
|
| 43 |
+
dill/tests/test_temp.py,sha256=BcYEy51GzdSbeyRpbgadA7akmypzmqkbybmY7A1ont0,2619
|
| 44 |
+
dill/tests/test_weakref.py,sha256=hVv3FqM7rl5VeT2ba0PL_7EZ8k5xjbeDKkKQMv3XNo4,2056
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/REQUESTED
ADDED
|
File without changes
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.29.0)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py2-none-any
|
| 5 |
+
Tag: py3-none-any
|
| 6 |
+
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/metadata.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"classifiers": ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Topic :: Scientific/Engineering", "Topic :: Software Development"], "download_url": "https://github.com/uqfoundation/dill/releases/download/dill-0.3.4/dill-0.3.4.tar.gz", "extensions": {"python.details": {"contacts": [{"name": "Mike McKerns", "role": "author"}, {"name": "Mike McKerns", "role": "maintainer"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/uqfoundation/dill"}}}, "extras": ["graph", "readline"], "generator": "bdist_wheel (0.29.0)", "license": "3-clause BSD", "metadata_version": "2.0", "name": "dill", "platform": "Linux", "requires_python": ">=2.7, !=3.0.*", "run_requires": [{"extra": "graph", "requires": ["objgraph (>=1.7.2)"]}], "summary": "serialize all of python", "version": "0.3.4"}
|
lib/python3.10/site-packages/dill-0.3.4.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
dill
|
lib/python3.10/site-packages/libkenlm.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72613f6e390dd15db8184ce6c2ca51f7a8d54de212a4b89c922885ee0efd1f41
|
| 3 |
+
size 760152
|
lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Apache License
|
| 3 |
+
Version 2.0, January 2004
|
| 4 |
+
http://www.apache.org/licenses/
|
| 5 |
+
|
| 6 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 7 |
+
|
| 8 |
+
1. Definitions.
|
| 9 |
+
|
| 10 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 11 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 12 |
+
|
| 13 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 14 |
+
the copyright owner that is granting the License.
|
| 15 |
+
|
| 16 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 17 |
+
other entities that control, are controlled by, or are under common
|
| 18 |
+
control with that entity. For the purposes of this definition,
|
| 19 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 20 |
+
direction or management of such entity, whether by contract or
|
| 21 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 22 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 23 |
+
|
| 24 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 25 |
+
exercising permissions granted by this License.
|
| 26 |
+
|
| 27 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 28 |
+
including but not limited to software source code, documentation
|
| 29 |
+
source, and configuration files.
|
| 30 |
+
|
| 31 |
+
"Object" form shall mean any form resulting from mechanical
|
| 32 |
+
transformation or translation of a Source form, including but
|
| 33 |
+
not limited to compiled object code, generated documentation,
|
| 34 |
+
and conversions to other media types.
|
| 35 |
+
|
| 36 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 37 |
+
Object form, made available under the License, as indicated by a
|
| 38 |
+
copyright notice that is included in or attached to the work
|
| 39 |
+
(an example is provided in the Appendix below).
|
| 40 |
+
|
| 41 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 42 |
+
form, that is based on (or derived from) the Work and for which the
|
| 43 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 44 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 45 |
+
of this License, Derivative Works shall not include works that remain
|
| 46 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 47 |
+
the Work and Derivative Works thereof.
|
| 48 |
+
|
| 49 |
+
"Contribution" shall mean any work of authorship, including
|
| 50 |
+
the original version of the Work and any modifications or additions
|
| 51 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 52 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 53 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 54 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 55 |
+
means any form of electronic, verbal, or written communication sent
|
| 56 |
+
to the Licensor or its representatives, including but not limited to
|
| 57 |
+
communication on electronic mailing lists, source code control systems,
|
| 58 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 59 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 60 |
+
excluding communication that is conspicuously marked or otherwise
|
| 61 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 62 |
+
|
| 63 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 64 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 65 |
+
subsequently incorporated within the Work.
|
| 66 |
+
|
| 67 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 68 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 69 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 70 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 71 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 72 |
+
Work and such Derivative Works in Source or Object form.
|
| 73 |
+
|
| 74 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 75 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 76 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 77 |
+
(except as stated in this section) patent license to make, have made,
|
| 78 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 79 |
+
where such license applies only to those patent claims licensable
|
| 80 |
+
by such Contributor that are necessarily infringed by their
|
| 81 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 82 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 83 |
+
institute patent litigation against any entity (including a
|
| 84 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 85 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 86 |
+
or contributory patent infringement, then any patent licenses
|
| 87 |
+
granted to You under this License for that Work shall terminate
|
| 88 |
+
as of the date such litigation is filed.
|
| 89 |
+
|
| 90 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 91 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 92 |
+
modifications, and in Source or Object form, provided that You
|
| 93 |
+
meet the following conditions:
|
| 94 |
+
|
| 95 |
+
(a) You must give any other recipients of the Work or
|
| 96 |
+
Derivative Works a copy of this License; and
|
| 97 |
+
|
| 98 |
+
(b) You must cause any modified files to carry prominent notices
|
| 99 |
+
stating that You changed the files; and
|
| 100 |
+
|
| 101 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 102 |
+
that You distribute, all copyright, patent, trademark, and
|
| 103 |
+
attribution notices from the Source form of the Work,
|
| 104 |
+
excluding those notices that do not pertain to any part of
|
| 105 |
+
the Derivative Works; and
|
| 106 |
+
|
| 107 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 108 |
+
distribution, then any Derivative Works that You distribute must
|
| 109 |
+
include a readable copy of the attribution notices contained
|
| 110 |
+
within such NOTICE file, excluding those notices that do not
|
| 111 |
+
pertain to any part of the Derivative Works, in at least one
|
| 112 |
+
of the following places: within a NOTICE text file distributed
|
| 113 |
+
as part of the Derivative Works; within the Source form or
|
| 114 |
+
documentation, if provided along with the Derivative Works; or,
|
| 115 |
+
within a display generated by the Derivative Works, if and
|
| 116 |
+
wherever such third-party notices normally appear. The contents
|
| 117 |
+
of the NOTICE file are for informational purposes only and
|
| 118 |
+
do not modify the License. You may add Your own attribution
|
| 119 |
+
notices within Derivative Works that You distribute, alongside
|
| 120 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 121 |
+
that such additional attribution notices cannot be construed
|
| 122 |
+
as modifying the License.
|
| 123 |
+
|
| 124 |
+
You may add Your own copyright statement to Your modifications and
|
| 125 |
+
may provide additional or different license terms and conditions
|
| 126 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 127 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 128 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 129 |
+
the conditions stated in this License.
|
| 130 |
+
|
| 131 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 132 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 133 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 134 |
+
this License, without any additional terms or conditions.
|
| 135 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 136 |
+
the terms of any separate license agreement you may have executed
|
| 137 |
+
with Licensor regarding such Contributions.
|
| 138 |
+
|
| 139 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 140 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 141 |
+
except as required for reasonable and customary use in describing the
|
| 142 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 143 |
+
|
| 144 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 145 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 146 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 147 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 148 |
+
implied, including, without limitation, any warranties or conditions
|
| 149 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 150 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 151 |
+
appropriateness of using or redistributing the Work and assume any
|
| 152 |
+
risks associated with Your exercise of permissions under this License.
|
| 153 |
+
|
| 154 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 155 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 156 |
+
unless required by applicable law (such as deliberate and grossly
|
| 157 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 158 |
+
liable to You for damages, including any direct, indirect, special,
|
| 159 |
+
incidental, or consequential damages of any character arising as a
|
| 160 |
+
result of this License or out of the use or inability to use the
|
| 161 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 162 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 163 |
+
other commercial damages or losses), even if such Contributor
|
| 164 |
+
has been advised of the possibility of such damages.
|
| 165 |
+
|
| 166 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 167 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 168 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 169 |
+
or other liability obligations and/or rights consistent with this
|
| 170 |
+
License. However, in accepting such obligations, You may act only
|
| 171 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 172 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 173 |
+
defend, and hold each Contributor harmless for any liability
|
| 174 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 175 |
+
of your accepting any such warranty or additional liability.
|
| 176 |
+
|
| 177 |
+
END OF TERMS AND CONDITIONS
|
| 178 |
+
|
| 179 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 180 |
+
|
| 181 |
+
To apply the Apache License to your work, attach the following
|
| 182 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 183 |
+
replaced with your own identifying information. (Don't include
|
| 184 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 185 |
+
comment syntax for the file format. We also recommend that a
|
| 186 |
+
file or class name and description of purpose be included on the
|
| 187 |
+
same "printed page" as the copyright notice for easier
|
| 188 |
+
identification within third-party archives.
|
| 189 |
+
|
| 190 |
+
Copyright [yyyy] [name of copyright owner]
|
| 191 |
+
|
| 192 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 193 |
+
you may not use this file except in compliance with the License.
|
| 194 |
+
You may obtain a copy of the License at
|
| 195 |
+
|
| 196 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 197 |
+
|
| 198 |
+
Unless required by applicable law or agreed to in writing, software
|
| 199 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 200 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 201 |
+
See the License for the specific language governing permissions and
|
| 202 |
+
limitations under the License.
|
lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/METADATA
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: ml-dtypes
|
| 3 |
+
Version: 0.3.2
|
| 4 |
+
Author-email: ml_dtypes authors <ml_dtypes@google.com>
|
| 5 |
+
License:
|
| 6 |
+
Apache License
|
| 7 |
+
Version 2.0, January 2004
|
| 8 |
+
http://www.apache.org/licenses/
|
| 9 |
+
|
| 10 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 11 |
+
|
| 12 |
+
1. Definitions.
|
| 13 |
+
|
| 14 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 15 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 16 |
+
|
| 17 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 18 |
+
the copyright owner that is granting the License.
|
| 19 |
+
|
| 20 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 21 |
+
other entities that control, are controlled by, or are under common
|
| 22 |
+
control with that entity. For the purposes of this definition,
|
| 23 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 24 |
+
direction or management of such entity, whether by contract or
|
| 25 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 26 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 27 |
+
|
| 28 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 29 |
+
exercising permissions granted by this License.
|
| 30 |
+
|
| 31 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 32 |
+
including but not limited to software source code, documentation
|
| 33 |
+
source, and configuration files.
|
| 34 |
+
|
| 35 |
+
"Object" form shall mean any form resulting from mechanical
|
| 36 |
+
transformation or translation of a Source form, including but
|
| 37 |
+
not limited to compiled object code, generated documentation,
|
| 38 |
+
and conversions to other media types.
|
| 39 |
+
|
| 40 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 41 |
+
Object form, made available under the License, as indicated by a
|
| 42 |
+
copyright notice that is included in or attached to the work
|
| 43 |
+
(an example is provided in the Appendix below).
|
| 44 |
+
|
| 45 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 46 |
+
form, that is based on (or derived from) the Work and for which the
|
| 47 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 48 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 49 |
+
of this License, Derivative Works shall not include works that remain
|
| 50 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 51 |
+
the Work and Derivative Works thereof.
|
| 52 |
+
|
| 53 |
+
"Contribution" shall mean any work of authorship, including
|
| 54 |
+
the original version of the Work and any modifications or additions
|
| 55 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 56 |
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
| 57 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 58 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 59 |
+
means any form of electronic, verbal, or written communication sent
|
| 60 |
+
to the Licensor or its representatives, including but not limited to
|
| 61 |
+
communication on electronic mailing lists, source code control systems,
|
| 62 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 63 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 64 |
+
excluding communication that is conspicuously marked or otherwise
|
| 65 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 66 |
+
|
| 67 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 68 |
+
on behalf of whom a Contribution has been received by Licensor and
|
| 69 |
+
subsequently incorporated within the Work.
|
| 70 |
+
|
| 71 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 72 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 73 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 74 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 75 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 76 |
+
Work and such Derivative Works in Source or Object form.
|
| 77 |
+
|
| 78 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 79 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 80 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 81 |
+
(except as stated in this section) patent license to make, have made,
|
| 82 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 83 |
+
where such license applies only to those patent claims licensable
|
| 84 |
+
by such Contributor that are necessarily infringed by their
|
| 85 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 86 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 87 |
+
institute patent litigation against any entity (including a
|
| 88 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 89 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 90 |
+
or contributory patent infringement, then any patent licenses
|
| 91 |
+
granted to You under this License for that Work shall terminate
|
| 92 |
+
as of the date such litigation is filed.
|
| 93 |
+
|
| 94 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 95 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 96 |
+
modifications, and in Source or Object form, provided that You
|
| 97 |
+
meet the following conditions:
|
| 98 |
+
|
| 99 |
+
(a) You must give any other recipients of the Work or
|
| 100 |
+
Derivative Works a copy of this License; and
|
| 101 |
+
|
| 102 |
+
(b) You must cause any modified files to carry prominent notices
|
| 103 |
+
stating that You changed the files; and
|
| 104 |
+
|
| 105 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 106 |
+
that You distribute, all copyright, patent, trademark, and
|
| 107 |
+
attribution notices from the Source form of the Work,
|
| 108 |
+
excluding those notices that do not pertain to any part of
|
| 109 |
+
the Derivative Works; and
|
| 110 |
+
|
| 111 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 112 |
+
distribution, then any Derivative Works that You distribute must
|
| 113 |
+
include a readable copy of the attribution notices contained
|
| 114 |
+
within such NOTICE file, excluding those notices that do not
|
| 115 |
+
pertain to any part of the Derivative Works, in at least one
|
| 116 |
+
of the following places: within a NOTICE text file distributed
|
| 117 |
+
as part of the Derivative Works; within the Source form or
|
| 118 |
+
documentation, if provided along with the Derivative Works; or,
|
| 119 |
+
within a display generated by the Derivative Works, if and
|
| 120 |
+
wherever such third-party notices normally appear. The contents
|
| 121 |
+
of the NOTICE file are for informational purposes only and
|
| 122 |
+
do not modify the License. You may add Your own attribution
|
| 123 |
+
notices within Derivative Works that You distribute, alongside
|
| 124 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 125 |
+
that such additional attribution notices cannot be construed
|
| 126 |
+
as modifying the License.
|
| 127 |
+
|
| 128 |
+
You may add Your own copyright statement to Your modifications and
|
| 129 |
+
may provide additional or different license terms and conditions
|
| 130 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 131 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 132 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 133 |
+
the conditions stated in this License.
|
| 134 |
+
|
| 135 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 136 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 137 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 138 |
+
this License, without any additional terms or conditions.
|
| 139 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 140 |
+
the terms of any separate license agreement you may have executed
|
| 141 |
+
with Licensor regarding such Contributions.
|
| 142 |
+
|
| 143 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 144 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 145 |
+
except as required for reasonable and customary use in describing the
|
| 146 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 147 |
+
|
| 148 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 149 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 150 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 151 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 152 |
+
implied, including, without limitation, any warranties or conditions
|
| 153 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 154 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 155 |
+
appropriateness of using or redistributing the Work and assume any
|
| 156 |
+
risks associated with Your exercise of permissions under this License.
|
| 157 |
+
|
| 158 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 159 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 160 |
+
unless required by applicable law (such as deliberate and grossly
|
| 161 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 162 |
+
liable to You for damages, including any direct, indirect, special,
|
| 163 |
+
incidental, or consequential damages of any character arising as a
|
| 164 |
+
result of this License or out of the use or inability to use the
|
| 165 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 166 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 167 |
+
other commercial damages or losses), even if such Contributor
|
| 168 |
+
has been advised of the possibility of such damages.
|
| 169 |
+
|
| 170 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 171 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 172 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 173 |
+
or other liability obligations and/or rights consistent with this
|
| 174 |
+
License. However, in accepting such obligations, You may act only
|
| 175 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 176 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 177 |
+
defend, and hold each Contributor harmless for any liability
|
| 178 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 179 |
+
of your accepting any such warranty or additional liability.
|
| 180 |
+
|
| 181 |
+
END OF TERMS AND CONDITIONS
|
| 182 |
+
|
| 183 |
+
APPENDIX: How to apply the Apache License to your work.
|
| 184 |
+
|
| 185 |
+
To apply the Apache License to your work, attach the following
|
| 186 |
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
| 187 |
+
replaced with your own identifying information. (Don't include
|
| 188 |
+
the brackets!) The text should be enclosed in the appropriate
|
| 189 |
+
comment syntax for the file format. We also recommend that a
|
| 190 |
+
file or class name and description of purpose be included on the
|
| 191 |
+
same "printed page" as the copyright notice for easier
|
| 192 |
+
identification within third-party archives.
|
| 193 |
+
|
| 194 |
+
Copyright [yyyy] [name of copyright owner]
|
| 195 |
+
|
| 196 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 197 |
+
you may not use this file except in compliance with the License.
|
| 198 |
+
You may obtain a copy of the License at
|
| 199 |
+
|
| 200 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 201 |
+
|
| 202 |
+
Unless required by applicable law or agreed to in writing, software
|
| 203 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 204 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 205 |
+
See the License for the specific language governing permissions and
|
| 206 |
+
limitations under the License.
|
| 207 |
+
|
| 208 |
+
Project-URL: homepage, https://github.com/jax-ml/ml_dtypes
|
| 209 |
+
Project-URL: repository, https://github.com/jax-ml/ml_dtypes
|
| 210 |
+
Classifier: Programming Language :: Python :: 3
|
| 211 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 212 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
| 213 |
+
Classifier: Intended Audience :: Science/Research
|
| 214 |
+
Requires-Python: >=3.9
|
| 215 |
+
Description-Content-Type: text/markdown
|
| 216 |
+
License-File: LICENSE
|
| 217 |
+
License-File: LICENSE.eigen
|
| 218 |
+
License-File: AUTHORS
|
| 219 |
+
Requires-Dist: numpy >1.20
|
| 220 |
+
Requires-Dist: numpy >=1.21.2 ; python_version >= "3.10"
|
| 221 |
+
Requires-Dist: numpy >=1.23.3 ; python_version >= "3.11"
|
| 222 |
+
Requires-Dist: numpy >=1.26.0 ; python_version >= "3.12"
|
| 223 |
+
Provides-Extra: dev
|
| 224 |
+
Requires-Dist: absl-py ; extra == 'dev'
|
| 225 |
+
Requires-Dist: pytest ; extra == 'dev'
|
| 226 |
+
Requires-Dist: pytest-xdist ; extra == 'dev'
|
| 227 |
+
Requires-Dist: pylint >=2.6.0 ; extra == 'dev'
|
| 228 |
+
Requires-Dist: pyink ; extra == 'dev'
|
| 229 |
+
|
| 230 |
+
# ml_dtypes
|
| 231 |
+
|
| 232 |
+
[](https://github.com/jax-ml/ml_dtypes/actions/workflows/test.yml)
|
| 233 |
+
[](https://github.com/jax-ml/ml_dtypes/actions/workflows/wheels.yml)
|
| 234 |
+
[](https://badge.fury.io/py/ml_dtypes)
|
| 235 |
+
|
| 236 |
+
`ml_dtypes` is a stand-alone implementation of several NumPy dtype extensions used in machine learning libraries, including:
|
| 237 |
+
|
| 238 |
+
- [`bfloat16`](https://en.wikipedia.org/wiki/Bfloat16_floating-point_format):
|
| 239 |
+
an alternative to the standard [`float16`](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) format
|
| 240 |
+
- `float8_*`: several experimental 8-bit floating point representations
|
| 241 |
+
including:
|
| 242 |
+
* `float8_e4m3b11fnuz`
|
| 243 |
+
* `float8_e4m3fn`
|
| 244 |
+
* `float8_e4m3fnuz`
|
| 245 |
+
* `float8_e5m2`
|
| 246 |
+
* `float8_e5m2fnuz`
|
| 247 |
+
- `int4` and `uint4`: low precision integer types.
|
| 248 |
+
|
| 249 |
+
See below for specifications of these number formats.
|
| 250 |
+
|
| 251 |
+
## Installation
|
| 252 |
+
|
| 253 |
+
The `ml_dtypes` package is tested with Python versions 3.9-3.12, and can be installed
|
| 254 |
+
with the following command:
|
| 255 |
+
```
|
| 256 |
+
pip install ml_dtypes
|
| 257 |
+
```
|
| 258 |
+
To test your installation, you can run the following:
|
| 259 |
+
```
|
| 260 |
+
pip install absl-py pytest
|
| 261 |
+
pytest --pyargs ml_dtypes
|
| 262 |
+
```
|
| 263 |
+
To build from source, clone the repository and run:
|
| 264 |
+
```
|
| 265 |
+
git submodule init
|
| 266 |
+
git submodule update
|
| 267 |
+
pip install .
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
## Example Usage
|
| 271 |
+
|
| 272 |
+
```python
|
| 273 |
+
>>> from ml_dtypes import bfloat16
|
| 274 |
+
>>> import numpy as np
|
| 275 |
+
>>> np.zeros(4, dtype=bfloat16)
|
| 276 |
+
array([0, 0, 0, 0], dtype=bfloat16)
|
| 277 |
+
```
|
| 278 |
+
Importing `ml_dtypes` also registers the data types with numpy, so that they may
|
| 279 |
+
be referred to by their string name:
|
| 280 |
+
|
| 281 |
+
```python
|
| 282 |
+
>>> np.dtype('bfloat16')
|
| 283 |
+
dtype(bfloat16)
|
| 284 |
+
>>> np.dtype('float8_e5m2')
|
| 285 |
+
dtype(float8_e5m2)
|
| 286 |
+
```
|
| 287 |
+
|
| 288 |
+
## Specifications of implemented floating point formats
|
| 289 |
+
|
| 290 |
+
### `bfloat16`
|
| 291 |
+
|
| 292 |
+
A `bfloat16` number is a single-precision float truncated at 16 bits.
|
| 293 |
+
|
| 294 |
+
Exponent: 8, Mantissa: 7, exponent bias: 127. IEEE 754, with NaN and inf.
|
| 295 |
+
|
| 296 |
+
### `float8_e4m3b11fnuz`
|
| 297 |
+
|
| 298 |
+
Exponent: 4, Mantissa: 3, bias: 11.
|
| 299 |
+
|
| 300 |
+
Extended range: no inf, NaN represented by 0b1000'0000.
|
| 301 |
+
|
| 302 |
+
### `float8_e4m3fn`
|
| 303 |
+
|
| 304 |
+
Exponent: 4, Mantissa: 3, bias: 7.
|
| 305 |
+
|
| 306 |
+
Extended range: no inf, NaN represented by 0bS111'1111.
|
| 307 |
+
|
| 308 |
+
The `fn` suffix is for consistency with the corresponding LLVM/MLIR type, signaling this type is not consistent with IEEE-754. The `f` indicates it is finite values only. The `n` indicates it includes NaNs, but only at the outer range.
|
| 309 |
+
|
| 310 |
+
### `float8_e4m3fnuz`
|
| 311 |
+
|
| 312 |
+
8-bit floating point with 3 bit mantissa.
|
| 313 |
+
|
| 314 |
+
An 8-bit floating point type with 1 sign bit, 4 bits exponent and 3 bits mantissa. The suffix `fnuz` is consistent with LLVM/MLIR naming and is derived from the differences to IEEE floating point conventions. `F` is for "finite" (no infinities), `N` for with special NaN encoding, `UZ` for unsigned zero.
|
| 315 |
+
|
| 316 |
+
This type has the following characteristics:
|
| 317 |
+
* bit encoding: S1E4M3 - `0bSEEEEMMM`
|
| 318 |
+
* exponent bias: 8
|
| 319 |
+
* infinities: Not supported
|
| 320 |
+
* NaNs: Supported with sign bit set to 1, exponent bits and mantissa bits set to all 0s - `0b10000000`
|
| 321 |
+
* denormals when exponent is 0
|
| 322 |
+
|
| 323 |
+
### `float8_e5m2`
|
| 324 |
+
|
| 325 |
+
Exponent: 5, Mantissa: 2, bias: 15. IEEE 754, with NaN and inf.
|
| 326 |
+
|
| 327 |
+
### `float8_e5m2fnuz`
|
| 328 |
+
|
| 329 |
+
8-bit floating point with 2 bit mantissa.
|
| 330 |
+
|
| 331 |
+
An 8-bit floating point type with 1 sign bit, 5 bits exponent and 2 bits mantissa. The suffix `fnuz` is consistent with LLVM/MLIR naming and is derived from the differences to IEEE floating point conventions. `F` is for "finite" (no infinities), `N` for with special NaN encoding, `UZ` for unsigned zero.
|
| 332 |
+
|
| 333 |
+
This type has the following characteristics:
|
| 334 |
+
* bit encoding: S1E5M2 - `0bSEEEEEMM`
|
| 335 |
+
* exponent bias: 16
|
| 336 |
+
* infinities: Not supported
|
| 337 |
+
* NaNs: Supported with sign bit set to 1, exponent bits and mantissa bits set to all 0s - `0b10000000`
|
| 338 |
+
* denormals when exponent is 0
|
| 339 |
+
|
| 340 |
+
## `int4` and `uint4`
|
| 341 |
+
|
| 342 |
+
4-bit integer types, where each element is represented unpacked (i.e., padded up
|
| 343 |
+
to a byte in memory).
|
| 344 |
+
|
| 345 |
+
NumPy does not support types smaller than a single byte. For example, the
|
| 346 |
+
distance between adjacent elements in an array (`.strides`) is expressed in
|
| 347 |
+
bytes. Relaxing this restriction would be a considerable engineering project.
|
| 348 |
+
The `int4` and `uint4` types therefore use an unpacked representation, where
|
| 349 |
+
each element of the array is padded up to a byte in memory. The lower four bits
|
| 350 |
+
of each byte contain the representation of the number, whereas the upper four
|
| 351 |
+
bits are ignored.
|
| 352 |
+
|
| 353 |
+
## Quirks of low-precision Arithmetic
|
| 354 |
+
|
| 355 |
+
If you're exploring the use of low-precision dtypes in your code, you should be
|
| 356 |
+
careful to anticipate when the precision loss might lead to surprising results.
|
| 357 |
+
One example is the behavior of aggregations like `sum`; consider this `bfloat16`
|
| 358 |
+
summation in NumPy (run with version 1.24.2):
|
| 359 |
+
|
| 360 |
+
```python
|
| 361 |
+
>>> from ml_dtypes import bfloat16
|
| 362 |
+
>>> import numpy as np
|
| 363 |
+
>>> rng = np.random.default_rng(seed=0)
|
| 364 |
+
>>> vals = rng.uniform(size=10000).astype(bfloat16)
|
| 365 |
+
>>> vals.sum()
|
| 366 |
+
256
|
| 367 |
+
```
|
| 368 |
+
The true sum should be close to 5000, but numpy returns exactly 256: this is
|
| 369 |
+
because `bfloat16` does not have the precision to increment `256` by values less than
|
| 370 |
+
`1`:
|
| 371 |
+
|
| 372 |
+
```python
|
| 373 |
+
>>> bfloat16(256) + bfloat16(1)
|
| 374 |
+
256
|
| 375 |
+
```
|
| 376 |
+
After 256, the next representable value in bfloat16 is 258:
|
| 377 |
+
|
| 378 |
+
```python
|
| 379 |
+
>>> np.nextafter(bfloat16(256), bfloat16(np.inf))
|
| 380 |
+
258
|
| 381 |
+
```
|
| 382 |
+
For better results you can specify that the accumulation should happen in a
|
| 383 |
+
higher-precision type like `float32`:
|
| 384 |
+
|
| 385 |
+
```python
|
| 386 |
+
>>> vals.sum(dtype='float32').astype(bfloat16)
|
| 387 |
+
4992
|
| 388 |
+
```
|
| 389 |
+
In contrast to NumPy, projects like [JAX](http://jax.readthedocs.io/) which support
|
| 390 |
+
low-precision arithmetic more natively will often do these kinds of higher-precision
|
| 391 |
+
accumulations automatically:
|
| 392 |
+
|
| 393 |
+
```python
|
| 394 |
+
>>> import jax.numpy as jnp
|
| 395 |
+
>>> jnp.array(vals).sum()
|
| 396 |
+
Array(4992, dtype=bfloat16)
|
| 397 |
+
```
|
| 398 |
+
|
| 399 |
+
## License
|
| 400 |
+
|
| 401 |
+
*This is not an officially supported Google product.*
|
| 402 |
+
|
| 403 |
+
The `ml_dtypes` source code is licensed under the Apache 2.0 license
|
| 404 |
+
(see [LICENSE](LICENSE)). Pre-compiled wheels are built with the
|
| 405 |
+
[EIGEN](https://eigen.tuxfamily.org/) project, which is released under the
|
| 406 |
+
MPL 2.0 license (see [LICENSE.eigen](LICENSE.eigen)).
|
lib/python3.10/site-packages/ml_dtypes-0.3.2.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ml_dtypes
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2005-2021 Fredrik Johansson and mpmath contributors
|
| 2 |
+
|
| 3 |
+
All rights reserved.
|
| 4 |
+
|
| 5 |
+
Redistribution and use in source and binary forms, with or without
|
| 6 |
+
modification, are permitted provided that the following conditions are met:
|
| 7 |
+
|
| 8 |
+
a. Redistributions of source code must retain the above copyright notice,
|
| 9 |
+
this list of conditions and the following disclaimer.
|
| 10 |
+
b. Redistributions in binary form must reproduce the above copyright
|
| 11 |
+
notice, this list of conditions and the following disclaimer in the
|
| 12 |
+
documentation and/or other materials provided with the distribution.
|
| 13 |
+
c. Neither the name of the copyright holder nor the names of its
|
| 14 |
+
contributors may be used to endorse or promote products derived
|
| 15 |
+
from this software without specific prior written permission.
|
| 16 |
+
|
| 17 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 18 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 19 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 20 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
|
| 21 |
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 22 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 23 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 24 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 25 |
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 26 |
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
| 27 |
+
DAMAGE.
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: mpmath
|
| 3 |
+
Version: 1.3.0
|
| 4 |
+
Summary: Python library for arbitrary-precision floating-point arithmetic
|
| 5 |
+
Home-page: http://mpmath.org/
|
| 6 |
+
Author: Fredrik Johansson
|
| 7 |
+
Author-email: fredrik.johansson@gmail.com
|
| 8 |
+
License: BSD
|
| 9 |
+
Project-URL: Source, https://github.com/fredrik-johansson/mpmath
|
| 10 |
+
Project-URL: Tracker, https://github.com/fredrik-johansson/mpmath/issues
|
| 11 |
+
Project-URL: Documentation, http://mpmath.org/doc/current/
|
| 12 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 13 |
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
| 14 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 15 |
+
Classifier: Programming Language :: Python
|
| 16 |
+
Classifier: Programming Language :: Python :: 2
|
| 17 |
+
Classifier: Programming Language :: Python :: 2.7
|
| 18 |
+
Classifier: Programming Language :: Python :: 3
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.5
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.6
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 24 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 25 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 26 |
+
License-File: LICENSE
|
| 27 |
+
Provides-Extra: develop
|
| 28 |
+
Requires-Dist: pytest (>=4.6) ; extra == 'develop'
|
| 29 |
+
Requires-Dist: pycodestyle ; extra == 'develop'
|
| 30 |
+
Requires-Dist: pytest-cov ; extra == 'develop'
|
| 31 |
+
Requires-Dist: codecov ; extra == 'develop'
|
| 32 |
+
Requires-Dist: wheel ; extra == 'develop'
|
| 33 |
+
Provides-Extra: docs
|
| 34 |
+
Requires-Dist: sphinx ; extra == 'docs'
|
| 35 |
+
Provides-Extra: gmpy
|
| 36 |
+
Requires-Dist: gmpy2 (>=2.1.0a4) ; (platform_python_implementation != "PyPy") and extra == 'gmpy'
|
| 37 |
+
Provides-Extra: tests
|
| 38 |
+
Requires-Dist: pytest (>=4.6) ; extra == 'tests'
|
| 39 |
+
|
| 40 |
+
mpmath
|
| 41 |
+
======
|
| 42 |
+
|
| 43 |
+
|pypi version| |Build status| |Code coverage status| |Zenodo Badge|
|
| 44 |
+
|
| 45 |
+
.. |pypi version| image:: https://img.shields.io/pypi/v/mpmath.svg
|
| 46 |
+
:target: https://pypi.python.org/pypi/mpmath
|
| 47 |
+
.. |Build status| image:: https://github.com/fredrik-johansson/mpmath/workflows/test/badge.svg
|
| 48 |
+
:target: https://github.com/fredrik-johansson/mpmath/actions?workflow=test
|
| 49 |
+
.. |Code coverage status| image:: https://codecov.io/gh/fredrik-johansson/mpmath/branch/master/graph/badge.svg
|
| 50 |
+
:target: https://codecov.io/gh/fredrik-johansson/mpmath
|
| 51 |
+
.. |Zenodo Badge| image:: https://zenodo.org/badge/2934512.svg
|
| 52 |
+
:target: https://zenodo.org/badge/latestdoi/2934512
|
| 53 |
+
|
| 54 |
+
A Python library for arbitrary-precision floating-point arithmetic.
|
| 55 |
+
|
| 56 |
+
Website: http://mpmath.org/
|
| 57 |
+
Main author: Fredrik Johansson <fredrik.johansson@gmail.com>
|
| 58 |
+
|
| 59 |
+
Mpmath is free software released under the New BSD License (see the
|
| 60 |
+
LICENSE file for details)
|
| 61 |
+
|
| 62 |
+
0. History and credits
|
| 63 |
+
----------------------
|
| 64 |
+
|
| 65 |
+
The following people (among others) have contributed major patches
|
| 66 |
+
or new features to mpmath:
|
| 67 |
+
|
| 68 |
+
* Pearu Peterson <pearu.peterson@gmail.com>
|
| 69 |
+
* Mario Pernici <mario.pernici@mi.infn.it>
|
| 70 |
+
* Ondrej Certik <ondrej@certik.cz>
|
| 71 |
+
* Vinzent Steinberg <vinzent.steinberg@gmail.cm>
|
| 72 |
+
* Nimish Telang <ntelang@gmail.com>
|
| 73 |
+
* Mike Taschuk <mtaschuk@ece.ualberta.ca>
|
| 74 |
+
* Case Van Horsen <casevh@gmail.com>
|
| 75 |
+
* Jorn Baayen <jorn.baayen@gmail.com>
|
| 76 |
+
* Chris Smith <smichr@gmail.com>
|
| 77 |
+
* Juan Arias de Reyna <arias@us.es>
|
| 78 |
+
* Ioannis Tziakos <itziakos@gmail.com>
|
| 79 |
+
* Aaron Meurer <asmeurer@gmail.com>
|
| 80 |
+
* Stefan Krastanov <krastanov.stefan@gmail.com>
|
| 81 |
+
* Ken Allen <ken.allen@sbcglobal.net>
|
| 82 |
+
* Timo Hartmann <thartmann15@gmail.com>
|
| 83 |
+
* Sergey B Kirpichev <skirpichev@gmail.com>
|
| 84 |
+
* Kris Kuhlman <kristopher.kuhlman@gmail.com>
|
| 85 |
+
* Paul Masson <paulmasson@analyticphysics.com>
|
| 86 |
+
* Michael Kagalenko <michael.kagalenko@gmail.com>
|
| 87 |
+
* Jonathan Warner <warnerjon12@gmail.com>
|
| 88 |
+
* Max Gaukler <max.gaukler@fau.de>
|
| 89 |
+
* Guillermo Navas-Palencia <g.navas.palencia@gmail.com>
|
| 90 |
+
* Nike Dattani <nike@hpqc.org>
|
| 91 |
+
|
| 92 |
+
Numerous other people have contributed by reporting bugs,
|
| 93 |
+
requesting new features, or suggesting improvements to the
|
| 94 |
+
documentation.
|
| 95 |
+
|
| 96 |
+
For a detailed changelog, including individual contributions,
|
| 97 |
+
see the CHANGES file.
|
| 98 |
+
|
| 99 |
+
Fredrik's work on mpmath during summer 2008 was sponsored by Google
|
| 100 |
+
as part of the Google Summer of Code program.
|
| 101 |
+
|
| 102 |
+
Fredrik's work on mpmath during summer 2009 was sponsored by the
|
| 103 |
+
American Institute of Mathematics under the support of the National Science
|
| 104 |
+
Foundation Grant No. 0757627 (FRG: L-functions and Modular Forms).
|
| 105 |
+
|
| 106 |
+
Any opinions, findings, and conclusions or recommendations expressed in this
|
| 107 |
+
material are those of the author(s) and do not necessarily reflect the
|
| 108 |
+
views of the sponsors.
|
| 109 |
+
|
| 110 |
+
Credit also goes to:
|
| 111 |
+
|
| 112 |
+
* The authors of the GMP library and the Python wrapper
|
| 113 |
+
gmpy, enabling mpmath to become much faster at
|
| 114 |
+
high precision
|
| 115 |
+
* The authors of MPFR, pari/gp, MPFUN, and other arbitrary-
|
| 116 |
+
precision libraries, whose documentation has been helpful
|
| 117 |
+
for implementing many of the algorithms in mpmath
|
| 118 |
+
* Wikipedia contributors; Abramowitz & Stegun; Gradshteyn & Ryzhik;
|
| 119 |
+
Wolfram Research for MathWorld and the Wolfram Functions site.
|
| 120 |
+
These are the main references used for special functions
|
| 121 |
+
implementations.
|
| 122 |
+
* George Brandl for developing the Sphinx documentation tool
|
| 123 |
+
used to build mpmath's documentation
|
| 124 |
+
|
| 125 |
+
Release history:
|
| 126 |
+
|
| 127 |
+
* Version 1.3.0 released on March 7, 2023
|
| 128 |
+
* Version 1.2.0 released on February 1, 2021
|
| 129 |
+
* Version 1.1.0 released on December 11, 2018
|
| 130 |
+
* Version 1.0.0 released on September 27, 2017
|
| 131 |
+
* Version 0.19 released on June 10, 2014
|
| 132 |
+
* Version 0.18 released on December 31, 2013
|
| 133 |
+
* Version 0.17 released on February 1, 2011
|
| 134 |
+
* Version 0.16 released on September 24, 2010
|
| 135 |
+
* Version 0.15 released on June 6, 2010
|
| 136 |
+
* Version 0.14 released on February 5, 2010
|
| 137 |
+
* Version 0.13 released on August 13, 2009
|
| 138 |
+
* Version 0.12 released on June 9, 2009
|
| 139 |
+
* Version 0.11 released on January 26, 2009
|
| 140 |
+
* Version 0.10 released on October 15, 2008
|
| 141 |
+
* Version 0.9 released on August 23, 2008
|
| 142 |
+
* Version 0.8 released on April 20, 2008
|
| 143 |
+
* Version 0.7 released on March 12, 2008
|
| 144 |
+
* Version 0.6 released on January 13, 2008
|
| 145 |
+
* Version 0.5 released on November 24, 2007
|
| 146 |
+
* Version 0.4 released on November 3, 2007
|
| 147 |
+
* Version 0.3 released on October 5, 2007
|
| 148 |
+
* Version 0.2 released on October 2, 2007
|
| 149 |
+
* Version 0.1 released on September 27, 2007
|
| 150 |
+
|
| 151 |
+
1. Download & installation
|
| 152 |
+
--------------------------
|
| 153 |
+
|
| 154 |
+
Mpmath requires Python 2.7 or 3.5 (or later versions). It has been tested
|
| 155 |
+
with CPython 2.7, 3.5 through 3.7 and for PyPy.
|
| 156 |
+
|
| 157 |
+
The latest release of mpmath can be downloaded from the mpmath
|
| 158 |
+
website and from https://github.com/fredrik-johansson/mpmath/releases
|
| 159 |
+
|
| 160 |
+
It should also be available in the Python Package Index at
|
| 161 |
+
https://pypi.python.org/pypi/mpmath
|
| 162 |
+
|
| 163 |
+
To install latest release of Mpmath with pip, simply run
|
| 164 |
+
|
| 165 |
+
``pip install mpmath``
|
| 166 |
+
|
| 167 |
+
Or unpack the mpmath archive and run
|
| 168 |
+
|
| 169 |
+
``python setup.py install``
|
| 170 |
+
|
| 171 |
+
Mpmath can also be installed using
|
| 172 |
+
|
| 173 |
+
``python -m easy_install mpmath``
|
| 174 |
+
|
| 175 |
+
The latest development code is available from
|
| 176 |
+
https://github.com/fredrik-johansson/mpmath
|
| 177 |
+
|
| 178 |
+
See the main documentation for more detailed instructions.
|
| 179 |
+
|
| 180 |
+
2. Running tests
|
| 181 |
+
----------------
|
| 182 |
+
|
| 183 |
+
The unit tests in mpmath/tests/ can be run via the script
|
| 184 |
+
runtests.py, but it is recommended to run them with py.test
|
| 185 |
+
(https://pytest.org/), especially
|
| 186 |
+
to generate more useful reports in case there are failures.
|
| 187 |
+
|
| 188 |
+
You may also want to check out the demo scripts in the demo
|
| 189 |
+
directory.
|
| 190 |
+
|
| 191 |
+
The master branch is automatically tested by Travis CI.
|
| 192 |
+
|
| 193 |
+
3. Documentation
|
| 194 |
+
----------------
|
| 195 |
+
|
| 196 |
+
Documentation in reStructuredText format is available in the
|
| 197 |
+
doc directory included with the source package. These files
|
| 198 |
+
are human-readable, but can be compiled to prettier HTML using
|
| 199 |
+
the build.py script (requires Sphinx, http://sphinx.pocoo.org/).
|
| 200 |
+
|
| 201 |
+
See setup.txt in the documentation for more information.
|
| 202 |
+
|
| 203 |
+
The most recent documentation is also available in HTML format:
|
| 204 |
+
|
| 205 |
+
http://mpmath.org/doc/current/
|
| 206 |
+
|
| 207 |
+
4. Known problems
|
| 208 |
+
-----------------
|
| 209 |
+
|
| 210 |
+
Mpmath is a work in progress. Major issues include:
|
| 211 |
+
|
| 212 |
+
* Some functions may return incorrect values when given extremely
|
| 213 |
+
large arguments or arguments very close to singularities.
|
| 214 |
+
|
| 215 |
+
* Directed rounding works for arithmetic operations. It is implemented
|
| 216 |
+
heuristically for other operations, and their results may be off by one
|
| 217 |
+
or two units in the last place (even if otherwise accurate).
|
| 218 |
+
|
| 219 |
+
* Some IEEE 754 features are not available. Inifinities and NaN are
|
| 220 |
+
partially supported; denormal rounding is currently not available
|
| 221 |
+
at all.
|
| 222 |
+
|
| 223 |
+
* The interface for switching precision and rounding is not finalized.
|
| 224 |
+
The current method is not threadsafe.
|
| 225 |
+
|
| 226 |
+
5. Help and bug reports
|
| 227 |
+
-----------------------
|
| 228 |
+
|
| 229 |
+
General questions and comments can be sent to the mpmath mailinglist,
|
| 230 |
+
mpmath@googlegroups.com
|
| 231 |
+
|
| 232 |
+
You can also report bugs and send patches to the mpmath issue tracker,
|
| 233 |
+
https://github.com/fredrik-johansson/mpmath/issues
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
mpmath-1.3.0.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
mpmath-1.3.0.dist-info/LICENSE,sha256=wmyugdpFCOXiSZhXd6M4IfGDIj67dNf4z7-Q_n7vL7c,1537
|
| 3 |
+
mpmath-1.3.0.dist-info/METADATA,sha256=RLZupES5wNGa6UgV01a_BHrmtoDBkmi1wmVofNaoFAY,8630
|
| 4 |
+
mpmath-1.3.0.dist-info/RECORD,,
|
| 5 |
+
mpmath-1.3.0.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
mpmath-1.3.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
| 7 |
+
mpmath-1.3.0.dist-info/top_level.txt,sha256=BUVWrh8EVlkOhM1n3X9S8msTaVcC-3s6Sjt60avHYus,7
|
| 8 |
+
mpmath/__init__.py,sha256=skFYTSwfwDBLChAV6pI3SdewgAQR3UBtyrfIK_Jdn-g,8765
|
| 9 |
+
mpmath/calculus/__init__.py,sha256=UAgCIJ1YmaeyTqpNzjBlCZGeIzLtUZMEEpl99VWNjus,162
|
| 10 |
+
mpmath/calculus/approximation.py,sha256=vyzu3YI6r63Oq1KFHrQz02mGXAcH23emqNYhJuUaFZ4,8817
|
| 11 |
+
mpmath/calculus/calculus.py,sha256=A0gSp0hxSyEDfugJViY3CeWalF-vK701YftzrjSQzQ4,112
|
| 12 |
+
mpmath/calculus/differentiation.py,sha256=2L6CBj8xtX9iip98NPbKsLtwtRjxi571wYmTMHFeL90,20226
|
| 13 |
+
mpmath/calculus/extrapolation.py,sha256=xM0rvk2DFEF4iR1Jhl-Y3aS93iW9VVJX7y9IGpmzC-A,73306
|
| 14 |
+
mpmath/calculus/inverselaplace.py,sha256=5-pn8N_t0PtgBTXixsXZ4xxrihK2J5gYsVfTKfDx4gA,36056
|
| 15 |
+
mpmath/calculus/odes.py,sha256=gaHiw7IJjsONNTAa6izFPZpmcg9uyTp8MULnGdzTIGo,9908
|
| 16 |
+
mpmath/calculus/optimization.py,sha256=bKnShXElBOmVOIOlFeksDsYCp9fYSmYwKmXDt0z26MM,32856
|
| 17 |
+
mpmath/calculus/polynomials.py,sha256=D16BhU_SHbVi06IxNwABHR-H77IylndNsN3muPTuFYs,7877
|
| 18 |
+
mpmath/calculus/quadrature.py,sha256=n-avtS8E43foV-5tr5lofgOBaiMUYE8AJjQcWI9QcKk,42432
|
| 19 |
+
mpmath/ctx_base.py,sha256=rfjmfMyA55x8R_cWFINUwWVTElfZmyx5erKDdauSEVw,15985
|
| 20 |
+
mpmath/ctx_fp.py,sha256=ctUjx_NoU0iFWk05cXDYCL2ZtLZOlWs1n6Zao3pbG2g,6572
|
| 21 |
+
mpmath/ctx_iv.py,sha256=tqdMr-GDfkZk1EhoGeCAajy7pQv-RWtrVqhYjfI8r4g,17211
|
| 22 |
+
mpmath/ctx_mp.py,sha256=d3r4t7xHNqSFtmqsA9Btq1Npy3WTM-pcM2_jeCyECxY,49452
|
| 23 |
+
mpmath/ctx_mp_python.py,sha256=3olYWo4lk1SnQ0A_IaZ181qqG8u5pxGat_v-L4Qtn3Y,37815
|
| 24 |
+
mpmath/function_docs.py,sha256=g4PP8n6ILXmHcLyA50sxK6Tmp_Z4_pRN-wDErU8D1i4,283512
|
| 25 |
+
mpmath/functions/__init__.py,sha256=YXVdhqv-6LKm6cr5xxtTNTtuD9zDPKGQl8GmS0xz2xo,330
|
| 26 |
+
mpmath/functions/bessel.py,sha256=dUPLu8frlK-vmf3-irX_7uvwyw4xccv6EIizmIZ88kM,37938
|
| 27 |
+
mpmath/functions/elliptic.py,sha256=qz0yVMb4lWEeOTDL_DWz5u5awmGIPKAsuZFJXgwHJNU,42237
|
| 28 |
+
mpmath/functions/expintegrals.py,sha256=75X_MRdYc1F_X73bgNiOJqwRlS2hqAzcFLl3RM2tCDc,11644
|
| 29 |
+
mpmath/functions/factorials.py,sha256=8_6kCR7e4k1GwxiAOJu0NRadeF4jA28qx4hidhu4ILk,5273
|
| 30 |
+
mpmath/functions/functions.py,sha256=ub2JExvqzCWLkm5yAm72Fr6fdWmZZUknq9_3w9MEigI,18100
|
| 31 |
+
mpmath/functions/hypergeometric.py,sha256=Z0OMAMC4ylK42n_SnamyFVnUx6zHLyCLCoJDSZ1JrHY,51570
|
| 32 |
+
mpmath/functions/orthogonal.py,sha256=FabkxKfBoSseA5flWu1a3re-2BYaew9augqIsT8LaLw,16097
|
| 33 |
+
mpmath/functions/qfunctions.py,sha256=a3EHGKQt_jMd4x9I772Jz-TGFnGY-arWqPvZGz9QSe0,7633
|
| 34 |
+
mpmath/functions/rszeta.py,sha256=yuUVp4ilIyDmXyE3WTBxDDjwfEJNypJnbPS-xPH5How,46184
|
| 35 |
+
mpmath/functions/signals.py,sha256=ELotwQaW1CDpv-eeJzOZ5c23NhfaZcj9_Gkb3psvS0Q,703
|
| 36 |
+
mpmath/functions/theta.py,sha256=KggOocczoMG6_HMoal4oEP7iZ4SKOou9JFE-WzY2r3M,37320
|
| 37 |
+
mpmath/functions/zeta.py,sha256=ue7JY7GXA0oX8q08sQJl2CSRrZ7kOt8HsftpVjnTwrE,36410
|
| 38 |
+
mpmath/functions/zetazeros.py,sha256=uq6TVyZBcY2MLX7VSdVfn0TOkowBLM9fXtnySEwaNzw,30858
|
| 39 |
+
mpmath/identification.py,sha256=7aMdngRAaeL_MafDUNbmEIlGQSklHDZ8pmPFt-OLgkw,29253
|
| 40 |
+
mpmath/libmp/__init__.py,sha256=UCDjLZw4brbklaCmSixCcPdLdHkz8sF_-6F_wr0duAg,3790
|
| 41 |
+
mpmath/libmp/backend.py,sha256=26A8pUkaGov26vrrFNQVyWJ5LDtK8sl3UHrYLecaTjA,3360
|
| 42 |
+
mpmath/libmp/gammazeta.py,sha256=Xqdw6PMoswDaSca_sOs-IglRuk3fb8c9p43M_lbcrlc,71469
|
| 43 |
+
mpmath/libmp/libelefun.py,sha256=joBZP4FOdxPfieWso1LPtSr6dHydpG_LQiF_bYQYWMg,43861
|
| 44 |
+
mpmath/libmp/libhyper.py,sha256=J9fmdDF6u27EcssEWvBuVaAa3hFjPvPN1SgRgu1dEbc,36624
|
| 45 |
+
mpmath/libmp/libintmath.py,sha256=aIRT0rkUZ_sdGQf3TNCLd-pBMvtQWjssbvFLfK7U0jc,16688
|
| 46 |
+
mpmath/libmp/libmpc.py,sha256=KBndUjs5YVS32-Id3fflDfYgpdW1Prx6zfo8Ez5Qbrs,26875
|
| 47 |
+
mpmath/libmp/libmpf.py,sha256=vpP0kNVkScbCVoZogJ4Watl4I7Ce0d4dzHVjfVe57so,45021
|
| 48 |
+
mpmath/libmp/libmpi.py,sha256=u0I5Eiwkqa-4-dXETi5k7MuaxBeZbvCAPFtl93U9YF0,27622
|
| 49 |
+
mpmath/math2.py,sha256=O5Dglg81SsW0wfHDUJcXOD8-cCaLvbVIvyw0sVmRbpI,18561
|
| 50 |
+
mpmath/matrices/__init__.py,sha256=ETzGDciYbq9ftiKwaMbJ15EI-KNXHrzRb-ZHehhqFjs,94
|
| 51 |
+
mpmath/matrices/calculus.py,sha256=PNRq-p2nxgT-fzC54K2depi8ddhdx6Q86G8qpUiHeUY,18609
|
| 52 |
+
mpmath/matrices/eigen.py,sha256=GbDXI3CixzEdXxr1G86uUWkAngAvd-05MmSQ-Tsu_5k,24394
|
| 53 |
+
mpmath/matrices/eigen_symmetric.py,sha256=FPKPeQr1cGYw6Y6ea32a1YdEWQDLP6JlQHEA2WfNLYg,58534
|
| 54 |
+
mpmath/matrices/linalg.py,sha256=04C3ijzMFom7ob5fXBCDfyPPdo3BIboIeE8x2A6vqF0,26958
|
| 55 |
+
mpmath/matrices/matrices.py,sha256=o78Eq62EHQnxcsR0LBoWDEGREOoN4L2iDM1q3dQrw0o,32331
|
| 56 |
+
mpmath/rational.py,sha256=64d56fvZXngYZT7nOAHeFRUX77eJ1A0R3rpfWBU-mSo,5976
|
| 57 |
+
mpmath/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 58 |
+
mpmath/tests/extratest_gamma.py,sha256=xidhXUelILcxtiPGoTBHjqUOKIJzEaZ_v3nntGQyWZQ,7228
|
| 59 |
+
mpmath/tests/extratest_zeta.py,sha256=sg10j9RhjBpV2EdUqyYhGV2ERWvM--EvwwGIz6HTmlw,1003
|
| 60 |
+
mpmath/tests/runtests.py,sha256=7NUV82F3K_5AhU8mCLUFf5OibtT7uloFCwPyM3l71wM,5189
|
| 61 |
+
mpmath/tests/test_basic_ops.py,sha256=dsB8DRG-GrPzBaZ-bIauYabaeqXbfqBo9SIP9BqcTSs,15348
|
| 62 |
+
mpmath/tests/test_bitwise.py,sha256=-nLYhgQbhDza3SQM63BhktYntACagqMYx9ib3dPnTKM,7686
|
| 63 |
+
mpmath/tests/test_calculus.py,sha256=4oxtNfMpO4RLLoOzrv7r9-h8BcqfBsJIE6UpsHe7c4w,9187
|
| 64 |
+
mpmath/tests/test_compatibility.py,sha256=_t3ASZ3jhfAMnN1voWX7PDNIDzn-3PokkJGIdT1x7y0,2306
|
| 65 |
+
mpmath/tests/test_convert.py,sha256=JPcDcTJIWh5prIxjx5DM1aNWgqlUoF2KpHvAgK3uHi4,8834
|
| 66 |
+
mpmath/tests/test_diff.py,sha256=qjiF8NxQ8vueuZ5ZHGPQ-kjcj_I7Jh_fEdFtaA8DzEI,2466
|
| 67 |
+
mpmath/tests/test_division.py,sha256=6lUeZfmaBWvvszdqlWLMHgXPjVsxvW1WZpd4-jFWCpU,5340
|
| 68 |
+
mpmath/tests/test_eigen.py,sha256=2mnqVATGbsJkvSVHPpitfAk881twFfb3LsO3XikV9Hs,3905
|
| 69 |
+
mpmath/tests/test_eigen_symmetric.py,sha256=v0VimCicIU2owASDMBaP-t-30uq-pXcsglt95KBtNO4,8778
|
| 70 |
+
mpmath/tests/test_elliptic.py,sha256=Kjiwq9Bb6N_OOzzWewGQ1M_PMa7vRs42V0t90gloZxo,26225
|
| 71 |
+
mpmath/tests/test_fp.py,sha256=AJo0FTyH4BuUnUsv176LD956om308KGYndy-b54KGxM,89997
|
| 72 |
+
mpmath/tests/test_functions.py,sha256=b47VywdomoOX6KmMmz9-iv2IqVIydwKSuUw2pWlFHrY,30955
|
| 73 |
+
mpmath/tests/test_functions2.py,sha256=vlw2RWhL1oTcifnOMDx1a_YzN96UgNNIE5STeKRv1HY,96990
|
| 74 |
+
mpmath/tests/test_gammazeta.py,sha256=AB34O0DV7AlEf9Z4brnCadeQU5-uAwhWRw5FZas65DA,27917
|
| 75 |
+
mpmath/tests/test_hp.py,sha256=6hcENu6Te2klPEiTSeLBIRPlH7PADlJwFKbx8xpnOhg,10461
|
| 76 |
+
mpmath/tests/test_identify.py,sha256=lGUIPfrB2paTg0cFUo64GmMzF77F9gs9FQjX7gxGHV8,692
|
| 77 |
+
mpmath/tests/test_interval.py,sha256=TjYd7a9ca6iRJiLjw06isLeZTuGoGAPmgleDZ0cYfJ0,17527
|
| 78 |
+
mpmath/tests/test_levin.py,sha256=P8M11yV1dj_gdSNv5xuwCzFiF86QyRDtPMjURy6wJ28,5090
|
| 79 |
+
mpmath/tests/test_linalg.py,sha256=miKEnwB8iwWV13hi1bF1cg3hgB4rTKOR0fvDVfWmXds,10440
|
| 80 |
+
mpmath/tests/test_matrices.py,sha256=qyA4Ml2CvNvW034lzB01G6wVgNr7UrgZqh2wkMXtpzM,7944
|
| 81 |
+
mpmath/tests/test_mpmath.py,sha256=LVyJUeofiaxW-zLKWVBCz59L9UQsjlW0Ts9_oBiEv_4,196
|
| 82 |
+
mpmath/tests/test_ode.py,sha256=zAxexBH4fnmFNO4bvEHbug1NJWC5zqfFaVDlYijowkY,1822
|
| 83 |
+
mpmath/tests/test_pickle.py,sha256=Y8CKmDLFsJHUqG8CDaBw5ilrPP4YT1xijVduLpQ7XFE,401
|
| 84 |
+
mpmath/tests/test_power.py,sha256=sz_K02SmNxpa6Kb1uJLN_N4tXTJGdQ___vPRshEN7Gk,5227
|
| 85 |
+
mpmath/tests/test_quad.py,sha256=49Ltft0vZ_kdKLL5s-Kj-BzAVoF5LPVEUeNUzdOkghI,3893
|
| 86 |
+
mpmath/tests/test_rootfinding.py,sha256=umQegEaKHmYOEl5jEyoD-VLKDtXsTJJkepKEr4c0dC0,3132
|
| 87 |
+
mpmath/tests/test_special.py,sha256=YbMIoMIkJEvvKYIzS0CXthJFG0--j6un7-tcE6b7FPM,2848
|
| 88 |
+
mpmath/tests/test_str.py,sha256=0WsGD9hMPRi8zcuYMA9Cu2mOvQiCFskPwMsMf8lBDK4,544
|
| 89 |
+
mpmath/tests/test_summation.py,sha256=fdNlsvRVOsbWxbhlyDLDaEO2S8kTJrRMKIvB5-aNci0,2035
|
| 90 |
+
mpmath/tests/test_trig.py,sha256=zPtkIEnZaThxcWur4k7BX8-2Jmj-AhO191Svv7ANYUU,4799
|
| 91 |
+
mpmath/tests/test_visualization.py,sha256=1PqtkoUx-WsKYgTRiu5o9pBc85kwhf1lzU2eobDQCJM,944
|
| 92 |
+
mpmath/tests/torture.py,sha256=LD95oES7JY2KroELK-m-jhvtbvZaKChnt0Cq7kFMNCw,7868
|
| 93 |
+
mpmath/usertools.py,sha256=a-TDw7XSRsPdBEffxOooDV4WDFfuXnO58P75dcAD87I,3029
|
| 94 |
+
mpmath/visualization.py,sha256=pnnbjcd9AhFVRBZavYX5gjx4ytK_kXoDDisYR6EpXhs,10627
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/REQUESTED
ADDED
|
File without changes
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: bdist_wheel (0.38.4)
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
| 5 |
+
|
lib/python3.10/site-packages/mpmath-1.3.0.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
mpmath
|
lib/python3.10/site-packages/pyasn1_modules/rfc1157.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 6 |
+
#
|
| 7 |
+
# SNMPv1 message syntax
|
| 8 |
+
#
|
| 9 |
+
# ASN.1 source from:
|
| 10 |
+
# http://www.ietf.org/rfc/rfc1157.txt
|
| 11 |
+
#
|
| 12 |
+
# Sample captures from:
|
| 13 |
+
# http://wiki.wireshark.org/SampleCaptures/
|
| 14 |
+
#
|
| 15 |
+
from pyasn1.type import namedtype
|
| 16 |
+
from pyasn1.type import namedval
|
| 17 |
+
from pyasn1.type import tag
|
| 18 |
+
from pyasn1.type import univ
|
| 19 |
+
|
| 20 |
+
from pyasn1_modules import rfc1155
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Version(univ.Integer):
|
| 24 |
+
namedValues = namedval.NamedValues(
|
| 25 |
+
('version-1', 0)
|
| 26 |
+
)
|
| 27 |
+
defaultValue = 0
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Community(univ.OctetString):
|
| 31 |
+
pass
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class RequestID(univ.Integer):
|
| 35 |
+
pass
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class ErrorStatus(univ.Integer):
|
| 39 |
+
namedValues = namedval.NamedValues(
|
| 40 |
+
('noError', 0),
|
| 41 |
+
('tooBig', 1),
|
| 42 |
+
('noSuchName', 2),
|
| 43 |
+
('badValue', 3),
|
| 44 |
+
('readOnly', 4),
|
| 45 |
+
('genErr', 5)
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
class ErrorIndex(univ.Integer):
|
| 50 |
+
pass
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class VarBind(univ.Sequence):
|
| 54 |
+
componentType = namedtype.NamedTypes(
|
| 55 |
+
namedtype.NamedType('name', rfc1155.ObjectName()),
|
| 56 |
+
namedtype.NamedType('value', rfc1155.ObjectSyntax())
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
class VarBindList(univ.SequenceOf):
|
| 61 |
+
componentType = VarBind()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class _RequestBase(univ.Sequence):
|
| 65 |
+
componentType = namedtype.NamedTypes(
|
| 66 |
+
namedtype.NamedType('request-id', RequestID()),
|
| 67 |
+
namedtype.NamedType('error-status', ErrorStatus()),
|
| 68 |
+
namedtype.NamedType('error-index', ErrorIndex()),
|
| 69 |
+
namedtype.NamedType('variable-bindings', VarBindList())
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class GetRequestPDU(_RequestBase):
|
| 74 |
+
tagSet = _RequestBase.tagSet.tagImplicitly(
|
| 75 |
+
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0)
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class GetNextRequestPDU(_RequestBase):
|
| 80 |
+
tagSet = _RequestBase.tagSet.tagImplicitly(
|
| 81 |
+
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 1)
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class GetResponsePDU(_RequestBase):
|
| 86 |
+
tagSet = _RequestBase.tagSet.tagImplicitly(
|
| 87 |
+
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 2)
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
class SetRequestPDU(_RequestBase):
|
| 92 |
+
tagSet = _RequestBase.tagSet.tagImplicitly(
|
| 93 |
+
tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 3)
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
class TrapPDU(univ.Sequence):
|
| 98 |
+
componentType = namedtype.NamedTypes(
|
| 99 |
+
namedtype.NamedType('enterprise', univ.ObjectIdentifier()),
|
| 100 |
+
namedtype.NamedType('agent-addr', rfc1155.NetworkAddress()),
|
| 101 |
+
namedtype.NamedType('generic-trap', univ.Integer().clone(
|
| 102 |
+
namedValues=namedval.NamedValues(('coldStart', 0), ('warmStart', 1), ('linkDown', 2), ('linkUp', 3),
|
| 103 |
+
('authenticationFailure', 4), ('egpNeighborLoss', 5),
|
| 104 |
+
('enterpriseSpecific', 6)))),
|
| 105 |
+
namedtype.NamedType('specific-trap', univ.Integer()),
|
| 106 |
+
namedtype.NamedType('time-stamp', rfc1155.TimeTicks()),
|
| 107 |
+
namedtype.NamedType('variable-bindings', VarBindList())
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
class Pdus(univ.Choice):
|
| 112 |
+
componentType = namedtype.NamedTypes(
|
| 113 |
+
namedtype.NamedType('get-request', GetRequestPDU()),
|
| 114 |
+
namedtype.NamedType('get-next-request', GetNextRequestPDU()),
|
| 115 |
+
namedtype.NamedType('get-response', GetResponsePDU()),
|
| 116 |
+
namedtype.NamedType('set-request', SetRequestPDU()),
|
| 117 |
+
namedtype.NamedType('trap', TrapPDU())
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class Message(univ.Sequence):
|
| 122 |
+
componentType = namedtype.NamedTypes(
|
| 123 |
+
namedtype.NamedType('version', Version()),
|
| 124 |
+
namedtype.NamedType('community', Community()),
|
| 125 |
+
namedtype.NamedType('data', Pdus())
|
| 126 |
+
)
|
lib/python3.10/site-packages/pyasn1_modules/rfc2560.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 6 |
+
#
|
| 7 |
+
# OCSP request/response syntax
|
| 8 |
+
#
|
| 9 |
+
# Derived from a minimal OCSP library (RFC2560) code written by
|
| 10 |
+
# Bud P. Bruegger <bud@ancitel.it>
|
| 11 |
+
# Copyright: Ancitel, S.p.a, Rome, Italy
|
| 12 |
+
# License: BSD
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
#
|
| 16 |
+
# current limitations:
|
| 17 |
+
# * request and response works only for a single certificate
|
| 18 |
+
# * only some values are parsed out of the response
|
| 19 |
+
# * the request does't set a nonce nor signature
|
| 20 |
+
# * there is no signature validation of the response
|
| 21 |
+
# * dates are left as strings in GeneralizedTime format -- datetime.datetime
|
| 22 |
+
# would be nicer
|
| 23 |
+
#
|
| 24 |
+
from pyasn1.type import namedtype
|
| 25 |
+
from pyasn1.type import namedval
|
| 26 |
+
from pyasn1.type import tag
|
| 27 |
+
from pyasn1.type import univ
|
| 28 |
+
from pyasn1.type import useful
|
| 29 |
+
|
| 30 |
+
from pyasn1_modules import rfc2459
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Start of OCSP module definitions
|
| 34 |
+
|
| 35 |
+
# This should be in directory Authentication Framework (X.509) module
|
| 36 |
+
|
| 37 |
+
class CRLReason(univ.Enumerated):
|
| 38 |
+
namedValues = namedval.NamedValues(
|
| 39 |
+
('unspecified', 0),
|
| 40 |
+
('keyCompromise', 1),
|
| 41 |
+
('cACompromise', 2),
|
| 42 |
+
('affiliationChanged', 3),
|
| 43 |
+
('superseded', 4),
|
| 44 |
+
('cessationOfOperation', 5),
|
| 45 |
+
('certificateHold', 6),
|
| 46 |
+
('removeFromCRL', 8),
|
| 47 |
+
('privilegeWithdrawn', 9),
|
| 48 |
+
('aACompromise', 10)
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# end of directory Authentication Framework (X.509) module
|
| 53 |
+
|
| 54 |
+
# This should be in PKIX Certificate Extensions module
|
| 55 |
+
|
| 56 |
+
class GeneralName(univ.OctetString):
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
# end of PKIX Certificate Extensions module
|
| 61 |
+
|
| 62 |
+
id_kp_OCSPSigning = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 3, 9))
|
| 63 |
+
id_pkix_ocsp = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1))
|
| 64 |
+
id_pkix_ocsp_basic = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 1))
|
| 65 |
+
id_pkix_ocsp_nonce = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 2))
|
| 66 |
+
id_pkix_ocsp_crl = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 3))
|
| 67 |
+
id_pkix_ocsp_response = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 4))
|
| 68 |
+
id_pkix_ocsp_nocheck = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 5))
|
| 69 |
+
id_pkix_ocsp_archive_cutoff = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 6))
|
| 70 |
+
id_pkix_ocsp_service_locator = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 48, 1, 7))
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
class AcceptableResponses(univ.SequenceOf):
|
| 74 |
+
componentType = univ.ObjectIdentifier()
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
class ArchiveCutoff(useful.GeneralizedTime):
|
| 78 |
+
pass
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
class UnknownInfo(univ.Null):
|
| 82 |
+
pass
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class RevokedInfo(univ.Sequence):
|
| 86 |
+
componentType = namedtype.NamedTypes(
|
| 87 |
+
namedtype.NamedType('revocationTime', useful.GeneralizedTime()),
|
| 88 |
+
namedtype.OptionalNamedType('revocationReason', CRLReason().subtype(
|
| 89 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class CertID(univ.Sequence):
|
| 94 |
+
componentType = namedtype.NamedTypes(
|
| 95 |
+
namedtype.NamedType('hashAlgorithm', rfc2459.AlgorithmIdentifier()),
|
| 96 |
+
namedtype.NamedType('issuerNameHash', univ.OctetString()),
|
| 97 |
+
namedtype.NamedType('issuerKeyHash', univ.OctetString()),
|
| 98 |
+
namedtype.NamedType('serialNumber', rfc2459.CertificateSerialNumber())
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class CertStatus(univ.Choice):
|
| 103 |
+
componentType = namedtype.NamedTypes(
|
| 104 |
+
namedtype.NamedType('good',
|
| 105 |
+
univ.Null().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 106 |
+
namedtype.NamedType('revoked',
|
| 107 |
+
RevokedInfo().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 108 |
+
namedtype.NamedType('unknown',
|
| 109 |
+
UnknownInfo().subtype(implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class SingleResponse(univ.Sequence):
|
| 114 |
+
componentType = namedtype.NamedTypes(
|
| 115 |
+
namedtype.NamedType('certID', CertID()),
|
| 116 |
+
namedtype.NamedType('certStatus', CertStatus()),
|
| 117 |
+
namedtype.NamedType('thisUpdate', useful.GeneralizedTime()),
|
| 118 |
+
namedtype.OptionalNamedType('nextUpdate', useful.GeneralizedTime().subtype(
|
| 119 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 120 |
+
namedtype.OptionalNamedType('singleExtensions', rfc2459.Extensions().subtype(
|
| 121 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
class KeyHash(univ.OctetString):
|
| 126 |
+
pass
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class ResponderID(univ.Choice):
|
| 130 |
+
componentType = namedtype.NamedTypes(
|
| 131 |
+
namedtype.NamedType('byName',
|
| 132 |
+
rfc2459.Name().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 133 |
+
namedtype.NamedType('byKey',
|
| 134 |
+
KeyHash().subtype(explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class Version(univ.Integer):
|
| 139 |
+
namedValues = namedval.NamedValues(('v1', 0))
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class ResponseData(univ.Sequence):
|
| 143 |
+
componentType = namedtype.NamedTypes(
|
| 144 |
+
namedtype.DefaultedNamedType('version', Version('v1').subtype(
|
| 145 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 146 |
+
namedtype.NamedType('responderID', ResponderID()),
|
| 147 |
+
namedtype.NamedType('producedAt', useful.GeneralizedTime()),
|
| 148 |
+
namedtype.NamedType('responses', univ.SequenceOf(componentType=SingleResponse())),
|
| 149 |
+
namedtype.OptionalNamedType('responseExtensions', rfc2459.Extensions().subtype(
|
| 150 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
class BasicOCSPResponse(univ.Sequence):
|
| 155 |
+
componentType = namedtype.NamedTypes(
|
| 156 |
+
namedtype.NamedType('tbsResponseData', ResponseData()),
|
| 157 |
+
namedtype.NamedType('signatureAlgorithm', rfc2459.AlgorithmIdentifier()),
|
| 158 |
+
namedtype.NamedType('signature', univ.BitString()),
|
| 159 |
+
namedtype.OptionalNamedType('certs', univ.SequenceOf(componentType=rfc2459.Certificate()).subtype(
|
| 160 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
class ResponseBytes(univ.Sequence):
|
| 165 |
+
componentType = namedtype.NamedTypes(
|
| 166 |
+
namedtype.NamedType('responseType', univ.ObjectIdentifier()),
|
| 167 |
+
namedtype.NamedType('response', univ.OctetString())
|
| 168 |
+
)
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
class OCSPResponseStatus(univ.Enumerated):
|
| 172 |
+
namedValues = namedval.NamedValues(
|
| 173 |
+
('successful', 0),
|
| 174 |
+
('malformedRequest', 1),
|
| 175 |
+
('internalError', 2),
|
| 176 |
+
('tryLater', 3),
|
| 177 |
+
('undefinedStatus', 4), # should never occur
|
| 178 |
+
('sigRequired', 5),
|
| 179 |
+
('unauthorized', 6)
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
class OCSPResponse(univ.Sequence):
|
| 184 |
+
componentType = namedtype.NamedTypes(
|
| 185 |
+
namedtype.NamedType('responseStatus', OCSPResponseStatus()),
|
| 186 |
+
namedtype.OptionalNamedType('responseBytes', ResponseBytes().subtype(
|
| 187 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
class Request(univ.Sequence):
|
| 192 |
+
componentType = namedtype.NamedTypes(
|
| 193 |
+
namedtype.NamedType('reqCert', CertID()),
|
| 194 |
+
namedtype.OptionalNamedType('singleRequestExtensions', rfc2459.Extensions().subtype(
|
| 195 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
class Signature(univ.Sequence):
|
| 200 |
+
componentType = namedtype.NamedTypes(
|
| 201 |
+
namedtype.NamedType('signatureAlgorithm', rfc2459.AlgorithmIdentifier()),
|
| 202 |
+
namedtype.NamedType('signature', univ.BitString()),
|
| 203 |
+
namedtype.OptionalNamedType('certs', univ.SequenceOf(componentType=rfc2459.Certificate()).subtype(
|
| 204 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class TBSRequest(univ.Sequence):
|
| 209 |
+
componentType = namedtype.NamedTypes(
|
| 210 |
+
namedtype.DefaultedNamedType('version', Version('v1').subtype(
|
| 211 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 212 |
+
namedtype.OptionalNamedType('requestorName', GeneralName().subtype(
|
| 213 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 214 |
+
namedtype.NamedType('requestList', univ.SequenceOf(componentType=Request())),
|
| 215 |
+
namedtype.OptionalNamedType('requestExtensions', rfc2459.Extensions().subtype(
|
| 216 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
class OCSPRequest(univ.Sequence):
|
| 221 |
+
componentType = namedtype.NamedTypes(
|
| 222 |
+
namedtype.NamedType('tbsRequest', TBSRequest()),
|
| 223 |
+
namedtype.OptionalNamedType('optionalSignature', Signature().subtype(
|
| 224 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0)))
|
| 225 |
+
)
|
lib/python3.10/site-packages/pyasn1_modules/rfc3412.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 6 |
+
#
|
| 7 |
+
# SNMPv3 message syntax
|
| 8 |
+
#
|
| 9 |
+
# ASN.1 source from:
|
| 10 |
+
# http://www.ietf.org/rfc/rfc3412.txt
|
| 11 |
+
#
|
| 12 |
+
from pyasn1.type import constraint
|
| 13 |
+
from pyasn1.type import namedtype
|
| 14 |
+
from pyasn1.type import univ
|
| 15 |
+
|
| 16 |
+
from pyasn1_modules import rfc1905
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class ScopedPDU(univ.Sequence):
|
| 20 |
+
componentType = namedtype.NamedTypes(
|
| 21 |
+
namedtype.NamedType('contextEngineId', univ.OctetString()),
|
| 22 |
+
namedtype.NamedType('contextName', univ.OctetString()),
|
| 23 |
+
namedtype.NamedType('data', rfc1905.PDUs())
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class ScopedPduData(univ.Choice):
|
| 28 |
+
componentType = namedtype.NamedTypes(
|
| 29 |
+
namedtype.NamedType('plaintext', ScopedPDU()),
|
| 30 |
+
namedtype.NamedType('encryptedPDU', univ.OctetString()),
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class HeaderData(univ.Sequence):
|
| 35 |
+
componentType = namedtype.NamedTypes(
|
| 36 |
+
namedtype.NamedType('msgID',
|
| 37 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
|
| 38 |
+
namedtype.NamedType('msgMaxSize',
|
| 39 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(484, 2147483647))),
|
| 40 |
+
namedtype.NamedType('msgFlags', univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(1, 1))),
|
| 41 |
+
namedtype.NamedType('msgSecurityModel',
|
| 42 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(1, 2147483647)))
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class SNMPv3Message(univ.Sequence):
|
| 47 |
+
componentType = namedtype.NamedTypes(
|
| 48 |
+
namedtype.NamedType('msgVersion',
|
| 49 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
|
| 50 |
+
namedtype.NamedType('msgGlobalData', HeaderData()),
|
| 51 |
+
namedtype.NamedType('msgSecurityParameters', univ.OctetString()),
|
| 52 |
+
namedtype.NamedType('msgData', ScopedPduData())
|
| 53 |
+
)
|
lib/python3.10/site-packages/pyasn1_modules/rfc3414.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
|
| 5 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 6 |
+
#
|
| 7 |
+
# SNMPv3 message syntax
|
| 8 |
+
#
|
| 9 |
+
# ASN.1 source from:
|
| 10 |
+
# http://www.ietf.org/rfc/rfc3414.txt
|
| 11 |
+
#
|
| 12 |
+
from pyasn1.type import constraint
|
| 13 |
+
from pyasn1.type import namedtype
|
| 14 |
+
from pyasn1.type import univ
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class UsmSecurityParameters(univ.Sequence):
|
| 18 |
+
componentType = namedtype.NamedTypes(
|
| 19 |
+
namedtype.NamedType('msgAuthoritativeEngineID', univ.OctetString()),
|
| 20 |
+
namedtype.NamedType('msgAuthoritativeEngineBoots',
|
| 21 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
|
| 22 |
+
namedtype.NamedType('msgAuthoritativeEngineTime',
|
| 23 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(0, 2147483647))),
|
| 24 |
+
namedtype.NamedType('msgUserName',
|
| 25 |
+
univ.OctetString().subtype(subtypeSpec=constraint.ValueSizeConstraint(0, 32))),
|
| 26 |
+
namedtype.NamedType('msgAuthenticationParameters', univ.OctetString()),
|
| 27 |
+
namedtype.NamedType('msgPrivacyParameters', univ.OctetString())
|
| 28 |
+
)
|
lib/python3.10/site-packages/pyasn1_modules/rfc3560.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# RSAES-OAEP Key Transport Algorithm in CMS
|
| 10 |
+
#
|
| 11 |
+
# Notice that all of the things needed in RFC 3560 are also defined
|
| 12 |
+
# in RFC 4055. So, they are all pulled from the RFC 4055 module into
|
| 13 |
+
# this one so that people looking a RFC 3560 can easily find them.
|
| 14 |
+
#
|
| 15 |
+
# ASN.1 source from:
|
| 16 |
+
# https://www.rfc-editor.org/rfc/rfc3560.txt
|
| 17 |
+
#
|
| 18 |
+
|
| 19 |
+
from pyasn1_modules import rfc4055
|
| 20 |
+
|
| 21 |
+
id_sha1 = rfc4055.id_sha1
|
| 22 |
+
|
| 23 |
+
id_sha256 = rfc4055.id_sha256
|
| 24 |
+
|
| 25 |
+
id_sha384 = rfc4055.id_sha384
|
| 26 |
+
|
| 27 |
+
id_sha512 = rfc4055.id_sha512
|
| 28 |
+
|
| 29 |
+
id_mgf1 = rfc4055.id_mgf1
|
| 30 |
+
|
| 31 |
+
rsaEncryption = rfc4055.rsaEncryption
|
| 32 |
+
|
| 33 |
+
id_RSAES_OAEP = rfc4055.id_RSAES_OAEP
|
| 34 |
+
|
| 35 |
+
id_pSpecified = rfc4055.id_pSpecified
|
| 36 |
+
|
| 37 |
+
sha1Identifier = rfc4055.sha1Identifier
|
| 38 |
+
|
| 39 |
+
sha256Identifier = rfc4055.sha256Identifier
|
| 40 |
+
|
| 41 |
+
sha384Identifier = rfc4055.sha384Identifier
|
| 42 |
+
|
| 43 |
+
sha512Identifier = rfc4055.sha512Identifier
|
| 44 |
+
|
| 45 |
+
mgf1SHA1Identifier = rfc4055.mgf1SHA1Identifier
|
| 46 |
+
|
| 47 |
+
mgf1SHA256Identifier = rfc4055.mgf1SHA256Identifier
|
| 48 |
+
|
| 49 |
+
mgf1SHA384Identifier = rfc4055.mgf1SHA384Identifier
|
| 50 |
+
|
| 51 |
+
mgf1SHA512Identifier = rfc4055.mgf1SHA512Identifier
|
| 52 |
+
|
| 53 |
+
pSpecifiedEmptyIdentifier = rfc4055.pSpecifiedEmptyIdentifier
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
class RSAES_OAEP_params(rfc4055.RSAES_OAEP_params):
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
rSAES_OAEP_Default_Params = RSAES_OAEP_params()
|
| 61 |
+
|
| 62 |
+
rSAES_OAEP_Default_Identifier = rfc4055.rSAES_OAEP_Default_Identifier
|
| 63 |
+
|
| 64 |
+
rSAES_OAEP_SHA256_Params = rfc4055.rSAES_OAEP_SHA256_Params
|
| 65 |
+
|
| 66 |
+
rSAES_OAEP_SHA256_Identifier = rfc4055.rSAES_OAEP_SHA256_Identifier
|
| 67 |
+
|
| 68 |
+
rSAES_OAEP_SHA384_Params = rfc4055.rSAES_OAEP_SHA384_Params
|
| 69 |
+
|
| 70 |
+
rSAES_OAEP_SHA384_Identifier = rfc4055.rSAES_OAEP_SHA384_Identifier
|
| 71 |
+
|
| 72 |
+
rSAES_OAEP_SHA512_Params = rfc4055.rSAES_OAEP_SHA512_Params
|
| 73 |
+
|
| 74 |
+
rSAES_OAEP_SHA512_Identifier = rfc4055.rSAES_OAEP_SHA512_Identifier
|
lib/python3.10/site-packages/pyasn1_modules/rfc4073.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley with some assistance from asn1ate v.0.6.0.
|
| 5 |
+
# Modified by Russ Housley to add a map for use with opentypes.
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 8 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 9 |
+
#
|
| 10 |
+
# Protecting Multiple Contents with the CMS
|
| 11 |
+
#
|
| 12 |
+
# ASN.1 source from:
|
| 13 |
+
# https://www.rfc-editor.org/rfc/rfc4073.txt
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
from pyasn1.type import constraint
|
| 17 |
+
from pyasn1.type import namedtype
|
| 18 |
+
from pyasn1.type import univ
|
| 19 |
+
|
| 20 |
+
from pyasn1_modules import rfc5652
|
| 21 |
+
|
| 22 |
+
MAX = float('inf')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
# Content Collection Content Type and Object Identifier
|
| 26 |
+
|
| 27 |
+
id_ct_contentCollection = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.19')
|
| 28 |
+
|
| 29 |
+
class ContentCollection(univ.SequenceOf):
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
ContentCollection.componentType = rfc5652.ContentInfo()
|
| 33 |
+
ContentCollection.sizeSpec = constraint.ValueSizeConstraint(1, MAX)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Content With Attributes Content Type and Object Identifier
|
| 37 |
+
|
| 38 |
+
id_ct_contentWithAttrs = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.20')
|
| 39 |
+
|
| 40 |
+
class ContentWithAttributes(univ.Sequence):
|
| 41 |
+
pass
|
| 42 |
+
|
| 43 |
+
ContentWithAttributes.componentType = namedtype.NamedTypes(
|
| 44 |
+
namedtype.NamedType('content', rfc5652.ContentInfo()),
|
| 45 |
+
namedtype.NamedType('attrs', univ.SequenceOf(
|
| 46 |
+
componentType=rfc5652.Attribute()).subtype(
|
| 47 |
+
sizeSpec=constraint.ValueSizeConstraint(1, MAX)))
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# Map of Content Type OIDs to Content Types is added to the
|
| 52 |
+
# ones that are in rfc5652.py
|
| 53 |
+
|
| 54 |
+
_cmsContentTypesMapUpdate = {
|
| 55 |
+
id_ct_contentCollection: ContentCollection(),
|
| 56 |
+
id_ct_contentWithAttrs: ContentWithAttributes(),
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
rfc5652.cmsContentTypesMap.update(_cmsContentTypesMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc4490.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley with assistance from asn1ate v.0.6.0.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Using the GOST 28147-89, GOST R 34.11-94, GOST R 34.10-94, and
|
| 10 |
+
# GOST R 34.10-2001 Algorithms with the CMS
|
| 11 |
+
#
|
| 12 |
+
# ASN.1 source from:
|
| 13 |
+
# https://www.rfc-editor.org/rfc/rfc4490.txt
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
from pyasn1.type import univ, char, namedtype, namedval, tag, constraint, useful
|
| 18 |
+
|
| 19 |
+
from pyasn1_modules import rfc4357
|
| 20 |
+
from pyasn1_modules import rfc5280
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
# Imports from RFC 4357
|
| 24 |
+
|
| 25 |
+
id_CryptoPro_algorithms = rfc4357.id_CryptoPro_algorithms
|
| 26 |
+
|
| 27 |
+
id_GostR3410_94 = rfc4357.id_GostR3410_94
|
| 28 |
+
|
| 29 |
+
id_GostR3410_2001 = rfc4357.id_GostR3410_2001
|
| 30 |
+
|
| 31 |
+
Gost28147_89_ParamSet = rfc4357.Gost28147_89_ParamSet
|
| 32 |
+
|
| 33 |
+
Gost28147_89_EncryptedKey = rfc4357.Gost28147_89_EncryptedKey
|
| 34 |
+
|
| 35 |
+
GostR3410_94_PublicKeyParameters = rfc4357.GostR3410_94_PublicKeyParameters
|
| 36 |
+
|
| 37 |
+
GostR3410_2001_PublicKeyParameters = rfc4357.GostR3410_2001_PublicKeyParameters
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# Imports from RFC 5280
|
| 41 |
+
|
| 42 |
+
SubjectPublicKeyInfo = rfc5280.SubjectPublicKeyInfo
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# CMS/PKCS#7 key agreement algorithms & parameters
|
| 46 |
+
|
| 47 |
+
class Gost28147_89_KeyWrapParameters(univ.Sequence):
|
| 48 |
+
componentType = namedtype.NamedTypes(
|
| 49 |
+
namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet()),
|
| 50 |
+
namedtype.OptionalNamedType('ukm', univ.OctetString().subtype(
|
| 51 |
+
subtypeSpec=constraint.ValueSizeConstraint(8, 8)))
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
id_Gost28147_89_CryptoPro_KeyWrap = id_CryptoPro_algorithms + (13, 1, )
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
id_Gost28147_89_None_KeyWrap = id_CryptoPro_algorithms + (13, 0, )
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
id_GostR3410_2001_CryptoPro_ESDH = id_CryptoPro_algorithms + (96, )
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
id_GostR3410_94_CryptoPro_ESDH = id_CryptoPro_algorithms + (97, )
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# CMS/PKCS#7 key transport algorithms & parameters
|
| 68 |
+
|
| 69 |
+
id_GostR3410_2001_KeyTransportSMIMECapability = id_GostR3410_2001
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
id_GostR3410_94_KeyTransportSMIMECapability = id_GostR3410_94
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class GostR3410_TransportParameters(univ.Sequence):
|
| 76 |
+
componentType = namedtype.NamedTypes(
|
| 77 |
+
namedtype.NamedType('encryptionParamSet', Gost28147_89_ParamSet()),
|
| 78 |
+
namedtype.OptionalNamedType('ephemeralPublicKey',
|
| 79 |
+
SubjectPublicKeyInfo().subtype(implicitTag=tag.Tag(
|
| 80 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 81 |
+
namedtype.NamedType('ukm', univ.OctetString().subtype(
|
| 82 |
+
subtypeSpec=constraint.ValueSizeConstraint(8, 8)))
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
class GostR3410_KeyTransport(univ.Sequence):
|
| 86 |
+
componentType = namedtype.NamedTypes(
|
| 87 |
+
namedtype.NamedType('sessionEncryptedKey', Gost28147_89_EncryptedKey()),
|
| 88 |
+
namedtype.OptionalNamedType('transportParameters',
|
| 89 |
+
GostR3410_TransportParameters().subtype(implicitTag=tag.Tag(
|
| 90 |
+
tag.tagClassContext, tag.tagFormatConstructed, 0)))
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
# GOST R 34.10-94 signature algorithm & parameters
|
| 95 |
+
|
| 96 |
+
class GostR3410_94_Signature(univ.OctetString):
|
| 97 |
+
subtypeSpec = constraint.ValueSizeConstraint(64, 64)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
# GOST R 34.10-2001 signature algorithms and parameters
|
| 101 |
+
|
| 102 |
+
class GostR3410_2001_Signature(univ.OctetString):
|
| 103 |
+
subtypeSpec = constraint.ValueSizeConstraint(64, 64)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
# Update the Algorithm Identifier map in rfc5280.py
|
| 107 |
+
|
| 108 |
+
_algorithmIdentifierMapUpdate = {
|
| 109 |
+
id_Gost28147_89_CryptoPro_KeyWrap: Gost28147_89_KeyWrapParameters(),
|
| 110 |
+
id_Gost28147_89_None_KeyWrap: Gost28147_89_KeyWrapParameters(),
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc4491.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Using the GOST R 34.10-94, GOST R 34.10-2001, and GOST R 34.11-94
|
| 10 |
+
# Algorithms with Certificates and CRLs
|
| 11 |
+
#
|
| 12 |
+
# ASN.1 source from:
|
| 13 |
+
# https://www.rfc-editor.org/rfc/rfc4491.txt
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
from pyasn1_modules import rfc4357
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# Signature Algorithm GOST R 34.10-94
|
| 20 |
+
|
| 21 |
+
id_GostR3411_94_with_GostR3410_94 = rfc4357.id_GostR3411_94_with_GostR3410_94
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# Signature Algorithm GOST R 34.10-2001
|
| 25 |
+
|
| 26 |
+
id_GostR3411_94_with_GostR3410_2001 = rfc4357.id_GostR3411_94_with_GostR3410_2001
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# GOST R 34.10-94 Keys
|
| 30 |
+
|
| 31 |
+
id_GostR3410_94 = rfc4357.id_GostR3410_94
|
| 32 |
+
|
| 33 |
+
GostR3410_2001_PublicKey = rfc4357.GostR3410_2001_PublicKey
|
| 34 |
+
|
| 35 |
+
GostR3410_2001_PublicKeyParameters = rfc4357.GostR3410_2001_PublicKeyParameters
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# GOST R 34.10-2001 Keys
|
| 39 |
+
|
| 40 |
+
id_GostR3410_2001 = rfc4357.id_GostR3410_2001
|
| 41 |
+
|
| 42 |
+
GostR3410_94_PublicKey = rfc4357.GostR3410_94_PublicKey
|
| 43 |
+
|
| 44 |
+
GostR3410_94_PublicKeyParameters = rfc4357.GostR3410_94_PublicKeyParameters
|
lib/python3.10/site-packages/pyasn1_modules/rfc5083.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is being contributed to of pyasn1-modules software.
|
| 2 |
+
#
|
| 3 |
+
# Created by Russ Housley without assistance from the asn1ate tool.
|
| 4 |
+
# Modified by Russ Housley to add a map for use with opentypes and
|
| 5 |
+
# simplify the code for the object identifier assignment.
|
| 6 |
+
#
|
| 7 |
+
# Copyright (c) 2018, 2019 Vigil Security, LLC
|
| 8 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 9 |
+
#
|
| 10 |
+
# Authenticated-Enveloped-Data for the Cryptographic Message Syntax (CMS)
|
| 11 |
+
#
|
| 12 |
+
# ASN.1 source from:
|
| 13 |
+
# https://www.rfc-editor.org/rfc/rfc5083.txt
|
| 14 |
+
|
| 15 |
+
from pyasn1.type import namedtype
|
| 16 |
+
from pyasn1.type import tag
|
| 17 |
+
from pyasn1.type import univ
|
| 18 |
+
|
| 19 |
+
from pyasn1_modules import rfc5652
|
| 20 |
+
|
| 21 |
+
MAX = float('inf')
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# CMS Authenticated-Enveloped-Data Content Type
|
| 25 |
+
|
| 26 |
+
id_ct_authEnvelopedData = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1.23')
|
| 27 |
+
|
| 28 |
+
class AuthEnvelopedData(univ.Sequence):
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
AuthEnvelopedData.componentType = namedtype.NamedTypes(
|
| 32 |
+
namedtype.NamedType('version', rfc5652.CMSVersion()),
|
| 33 |
+
namedtype.OptionalNamedType('originatorInfo', rfc5652.OriginatorInfo().subtype(
|
| 34 |
+
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatConstructed, 0))),
|
| 35 |
+
namedtype.NamedType('recipientInfos', rfc5652.RecipientInfos()),
|
| 36 |
+
namedtype.NamedType('authEncryptedContentInfo', rfc5652.EncryptedContentInfo()),
|
| 37 |
+
namedtype.OptionalNamedType('authAttrs', rfc5652.AuthAttributes().subtype(
|
| 38 |
+
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 39 |
+
namedtype.NamedType('mac', rfc5652.MessageAuthenticationCode()),
|
| 40 |
+
namedtype.OptionalNamedType('unauthAttrs', rfc5652.UnauthAttributes().subtype(
|
| 41 |
+
implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2)))
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# Map of Content Type OIDs to Content Types is added to the
|
| 46 |
+
# ones that are in rfc5652.py
|
| 47 |
+
|
| 48 |
+
_cmsContentTypesMapUpdate = {
|
| 49 |
+
id_ct_authEnvelopedData: AuthEnvelopedData(),
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
rfc5652.cmsContentTypesMap.update(_cmsContentTypesMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc5697.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is being contributed to pyasn1-modules software.
|
| 2 |
+
#
|
| 3 |
+
# Created by Russ Housley.
|
| 4 |
+
#
|
| 5 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 6 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 7 |
+
#
|
| 8 |
+
# Other Certificates Extension
|
| 9 |
+
#
|
| 10 |
+
# ASN.1 source from:
|
| 11 |
+
# https://www.rfc-editor.org/rfc/rfc5697.txt
|
| 12 |
+
|
| 13 |
+
from pyasn1.type import namedtype
|
| 14 |
+
from pyasn1.type import univ
|
| 15 |
+
|
| 16 |
+
from pyasn1_modules import rfc5280
|
| 17 |
+
from pyasn1_modules import rfc4055
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Imports from RFC 5280
|
| 21 |
+
|
| 22 |
+
AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
|
| 23 |
+
|
| 24 |
+
CertificateSerialNumber = rfc5280.CertificateSerialNumber
|
| 25 |
+
|
| 26 |
+
GeneralNames = rfc5280.GeneralNames
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Imports from RFC 4055
|
| 30 |
+
|
| 31 |
+
id_sha1 = rfc4055.id_sha1
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# Imports from RFC 5055
|
| 35 |
+
# These are defined here because a module for RFC 5055 does not exist yet
|
| 36 |
+
|
| 37 |
+
class SCVPIssuerSerial(univ.Sequence):
|
| 38 |
+
componentType = namedtype.NamedTypes(
|
| 39 |
+
namedtype.NamedType('issuer', GeneralNames()),
|
| 40 |
+
namedtype.NamedType('serialNumber', CertificateSerialNumber())
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
sha1_alg_id = AlgorithmIdentifier()
|
| 45 |
+
sha1_alg_id['algorithm'] = id_sha1
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
class SCVPCertID(univ.Sequence):
|
| 49 |
+
componentType = namedtype.NamedTypes(
|
| 50 |
+
namedtype.NamedType('certHash', univ.OctetString()),
|
| 51 |
+
namedtype.NamedType('issuerSerial', SCVPIssuerSerial()),
|
| 52 |
+
namedtype.DefaultedNamedType('hashAlgorithm', sha1_alg_id)
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Other Certificates Extension
|
| 57 |
+
|
| 58 |
+
id_pe_otherCerts = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, 1, 19,))
|
| 59 |
+
|
| 60 |
+
class OtherCertificates(univ.SequenceOf):
|
| 61 |
+
componentType = SCVPCertID()
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
# Update of certificate extension map in rfc5280.py
|
| 65 |
+
|
| 66 |
+
_certificateExtensionsMapUpdate = {
|
| 67 |
+
id_pe_otherCerts: OtherCertificates(),
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc5752.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley with assistance from asn1ate v.0.6.0.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Multiple Signatures in Cryptographic Message Syntax (CMS)
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc5752.txt
|
| 13 |
+
# https://www.rfc-editor.org/errata/eid4444
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
from pyasn1.type import namedtype
|
| 17 |
+
from pyasn1.type import univ
|
| 18 |
+
|
| 19 |
+
from pyasn1_modules import rfc5035
|
| 20 |
+
from pyasn1_modules import rfc5652
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class SignAttrsHash(univ.Sequence):
|
| 24 |
+
componentType = namedtype.NamedTypes(
|
| 25 |
+
namedtype.NamedType('algID', rfc5652.DigestAlgorithmIdentifier()),
|
| 26 |
+
namedtype.NamedType('hash', univ.OctetString())
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class MultipleSignatures(univ.Sequence):
|
| 31 |
+
componentType = namedtype.NamedTypes(
|
| 32 |
+
namedtype.NamedType('bodyHashAlg', rfc5652.DigestAlgorithmIdentifier()),
|
| 33 |
+
namedtype.NamedType('signAlg', rfc5652.SignatureAlgorithmIdentifier()),
|
| 34 |
+
namedtype.NamedType('signAttrsHash', SignAttrsHash()),
|
| 35 |
+
namedtype.OptionalNamedType('cert', rfc5035.ESSCertIDv2())
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
id_aa_multipleSignatures = univ.ObjectIdentifier('1.2.840.113549.1.9.16.2.51')
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Map of Attribute Type OIDs to Attributes added to the
|
| 43 |
+
# ones that are in rfc5652.py
|
| 44 |
+
|
| 45 |
+
_cmsAttributesMapUpdate = {
|
| 46 |
+
id_aa_multipleSignatures: MultipleSignatures(),
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
rfc5652.cmsAttributesMap.update(_cmsAttributesMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc5755.py
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley with assistance from asn1ate v.0.6.0.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# An Internet Attribute Certificate Profile for Authorization
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc5755.txt
|
| 13 |
+
# https://www.rfc-editor.org/rfc/rfc5912.txt (see Section 13)
|
| 14 |
+
#
|
| 15 |
+
|
| 16 |
+
from pyasn1.type import char
|
| 17 |
+
from pyasn1.type import constraint
|
| 18 |
+
from pyasn1.type import namedtype
|
| 19 |
+
from pyasn1.type import namedval
|
| 20 |
+
from pyasn1.type import opentype
|
| 21 |
+
from pyasn1.type import tag
|
| 22 |
+
from pyasn1.type import univ
|
| 23 |
+
from pyasn1.type import useful
|
| 24 |
+
|
| 25 |
+
from pyasn1_modules import rfc5280
|
| 26 |
+
from pyasn1_modules import rfc5652
|
| 27 |
+
|
| 28 |
+
MAX = float('inf')
|
| 29 |
+
|
| 30 |
+
# Map for Security Category type to value
|
| 31 |
+
|
| 32 |
+
securityCategoryMap = { }
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Imports from RFC 5652
|
| 36 |
+
|
| 37 |
+
ContentInfo = rfc5652.ContentInfo
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# Imports from RFC 5280
|
| 41 |
+
|
| 42 |
+
AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
|
| 43 |
+
|
| 44 |
+
Attribute = rfc5280.Attribute
|
| 45 |
+
|
| 46 |
+
AuthorityInfoAccessSyntax = rfc5280.AuthorityInfoAccessSyntax
|
| 47 |
+
|
| 48 |
+
AuthorityKeyIdentifier = rfc5280.AuthorityKeyIdentifier
|
| 49 |
+
|
| 50 |
+
CertificateSerialNumber = rfc5280.CertificateSerialNumber
|
| 51 |
+
|
| 52 |
+
CRLDistributionPoints = rfc5280.CRLDistributionPoints
|
| 53 |
+
|
| 54 |
+
Extensions = rfc5280.Extensions
|
| 55 |
+
|
| 56 |
+
Extension = rfc5280.Extension
|
| 57 |
+
|
| 58 |
+
GeneralNames = rfc5280.GeneralNames
|
| 59 |
+
|
| 60 |
+
GeneralName = rfc5280.GeneralName
|
| 61 |
+
|
| 62 |
+
UniqueIdentifier = rfc5280.UniqueIdentifier
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
# Object Identifier arcs
|
| 66 |
+
|
| 67 |
+
id_pkix = univ.ObjectIdentifier((1, 3, 6, 1, 5, 5, 7, ))
|
| 68 |
+
|
| 69 |
+
id_pe = id_pkix + (1, )
|
| 70 |
+
|
| 71 |
+
id_kp = id_pkix + (3, )
|
| 72 |
+
|
| 73 |
+
id_aca = id_pkix + (10, )
|
| 74 |
+
|
| 75 |
+
id_ad = id_pkix + (48, )
|
| 76 |
+
|
| 77 |
+
id_at = univ.ObjectIdentifier((2, 5, 4, ))
|
| 78 |
+
|
| 79 |
+
id_ce = univ.ObjectIdentifier((2, 5, 29, ))
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# Attribute Certificate
|
| 83 |
+
|
| 84 |
+
class AttCertVersion(univ.Integer):
|
| 85 |
+
namedValues = namedval.NamedValues(
|
| 86 |
+
('v2', 1)
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class IssuerSerial(univ.Sequence):
|
| 91 |
+
componentType = namedtype.NamedTypes(
|
| 92 |
+
namedtype.NamedType('issuer', GeneralNames()),
|
| 93 |
+
namedtype.NamedType('serial', CertificateSerialNumber()),
|
| 94 |
+
namedtype.OptionalNamedType('issuerUID', UniqueIdentifier())
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
class ObjectDigestInfo(univ.Sequence):
|
| 99 |
+
componentType = namedtype.NamedTypes(
|
| 100 |
+
namedtype.NamedType('digestedObjectType',
|
| 101 |
+
univ.Enumerated(namedValues=namedval.NamedValues(
|
| 102 |
+
('publicKey', 0),
|
| 103 |
+
('publicKeyCert', 1),
|
| 104 |
+
('otherObjectTypes', 2)))),
|
| 105 |
+
namedtype.OptionalNamedType('otherObjectTypeID',
|
| 106 |
+
univ.ObjectIdentifier()),
|
| 107 |
+
namedtype.NamedType('digestAlgorithm',
|
| 108 |
+
AlgorithmIdentifier()),
|
| 109 |
+
namedtype.NamedType('objectDigest',
|
| 110 |
+
univ.BitString())
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
class Holder(univ.Sequence):
|
| 115 |
+
componentType = namedtype.NamedTypes(
|
| 116 |
+
namedtype.OptionalNamedType('baseCertificateID',
|
| 117 |
+
IssuerSerial().subtype(implicitTag=tag.Tag(
|
| 118 |
+
tag.tagClassContext, tag.tagFormatConstructed, 0))),
|
| 119 |
+
namedtype.OptionalNamedType('entityName',
|
| 120 |
+
GeneralNames().subtype(implicitTag=tag.Tag(
|
| 121 |
+
tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 122 |
+
namedtype.OptionalNamedType('objectDigestInfo',
|
| 123 |
+
ObjectDigestInfo().subtype(implicitTag=tag.Tag(
|
| 124 |
+
tag.tagClassContext, tag.tagFormatConstructed, 2)))
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
class V2Form(univ.Sequence):
|
| 129 |
+
componentType = namedtype.NamedTypes(
|
| 130 |
+
namedtype.OptionalNamedType('issuerName',
|
| 131 |
+
GeneralNames()),
|
| 132 |
+
namedtype.OptionalNamedType('baseCertificateID',
|
| 133 |
+
IssuerSerial().subtype(implicitTag=tag.Tag(
|
| 134 |
+
tag.tagClassContext, tag.tagFormatConstructed, 0))),
|
| 135 |
+
namedtype.OptionalNamedType('objectDigestInfo',
|
| 136 |
+
ObjectDigestInfo().subtype(implicitTag=tag.Tag(
|
| 137 |
+
tag.tagClassContext, tag.tagFormatConstructed, 1)))
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
class AttCertIssuer(univ.Choice):
|
| 142 |
+
componentType = namedtype.NamedTypes(
|
| 143 |
+
namedtype.NamedType('v1Form', GeneralNames()),
|
| 144 |
+
namedtype.NamedType('v2Form', V2Form().subtype(implicitTag=tag.Tag(
|
| 145 |
+
tag.tagClassContext, tag.tagFormatConstructed, 0)))
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class AttCertValidityPeriod(univ.Sequence):
|
| 150 |
+
componentType = namedtype.NamedTypes(
|
| 151 |
+
namedtype.NamedType('notBeforeTime', useful.GeneralizedTime()),
|
| 152 |
+
namedtype.NamedType('notAfterTime', useful.GeneralizedTime())
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
class AttributeCertificateInfo(univ.Sequence):
|
| 157 |
+
componentType = namedtype.NamedTypes(
|
| 158 |
+
namedtype.NamedType('version',
|
| 159 |
+
AttCertVersion()),
|
| 160 |
+
namedtype.NamedType('holder',
|
| 161 |
+
Holder()),
|
| 162 |
+
namedtype.NamedType('issuer',
|
| 163 |
+
AttCertIssuer()),
|
| 164 |
+
namedtype.NamedType('signature',
|
| 165 |
+
AlgorithmIdentifier()),
|
| 166 |
+
namedtype.NamedType('serialNumber',
|
| 167 |
+
CertificateSerialNumber()),
|
| 168 |
+
namedtype.NamedType('attrCertValidityPeriod',
|
| 169 |
+
AttCertValidityPeriod()),
|
| 170 |
+
namedtype.NamedType('attributes',
|
| 171 |
+
univ.SequenceOf(componentType=Attribute())),
|
| 172 |
+
namedtype.OptionalNamedType('issuerUniqueID',
|
| 173 |
+
UniqueIdentifier()),
|
| 174 |
+
namedtype.OptionalNamedType('extensions',
|
| 175 |
+
Extensions())
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
class AttributeCertificate(univ.Sequence):
|
| 180 |
+
componentType = namedtype.NamedTypes(
|
| 181 |
+
namedtype.NamedType('acinfo', AttributeCertificateInfo()),
|
| 182 |
+
namedtype.NamedType('signatureAlgorithm', AlgorithmIdentifier()),
|
| 183 |
+
namedtype.NamedType('signatureValue', univ.BitString())
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
# Attribute Certificate Extensions
|
| 188 |
+
|
| 189 |
+
id_pe_ac_auditIdentity = id_pe + (4, )
|
| 190 |
+
|
| 191 |
+
id_ce_noRevAvail = id_ce + (56, )
|
| 192 |
+
|
| 193 |
+
id_ce_targetInformation = id_ce + (55, )
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class TargetCert(univ.Sequence):
|
| 197 |
+
componentType = namedtype.NamedTypes(
|
| 198 |
+
namedtype.NamedType('targetCertificate', IssuerSerial()),
|
| 199 |
+
namedtype.OptionalNamedType('targetName', GeneralName()),
|
| 200 |
+
namedtype.OptionalNamedType('certDigestInfo', ObjectDigestInfo())
|
| 201 |
+
)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
class Target(univ.Choice):
|
| 205 |
+
componentType = namedtype.NamedTypes(
|
| 206 |
+
namedtype.NamedType('targetName',
|
| 207 |
+
GeneralName().subtype(implicitTag=tag.Tag(
|
| 208 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 209 |
+
namedtype.NamedType('targetGroup',
|
| 210 |
+
GeneralName().subtype(implicitTag=tag.Tag(
|
| 211 |
+
tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 212 |
+
namedtype.NamedType('targetCert',
|
| 213 |
+
TargetCert().subtype(implicitTag=tag.Tag(
|
| 214 |
+
tag.tagClassContext, tag.tagFormatConstructed, 2)))
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
class Targets(univ.SequenceOf):
|
| 219 |
+
componentType = Target()
|
| 220 |
+
|
| 221 |
+
|
| 222 |
+
id_pe_ac_proxying = id_pe + (10, )
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
class ProxyInfo(univ.SequenceOf):
|
| 226 |
+
componentType = Targets()
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
id_pe_aaControls = id_pe + (6, )
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
class AttrSpec(univ.SequenceOf):
|
| 233 |
+
componentType = univ.ObjectIdentifier()
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
class AAControls(univ.Sequence):
|
| 237 |
+
componentType = namedtype.NamedTypes(
|
| 238 |
+
namedtype.OptionalNamedType('pathLenConstraint',
|
| 239 |
+
univ.Integer().subtype(
|
| 240 |
+
subtypeSpec=constraint.ValueRangeConstraint(0, MAX))),
|
| 241 |
+
namedtype.OptionalNamedType('permittedAttrs',
|
| 242 |
+
AttrSpec().subtype(implicitTag=tag.Tag(
|
| 243 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 244 |
+
namedtype.OptionalNamedType('excludedAttrs',
|
| 245 |
+
AttrSpec().subtype(implicitTag=tag.Tag(
|
| 246 |
+
tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 247 |
+
namedtype.DefaultedNamedType('permitUnSpecified',
|
| 248 |
+
univ.Boolean().subtype(value=1))
|
| 249 |
+
)
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
# Attribute Certificate Attributes
|
| 253 |
+
|
| 254 |
+
id_aca_authenticationInfo = id_aca + (1, )
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
id_aca_accessIdentity = id_aca + (2, )
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
class SvceAuthInfo(univ.Sequence):
|
| 261 |
+
componentType = namedtype.NamedTypes(
|
| 262 |
+
namedtype.NamedType('service', GeneralName()),
|
| 263 |
+
namedtype.NamedType('ident', GeneralName()),
|
| 264 |
+
namedtype.OptionalNamedType('authInfo', univ.OctetString())
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
id_aca_chargingIdentity = id_aca + (3, )
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
id_aca_group = id_aca + (4, )
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
class IetfAttrSyntax(univ.Sequence):
|
| 275 |
+
componentType = namedtype.NamedTypes(
|
| 276 |
+
namedtype.OptionalNamedType('policyAuthority',
|
| 277 |
+
GeneralNames().subtype(implicitTag=tag.Tag(
|
| 278 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 279 |
+
namedtype.NamedType('values', univ.SequenceOf(
|
| 280 |
+
componentType=univ.Choice(componentType=namedtype.NamedTypes(
|
| 281 |
+
namedtype.NamedType('octets', univ.OctetString()),
|
| 282 |
+
namedtype.NamedType('oid', univ.ObjectIdentifier()),
|
| 283 |
+
namedtype.NamedType('string', char.UTF8String())
|
| 284 |
+
))
|
| 285 |
+
))
|
| 286 |
+
)
|
| 287 |
+
|
| 288 |
+
|
| 289 |
+
id_at_role = id_at + (72,)
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
class RoleSyntax(univ.Sequence):
|
| 293 |
+
componentType = namedtype.NamedTypes(
|
| 294 |
+
namedtype.OptionalNamedType('roleAuthority',
|
| 295 |
+
GeneralNames().subtype(implicitTag=tag.Tag(
|
| 296 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 297 |
+
namedtype.NamedType('roleName',
|
| 298 |
+
GeneralName().subtype(implicitTag=tag.Tag(
|
| 299 |
+
tag.tagClassContext, tag.tagFormatSimple, 1)))
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
class ClassList(univ.BitString):
|
| 304 |
+
namedValues = namedval.NamedValues(
|
| 305 |
+
('unmarked', 0),
|
| 306 |
+
('unclassified', 1),
|
| 307 |
+
('restricted', 2),
|
| 308 |
+
('confidential', 3),
|
| 309 |
+
('secret', 4),
|
| 310 |
+
('topSecret', 5)
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
class SecurityCategory(univ.Sequence):
|
| 315 |
+
componentType = namedtype.NamedTypes(
|
| 316 |
+
namedtype.NamedType('type',
|
| 317 |
+
univ.ObjectIdentifier().subtype(implicitTag=tag.Tag(
|
| 318 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 319 |
+
namedtype.NamedType('value',
|
| 320 |
+
univ.Any().subtype(implicitTag=tag.Tag(
|
| 321 |
+
tag.tagClassContext, tag.tagFormatSimple, 1)),
|
| 322 |
+
openType=opentype.OpenType('type', securityCategoryMap))
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
id_at_clearance = univ.ObjectIdentifier((2, 5, 4, 55, ))
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
class Clearance(univ.Sequence):
|
| 330 |
+
componentType = namedtype.NamedTypes(
|
| 331 |
+
namedtype.NamedType('policyId',
|
| 332 |
+
univ.ObjectIdentifier()),
|
| 333 |
+
namedtype.DefaultedNamedType('classList',
|
| 334 |
+
ClassList().subtype(value='unclassified')),
|
| 335 |
+
namedtype.OptionalNamedType('securityCategories',
|
| 336 |
+
univ.SetOf(componentType=SecurityCategory()))
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
id_at_clearance_rfc3281 = univ.ObjectIdentifier((2, 5, 1, 5, 55, ))
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
class Clearance_rfc3281(univ.Sequence):
|
| 344 |
+
componentType = namedtype.NamedTypes(
|
| 345 |
+
namedtype.NamedType('policyId',
|
| 346 |
+
univ.ObjectIdentifier().subtype(implicitTag=tag.Tag(
|
| 347 |
+
tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 348 |
+
namedtype.DefaultedNamedType('classList',
|
| 349 |
+
ClassList().subtype(implicitTag=tag.Tag(
|
| 350 |
+
tag.tagClassContext, tag.tagFormatSimple, 1)).subtype(
|
| 351 |
+
value='unclassified')),
|
| 352 |
+
namedtype.OptionalNamedType('securityCategories',
|
| 353 |
+
univ.SetOf(componentType=SecurityCategory()).subtype(
|
| 354 |
+
implicitTag=tag.Tag(
|
| 355 |
+
tag.tagClassContext, tag.tagFormatSimple, 2)))
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
id_aca_encAttrs = id_aca + (6, )
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class ACClearAttrs(univ.Sequence):
|
| 363 |
+
componentType = namedtype.NamedTypes(
|
| 364 |
+
namedtype.NamedType('acIssuer', GeneralName()),
|
| 365 |
+
namedtype.NamedType('acSerial', univ.Integer()),
|
| 366 |
+
namedtype.NamedType('attrs', univ.SequenceOf(componentType=Attribute()))
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
# Map of Certificate Extension OIDs to Extensions added to the
|
| 371 |
+
# ones that are in rfc5280.py
|
| 372 |
+
|
| 373 |
+
_certificateExtensionsMapUpdate = {
|
| 374 |
+
id_pe_ac_auditIdentity: univ.OctetString(),
|
| 375 |
+
id_ce_noRevAvail: univ.Null(),
|
| 376 |
+
id_ce_targetInformation: Targets(),
|
| 377 |
+
id_pe_ac_proxying: ProxyInfo(),
|
| 378 |
+
id_pe_aaControls: AAControls(),
|
| 379 |
+
}
|
| 380 |
+
|
| 381 |
+
rfc5280.certificateExtensionsMap.update(_certificateExtensionsMapUpdate)
|
| 382 |
+
|
| 383 |
+
|
| 384 |
+
# Map of AttributeType OIDs to AttributeValue added to the
|
| 385 |
+
# ones that are in rfc5280.py
|
| 386 |
+
|
| 387 |
+
_certificateAttributesMapUpdate = {
|
| 388 |
+
id_aca_authenticationInfo: SvceAuthInfo(),
|
| 389 |
+
id_aca_accessIdentity: SvceAuthInfo(),
|
| 390 |
+
id_aca_chargingIdentity: IetfAttrSyntax(),
|
| 391 |
+
id_aca_group: IetfAttrSyntax(),
|
| 392 |
+
id_at_role: RoleSyntax(),
|
| 393 |
+
id_at_clearance: Clearance(),
|
| 394 |
+
id_at_clearance_rfc3281: Clearance_rfc3281(),
|
| 395 |
+
id_aca_encAttrs: ContentInfo(),
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
rfc5280.certificateAttributesMap.update(_certificateAttributesMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc5915.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is being contributed to pyasn1-modules software.
|
| 2 |
+
#
|
| 3 |
+
# Created by Russ Housley with assistance from asn1ate v.0.6.0.
|
| 4 |
+
#
|
| 5 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 6 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 7 |
+
#
|
| 8 |
+
# Elliptic Curve Private Key
|
| 9 |
+
#
|
| 10 |
+
# ASN.1 source from:
|
| 11 |
+
# https://www.rfc-editor.org/rfc/rfc5915.txt
|
| 12 |
+
|
| 13 |
+
from pyasn1.type import namedtype
|
| 14 |
+
from pyasn1.type import namedval
|
| 15 |
+
from pyasn1.type import tag
|
| 16 |
+
from pyasn1.type import univ
|
| 17 |
+
|
| 18 |
+
from pyasn1_modules import rfc5480
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class ECPrivateKey(univ.Sequence):
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
ECPrivateKey.componentType = namedtype.NamedTypes(
|
| 25 |
+
namedtype.NamedType('version', univ.Integer(
|
| 26 |
+
namedValues=namedval.NamedValues(('ecPrivkeyVer1', 1)))),
|
| 27 |
+
namedtype.NamedType('privateKey', univ.OctetString()),
|
| 28 |
+
namedtype.OptionalNamedType('parameters', rfc5480.ECParameters().subtype(
|
| 29 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 0))),
|
| 30 |
+
namedtype.OptionalNamedType('publicKey', univ.BitString().subtype(
|
| 31 |
+
explicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 1)))
|
| 32 |
+
)
|
lib/python3.10/site-packages/pyasn1_modules/rfc8018.py
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# PKCS #5: Password-Based Cryptography Specification, Version 2.1
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc8018.txt
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
from pyasn1.type import constraint
|
| 16 |
+
from pyasn1.type import namedtype
|
| 17 |
+
from pyasn1.type import namedval
|
| 18 |
+
from pyasn1.type import univ
|
| 19 |
+
|
| 20 |
+
from pyasn1_modules import rfc3565
|
| 21 |
+
from pyasn1_modules import rfc5280
|
| 22 |
+
|
| 23 |
+
MAX = float('inf')
|
| 24 |
+
|
| 25 |
+
def _OID(*components):
|
| 26 |
+
output = []
|
| 27 |
+
for x in tuple(components):
|
| 28 |
+
if isinstance(x, univ.ObjectIdentifier):
|
| 29 |
+
output.extend(list(x))
|
| 30 |
+
else:
|
| 31 |
+
output.append(int(x))
|
| 32 |
+
|
| 33 |
+
return univ.ObjectIdentifier(output)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Import from RFC 3565
|
| 37 |
+
|
| 38 |
+
AES_IV = rfc3565.AES_IV
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
# Import from RFC 5280
|
| 42 |
+
|
| 43 |
+
AlgorithmIdentifier = rfc5280.AlgorithmIdentifier
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
# Basic object identifiers
|
| 47 |
+
|
| 48 |
+
nistAlgorithms = _OID(2, 16, 840, 1, 101, 3, 4)
|
| 49 |
+
|
| 50 |
+
aes = _OID(nistAlgorithms, 1)
|
| 51 |
+
|
| 52 |
+
oiw = _OID(1, 3, 14)
|
| 53 |
+
|
| 54 |
+
rsadsi = _OID(1, 2, 840, 113549)
|
| 55 |
+
|
| 56 |
+
pkcs = _OID(rsadsi, 1)
|
| 57 |
+
|
| 58 |
+
digestAlgorithm = _OID(rsadsi, 2)
|
| 59 |
+
|
| 60 |
+
encryptionAlgorithm = _OID(rsadsi, 3)
|
| 61 |
+
|
| 62 |
+
pkcs_5 = _OID(pkcs, 5)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# HMAC object identifiers
|
| 67 |
+
|
| 68 |
+
id_hmacWithSHA1 = _OID(digestAlgorithm, 7)
|
| 69 |
+
|
| 70 |
+
id_hmacWithSHA224 = _OID(digestAlgorithm, 8)
|
| 71 |
+
|
| 72 |
+
id_hmacWithSHA256 = _OID(digestAlgorithm, 9)
|
| 73 |
+
|
| 74 |
+
id_hmacWithSHA384 = _OID(digestAlgorithm, 10)
|
| 75 |
+
|
| 76 |
+
id_hmacWithSHA512 = _OID(digestAlgorithm, 11)
|
| 77 |
+
|
| 78 |
+
id_hmacWithSHA512_224 = _OID(digestAlgorithm, 12)
|
| 79 |
+
|
| 80 |
+
id_hmacWithSHA512_256 = _OID(digestAlgorithm, 13)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# PBES1 object identifiers
|
| 84 |
+
|
| 85 |
+
pbeWithMD2AndDES_CBC = _OID(pkcs_5, 1)
|
| 86 |
+
|
| 87 |
+
pbeWithMD2AndRC2_CBC = _OID(pkcs_5, 4)
|
| 88 |
+
|
| 89 |
+
pbeWithMD5AndDES_CBC = _OID(pkcs_5, 3)
|
| 90 |
+
|
| 91 |
+
pbeWithMD5AndRC2_CBC = _OID(pkcs_5, 6)
|
| 92 |
+
|
| 93 |
+
pbeWithSHA1AndDES_CBC = _OID(pkcs_5, 10)
|
| 94 |
+
|
| 95 |
+
pbeWithSHA1AndRC2_CBC = _OID(pkcs_5, 11)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
# Supporting techniques object identifiers
|
| 99 |
+
|
| 100 |
+
desCBC = _OID(oiw, 3, 2, 7)
|
| 101 |
+
|
| 102 |
+
des_EDE3_CBC = _OID(encryptionAlgorithm, 7)
|
| 103 |
+
|
| 104 |
+
rc2CBC = _OID(encryptionAlgorithm, 2)
|
| 105 |
+
|
| 106 |
+
rc5_CBC_PAD = _OID(encryptionAlgorithm, 9)
|
| 107 |
+
|
| 108 |
+
aes128_CBC_PAD = _OID(aes, 2)
|
| 109 |
+
|
| 110 |
+
aes192_CBC_PAD = _OID(aes, 22)
|
| 111 |
+
|
| 112 |
+
aes256_CBC_PAD = _OID(aes, 42)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
# PBES1
|
| 116 |
+
|
| 117 |
+
class PBEParameter(univ.Sequence):
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
PBEParameter.componentType = namedtype.NamedTypes(
|
| 121 |
+
namedtype.NamedType('salt', univ.OctetString().subtype(
|
| 122 |
+
subtypeSpec=constraint.ValueSizeConstraint(8, 8))),
|
| 123 |
+
namedtype.NamedType('iterationCount', univ.Integer())
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
# PBES2
|
| 128 |
+
|
| 129 |
+
id_PBES2 = _OID(pkcs_5, 13)
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class PBES2_params(univ.Sequence):
|
| 133 |
+
pass
|
| 134 |
+
|
| 135 |
+
PBES2_params.componentType = namedtype.NamedTypes(
|
| 136 |
+
namedtype.NamedType('keyDerivationFunc', AlgorithmIdentifier()),
|
| 137 |
+
namedtype.NamedType('encryptionScheme', AlgorithmIdentifier())
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
# PBMAC1
|
| 142 |
+
|
| 143 |
+
id_PBMAC1 = _OID(pkcs_5, 14)
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
class PBMAC1_params(univ.Sequence):
|
| 147 |
+
pass
|
| 148 |
+
|
| 149 |
+
PBMAC1_params.componentType = namedtype.NamedTypes(
|
| 150 |
+
namedtype.NamedType('keyDerivationFunc', AlgorithmIdentifier()),
|
| 151 |
+
namedtype.NamedType('messageAuthScheme', AlgorithmIdentifier())
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
# PBKDF2
|
| 156 |
+
|
| 157 |
+
id_PBKDF2 = _OID(pkcs_5, 12)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
algid_hmacWithSHA1 = AlgorithmIdentifier()
|
| 161 |
+
algid_hmacWithSHA1['algorithm'] = id_hmacWithSHA1
|
| 162 |
+
algid_hmacWithSHA1['parameters'] = univ.Null("")
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class PBKDF2_params(univ.Sequence):
|
| 166 |
+
pass
|
| 167 |
+
|
| 168 |
+
PBKDF2_params.componentType = namedtype.NamedTypes(
|
| 169 |
+
namedtype.NamedType('salt', univ.Choice(componentType=namedtype.NamedTypes(
|
| 170 |
+
namedtype.NamedType('specified', univ.OctetString()),
|
| 171 |
+
namedtype.NamedType('otherSource', AlgorithmIdentifier())
|
| 172 |
+
))),
|
| 173 |
+
namedtype.NamedType('iterationCount', univ.Integer().subtype(
|
| 174 |
+
subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
|
| 175 |
+
namedtype.OptionalNamedType('keyLength', univ.Integer().subtype(
|
| 176 |
+
subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
|
| 177 |
+
namedtype.DefaultedNamedType('prf', algid_hmacWithSHA1)
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
# RC2 CBC algorithm parameter
|
| 182 |
+
|
| 183 |
+
class RC2_CBC_Parameter(univ.Sequence):
|
| 184 |
+
pass
|
| 185 |
+
|
| 186 |
+
RC2_CBC_Parameter.componentType = namedtype.NamedTypes(
|
| 187 |
+
namedtype.OptionalNamedType('rc2ParameterVersion', univ.Integer()),
|
| 188 |
+
namedtype.NamedType('iv', univ.OctetString().subtype(
|
| 189 |
+
subtypeSpec=constraint.ValueSizeConstraint(8, 8)))
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
# RC5 CBC algorithm parameter
|
| 194 |
+
|
| 195 |
+
class RC5_CBC_Parameters(univ.Sequence):
|
| 196 |
+
pass
|
| 197 |
+
|
| 198 |
+
RC5_CBC_Parameters.componentType = namedtype.NamedTypes(
|
| 199 |
+
namedtype.NamedType('version',
|
| 200 |
+
univ.Integer(namedValues=namedval.NamedValues(('v1_0', 16))).subtype(
|
| 201 |
+
subtypeSpec=constraint.SingleValueConstraint(16))),
|
| 202 |
+
namedtype.NamedType('rounds',
|
| 203 |
+
univ.Integer().subtype(subtypeSpec=constraint.ValueRangeConstraint(8, 127))),
|
| 204 |
+
namedtype.NamedType('blockSizeInBits',
|
| 205 |
+
univ.Integer().subtype(subtypeSpec=constraint.SingleValueConstraint(64, 128))),
|
| 206 |
+
namedtype.OptionalNamedType('iv', univ.OctetString())
|
| 207 |
+
)
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
# Initialization Vector for AES: OCTET STRING (SIZE(16))
|
| 211 |
+
|
| 212 |
+
class AES_IV(univ.OctetString):
|
| 213 |
+
pass
|
| 214 |
+
|
| 215 |
+
AES_IV.subtypeSpec = constraint.ValueSizeConstraint(16, 16)
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
# Initialization Vector for DES: OCTET STRING (SIZE(8))
|
| 219 |
+
|
| 220 |
+
class DES_IV(univ.OctetString):
|
| 221 |
+
pass
|
| 222 |
+
|
| 223 |
+
DES_IV.subtypeSpec = constraint.ValueSizeConstraint(8, 8)
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
# Update the Algorithm Identifier map
|
| 227 |
+
|
| 228 |
+
_algorithmIdentifierMapUpdate = {
|
| 229 |
+
# PBKDF2-PRFs
|
| 230 |
+
id_hmacWithSHA1: univ.Null(),
|
| 231 |
+
id_hmacWithSHA224: univ.Null(),
|
| 232 |
+
id_hmacWithSHA256: univ.Null(),
|
| 233 |
+
id_hmacWithSHA384: univ.Null(),
|
| 234 |
+
id_hmacWithSHA512: univ.Null(),
|
| 235 |
+
id_hmacWithSHA512_224: univ.Null(),
|
| 236 |
+
id_hmacWithSHA512_256: univ.Null(),
|
| 237 |
+
# PBES1Algorithms
|
| 238 |
+
pbeWithMD2AndDES_CBC: PBEParameter(),
|
| 239 |
+
pbeWithMD2AndRC2_CBC: PBEParameter(),
|
| 240 |
+
pbeWithMD5AndDES_CBC: PBEParameter(),
|
| 241 |
+
pbeWithMD5AndRC2_CBC: PBEParameter(),
|
| 242 |
+
pbeWithSHA1AndDES_CBC: PBEParameter(),
|
| 243 |
+
pbeWithSHA1AndRC2_CBC: PBEParameter(),
|
| 244 |
+
# PBES2Algorithms
|
| 245 |
+
id_PBES2: PBES2_params(),
|
| 246 |
+
# PBES2-KDFs
|
| 247 |
+
id_PBKDF2: PBKDF2_params(),
|
| 248 |
+
# PBMAC1Algorithms
|
| 249 |
+
id_PBMAC1: PBMAC1_params(),
|
| 250 |
+
# SupportingAlgorithms
|
| 251 |
+
desCBC: DES_IV(),
|
| 252 |
+
des_EDE3_CBC: DES_IV(),
|
| 253 |
+
rc2CBC: RC2_CBC_Parameter(),
|
| 254 |
+
rc5_CBC_PAD: RC5_CBC_Parameters(),
|
| 255 |
+
aes128_CBC_PAD: AES_IV(),
|
| 256 |
+
aes192_CBC_PAD: AES_IV(),
|
| 257 |
+
aes256_CBC_PAD: AES_IV(),
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
rfc5280.algorithmIdentifierMap.update(_algorithmIdentifierMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc8358.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Digital Signatures on Internet-Draft Documents
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc8358.txt
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
from pyasn1.type import univ
|
| 16 |
+
|
| 17 |
+
from pyasn1_modules import rfc5652
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
id_ct = univ.ObjectIdentifier('1.2.840.113549.1.9.16.1')
|
| 21 |
+
|
| 22 |
+
id_ct_asciiTextWithCRLF = id_ct + (27, )
|
| 23 |
+
|
| 24 |
+
id_ct_epub = id_ct + (39, )
|
| 25 |
+
|
| 26 |
+
id_ct_htmlWithCRLF = id_ct + (38, )
|
| 27 |
+
|
| 28 |
+
id_ct_pdf = id_ct + (29, )
|
| 29 |
+
|
| 30 |
+
id_ct_postscript = id_ct + (30, )
|
| 31 |
+
|
| 32 |
+
id_ct_utf8TextWithCRLF = id_ct + (37, )
|
| 33 |
+
|
| 34 |
+
id_ct_xml = id_ct + (28, )
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Map of Content Type OIDs to Content Types is added to the
|
| 38 |
+
# ones that are in rfc5652.py
|
| 39 |
+
|
| 40 |
+
_cmsContentTypesMapUpdate = {
|
| 41 |
+
id_ct_asciiTextWithCRLF: univ.OctetString(),
|
| 42 |
+
id_ct_epub: univ.OctetString(),
|
| 43 |
+
id_ct_htmlWithCRLF: univ.OctetString(),
|
| 44 |
+
id_ct_pdf: univ.OctetString(),
|
| 45 |
+
id_ct_postscript: univ.OctetString(),
|
| 46 |
+
id_ct_utf8TextWithCRLF: univ.OctetString(),
|
| 47 |
+
id_ct_xml: univ.OctetString(),
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
rfc5652.cmsContentTypesMap.update(_cmsContentTypesMapUpdate)
|
lib/python3.10/site-packages/pyasn1_modules/rfc8619.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Algorithm Identifiers for HKDF
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc8619.txt
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
from pyasn1.type import univ
|
| 16 |
+
|
| 17 |
+
from pyasn1_modules import rfc5280
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Object Identifiers
|
| 21 |
+
|
| 22 |
+
id_alg_hkdf_with_sha256 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.28')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
id_alg_hkdf_with_sha384 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.29')
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
id_alg_hkdf_with_sha512 = univ.ObjectIdentifier('1.2.840.113549.1.9.16.3.30')
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Key Derivation Algorithm Identifiers
|
| 32 |
+
|
| 33 |
+
kda_hkdf_with_sha256 = rfc5280.AlgorithmIdentifier()
|
| 34 |
+
kda_hkdf_with_sha256['algorithm'] = id_alg_hkdf_with_sha256
|
| 35 |
+
# kda_hkdf_with_sha256['parameters'] are absent
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
kda_hkdf_with_sha384 = rfc5280.AlgorithmIdentifier()
|
| 39 |
+
kda_hkdf_with_sha384['algorithm'] = id_alg_hkdf_with_sha384
|
| 40 |
+
# kda_hkdf_with_sha384['parameters'] are absent
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
kda_hkdf_with_sha512 = rfc5280.AlgorithmIdentifier()
|
| 44 |
+
kda_hkdf_with_sha512['algorithm'] = id_alg_hkdf_with_sha512
|
| 45 |
+
# kda_hkdf_with_sha512['parameters'] are absent
|
lib/python3.10/site-packages/pyasn1_modules/rfc8696.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#
|
| 2 |
+
# This file is part of pyasn1-modules software.
|
| 3 |
+
#
|
| 4 |
+
# Created by Russ Housley with some assistance from asn1ate v.0.6.0.
|
| 5 |
+
#
|
| 6 |
+
# Copyright (c) 2019, Vigil Security, LLC
|
| 7 |
+
# License: http://snmplabs.com/pyasn1/license.html
|
| 8 |
+
#
|
| 9 |
+
# Using Pre-Shared Key (PSK) in the Cryptographic Message Syntax (CMS)
|
| 10 |
+
#
|
| 11 |
+
# ASN.1 source from:
|
| 12 |
+
# https://www.rfc-editor.org/rfc/rfc8696.txt
|
| 13 |
+
#
|
| 14 |
+
|
| 15 |
+
from pyasn1.type import constraint
|
| 16 |
+
from pyasn1.type import namedtype
|
| 17 |
+
from pyasn1.type import namedval
|
| 18 |
+
from pyasn1.type import tag
|
| 19 |
+
from pyasn1.type import univ
|
| 20 |
+
|
| 21 |
+
from pyasn1_modules import rfc5652
|
| 22 |
+
|
| 23 |
+
MAX = float('inf')
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
id_ori = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13')
|
| 27 |
+
|
| 28 |
+
id_ori_keyTransPSK = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13.1')
|
| 29 |
+
|
| 30 |
+
id_ori_keyAgreePSK = univ.ObjectIdentifier('1.2.840.113549.1.9.16.13.2')
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class PreSharedKeyIdentifier(univ.OctetString):
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class KeyTransRecipientInfos(univ.SequenceOf):
|
| 38 |
+
componentType = rfc5652.KeyTransRecipientInfo()
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
class KeyTransPSKRecipientInfo(univ.Sequence):
|
| 42 |
+
componentType = namedtype.NamedTypes(
|
| 43 |
+
namedtype.NamedType('version',
|
| 44 |
+
rfc5652.CMSVersion()),
|
| 45 |
+
namedtype.NamedType('pskid',
|
| 46 |
+
PreSharedKeyIdentifier()),
|
| 47 |
+
namedtype.NamedType('kdfAlgorithm',
|
| 48 |
+
rfc5652.KeyDerivationAlgorithmIdentifier()),
|
| 49 |
+
namedtype.NamedType('keyEncryptionAlgorithm',
|
| 50 |
+
rfc5652.KeyEncryptionAlgorithmIdentifier()),
|
| 51 |
+
namedtype.NamedType('ktris',
|
| 52 |
+
KeyTransRecipientInfos()),
|
| 53 |
+
namedtype.NamedType('encryptedKey',
|
| 54 |
+
rfc5652.EncryptedKey())
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
class KeyAgreePSKRecipientInfo(univ.Sequence):
|
| 59 |
+
componentType = namedtype.NamedTypes(
|
| 60 |
+
namedtype.NamedType('version',
|
| 61 |
+
rfc5652.CMSVersion()),
|
| 62 |
+
namedtype.NamedType('pskid',
|
| 63 |
+
PreSharedKeyIdentifier()),
|
| 64 |
+
namedtype.NamedType('originator',
|
| 65 |
+
rfc5652.OriginatorIdentifierOrKey().subtype(explicitTag=tag.Tag(
|
| 66 |
+
tag.tagClassContext, tag.tagFormatConstructed, 0))),
|
| 67 |
+
namedtype.OptionalNamedType('ukm',
|
| 68 |
+
rfc5652.UserKeyingMaterial().subtype(explicitTag=tag.Tag(
|
| 69 |
+
tag.tagClassContext, tag.tagFormatSimple, 1))),
|
| 70 |
+
namedtype.NamedType('kdfAlgorithm',
|
| 71 |
+
rfc5652.KeyDerivationAlgorithmIdentifier()),
|
| 72 |
+
namedtype.NamedType('keyEncryptionAlgorithm',
|
| 73 |
+
rfc5652.KeyEncryptionAlgorithmIdentifier()),
|
| 74 |
+
namedtype.NamedType('recipientEncryptedKeys',
|
| 75 |
+
rfc5652.RecipientEncryptedKeys())
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class CMSORIforPSKOtherInfo(univ.Sequence):
|
| 80 |
+
componentType = namedtype.NamedTypes(
|
| 81 |
+
namedtype.NamedType('psk',
|
| 82 |
+
univ.OctetString()),
|
| 83 |
+
namedtype.NamedType('keyMgmtAlgType',
|
| 84 |
+
univ.Enumerated(namedValues=namedval.NamedValues(
|
| 85 |
+
('keyTrans', 5), ('keyAgree', 10)))),
|
| 86 |
+
namedtype.NamedType('keyEncryptionAlgorithm',
|
| 87 |
+
rfc5652.KeyEncryptionAlgorithmIdentifier()),
|
| 88 |
+
namedtype.NamedType('pskLength',
|
| 89 |
+
univ.Integer().subtype(
|
| 90 |
+
subtypeSpec=constraint.ValueRangeConstraint(1, MAX))),
|
| 91 |
+
namedtype.NamedType('kdkLength',
|
| 92 |
+
univ.Integer().subtype(
|
| 93 |
+
subtypeSpec=constraint.ValueRangeConstraint(1, MAX)))
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
# Update the CMS Other Recipient Info map in rfc5652.py
|
| 98 |
+
|
| 99 |
+
_otherRecipientInfoMapUpdate = {
|
| 100 |
+
id_ori_keyTransPSK: KeyTransPSKRecipientInfo(),
|
| 101 |
+
id_ori_keyAgreePSK: KeyAgreePSKRecipientInfo(),
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
rfc5652.otherRecipientInfoMap.update(_otherRecipientInfoMapUpdate)
|
lib/python3.10/site-packages/urllib3/__init__.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more
|
| 3 |
+
"""
|
| 4 |
+
from __future__ import absolute_import
|
| 5 |
+
|
| 6 |
+
# Set default logging handler to avoid "No handler found" warnings.
|
| 7 |
+
import logging
|
| 8 |
+
import warnings
|
| 9 |
+
from logging import NullHandler
|
| 10 |
+
|
| 11 |
+
from . import exceptions
|
| 12 |
+
from ._version import __version__
|
| 13 |
+
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
|
| 14 |
+
from .filepost import encode_multipart_formdata
|
| 15 |
+
from .poolmanager import PoolManager, ProxyManager, proxy_from_url
|
| 16 |
+
from .response import HTTPResponse
|
| 17 |
+
from .util.request import make_headers
|
| 18 |
+
from .util.retry import Retry
|
| 19 |
+
from .util.timeout import Timeout
|
| 20 |
+
from .util.url import get_host
|
| 21 |
+
|
| 22 |
+
# === NOTE TO REPACKAGERS AND VENDORS ===
|
| 23 |
+
# Please delete this block, this logic is only
|
| 24 |
+
# for urllib3 being distributed via PyPI.
|
| 25 |
+
# See: https://github.com/urllib3/urllib3/issues/2680
|
| 26 |
+
try:
|
| 27 |
+
import urllib3_secure_extra # type: ignore # noqa: F401
|
| 28 |
+
except ImportError:
|
| 29 |
+
pass
|
| 30 |
+
else:
|
| 31 |
+
warnings.warn(
|
| 32 |
+
"'urllib3[secure]' extra is deprecated and will be removed "
|
| 33 |
+
"in a future release of urllib3 2.x. Read more in this issue: "
|
| 34 |
+
"https://github.com/urllib3/urllib3/issues/2680",
|
| 35 |
+
category=DeprecationWarning,
|
| 36 |
+
stacklevel=2,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
__author__ = "Andrey Petrov (andrey.petrov@shazow.net)"
|
| 40 |
+
__license__ = "MIT"
|
| 41 |
+
__version__ = __version__
|
| 42 |
+
|
| 43 |
+
__all__ = (
|
| 44 |
+
"HTTPConnectionPool",
|
| 45 |
+
"HTTPSConnectionPool",
|
| 46 |
+
"PoolManager",
|
| 47 |
+
"ProxyManager",
|
| 48 |
+
"HTTPResponse",
|
| 49 |
+
"Retry",
|
| 50 |
+
"Timeout",
|
| 51 |
+
"add_stderr_logger",
|
| 52 |
+
"connection_from_url",
|
| 53 |
+
"disable_warnings",
|
| 54 |
+
"encode_multipart_formdata",
|
| 55 |
+
"get_host",
|
| 56 |
+
"make_headers",
|
| 57 |
+
"proxy_from_url",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
logging.getLogger(__name__).addHandler(NullHandler())
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def add_stderr_logger(level=logging.DEBUG):
|
| 64 |
+
"""
|
| 65 |
+
Helper for quickly adding a StreamHandler to the logger. Useful for
|
| 66 |
+
debugging.
|
| 67 |
+
|
| 68 |
+
Returns the handler after adding it.
|
| 69 |
+
"""
|
| 70 |
+
# This method needs to be in this __init__.py to get the __name__ correct
|
| 71 |
+
# even if urllib3 is vendored within another package.
|
| 72 |
+
logger = logging.getLogger(__name__)
|
| 73 |
+
handler = logging.StreamHandler()
|
| 74 |
+
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))
|
| 75 |
+
logger.addHandler(handler)
|
| 76 |
+
logger.setLevel(level)
|
| 77 |
+
logger.debug("Added a stderr logging handler to logger: %s", __name__)
|
| 78 |
+
return handler
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
# ... Clean up.
|
| 82 |
+
del NullHandler
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
# All warning filters *must* be appended unless you're really certain that they
|
| 86 |
+
# shouldn't be: otherwise, it's very hard for users to use most Python
|
| 87 |
+
# mechanisms to silence them.
|
| 88 |
+
# SecurityWarning's always go off by default.
|
| 89 |
+
warnings.simplefilter("always", exceptions.SecurityWarning, append=True)
|
| 90 |
+
# SubjectAltNameWarning's should go off once per host
|
| 91 |
+
warnings.simplefilter("default", exceptions.SubjectAltNameWarning, append=True)
|
| 92 |
+
# InsecurePlatformWarning's don't vary between requests, so we keep it default.
|
| 93 |
+
warnings.simplefilter("default", exceptions.InsecurePlatformWarning, append=True)
|
| 94 |
+
# SNIMissingWarnings should go off only once.
|
| 95 |
+
warnings.simplefilter("default", exceptions.SNIMissingWarning, append=True)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def disable_warnings(category=exceptions.HTTPWarning):
|
| 99 |
+
"""
|
| 100 |
+
Helper for quickly disabling all urllib3 warnings.
|
| 101 |
+
"""
|
| 102 |
+
warnings.simplefilter("ignore", category)
|
lib/python3.10/site-packages/urllib3/_collections.py
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import
|
| 2 |
+
|
| 3 |
+
try:
|
| 4 |
+
from collections.abc import Mapping, MutableMapping
|
| 5 |
+
except ImportError:
|
| 6 |
+
from collections import Mapping, MutableMapping
|
| 7 |
+
try:
|
| 8 |
+
from threading import RLock
|
| 9 |
+
except ImportError: # Platform-specific: No threads available
|
| 10 |
+
|
| 11 |
+
class RLock:
|
| 12 |
+
def __enter__(self):
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
def __exit__(self, exc_type, exc_value, traceback):
|
| 16 |
+
pass
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from collections import OrderedDict
|
| 20 |
+
|
| 21 |
+
from .exceptions import InvalidHeader
|
| 22 |
+
from .packages import six
|
| 23 |
+
from .packages.six import iterkeys, itervalues
|
| 24 |
+
|
| 25 |
+
__all__ = ["RecentlyUsedContainer", "HTTPHeaderDict"]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
_Null = object()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class RecentlyUsedContainer(MutableMapping):
|
| 32 |
+
"""
|
| 33 |
+
Provides a thread-safe dict-like container which maintains up to
|
| 34 |
+
``maxsize`` keys while throwing away the least-recently-used keys beyond
|
| 35 |
+
``maxsize``.
|
| 36 |
+
|
| 37 |
+
:param maxsize:
|
| 38 |
+
Maximum number of recent elements to retain.
|
| 39 |
+
|
| 40 |
+
:param dispose_func:
|
| 41 |
+
Every time an item is evicted from the container,
|
| 42 |
+
``dispose_func(value)`` is called. Callback which will get called
|
| 43 |
+
"""
|
| 44 |
+
|
| 45 |
+
ContainerCls = OrderedDict
|
| 46 |
+
|
| 47 |
+
def __init__(self, maxsize=10, dispose_func=None):
|
| 48 |
+
self._maxsize = maxsize
|
| 49 |
+
self.dispose_func = dispose_func
|
| 50 |
+
|
| 51 |
+
self._container = self.ContainerCls()
|
| 52 |
+
self.lock = RLock()
|
| 53 |
+
|
| 54 |
+
def __getitem__(self, key):
|
| 55 |
+
# Re-insert the item, moving it to the end of the eviction line.
|
| 56 |
+
with self.lock:
|
| 57 |
+
item = self._container.pop(key)
|
| 58 |
+
self._container[key] = item
|
| 59 |
+
return item
|
| 60 |
+
|
| 61 |
+
def __setitem__(self, key, value):
|
| 62 |
+
evicted_value = _Null
|
| 63 |
+
with self.lock:
|
| 64 |
+
# Possibly evict the existing value of 'key'
|
| 65 |
+
evicted_value = self._container.get(key, _Null)
|
| 66 |
+
self._container[key] = value
|
| 67 |
+
|
| 68 |
+
# If we didn't evict an existing value, we might have to evict the
|
| 69 |
+
# least recently used item from the beginning of the container.
|
| 70 |
+
if len(self._container) > self._maxsize:
|
| 71 |
+
_key, evicted_value = self._container.popitem(last=False)
|
| 72 |
+
|
| 73 |
+
if self.dispose_func and evicted_value is not _Null:
|
| 74 |
+
self.dispose_func(evicted_value)
|
| 75 |
+
|
| 76 |
+
def __delitem__(self, key):
|
| 77 |
+
with self.lock:
|
| 78 |
+
value = self._container.pop(key)
|
| 79 |
+
|
| 80 |
+
if self.dispose_func:
|
| 81 |
+
self.dispose_func(value)
|
| 82 |
+
|
| 83 |
+
def __len__(self):
|
| 84 |
+
with self.lock:
|
| 85 |
+
return len(self._container)
|
| 86 |
+
|
| 87 |
+
def __iter__(self):
|
| 88 |
+
raise NotImplementedError(
|
| 89 |
+
"Iteration over this class is unlikely to be threadsafe."
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
def clear(self):
|
| 93 |
+
with self.lock:
|
| 94 |
+
# Copy pointers to all values, then wipe the mapping
|
| 95 |
+
values = list(itervalues(self._container))
|
| 96 |
+
self._container.clear()
|
| 97 |
+
|
| 98 |
+
if self.dispose_func:
|
| 99 |
+
for value in values:
|
| 100 |
+
self.dispose_func(value)
|
| 101 |
+
|
| 102 |
+
def keys(self):
|
| 103 |
+
with self.lock:
|
| 104 |
+
return list(iterkeys(self._container))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
class HTTPHeaderDict(MutableMapping):
|
| 108 |
+
"""
|
| 109 |
+
:param headers:
|
| 110 |
+
An iterable of field-value pairs. Must not contain multiple field names
|
| 111 |
+
when compared case-insensitively.
|
| 112 |
+
|
| 113 |
+
:param kwargs:
|
| 114 |
+
Additional field-value pairs to pass in to ``dict.update``.
|
| 115 |
+
|
| 116 |
+
A ``dict`` like container for storing HTTP Headers.
|
| 117 |
+
|
| 118 |
+
Field names are stored and compared case-insensitively in compliance with
|
| 119 |
+
RFC 7230. Iteration provides the first case-sensitive key seen for each
|
| 120 |
+
case-insensitive pair.
|
| 121 |
+
|
| 122 |
+
Using ``__setitem__`` syntax overwrites fields that compare equal
|
| 123 |
+
case-insensitively in order to maintain ``dict``'s api. For fields that
|
| 124 |
+
compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
|
| 125 |
+
in a loop.
|
| 126 |
+
|
| 127 |
+
If multiple fields that are equal case-insensitively are passed to the
|
| 128 |
+
constructor or ``.update``, the behavior is undefined and some will be
|
| 129 |
+
lost.
|
| 130 |
+
|
| 131 |
+
>>> headers = HTTPHeaderDict()
|
| 132 |
+
>>> headers.add('Set-Cookie', 'foo=bar')
|
| 133 |
+
>>> headers.add('set-cookie', 'baz=quxx')
|
| 134 |
+
>>> headers['content-length'] = '7'
|
| 135 |
+
>>> headers['SET-cookie']
|
| 136 |
+
'foo=bar, baz=quxx'
|
| 137 |
+
>>> headers['Content-Length']
|
| 138 |
+
'7'
|
| 139 |
+
"""
|
| 140 |
+
|
| 141 |
+
def __init__(self, headers=None, **kwargs):
|
| 142 |
+
super(HTTPHeaderDict, self).__init__()
|
| 143 |
+
self._container = OrderedDict()
|
| 144 |
+
if headers is not None:
|
| 145 |
+
if isinstance(headers, HTTPHeaderDict):
|
| 146 |
+
self._copy_from(headers)
|
| 147 |
+
else:
|
| 148 |
+
self.extend(headers)
|
| 149 |
+
if kwargs:
|
| 150 |
+
self.extend(kwargs)
|
| 151 |
+
|
| 152 |
+
def __setitem__(self, key, val):
|
| 153 |
+
self._container[key.lower()] = [key, val]
|
| 154 |
+
return self._container[key.lower()]
|
| 155 |
+
|
| 156 |
+
def __getitem__(self, key):
|
| 157 |
+
val = self._container[key.lower()]
|
| 158 |
+
return ", ".join(val[1:])
|
| 159 |
+
|
| 160 |
+
def __delitem__(self, key):
|
| 161 |
+
del self._container[key.lower()]
|
| 162 |
+
|
| 163 |
+
def __contains__(self, key):
|
| 164 |
+
return key.lower() in self._container
|
| 165 |
+
|
| 166 |
+
def __eq__(self, other):
|
| 167 |
+
if not isinstance(other, Mapping) and not hasattr(other, "keys"):
|
| 168 |
+
return False
|
| 169 |
+
if not isinstance(other, type(self)):
|
| 170 |
+
other = type(self)(other)
|
| 171 |
+
return dict((k.lower(), v) for k, v in self.itermerged()) == dict(
|
| 172 |
+
(k.lower(), v) for k, v in other.itermerged()
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
def __ne__(self, other):
|
| 176 |
+
return not self.__eq__(other)
|
| 177 |
+
|
| 178 |
+
if six.PY2: # Python 2
|
| 179 |
+
iterkeys = MutableMapping.iterkeys
|
| 180 |
+
itervalues = MutableMapping.itervalues
|
| 181 |
+
|
| 182 |
+
__marker = object()
|
| 183 |
+
|
| 184 |
+
def __len__(self):
|
| 185 |
+
return len(self._container)
|
| 186 |
+
|
| 187 |
+
def __iter__(self):
|
| 188 |
+
# Only provide the originally cased names
|
| 189 |
+
for vals in self._container.values():
|
| 190 |
+
yield vals[0]
|
| 191 |
+
|
| 192 |
+
def pop(self, key, default=__marker):
|
| 193 |
+
"""D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
|
| 194 |
+
If key is not found, d is returned if given, otherwise KeyError is raised.
|
| 195 |
+
"""
|
| 196 |
+
# Using the MutableMapping function directly fails due to the private marker.
|
| 197 |
+
# Using ordinary dict.pop would expose the internal structures.
|
| 198 |
+
# So let's reinvent the wheel.
|
| 199 |
+
try:
|
| 200 |
+
value = self[key]
|
| 201 |
+
except KeyError:
|
| 202 |
+
if default is self.__marker:
|
| 203 |
+
raise
|
| 204 |
+
return default
|
| 205 |
+
else:
|
| 206 |
+
del self[key]
|
| 207 |
+
return value
|
| 208 |
+
|
| 209 |
+
def discard(self, key):
|
| 210 |
+
try:
|
| 211 |
+
del self[key]
|
| 212 |
+
except KeyError:
|
| 213 |
+
pass
|
| 214 |
+
|
| 215 |
+
def add(self, key, val):
|
| 216 |
+
"""Adds a (name, value) pair, doesn't overwrite the value if it already
|
| 217 |
+
exists.
|
| 218 |
+
|
| 219 |
+
>>> headers = HTTPHeaderDict(foo='bar')
|
| 220 |
+
>>> headers.add('Foo', 'baz')
|
| 221 |
+
>>> headers['foo']
|
| 222 |
+
'bar, baz'
|
| 223 |
+
"""
|
| 224 |
+
key_lower = key.lower()
|
| 225 |
+
new_vals = [key, val]
|
| 226 |
+
# Keep the common case aka no item present as fast as possible
|
| 227 |
+
vals = self._container.setdefault(key_lower, new_vals)
|
| 228 |
+
if new_vals is not vals:
|
| 229 |
+
vals.append(val)
|
| 230 |
+
|
| 231 |
+
def extend(self, *args, **kwargs):
|
| 232 |
+
"""Generic import function for any type of header-like object.
|
| 233 |
+
Adapted version of MutableMapping.update in order to insert items
|
| 234 |
+
with self.add instead of self.__setitem__
|
| 235 |
+
"""
|
| 236 |
+
if len(args) > 1:
|
| 237 |
+
raise TypeError(
|
| 238 |
+
"extend() takes at most 1 positional "
|
| 239 |
+
"arguments ({0} given)".format(len(args))
|
| 240 |
+
)
|
| 241 |
+
other = args[0] if len(args) >= 1 else ()
|
| 242 |
+
|
| 243 |
+
if isinstance(other, HTTPHeaderDict):
|
| 244 |
+
for key, val in other.iteritems():
|
| 245 |
+
self.add(key, val)
|
| 246 |
+
elif isinstance(other, Mapping):
|
| 247 |
+
for key in other:
|
| 248 |
+
self.add(key, other[key])
|
| 249 |
+
elif hasattr(other, "keys"):
|
| 250 |
+
for key in other.keys():
|
| 251 |
+
self.add(key, other[key])
|
| 252 |
+
else:
|
| 253 |
+
for key, value in other:
|
| 254 |
+
self.add(key, value)
|
| 255 |
+
|
| 256 |
+
for key, value in kwargs.items():
|
| 257 |
+
self.add(key, value)
|
| 258 |
+
|
| 259 |
+
def getlist(self, key, default=__marker):
|
| 260 |
+
"""Returns a list of all the values for the named field. Returns an
|
| 261 |
+
empty list if the key doesn't exist."""
|
| 262 |
+
try:
|
| 263 |
+
vals = self._container[key.lower()]
|
| 264 |
+
except KeyError:
|
| 265 |
+
if default is self.__marker:
|
| 266 |
+
return []
|
| 267 |
+
return default
|
| 268 |
+
else:
|
| 269 |
+
return vals[1:]
|
| 270 |
+
|
| 271 |
+
def _prepare_for_method_change(self):
|
| 272 |
+
"""
|
| 273 |
+
Remove content-specific header fields before changing the request
|
| 274 |
+
method to GET or HEAD according to RFC 9110, Section 15.4.
|
| 275 |
+
"""
|
| 276 |
+
content_specific_headers = [
|
| 277 |
+
"Content-Encoding",
|
| 278 |
+
"Content-Language",
|
| 279 |
+
"Content-Location",
|
| 280 |
+
"Content-Type",
|
| 281 |
+
"Content-Length",
|
| 282 |
+
"Digest",
|
| 283 |
+
"Last-Modified",
|
| 284 |
+
]
|
| 285 |
+
for header in content_specific_headers:
|
| 286 |
+
self.discard(header)
|
| 287 |
+
return self
|
| 288 |
+
|
| 289 |
+
# Backwards compatibility for httplib
|
| 290 |
+
getheaders = getlist
|
| 291 |
+
getallmatchingheaders = getlist
|
| 292 |
+
iget = getlist
|
| 293 |
+
|
| 294 |
+
# Backwards compatibility for http.cookiejar
|
| 295 |
+
get_all = getlist
|
| 296 |
+
|
| 297 |
+
def __repr__(self):
|
| 298 |
+
return "%s(%s)" % (type(self).__name__, dict(self.itermerged()))
|
| 299 |
+
|
| 300 |
+
def _copy_from(self, other):
|
| 301 |
+
for key in other:
|
| 302 |
+
val = other.getlist(key)
|
| 303 |
+
if isinstance(val, list):
|
| 304 |
+
# Don't need to convert tuples
|
| 305 |
+
val = list(val)
|
| 306 |
+
self._container[key.lower()] = [key] + val
|
| 307 |
+
|
| 308 |
+
def copy(self):
|
| 309 |
+
clone = type(self)()
|
| 310 |
+
clone._copy_from(self)
|
| 311 |
+
return clone
|
| 312 |
+
|
| 313 |
+
def iteritems(self):
|
| 314 |
+
"""Iterate over all header lines, including duplicate ones."""
|
| 315 |
+
for key in self:
|
| 316 |
+
vals = self._container[key.lower()]
|
| 317 |
+
for val in vals[1:]:
|
| 318 |
+
yield vals[0], val
|
| 319 |
+
|
| 320 |
+
def itermerged(self):
|
| 321 |
+
"""Iterate over all headers, merging duplicate ones together."""
|
| 322 |
+
for key in self:
|
| 323 |
+
val = self._container[key.lower()]
|
| 324 |
+
yield val[0], ", ".join(val[1:])
|
| 325 |
+
|
| 326 |
+
def items(self):
|
| 327 |
+
return list(self.iteritems())
|
| 328 |
+
|
| 329 |
+
@classmethod
|
| 330 |
+
def from_httplib(cls, message): # Python 2
|
| 331 |
+
"""Read headers from a Python 2 httplib message object."""
|
| 332 |
+
# python2.7 does not expose a proper API for exporting multiheaders
|
| 333 |
+
# efficiently. This function re-reads raw lines from the message
|
| 334 |
+
# object and extracts the multiheaders properly.
|
| 335 |
+
obs_fold_continued_leaders = (" ", "\t")
|
| 336 |
+
headers = []
|
| 337 |
+
|
| 338 |
+
for line in message.headers:
|
| 339 |
+
if line.startswith(obs_fold_continued_leaders):
|
| 340 |
+
if not headers:
|
| 341 |
+
# We received a header line that starts with OWS as described
|
| 342 |
+
# in RFC-7230 S3.2.4. This indicates a multiline header, but
|
| 343 |
+
# there exists no previous header to which we can attach it.
|
| 344 |
+
raise InvalidHeader(
|
| 345 |
+
"Header continuation with no previous header: %s" % line
|
| 346 |
+
)
|
| 347 |
+
else:
|
| 348 |
+
key, value = headers[-1]
|
| 349 |
+
headers[-1] = (key, value + " " + line.strip())
|
| 350 |
+
continue
|
| 351 |
+
|
| 352 |
+
key, value = line.split(":", 1)
|
| 353 |
+
headers.append((key, value.strip()))
|
| 354 |
+
|
| 355 |
+
return cls(headers)
|
lib/python3.10/site-packages/urllib3/_version.py
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is protected via CODEOWNERS
|
| 2 |
+
__version__ = "1.26.20"
|
lib/python3.10/site-packages/urllib3/connection.py
ADDED
|
@@ -0,0 +1,572 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import
|
| 2 |
+
|
| 3 |
+
import datetime
|
| 4 |
+
import logging
|
| 5 |
+
import os
|
| 6 |
+
import re
|
| 7 |
+
import socket
|
| 8 |
+
import warnings
|
| 9 |
+
from socket import error as SocketError
|
| 10 |
+
from socket import timeout as SocketTimeout
|
| 11 |
+
|
| 12 |
+
from .packages import six
|
| 13 |
+
from .packages.six.moves.http_client import HTTPConnection as _HTTPConnection
|
| 14 |
+
from .packages.six.moves.http_client import HTTPException # noqa: F401
|
| 15 |
+
from .util.proxy import create_proxy_ssl_context
|
| 16 |
+
|
| 17 |
+
try: # Compiled with SSL?
|
| 18 |
+
import ssl
|
| 19 |
+
|
| 20 |
+
BaseSSLError = ssl.SSLError
|
| 21 |
+
except (ImportError, AttributeError): # Platform-specific: No SSL.
|
| 22 |
+
ssl = None
|
| 23 |
+
|
| 24 |
+
class BaseSSLError(BaseException):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
try:
|
| 29 |
+
# Python 3: not a no-op, we're adding this to the namespace so it can be imported.
|
| 30 |
+
ConnectionError = ConnectionError
|
| 31 |
+
except NameError:
|
| 32 |
+
# Python 2
|
| 33 |
+
class ConnectionError(Exception):
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
try: # Python 3:
|
| 38 |
+
# Not a no-op, we're adding this to the namespace so it can be imported.
|
| 39 |
+
BrokenPipeError = BrokenPipeError
|
| 40 |
+
except NameError: # Python 2:
|
| 41 |
+
|
| 42 |
+
class BrokenPipeError(Exception):
|
| 43 |
+
pass
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
from ._collections import HTTPHeaderDict # noqa (historical, removed in v2)
|
| 47 |
+
from ._version import __version__
|
| 48 |
+
from .exceptions import (
|
| 49 |
+
ConnectTimeoutError,
|
| 50 |
+
NewConnectionError,
|
| 51 |
+
SubjectAltNameWarning,
|
| 52 |
+
SystemTimeWarning,
|
| 53 |
+
)
|
| 54 |
+
from .util import SKIP_HEADER, SKIPPABLE_HEADERS, connection
|
| 55 |
+
from .util.ssl_ import (
|
| 56 |
+
assert_fingerprint,
|
| 57 |
+
create_urllib3_context,
|
| 58 |
+
is_ipaddress,
|
| 59 |
+
resolve_cert_reqs,
|
| 60 |
+
resolve_ssl_version,
|
| 61 |
+
ssl_wrap_socket,
|
| 62 |
+
)
|
| 63 |
+
from .util.ssl_match_hostname import CertificateError, match_hostname
|
| 64 |
+
|
| 65 |
+
log = logging.getLogger(__name__)
|
| 66 |
+
|
| 67 |
+
port_by_scheme = {"http": 80, "https": 443}
|
| 68 |
+
|
| 69 |
+
# When it comes time to update this value as a part of regular maintenance
|
| 70 |
+
# (ie test_recent_date is failing) update it to ~6 months before the current date.
|
| 71 |
+
RECENT_DATE = datetime.date(2024, 1, 1)
|
| 72 |
+
|
| 73 |
+
_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class HTTPConnection(_HTTPConnection, object):
|
| 77 |
+
"""
|
| 78 |
+
Based on :class:`http.client.HTTPConnection` but provides an extra constructor
|
| 79 |
+
backwards-compatibility layer between older and newer Pythons.
|
| 80 |
+
|
| 81 |
+
Additional keyword parameters are used to configure attributes of the connection.
|
| 82 |
+
Accepted parameters include:
|
| 83 |
+
|
| 84 |
+
- ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
|
| 85 |
+
- ``source_address``: Set the source address for the current connection.
|
| 86 |
+
- ``socket_options``: Set specific options on the underlying socket. If not specified, then
|
| 87 |
+
defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
|
| 88 |
+
Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.
|
| 89 |
+
|
| 90 |
+
For example, if you wish to enable TCP Keep Alive in addition to the defaults,
|
| 91 |
+
you might pass:
|
| 92 |
+
|
| 93 |
+
.. code-block:: python
|
| 94 |
+
|
| 95 |
+
HTTPConnection.default_socket_options + [
|
| 96 |
+
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
|
| 97 |
+
]
|
| 98 |
+
|
| 99 |
+
Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
default_port = port_by_scheme["http"]
|
| 103 |
+
|
| 104 |
+
#: Disable Nagle's algorithm by default.
|
| 105 |
+
#: ``[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]``
|
| 106 |
+
default_socket_options = [(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]
|
| 107 |
+
|
| 108 |
+
#: Whether this connection verifies the host's certificate.
|
| 109 |
+
is_verified = False
|
| 110 |
+
|
| 111 |
+
#: Whether this proxy connection (if used) verifies the proxy host's
|
| 112 |
+
#: certificate.
|
| 113 |
+
proxy_is_verified = None
|
| 114 |
+
|
| 115 |
+
def __init__(self, *args, **kw):
|
| 116 |
+
if not six.PY2:
|
| 117 |
+
kw.pop("strict", None)
|
| 118 |
+
|
| 119 |
+
# Pre-set source_address.
|
| 120 |
+
self.source_address = kw.get("source_address")
|
| 121 |
+
|
| 122 |
+
#: The socket options provided by the user. If no options are
|
| 123 |
+
#: provided, we use the default options.
|
| 124 |
+
self.socket_options = kw.pop("socket_options", self.default_socket_options)
|
| 125 |
+
|
| 126 |
+
# Proxy options provided by the user.
|
| 127 |
+
self.proxy = kw.pop("proxy", None)
|
| 128 |
+
self.proxy_config = kw.pop("proxy_config", None)
|
| 129 |
+
|
| 130 |
+
_HTTPConnection.__init__(self, *args, **kw)
|
| 131 |
+
|
| 132 |
+
@property
|
| 133 |
+
def host(self):
|
| 134 |
+
"""
|
| 135 |
+
Getter method to remove any trailing dots that indicate the hostname is an FQDN.
|
| 136 |
+
|
| 137 |
+
In general, SSL certificates don't include the trailing dot indicating a
|
| 138 |
+
fully-qualified domain name, and thus, they don't validate properly when
|
| 139 |
+
checked against a domain name that includes the dot. In addition, some
|
| 140 |
+
servers may not expect to receive the trailing dot when provided.
|
| 141 |
+
|
| 142 |
+
However, the hostname with trailing dot is critical to DNS resolution; doing a
|
| 143 |
+
lookup with the trailing dot will properly only resolve the appropriate FQDN,
|
| 144 |
+
whereas a lookup without a trailing dot will search the system's search domain
|
| 145 |
+
list. Thus, it's important to keep the original host around for use only in
|
| 146 |
+
those cases where it's appropriate (i.e., when doing DNS lookup to establish the
|
| 147 |
+
actual TCP connection across which we're going to send HTTP requests).
|
| 148 |
+
"""
|
| 149 |
+
return self._dns_host.rstrip(".")
|
| 150 |
+
|
| 151 |
+
@host.setter
|
| 152 |
+
def host(self, value):
|
| 153 |
+
"""
|
| 154 |
+
Setter for the `host` property.
|
| 155 |
+
|
| 156 |
+
We assume that only urllib3 uses the _dns_host attribute; httplib itself
|
| 157 |
+
only uses `host`, and it seems reasonable that other libraries follow suit.
|
| 158 |
+
"""
|
| 159 |
+
self._dns_host = value
|
| 160 |
+
|
| 161 |
+
def _new_conn(self):
|
| 162 |
+
"""Establish a socket connection and set nodelay settings on it.
|
| 163 |
+
|
| 164 |
+
:return: New socket connection.
|
| 165 |
+
"""
|
| 166 |
+
extra_kw = {}
|
| 167 |
+
if self.source_address:
|
| 168 |
+
extra_kw["source_address"] = self.source_address
|
| 169 |
+
|
| 170 |
+
if self.socket_options:
|
| 171 |
+
extra_kw["socket_options"] = self.socket_options
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
conn = connection.create_connection(
|
| 175 |
+
(self._dns_host, self.port), self.timeout, **extra_kw
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
except SocketTimeout:
|
| 179 |
+
raise ConnectTimeoutError(
|
| 180 |
+
self,
|
| 181 |
+
"Connection to %s timed out. (connect timeout=%s)"
|
| 182 |
+
% (self.host, self.timeout),
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
except SocketError as e:
|
| 186 |
+
raise NewConnectionError(
|
| 187 |
+
self, "Failed to establish a new connection: %s" % e
|
| 188 |
+
)
|
| 189 |
+
|
| 190 |
+
return conn
|
| 191 |
+
|
| 192 |
+
def _is_using_tunnel(self):
|
| 193 |
+
# Google App Engine's httplib does not define _tunnel_host
|
| 194 |
+
return getattr(self, "_tunnel_host", None)
|
| 195 |
+
|
| 196 |
+
def _prepare_conn(self, conn):
|
| 197 |
+
self.sock = conn
|
| 198 |
+
if self._is_using_tunnel():
|
| 199 |
+
# TODO: Fix tunnel so it doesn't depend on self.sock state.
|
| 200 |
+
self._tunnel()
|
| 201 |
+
# Mark this connection as not reusable
|
| 202 |
+
self.auto_open = 0
|
| 203 |
+
|
| 204 |
+
def connect(self):
|
| 205 |
+
conn = self._new_conn()
|
| 206 |
+
self._prepare_conn(conn)
|
| 207 |
+
|
| 208 |
+
def putrequest(self, method, url, *args, **kwargs):
|
| 209 |
+
""" """
|
| 210 |
+
# Empty docstring because the indentation of CPython's implementation
|
| 211 |
+
# is broken but we don't want this method in our documentation.
|
| 212 |
+
match = _CONTAINS_CONTROL_CHAR_RE.search(method)
|
| 213 |
+
if match:
|
| 214 |
+
raise ValueError(
|
| 215 |
+
"Method cannot contain non-token characters %r (found at least %r)"
|
| 216 |
+
% (method, match.group())
|
| 217 |
+
)
|
| 218 |
+
|
| 219 |
+
return _HTTPConnection.putrequest(self, method, url, *args, **kwargs)
|
| 220 |
+
|
| 221 |
+
def putheader(self, header, *values):
|
| 222 |
+
""" """
|
| 223 |
+
if not any(isinstance(v, str) and v == SKIP_HEADER for v in values):
|
| 224 |
+
_HTTPConnection.putheader(self, header, *values)
|
| 225 |
+
elif six.ensure_str(header.lower()) not in SKIPPABLE_HEADERS:
|
| 226 |
+
raise ValueError(
|
| 227 |
+
"urllib3.util.SKIP_HEADER only supports '%s'"
|
| 228 |
+
% ("', '".join(map(str.title, sorted(SKIPPABLE_HEADERS))),)
|
| 229 |
+
)
|
| 230 |
+
|
| 231 |
+
def request(self, method, url, body=None, headers=None):
|
| 232 |
+
# Update the inner socket's timeout value to send the request.
|
| 233 |
+
# This only triggers if the connection is re-used.
|
| 234 |
+
if getattr(self, "sock", None) is not None:
|
| 235 |
+
self.sock.settimeout(self.timeout)
|
| 236 |
+
|
| 237 |
+
if headers is None:
|
| 238 |
+
headers = {}
|
| 239 |
+
else:
|
| 240 |
+
# Avoid modifying the headers passed into .request()
|
| 241 |
+
headers = headers.copy()
|
| 242 |
+
if "user-agent" not in (six.ensure_str(k.lower()) for k in headers):
|
| 243 |
+
headers["User-Agent"] = _get_default_user_agent()
|
| 244 |
+
super(HTTPConnection, self).request(method, url, body=body, headers=headers)
|
| 245 |
+
|
| 246 |
+
def request_chunked(self, method, url, body=None, headers=None):
|
| 247 |
+
"""
|
| 248 |
+
Alternative to the common request method, which sends the
|
| 249 |
+
body with chunked encoding and not as one block
|
| 250 |
+
"""
|
| 251 |
+
headers = headers or {}
|
| 252 |
+
header_keys = set([six.ensure_str(k.lower()) for k in headers])
|
| 253 |
+
skip_accept_encoding = "accept-encoding" in header_keys
|
| 254 |
+
skip_host = "host" in header_keys
|
| 255 |
+
self.putrequest(
|
| 256 |
+
method, url, skip_accept_encoding=skip_accept_encoding, skip_host=skip_host
|
| 257 |
+
)
|
| 258 |
+
if "user-agent" not in header_keys:
|
| 259 |
+
self.putheader("User-Agent", _get_default_user_agent())
|
| 260 |
+
for header, value in headers.items():
|
| 261 |
+
self.putheader(header, value)
|
| 262 |
+
if "transfer-encoding" not in header_keys:
|
| 263 |
+
self.putheader("Transfer-Encoding", "chunked")
|
| 264 |
+
self.endheaders()
|
| 265 |
+
|
| 266 |
+
if body is not None:
|
| 267 |
+
stringish_types = six.string_types + (bytes,)
|
| 268 |
+
if isinstance(body, stringish_types):
|
| 269 |
+
body = (body,)
|
| 270 |
+
for chunk in body:
|
| 271 |
+
if not chunk:
|
| 272 |
+
continue
|
| 273 |
+
if not isinstance(chunk, bytes):
|
| 274 |
+
chunk = chunk.encode("utf8")
|
| 275 |
+
len_str = hex(len(chunk))[2:]
|
| 276 |
+
to_send = bytearray(len_str.encode())
|
| 277 |
+
to_send += b"\r\n"
|
| 278 |
+
to_send += chunk
|
| 279 |
+
to_send += b"\r\n"
|
| 280 |
+
self.send(to_send)
|
| 281 |
+
|
| 282 |
+
# After the if clause, to always have a closed body
|
| 283 |
+
self.send(b"0\r\n\r\n")
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
class HTTPSConnection(HTTPConnection):
|
| 287 |
+
"""
|
| 288 |
+
Many of the parameters to this constructor are passed to the underlying SSL
|
| 289 |
+
socket by means of :py:func:`urllib3.util.ssl_wrap_socket`.
|
| 290 |
+
"""
|
| 291 |
+
|
| 292 |
+
default_port = port_by_scheme["https"]
|
| 293 |
+
|
| 294 |
+
cert_reqs = None
|
| 295 |
+
ca_certs = None
|
| 296 |
+
ca_cert_dir = None
|
| 297 |
+
ca_cert_data = None
|
| 298 |
+
ssl_version = None
|
| 299 |
+
assert_fingerprint = None
|
| 300 |
+
tls_in_tls_required = False
|
| 301 |
+
|
| 302 |
+
def __init__(
|
| 303 |
+
self,
|
| 304 |
+
host,
|
| 305 |
+
port=None,
|
| 306 |
+
key_file=None,
|
| 307 |
+
cert_file=None,
|
| 308 |
+
key_password=None,
|
| 309 |
+
strict=None,
|
| 310 |
+
timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
|
| 311 |
+
ssl_context=None,
|
| 312 |
+
server_hostname=None,
|
| 313 |
+
**kw
|
| 314 |
+
):
|
| 315 |
+
|
| 316 |
+
HTTPConnection.__init__(self, host, port, strict=strict, timeout=timeout, **kw)
|
| 317 |
+
|
| 318 |
+
self.key_file = key_file
|
| 319 |
+
self.cert_file = cert_file
|
| 320 |
+
self.key_password = key_password
|
| 321 |
+
self.ssl_context = ssl_context
|
| 322 |
+
self.server_hostname = server_hostname
|
| 323 |
+
|
| 324 |
+
# Required property for Google AppEngine 1.9.0 which otherwise causes
|
| 325 |
+
# HTTPS requests to go out as HTTP. (See Issue #356)
|
| 326 |
+
self._protocol = "https"
|
| 327 |
+
|
| 328 |
+
def set_cert(
|
| 329 |
+
self,
|
| 330 |
+
key_file=None,
|
| 331 |
+
cert_file=None,
|
| 332 |
+
cert_reqs=None,
|
| 333 |
+
key_password=None,
|
| 334 |
+
ca_certs=None,
|
| 335 |
+
assert_hostname=None,
|
| 336 |
+
assert_fingerprint=None,
|
| 337 |
+
ca_cert_dir=None,
|
| 338 |
+
ca_cert_data=None,
|
| 339 |
+
):
|
| 340 |
+
"""
|
| 341 |
+
This method should only be called once, before the connection is used.
|
| 342 |
+
"""
|
| 343 |
+
# If cert_reqs is not provided we'll assume CERT_REQUIRED unless we also
|
| 344 |
+
# have an SSLContext object in which case we'll use its verify_mode.
|
| 345 |
+
if cert_reqs is None:
|
| 346 |
+
if self.ssl_context is not None:
|
| 347 |
+
cert_reqs = self.ssl_context.verify_mode
|
| 348 |
+
else:
|
| 349 |
+
cert_reqs = resolve_cert_reqs(None)
|
| 350 |
+
|
| 351 |
+
self.key_file = key_file
|
| 352 |
+
self.cert_file = cert_file
|
| 353 |
+
self.cert_reqs = cert_reqs
|
| 354 |
+
self.key_password = key_password
|
| 355 |
+
self.assert_hostname = assert_hostname
|
| 356 |
+
self.assert_fingerprint = assert_fingerprint
|
| 357 |
+
self.ca_certs = ca_certs and os.path.expanduser(ca_certs)
|
| 358 |
+
self.ca_cert_dir = ca_cert_dir and os.path.expanduser(ca_cert_dir)
|
| 359 |
+
self.ca_cert_data = ca_cert_data
|
| 360 |
+
|
| 361 |
+
def connect(self):
|
| 362 |
+
# Add certificate verification
|
| 363 |
+
self.sock = conn = self._new_conn()
|
| 364 |
+
hostname = self.host
|
| 365 |
+
tls_in_tls = False
|
| 366 |
+
|
| 367 |
+
if self._is_using_tunnel():
|
| 368 |
+
if self.tls_in_tls_required:
|
| 369 |
+
self.sock = conn = self._connect_tls_proxy(hostname, conn)
|
| 370 |
+
tls_in_tls = True
|
| 371 |
+
|
| 372 |
+
# Calls self._set_hostport(), so self.host is
|
| 373 |
+
# self._tunnel_host below.
|
| 374 |
+
self._tunnel()
|
| 375 |
+
# Mark this connection as not reusable
|
| 376 |
+
self.auto_open = 0
|
| 377 |
+
|
| 378 |
+
# Override the host with the one we're requesting data from.
|
| 379 |
+
hostname = self._tunnel_host
|
| 380 |
+
|
| 381 |
+
server_hostname = hostname
|
| 382 |
+
if self.server_hostname is not None:
|
| 383 |
+
server_hostname = self.server_hostname
|
| 384 |
+
|
| 385 |
+
is_time_off = datetime.date.today() < RECENT_DATE
|
| 386 |
+
if is_time_off:
|
| 387 |
+
warnings.warn(
|
| 388 |
+
(
|
| 389 |
+
"System time is way off (before {0}). This will probably "
|
| 390 |
+
"lead to SSL verification errors"
|
| 391 |
+
).format(RECENT_DATE),
|
| 392 |
+
SystemTimeWarning,
|
| 393 |
+
)
|
| 394 |
+
|
| 395 |
+
# Wrap socket using verification with the root certs in
|
| 396 |
+
# trusted_root_certs
|
| 397 |
+
default_ssl_context = False
|
| 398 |
+
if self.ssl_context is None:
|
| 399 |
+
default_ssl_context = True
|
| 400 |
+
self.ssl_context = create_urllib3_context(
|
| 401 |
+
ssl_version=resolve_ssl_version(self.ssl_version),
|
| 402 |
+
cert_reqs=resolve_cert_reqs(self.cert_reqs),
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
context = self.ssl_context
|
| 406 |
+
context.verify_mode = resolve_cert_reqs(self.cert_reqs)
|
| 407 |
+
|
| 408 |
+
# Try to load OS default certs if none are given.
|
| 409 |
+
# Works well on Windows (requires Python3.4+)
|
| 410 |
+
if (
|
| 411 |
+
not self.ca_certs
|
| 412 |
+
and not self.ca_cert_dir
|
| 413 |
+
and not self.ca_cert_data
|
| 414 |
+
and default_ssl_context
|
| 415 |
+
and hasattr(context, "load_default_certs")
|
| 416 |
+
):
|
| 417 |
+
context.load_default_certs()
|
| 418 |
+
|
| 419 |
+
self.sock = ssl_wrap_socket(
|
| 420 |
+
sock=conn,
|
| 421 |
+
keyfile=self.key_file,
|
| 422 |
+
certfile=self.cert_file,
|
| 423 |
+
key_password=self.key_password,
|
| 424 |
+
ca_certs=self.ca_certs,
|
| 425 |
+
ca_cert_dir=self.ca_cert_dir,
|
| 426 |
+
ca_cert_data=self.ca_cert_data,
|
| 427 |
+
server_hostname=server_hostname,
|
| 428 |
+
ssl_context=context,
|
| 429 |
+
tls_in_tls=tls_in_tls,
|
| 430 |
+
)
|
| 431 |
+
|
| 432 |
+
# If we're using all defaults and the connection
|
| 433 |
+
# is TLSv1 or TLSv1.1 we throw a DeprecationWarning
|
| 434 |
+
# for the host.
|
| 435 |
+
if (
|
| 436 |
+
default_ssl_context
|
| 437 |
+
and self.ssl_version is None
|
| 438 |
+
and hasattr(self.sock, "version")
|
| 439 |
+
and self.sock.version() in {"TLSv1", "TLSv1.1"}
|
| 440 |
+
): # Defensive:
|
| 441 |
+
warnings.warn(
|
| 442 |
+
"Negotiating TLSv1/TLSv1.1 by default is deprecated "
|
| 443 |
+
"and will be disabled in urllib3 v2.0.0. Connecting to "
|
| 444 |
+
"'%s' with '%s' can be enabled by explicitly opting-in "
|
| 445 |
+
"with 'ssl_version'" % (self.host, self.sock.version()),
|
| 446 |
+
DeprecationWarning,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
if self.assert_fingerprint:
|
| 450 |
+
assert_fingerprint(
|
| 451 |
+
self.sock.getpeercert(binary_form=True), self.assert_fingerprint
|
| 452 |
+
)
|
| 453 |
+
elif (
|
| 454 |
+
context.verify_mode != ssl.CERT_NONE
|
| 455 |
+
and not getattr(context, "check_hostname", False)
|
| 456 |
+
and self.assert_hostname is not False
|
| 457 |
+
):
|
| 458 |
+
# While urllib3 attempts to always turn off hostname matching from
|
| 459 |
+
# the TLS library, this cannot always be done. So we check whether
|
| 460 |
+
# the TLS Library still thinks it's matching hostnames.
|
| 461 |
+
cert = self.sock.getpeercert()
|
| 462 |
+
if not cert.get("subjectAltName", ()):
|
| 463 |
+
warnings.warn(
|
| 464 |
+
(
|
| 465 |
+
"Certificate for {0} has no `subjectAltName`, falling back to check for a "
|
| 466 |
+
"`commonName` for now. This feature is being removed by major browsers and "
|
| 467 |
+
"deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 "
|
| 468 |
+
"for details.)".format(hostname)
|
| 469 |
+
),
|
| 470 |
+
SubjectAltNameWarning,
|
| 471 |
+
)
|
| 472 |
+
_match_hostname(cert, self.assert_hostname or server_hostname)
|
| 473 |
+
|
| 474 |
+
self.is_verified = (
|
| 475 |
+
context.verify_mode == ssl.CERT_REQUIRED
|
| 476 |
+
or self.assert_fingerprint is not None
|
| 477 |
+
)
|
| 478 |
+
|
| 479 |
+
def _connect_tls_proxy(self, hostname, conn):
|
| 480 |
+
"""
|
| 481 |
+
Establish a TLS connection to the proxy using the provided SSL context.
|
| 482 |
+
"""
|
| 483 |
+
proxy_config = self.proxy_config
|
| 484 |
+
ssl_context = proxy_config.ssl_context
|
| 485 |
+
if ssl_context:
|
| 486 |
+
# If the user provided a proxy context, we assume CA and client
|
| 487 |
+
# certificates have already been set
|
| 488 |
+
return ssl_wrap_socket(
|
| 489 |
+
sock=conn,
|
| 490 |
+
server_hostname=hostname,
|
| 491 |
+
ssl_context=ssl_context,
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
ssl_context = create_proxy_ssl_context(
|
| 495 |
+
self.ssl_version,
|
| 496 |
+
self.cert_reqs,
|
| 497 |
+
self.ca_certs,
|
| 498 |
+
self.ca_cert_dir,
|
| 499 |
+
self.ca_cert_data,
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
# If no cert was provided, use only the default options for server
|
| 503 |
+
# certificate validation
|
| 504 |
+
socket = ssl_wrap_socket(
|
| 505 |
+
sock=conn,
|
| 506 |
+
ca_certs=self.ca_certs,
|
| 507 |
+
ca_cert_dir=self.ca_cert_dir,
|
| 508 |
+
ca_cert_data=self.ca_cert_data,
|
| 509 |
+
server_hostname=hostname,
|
| 510 |
+
ssl_context=ssl_context,
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
if ssl_context.verify_mode != ssl.CERT_NONE and not getattr(
|
| 514 |
+
ssl_context, "check_hostname", False
|
| 515 |
+
):
|
| 516 |
+
# While urllib3 attempts to always turn off hostname matching from
|
| 517 |
+
# the TLS library, this cannot always be done. So we check whether
|
| 518 |
+
# the TLS Library still thinks it's matching hostnames.
|
| 519 |
+
cert = socket.getpeercert()
|
| 520 |
+
if not cert.get("subjectAltName", ()):
|
| 521 |
+
warnings.warn(
|
| 522 |
+
(
|
| 523 |
+
"Certificate for {0} has no `subjectAltName`, falling back to check for a "
|
| 524 |
+
"`commonName` for now. This feature is being removed by major browsers and "
|
| 525 |
+
"deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 "
|
| 526 |
+
"for details.)".format(hostname)
|
| 527 |
+
),
|
| 528 |
+
SubjectAltNameWarning,
|
| 529 |
+
)
|
| 530 |
+
_match_hostname(cert, hostname)
|
| 531 |
+
|
| 532 |
+
self.proxy_is_verified = ssl_context.verify_mode == ssl.CERT_REQUIRED
|
| 533 |
+
return socket
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
def _match_hostname(cert, asserted_hostname):
|
| 537 |
+
# Our upstream implementation of ssl.match_hostname()
|
| 538 |
+
# only applies this normalization to IP addresses so it doesn't
|
| 539 |
+
# match DNS SANs so we do the same thing!
|
| 540 |
+
stripped_hostname = asserted_hostname.strip("u[]")
|
| 541 |
+
if is_ipaddress(stripped_hostname):
|
| 542 |
+
asserted_hostname = stripped_hostname
|
| 543 |
+
|
| 544 |
+
try:
|
| 545 |
+
match_hostname(cert, asserted_hostname)
|
| 546 |
+
except CertificateError as e:
|
| 547 |
+
log.warning(
|
| 548 |
+
"Certificate did not match expected hostname: %s. Certificate: %s",
|
| 549 |
+
asserted_hostname,
|
| 550 |
+
cert,
|
| 551 |
+
)
|
| 552 |
+
# Add cert to exception and reraise so client code can inspect
|
| 553 |
+
# the cert when catching the exception, if they want to
|
| 554 |
+
e._peer_cert = cert
|
| 555 |
+
raise
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
def _get_default_user_agent():
|
| 559 |
+
return "python-urllib3/%s" % __version__
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
class DummyConnection(object):
|
| 563 |
+
"""Used to detect a failed ConnectionCls import."""
|
| 564 |
+
|
| 565 |
+
pass
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
if not ssl:
|
| 569 |
+
HTTPSConnection = DummyConnection # noqa: F811
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
VerifiedHTTPSConnection = HTTPSConnection
|
lib/python3.10/site-packages/urllib3/connectionpool.py
ADDED
|
@@ -0,0 +1,1140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import absolute_import
|
| 2 |
+
|
| 3 |
+
import errno
|
| 4 |
+
import logging
|
| 5 |
+
import re
|
| 6 |
+
import socket
|
| 7 |
+
import sys
|
| 8 |
+
import warnings
|
| 9 |
+
from socket import error as SocketError
|
| 10 |
+
from socket import timeout as SocketTimeout
|
| 11 |
+
|
| 12 |
+
from ._collections import HTTPHeaderDict
|
| 13 |
+
from .connection import (
|
| 14 |
+
BaseSSLError,
|
| 15 |
+
BrokenPipeError,
|
| 16 |
+
DummyConnection,
|
| 17 |
+
HTTPConnection,
|
| 18 |
+
HTTPException,
|
| 19 |
+
HTTPSConnection,
|
| 20 |
+
VerifiedHTTPSConnection,
|
| 21 |
+
port_by_scheme,
|
| 22 |
+
)
|
| 23 |
+
from .exceptions import (
|
| 24 |
+
ClosedPoolError,
|
| 25 |
+
EmptyPoolError,
|
| 26 |
+
HeaderParsingError,
|
| 27 |
+
HostChangedError,
|
| 28 |
+
InsecureRequestWarning,
|
| 29 |
+
LocationValueError,
|
| 30 |
+
MaxRetryError,
|
| 31 |
+
NewConnectionError,
|
| 32 |
+
ProtocolError,
|
| 33 |
+
ProxyError,
|
| 34 |
+
ReadTimeoutError,
|
| 35 |
+
SSLError,
|
| 36 |
+
TimeoutError,
|
| 37 |
+
)
|
| 38 |
+
from .packages import six
|
| 39 |
+
from .packages.six.moves import queue
|
| 40 |
+
from .request import RequestMethods
|
| 41 |
+
from .response import HTTPResponse
|
| 42 |
+
from .util.connection import is_connection_dropped
|
| 43 |
+
from .util.proxy import connection_requires_http_tunnel
|
| 44 |
+
from .util.queue import LifoQueue
|
| 45 |
+
from .util.request import set_file_position
|
| 46 |
+
from .util.response import assert_header_parsing
|
| 47 |
+
from .util.retry import Retry
|
| 48 |
+
from .util.ssl_match_hostname import CertificateError
|
| 49 |
+
from .util.timeout import Timeout
|
| 50 |
+
from .util.url import Url, _encode_target
|
| 51 |
+
from .util.url import _normalize_host as normalize_host
|
| 52 |
+
from .util.url import get_host, parse_url
|
| 53 |
+
|
| 54 |
+
try: # Platform-specific: Python 3
|
| 55 |
+
import weakref
|
| 56 |
+
|
| 57 |
+
weakref_finalize = weakref.finalize
|
| 58 |
+
except AttributeError: # Platform-specific: Python 2
|
| 59 |
+
from .packages.backports.weakref_finalize import weakref_finalize
|
| 60 |
+
|
| 61 |
+
xrange = six.moves.xrange
|
| 62 |
+
|
| 63 |
+
log = logging.getLogger(__name__)
|
| 64 |
+
|
| 65 |
+
_Default = object()
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Pool objects
|
| 69 |
+
class ConnectionPool(object):
|
| 70 |
+
"""
|
| 71 |
+
Base class for all connection pools, such as
|
| 72 |
+
:class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.
|
| 73 |
+
|
| 74 |
+
.. note::
|
| 75 |
+
ConnectionPool.urlopen() does not normalize or percent-encode target URIs
|
| 76 |
+
which is useful if your target server doesn't support percent-encoded
|
| 77 |
+
target URIs.
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
scheme = None
|
| 81 |
+
QueueCls = LifoQueue
|
| 82 |
+
|
| 83 |
+
def __init__(self, host, port=None):
|
| 84 |
+
if not host:
|
| 85 |
+
raise LocationValueError("No host specified.")
|
| 86 |
+
|
| 87 |
+
self.host = _normalize_host(host, scheme=self.scheme)
|
| 88 |
+
self._proxy_host = host.lower()
|
| 89 |
+
self.port = port
|
| 90 |
+
|
| 91 |
+
def __str__(self):
|
| 92 |
+
return "%s(host=%r, port=%r)" % (type(self).__name__, self.host, self.port)
|
| 93 |
+
|
| 94 |
+
def __enter__(self):
|
| 95 |
+
return self
|
| 96 |
+
|
| 97 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 98 |
+
self.close()
|
| 99 |
+
# Return False to re-raise any potential exceptions
|
| 100 |
+
return False
|
| 101 |
+
|
| 102 |
+
def close(self):
|
| 103 |
+
"""
|
| 104 |
+
Close all pooled connections and disable the pool.
|
| 105 |
+
"""
|
| 106 |
+
pass
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
# This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l252
|
| 110 |
+
_blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class HTTPConnectionPool(ConnectionPool, RequestMethods):
|
| 114 |
+
"""
|
| 115 |
+
Thread-safe connection pool for one host.
|
| 116 |
+
|
| 117 |
+
:param host:
|
| 118 |
+
Host used for this HTTP Connection (e.g. "localhost"), passed into
|
| 119 |
+
:class:`http.client.HTTPConnection`.
|
| 120 |
+
|
| 121 |
+
:param port:
|
| 122 |
+
Port used for this HTTP Connection (None is equivalent to 80), passed
|
| 123 |
+
into :class:`http.client.HTTPConnection`.
|
| 124 |
+
|
| 125 |
+
:param strict:
|
| 126 |
+
Causes BadStatusLine to be raised if the status line can't be parsed
|
| 127 |
+
as a valid HTTP/1.0 or 1.1 status line, passed into
|
| 128 |
+
:class:`http.client.HTTPConnection`.
|
| 129 |
+
|
| 130 |
+
.. note::
|
| 131 |
+
Only works in Python 2. This parameter is ignored in Python 3.
|
| 132 |
+
|
| 133 |
+
:param timeout:
|
| 134 |
+
Socket timeout in seconds for each individual connection. This can
|
| 135 |
+
be a float or integer, which sets the timeout for the HTTP request,
|
| 136 |
+
or an instance of :class:`urllib3.util.Timeout` which gives you more
|
| 137 |
+
fine-grained control over request timeouts. After the constructor has
|
| 138 |
+
been parsed, this is always a `urllib3.util.Timeout` object.
|
| 139 |
+
|
| 140 |
+
:param maxsize:
|
| 141 |
+
Number of connections to save that can be reused. More than 1 is useful
|
| 142 |
+
in multithreaded situations. If ``block`` is set to False, more
|
| 143 |
+
connections will be created but they will not be saved once they've
|
| 144 |
+
been used.
|
| 145 |
+
|
| 146 |
+
:param block:
|
| 147 |
+
If set to True, no more than ``maxsize`` connections will be used at
|
| 148 |
+
a time. When no free connections are available, the call will block
|
| 149 |
+
until a connection has been released. This is a useful side effect for
|
| 150 |
+
particular multithreaded situations where one does not want to use more
|
| 151 |
+
than maxsize connections per host to prevent flooding.
|
| 152 |
+
|
| 153 |
+
:param headers:
|
| 154 |
+
Headers to include with all requests, unless other headers are given
|
| 155 |
+
explicitly.
|
| 156 |
+
|
| 157 |
+
:param retries:
|
| 158 |
+
Retry configuration to use by default with requests in this pool.
|
| 159 |
+
|
| 160 |
+
:param _proxy:
|
| 161 |
+
Parsed proxy URL, should not be used directly, instead, see
|
| 162 |
+
:class:`urllib3.ProxyManager`
|
| 163 |
+
|
| 164 |
+
:param _proxy_headers:
|
| 165 |
+
A dictionary with proxy headers, should not be used directly,
|
| 166 |
+
instead, see :class:`urllib3.ProxyManager`
|
| 167 |
+
|
| 168 |
+
:param \\**conn_kw:
|
| 169 |
+
Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`,
|
| 170 |
+
:class:`urllib3.connection.HTTPSConnection` instances.
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
scheme = "http"
|
| 174 |
+
ConnectionCls = HTTPConnection
|
| 175 |
+
ResponseCls = HTTPResponse
|
| 176 |
+
|
| 177 |
+
def __init__(
|
| 178 |
+
self,
|
| 179 |
+
host,
|
| 180 |
+
port=None,
|
| 181 |
+
strict=False,
|
| 182 |
+
timeout=Timeout.DEFAULT_TIMEOUT,
|
| 183 |
+
maxsize=1,
|
| 184 |
+
block=False,
|
| 185 |
+
headers=None,
|
| 186 |
+
retries=None,
|
| 187 |
+
_proxy=None,
|
| 188 |
+
_proxy_headers=None,
|
| 189 |
+
_proxy_config=None,
|
| 190 |
+
**conn_kw
|
| 191 |
+
):
|
| 192 |
+
ConnectionPool.__init__(self, host, port)
|
| 193 |
+
RequestMethods.__init__(self, headers)
|
| 194 |
+
|
| 195 |
+
self.strict = strict
|
| 196 |
+
|
| 197 |
+
if not isinstance(timeout, Timeout):
|
| 198 |
+
timeout = Timeout.from_float(timeout)
|
| 199 |
+
|
| 200 |
+
if retries is None:
|
| 201 |
+
retries = Retry.DEFAULT
|
| 202 |
+
|
| 203 |
+
self.timeout = timeout
|
| 204 |
+
self.retries = retries
|
| 205 |
+
|
| 206 |
+
self.pool = self.QueueCls(maxsize)
|
| 207 |
+
self.block = block
|
| 208 |
+
|
| 209 |
+
self.proxy = _proxy
|
| 210 |
+
self.proxy_headers = _proxy_headers or {}
|
| 211 |
+
self.proxy_config = _proxy_config
|
| 212 |
+
|
| 213 |
+
# Fill the queue up so that doing get() on it will block properly
|
| 214 |
+
for _ in xrange(maxsize):
|
| 215 |
+
self.pool.put(None)
|
| 216 |
+
|
| 217 |
+
# These are mostly for testing and debugging purposes.
|
| 218 |
+
self.num_connections = 0
|
| 219 |
+
self.num_requests = 0
|
| 220 |
+
self.conn_kw = conn_kw
|
| 221 |
+
|
| 222 |
+
if self.proxy:
|
| 223 |
+
# Enable Nagle's algorithm for proxies, to avoid packet fragmentation.
|
| 224 |
+
# We cannot know if the user has added default socket options, so we cannot replace the
|
| 225 |
+
# list.
|
| 226 |
+
self.conn_kw.setdefault("socket_options", [])
|
| 227 |
+
|
| 228 |
+
self.conn_kw["proxy"] = self.proxy
|
| 229 |
+
self.conn_kw["proxy_config"] = self.proxy_config
|
| 230 |
+
|
| 231 |
+
# Do not pass 'self' as callback to 'finalize'.
|
| 232 |
+
# Then the 'finalize' would keep an endless living (leak) to self.
|
| 233 |
+
# By just passing a reference to the pool allows the garbage collector
|
| 234 |
+
# to free self if nobody else has a reference to it.
|
| 235 |
+
pool = self.pool
|
| 236 |
+
|
| 237 |
+
# Close all the HTTPConnections in the pool before the
|
| 238 |
+
# HTTPConnectionPool object is garbage collected.
|
| 239 |
+
weakref_finalize(self, _close_pool_connections, pool)
|
| 240 |
+
|
| 241 |
+
def _new_conn(self):
|
| 242 |
+
"""
|
| 243 |
+
Return a fresh :class:`HTTPConnection`.
|
| 244 |
+
"""
|
| 245 |
+
self.num_connections += 1
|
| 246 |
+
log.debug(
|
| 247 |
+
"Starting new HTTP connection (%d): %s:%s",
|
| 248 |
+
self.num_connections,
|
| 249 |
+
self.host,
|
| 250 |
+
self.port or "80",
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
conn = self.ConnectionCls(
|
| 254 |
+
host=self.host,
|
| 255 |
+
port=self.port,
|
| 256 |
+
timeout=self.timeout.connect_timeout,
|
| 257 |
+
strict=self.strict,
|
| 258 |
+
**self.conn_kw
|
| 259 |
+
)
|
| 260 |
+
return conn
|
| 261 |
+
|
| 262 |
+
def _get_conn(self, timeout=None):
|
| 263 |
+
"""
|
| 264 |
+
Get a connection. Will return a pooled connection if one is available.
|
| 265 |
+
|
| 266 |
+
If no connections are available and :prop:`.block` is ``False``, then a
|
| 267 |
+
fresh connection is returned.
|
| 268 |
+
|
| 269 |
+
:param timeout:
|
| 270 |
+
Seconds to wait before giving up and raising
|
| 271 |
+
:class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
|
| 272 |
+
:prop:`.block` is ``True``.
|
| 273 |
+
"""
|
| 274 |
+
conn = None
|
| 275 |
+
try:
|
| 276 |
+
conn = self.pool.get(block=self.block, timeout=timeout)
|
| 277 |
+
|
| 278 |
+
except AttributeError: # self.pool is None
|
| 279 |
+
raise ClosedPoolError(self, "Pool is closed.")
|
| 280 |
+
|
| 281 |
+
except queue.Empty:
|
| 282 |
+
if self.block:
|
| 283 |
+
raise EmptyPoolError(
|
| 284 |
+
self,
|
| 285 |
+
"Pool reached maximum size and no more connections are allowed.",
|
| 286 |
+
)
|
| 287 |
+
pass # Oh well, we'll create a new connection then
|
| 288 |
+
|
| 289 |
+
# If this is a persistent connection, check if it got disconnected
|
| 290 |
+
if conn and is_connection_dropped(conn):
|
| 291 |
+
log.debug("Resetting dropped connection: %s", self.host)
|
| 292 |
+
conn.close()
|
| 293 |
+
if getattr(conn, "auto_open", 1) == 0:
|
| 294 |
+
# This is a proxied connection that has been mutated by
|
| 295 |
+
# http.client._tunnel() and cannot be reused (since it would
|
| 296 |
+
# attempt to bypass the proxy)
|
| 297 |
+
conn = None
|
| 298 |
+
|
| 299 |
+
return conn or self._new_conn()
|
| 300 |
+
|
| 301 |
+
def _put_conn(self, conn):
|
| 302 |
+
"""
|
| 303 |
+
Put a connection back into the pool.
|
| 304 |
+
|
| 305 |
+
:param conn:
|
| 306 |
+
Connection object for the current host and port as returned by
|
| 307 |
+
:meth:`._new_conn` or :meth:`._get_conn`.
|
| 308 |
+
|
| 309 |
+
If the pool is already full, the connection is closed and discarded
|
| 310 |
+
because we exceeded maxsize. If connections are discarded frequently,
|
| 311 |
+
then maxsize should be increased.
|
| 312 |
+
|
| 313 |
+
If the pool is closed, then the connection will be closed and discarded.
|
| 314 |
+
"""
|
| 315 |
+
try:
|
| 316 |
+
self.pool.put(conn, block=False)
|
| 317 |
+
return # Everything is dandy, done.
|
| 318 |
+
except AttributeError:
|
| 319 |
+
# self.pool is None.
|
| 320 |
+
pass
|
| 321 |
+
except queue.Full:
|
| 322 |
+
# This should never happen if self.block == True
|
| 323 |
+
log.warning(
|
| 324 |
+
"Connection pool is full, discarding connection: %s. Connection pool size: %s",
|
| 325 |
+
self.host,
|
| 326 |
+
self.pool.qsize(),
|
| 327 |
+
)
|
| 328 |
+
# Connection never got put back into the pool, close it.
|
| 329 |
+
if conn:
|
| 330 |
+
conn.close()
|
| 331 |
+
|
| 332 |
+
def _validate_conn(self, conn):
|
| 333 |
+
"""
|
| 334 |
+
Called right before a request is made, after the socket is created.
|
| 335 |
+
"""
|
| 336 |
+
pass
|
| 337 |
+
|
| 338 |
+
def _prepare_proxy(self, conn):
|
| 339 |
+
# Nothing to do for HTTP connections.
|
| 340 |
+
pass
|
| 341 |
+
|
| 342 |
+
def _get_timeout(self, timeout):
|
| 343 |
+
"""Helper that always returns a :class:`urllib3.util.Timeout`"""
|
| 344 |
+
if timeout is _Default:
|
| 345 |
+
return self.timeout.clone()
|
| 346 |
+
|
| 347 |
+
if isinstance(timeout, Timeout):
|
| 348 |
+
return timeout.clone()
|
| 349 |
+
else:
|
| 350 |
+
# User passed us an int/float. This is for backwards compatibility,
|
| 351 |
+
# can be removed later
|
| 352 |
+
return Timeout.from_float(timeout)
|
| 353 |
+
|
| 354 |
+
def _raise_timeout(self, err, url, timeout_value):
|
| 355 |
+
"""Is the error actually a timeout? Will raise a ReadTimeout or pass"""
|
| 356 |
+
|
| 357 |
+
if isinstance(err, SocketTimeout):
|
| 358 |
+
raise ReadTimeoutError(
|
| 359 |
+
self, url, "Read timed out. (read timeout=%s)" % timeout_value
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
# See the above comment about EAGAIN in Python 3. In Python 2 we have
|
| 363 |
+
# to specifically catch it and throw the timeout error
|
| 364 |
+
if hasattr(err, "errno") and err.errno in _blocking_errnos:
|
| 365 |
+
raise ReadTimeoutError(
|
| 366 |
+
self, url, "Read timed out. (read timeout=%s)" % timeout_value
|
| 367 |
+
)
|
| 368 |
+
|
| 369 |
+
# Catch possible read timeouts thrown as SSL errors. If not the
|
| 370 |
+
# case, rethrow the original. We need to do this because of:
|
| 371 |
+
# http://bugs.python.org/issue10272
|
| 372 |
+
if "timed out" in str(err) or "did not complete (read)" in str(
|
| 373 |
+
err
|
| 374 |
+
): # Python < 2.7.4
|
| 375 |
+
raise ReadTimeoutError(
|
| 376 |
+
self, url, "Read timed out. (read timeout=%s)" % timeout_value
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
def _make_request(
|
| 380 |
+
self, conn, method, url, timeout=_Default, chunked=False, **httplib_request_kw
|
| 381 |
+
):
|
| 382 |
+
"""
|
| 383 |
+
Perform a request on a given urllib connection object taken from our
|
| 384 |
+
pool.
|
| 385 |
+
|
| 386 |
+
:param conn:
|
| 387 |
+
a connection from one of our connection pools
|
| 388 |
+
|
| 389 |
+
:param timeout:
|
| 390 |
+
Socket timeout in seconds for the request. This can be a
|
| 391 |
+
float or integer, which will set the same timeout value for
|
| 392 |
+
the socket connect and the socket read, or an instance of
|
| 393 |
+
:class:`urllib3.util.Timeout`, which gives you more fine-grained
|
| 394 |
+
control over your timeouts.
|
| 395 |
+
"""
|
| 396 |
+
self.num_requests += 1
|
| 397 |
+
|
| 398 |
+
timeout_obj = self._get_timeout(timeout)
|
| 399 |
+
timeout_obj.start_connect()
|
| 400 |
+
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
|
| 401 |
+
|
| 402 |
+
# Trigger any extra validation we need to do.
|
| 403 |
+
try:
|
| 404 |
+
self._validate_conn(conn)
|
| 405 |
+
except (SocketTimeout, BaseSSLError) as e:
|
| 406 |
+
# Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
|
| 407 |
+
self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
|
| 408 |
+
raise
|
| 409 |
+
|
| 410 |
+
# conn.request() calls http.client.*.request, not the method in
|
| 411 |
+
# urllib3.request. It also calls makefile (recv) on the socket.
|
| 412 |
+
try:
|
| 413 |
+
if chunked:
|
| 414 |
+
conn.request_chunked(method, url, **httplib_request_kw)
|
| 415 |
+
else:
|
| 416 |
+
conn.request(method, url, **httplib_request_kw)
|
| 417 |
+
|
| 418 |
+
# We are swallowing BrokenPipeError (errno.EPIPE) since the server is
|
| 419 |
+
# legitimately able to close the connection after sending a valid response.
|
| 420 |
+
# With this behaviour, the received response is still readable.
|
| 421 |
+
except BrokenPipeError:
|
| 422 |
+
# Python 3
|
| 423 |
+
pass
|
| 424 |
+
except IOError as e:
|
| 425 |
+
# Python 2 and macOS/Linux
|
| 426 |
+
# EPIPE and ESHUTDOWN are BrokenPipeError on Python 2, and EPROTOTYPE/ECONNRESET are needed on macOS
|
| 427 |
+
# https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
|
| 428 |
+
if e.errno not in {
|
| 429 |
+
errno.EPIPE,
|
| 430 |
+
errno.ESHUTDOWN,
|
| 431 |
+
errno.EPROTOTYPE,
|
| 432 |
+
errno.ECONNRESET,
|
| 433 |
+
}:
|
| 434 |
+
raise
|
| 435 |
+
|
| 436 |
+
# Reset the timeout for the recv() on the socket
|
| 437 |
+
read_timeout = timeout_obj.read_timeout
|
| 438 |
+
|
| 439 |
+
# App Engine doesn't have a sock attr
|
| 440 |
+
if getattr(conn, "sock", None):
|
| 441 |
+
# In Python 3 socket.py will catch EAGAIN and return None when you
|
| 442 |
+
# try and read into the file pointer created by http.client, which
|
| 443 |
+
# instead raises a BadStatusLine exception. Instead of catching
|
| 444 |
+
# the exception and assuming all BadStatusLine exceptions are read
|
| 445 |
+
# timeouts, check for a zero timeout before making the request.
|
| 446 |
+
if read_timeout == 0:
|
| 447 |
+
raise ReadTimeoutError(
|
| 448 |
+
self, url, "Read timed out. (read timeout=%s)" % read_timeout
|
| 449 |
+
)
|
| 450 |
+
if read_timeout is Timeout.DEFAULT_TIMEOUT:
|
| 451 |
+
conn.sock.settimeout(socket.getdefaulttimeout())
|
| 452 |
+
else: # None or a value
|
| 453 |
+
conn.sock.settimeout(read_timeout)
|
| 454 |
+
|
| 455 |
+
# Receive the response from the server
|
| 456 |
+
try:
|
| 457 |
+
try:
|
| 458 |
+
# Python 2.7, use buffering of HTTP responses
|
| 459 |
+
httplib_response = conn.getresponse(buffering=True)
|
| 460 |
+
except TypeError:
|
| 461 |
+
# Python 3
|
| 462 |
+
try:
|
| 463 |
+
httplib_response = conn.getresponse()
|
| 464 |
+
except BaseException as e:
|
| 465 |
+
# Remove the TypeError from the exception chain in
|
| 466 |
+
# Python 3 (including for exceptions like SystemExit).
|
| 467 |
+
# Otherwise it looks like a bug in the code.
|
| 468 |
+
six.raise_from(e, None)
|
| 469 |
+
except (SocketTimeout, BaseSSLError, SocketError) as e:
|
| 470 |
+
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
|
| 471 |
+
raise
|
| 472 |
+
|
| 473 |
+
# AppEngine doesn't have a version attr.
|
| 474 |
+
http_version = getattr(conn, "_http_vsn_str", "HTTP/?")
|
| 475 |
+
log.debug(
|
| 476 |
+
'%s://%s:%s "%s %s %s" %s %s',
|
| 477 |
+
self.scheme,
|
| 478 |
+
self.host,
|
| 479 |
+
self.port,
|
| 480 |
+
method,
|
| 481 |
+
url,
|
| 482 |
+
http_version,
|
| 483 |
+
httplib_response.status,
|
| 484 |
+
httplib_response.length,
|
| 485 |
+
)
|
| 486 |
+
|
| 487 |
+
try:
|
| 488 |
+
assert_header_parsing(httplib_response.msg)
|
| 489 |
+
except (HeaderParsingError, TypeError) as hpe: # Platform-specific: Python 3
|
| 490 |
+
log.warning(
|
| 491 |
+
"Failed to parse headers (url=%s): %s",
|
| 492 |
+
self._absolute_url(url),
|
| 493 |
+
hpe,
|
| 494 |
+
exc_info=True,
|
| 495 |
+
)
|
| 496 |
+
|
| 497 |
+
return httplib_response
|
| 498 |
+
|
| 499 |
+
def _absolute_url(self, path):
|
| 500 |
+
return Url(scheme=self.scheme, host=self.host, port=self.port, path=path).url
|
| 501 |
+
|
| 502 |
+
def close(self):
|
| 503 |
+
"""
|
| 504 |
+
Close all pooled connections and disable the pool.
|
| 505 |
+
"""
|
| 506 |
+
if self.pool is None:
|
| 507 |
+
return
|
| 508 |
+
# Disable access to the pool
|
| 509 |
+
old_pool, self.pool = self.pool, None
|
| 510 |
+
|
| 511 |
+
# Close all the HTTPConnections in the pool.
|
| 512 |
+
_close_pool_connections(old_pool)
|
| 513 |
+
|
| 514 |
+
def is_same_host(self, url):
|
| 515 |
+
"""
|
| 516 |
+
Check if the given ``url`` is a member of the same host as this
|
| 517 |
+
connection pool.
|
| 518 |
+
"""
|
| 519 |
+
if url.startswith("/"):
|
| 520 |
+
return True
|
| 521 |
+
|
| 522 |
+
# TODO: Add optional support for socket.gethostbyname checking.
|
| 523 |
+
scheme, host, port = get_host(url)
|
| 524 |
+
if host is not None:
|
| 525 |
+
host = _normalize_host(host, scheme=scheme)
|
| 526 |
+
|
| 527 |
+
# Use explicit default port for comparison when none is given
|
| 528 |
+
if self.port and not port:
|
| 529 |
+
port = port_by_scheme.get(scheme)
|
| 530 |
+
elif not self.port and port == port_by_scheme.get(scheme):
|
| 531 |
+
port = None
|
| 532 |
+
|
| 533 |
+
return (scheme, host, port) == (self.scheme, self.host, self.port)
|
| 534 |
+
|
| 535 |
+
def urlopen(
|
| 536 |
+
self,
|
| 537 |
+
method,
|
| 538 |
+
url,
|
| 539 |
+
body=None,
|
| 540 |
+
headers=None,
|
| 541 |
+
retries=None,
|
| 542 |
+
redirect=True,
|
| 543 |
+
assert_same_host=True,
|
| 544 |
+
timeout=_Default,
|
| 545 |
+
pool_timeout=None,
|
| 546 |
+
release_conn=None,
|
| 547 |
+
chunked=False,
|
| 548 |
+
body_pos=None,
|
| 549 |
+
**response_kw
|
| 550 |
+
):
|
| 551 |
+
"""
|
| 552 |
+
Get a connection from the pool and perform an HTTP request. This is the
|
| 553 |
+
lowest level call for making a request, so you'll need to specify all
|
| 554 |
+
the raw details.
|
| 555 |
+
|
| 556 |
+
.. note::
|
| 557 |
+
|
| 558 |
+
More commonly, it's appropriate to use a convenience method provided
|
| 559 |
+
by :class:`.RequestMethods`, such as :meth:`request`.
|
| 560 |
+
|
| 561 |
+
.. note::
|
| 562 |
+
|
| 563 |
+
`release_conn` will only behave as expected if
|
| 564 |
+
`preload_content=False` because we want to make
|
| 565 |
+
`preload_content=False` the default behaviour someday soon without
|
| 566 |
+
breaking backwards compatibility.
|
| 567 |
+
|
| 568 |
+
:param method:
|
| 569 |
+
HTTP request method (such as GET, POST, PUT, etc.)
|
| 570 |
+
|
| 571 |
+
:param url:
|
| 572 |
+
The URL to perform the request on.
|
| 573 |
+
|
| 574 |
+
:param body:
|
| 575 |
+
Data to send in the request body, either :class:`str`, :class:`bytes`,
|
| 576 |
+
an iterable of :class:`str`/:class:`bytes`, or a file-like object.
|
| 577 |
+
|
| 578 |
+
:param headers:
|
| 579 |
+
Dictionary of custom headers to send, such as User-Agent,
|
| 580 |
+
If-None-Match, etc. If None, pool headers are used. If provided,
|
| 581 |
+
these headers completely replace any pool-specific headers.
|
| 582 |
+
|
| 583 |
+
:param retries:
|
| 584 |
+
Configure the number of retries to allow before raising a
|
| 585 |
+
:class:`~urllib3.exceptions.MaxRetryError` exception.
|
| 586 |
+
|
| 587 |
+
Pass ``None`` to retry until you receive a response. Pass a
|
| 588 |
+
:class:`~urllib3.util.retry.Retry` object for fine-grained control
|
| 589 |
+
over different types of retries.
|
| 590 |
+
Pass an integer number to retry connection errors that many times,
|
| 591 |
+
but no other types of errors. Pass zero to never retry.
|
| 592 |
+
|
| 593 |
+
If ``False``, then retries are disabled and any exception is raised
|
| 594 |
+
immediately. Also, instead of raising a MaxRetryError on redirects,
|
| 595 |
+
the redirect response will be returned.
|
| 596 |
+
|
| 597 |
+
:type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
|
| 598 |
+
|
| 599 |
+
:param redirect:
|
| 600 |
+
If True, automatically handle redirects (status codes 301, 302,
|
| 601 |
+
303, 307, 308). Each redirect counts as a retry. Disabling retries
|
| 602 |
+
will disable redirect, too.
|
| 603 |
+
|
| 604 |
+
:param assert_same_host:
|
| 605 |
+
If ``True``, will make sure that the host of the pool requests is
|
| 606 |
+
consistent else will raise HostChangedError. When ``False``, you can
|
| 607 |
+
use the pool on an HTTP proxy and request foreign hosts.
|
| 608 |
+
|
| 609 |
+
:param timeout:
|
| 610 |
+
If specified, overrides the default timeout for this one
|
| 611 |
+
request. It may be a float (in seconds) or an instance of
|
| 612 |
+
:class:`urllib3.util.Timeout`.
|
| 613 |
+
|
| 614 |
+
:param pool_timeout:
|
| 615 |
+
If set and the pool is set to block=True, then this method will
|
| 616 |
+
block for ``pool_timeout`` seconds and raise EmptyPoolError if no
|
| 617 |
+
connection is available within the time period.
|
| 618 |
+
|
| 619 |
+
:param release_conn:
|
| 620 |
+
If False, then the urlopen call will not release the connection
|
| 621 |
+
back into the pool once a response is received (but will release if
|
| 622 |
+
you read the entire contents of the response such as when
|
| 623 |
+
`preload_content=True`). This is useful if you're not preloading
|
| 624 |
+
the response's content immediately. You will need to call
|
| 625 |
+
``r.release_conn()`` on the response ``r`` to return the connection
|
| 626 |
+
back into the pool. If None, it takes the value of
|
| 627 |
+
``response_kw.get('preload_content', True)``.
|
| 628 |
+
|
| 629 |
+
:param chunked:
|
| 630 |
+
If True, urllib3 will send the body using chunked transfer
|
| 631 |
+
encoding. Otherwise, urllib3 will send the body using the standard
|
| 632 |
+
content-length form. Defaults to False.
|
| 633 |
+
|
| 634 |
+
:param int body_pos:
|
| 635 |
+
Position to seek to in file-like body in the event of a retry or
|
| 636 |
+
redirect. Typically this won't need to be set because urllib3 will
|
| 637 |
+
auto-populate the value when needed.
|
| 638 |
+
|
| 639 |
+
:param \\**response_kw:
|
| 640 |
+
Additional parameters are passed to
|
| 641 |
+
:meth:`urllib3.response.HTTPResponse.from_httplib`
|
| 642 |
+
"""
|
| 643 |
+
|
| 644 |
+
parsed_url = parse_url(url)
|
| 645 |
+
destination_scheme = parsed_url.scheme
|
| 646 |
+
|
| 647 |
+
if headers is None:
|
| 648 |
+
headers = self.headers
|
| 649 |
+
|
| 650 |
+
if not isinstance(retries, Retry):
|
| 651 |
+
retries = Retry.from_int(retries, redirect=redirect, default=self.retries)
|
| 652 |
+
|
| 653 |
+
if release_conn is None:
|
| 654 |
+
release_conn = response_kw.get("preload_content", True)
|
| 655 |
+
|
| 656 |
+
# Check host
|
| 657 |
+
if assert_same_host and not self.is_same_host(url):
|
| 658 |
+
raise HostChangedError(self, url, retries)
|
| 659 |
+
|
| 660 |
+
# Ensure that the URL we're connecting to is properly encoded
|
| 661 |
+
if url.startswith("/"):
|
| 662 |
+
url = six.ensure_str(_encode_target(url))
|
| 663 |
+
else:
|
| 664 |
+
url = six.ensure_str(parsed_url.url)
|
| 665 |
+
|
| 666 |
+
conn = None
|
| 667 |
+
|
| 668 |
+
# Track whether `conn` needs to be released before
|
| 669 |
+
# returning/raising/recursing. Update this variable if necessary, and
|
| 670 |
+
# leave `release_conn` constant throughout the function. That way, if
|
| 671 |
+
# the function recurses, the original value of `release_conn` will be
|
| 672 |
+
# passed down into the recursive call, and its value will be respected.
|
| 673 |
+
#
|
| 674 |
+
# See issue #651 [1] for details.
|
| 675 |
+
#
|
| 676 |
+
# [1] <https://github.com/urllib3/urllib3/issues/651>
|
| 677 |
+
release_this_conn = release_conn
|
| 678 |
+
|
| 679 |
+
http_tunnel_required = connection_requires_http_tunnel(
|
| 680 |
+
self.proxy, self.proxy_config, destination_scheme
|
| 681 |
+
)
|
| 682 |
+
|
| 683 |
+
# Merge the proxy headers. Only done when not using HTTP CONNECT. We
|
| 684 |
+
# have to copy the headers dict so we can safely change it without those
|
| 685 |
+
# changes being reflected in anyone else's copy.
|
| 686 |
+
if not http_tunnel_required:
|
| 687 |
+
headers = headers.copy()
|
| 688 |
+
headers.update(self.proxy_headers)
|
| 689 |
+
|
| 690 |
+
# Must keep the exception bound to a separate variable or else Python 3
|
| 691 |
+
# complains about UnboundLocalError.
|
| 692 |
+
err = None
|
| 693 |
+
|
| 694 |
+
# Keep track of whether we cleanly exited the except block. This
|
| 695 |
+
# ensures we do proper cleanup in finally.
|
| 696 |
+
clean_exit = False
|
| 697 |
+
|
| 698 |
+
# Rewind body position, if needed. Record current position
|
| 699 |
+
# for future rewinds in the event of a redirect/retry.
|
| 700 |
+
body_pos = set_file_position(body, body_pos)
|
| 701 |
+
|
| 702 |
+
try:
|
| 703 |
+
# Request a connection from the queue.
|
| 704 |
+
timeout_obj = self._get_timeout(timeout)
|
| 705 |
+
conn = self._get_conn(timeout=pool_timeout)
|
| 706 |
+
|
| 707 |
+
conn.timeout = timeout_obj.connect_timeout
|
| 708 |
+
|
| 709 |
+
is_new_proxy_conn = self.proxy is not None and not getattr(
|
| 710 |
+
conn, "sock", None
|
| 711 |
+
)
|
| 712 |
+
if is_new_proxy_conn and http_tunnel_required:
|
| 713 |
+
self._prepare_proxy(conn)
|
| 714 |
+
|
| 715 |
+
# Make the request on the httplib connection object.
|
| 716 |
+
httplib_response = self._make_request(
|
| 717 |
+
conn,
|
| 718 |
+
method,
|
| 719 |
+
url,
|
| 720 |
+
timeout=timeout_obj,
|
| 721 |
+
body=body,
|
| 722 |
+
headers=headers,
|
| 723 |
+
chunked=chunked,
|
| 724 |
+
)
|
| 725 |
+
|
| 726 |
+
# If we're going to release the connection in ``finally:``, then
|
| 727 |
+
# the response doesn't need to know about the connection. Otherwise
|
| 728 |
+
# it will also try to release it and we'll have a double-release
|
| 729 |
+
# mess.
|
| 730 |
+
response_conn = conn if not release_conn else None
|
| 731 |
+
|
| 732 |
+
# Pass method to Response for length checking
|
| 733 |
+
response_kw["request_method"] = method
|
| 734 |
+
|
| 735 |
+
# Import httplib's response into our own wrapper object
|
| 736 |
+
response = self.ResponseCls.from_httplib(
|
| 737 |
+
httplib_response,
|
| 738 |
+
pool=self,
|
| 739 |
+
connection=response_conn,
|
| 740 |
+
retries=retries,
|
| 741 |
+
**response_kw
|
| 742 |
+
)
|
| 743 |
+
|
| 744 |
+
# Everything went great!
|
| 745 |
+
clean_exit = True
|
| 746 |
+
|
| 747 |
+
except EmptyPoolError:
|
| 748 |
+
# Didn't get a connection from the pool, no need to clean up
|
| 749 |
+
clean_exit = True
|
| 750 |
+
release_this_conn = False
|
| 751 |
+
raise
|
| 752 |
+
|
| 753 |
+
except (
|
| 754 |
+
TimeoutError,
|
| 755 |
+
HTTPException,
|
| 756 |
+
SocketError,
|
| 757 |
+
ProtocolError,
|
| 758 |
+
BaseSSLError,
|
| 759 |
+
SSLError,
|
| 760 |
+
CertificateError,
|
| 761 |
+
) as e:
|
| 762 |
+
# Discard the connection for these exceptions. It will be
|
| 763 |
+
# replaced during the next _get_conn() call.
|
| 764 |
+
clean_exit = False
|
| 765 |
+
|
| 766 |
+
def _is_ssl_error_message_from_http_proxy(ssl_error):
|
| 767 |
+
# We're trying to detect the message 'WRONG_VERSION_NUMBER' but
|
| 768 |
+
# SSLErrors are kinda all over the place when it comes to the message,
|
| 769 |
+
# so we try to cover our bases here!
|
| 770 |
+
message = " ".join(re.split("[^a-z]", str(ssl_error).lower()))
|
| 771 |
+
return (
|
| 772 |
+
"wrong version number" in message
|
| 773 |
+
or "unknown protocol" in message
|
| 774 |
+
or "record layer failure" in message
|
| 775 |
+
)
|
| 776 |
+
|
| 777 |
+
# Try to detect a common user error with proxies which is to
|
| 778 |
+
# set an HTTP proxy to be HTTPS when it should be 'http://'
|
| 779 |
+
# (ie {'http': 'http://proxy', 'https': 'https://proxy'})
|
| 780 |
+
# Instead we add a nice error message and point to a URL.
|
| 781 |
+
if (
|
| 782 |
+
isinstance(e, BaseSSLError)
|
| 783 |
+
and self.proxy
|
| 784 |
+
and _is_ssl_error_message_from_http_proxy(e)
|
| 785 |
+
and conn.proxy
|
| 786 |
+
and conn.proxy.scheme == "https"
|
| 787 |
+
):
|
| 788 |
+
e = ProxyError(
|
| 789 |
+
"Your proxy appears to only use HTTP and not HTTPS, "
|
| 790 |
+
"try changing your proxy URL to be HTTP. See: "
|
| 791 |
+
"https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html"
|
| 792 |
+
"#https-proxy-error-http-proxy",
|
| 793 |
+
SSLError(e),
|
| 794 |
+
)
|
| 795 |
+
elif isinstance(e, (BaseSSLError, CertificateError)):
|
| 796 |
+
e = SSLError(e)
|
| 797 |
+
elif isinstance(e, (SocketError, NewConnectionError)) and self.proxy:
|
| 798 |
+
e = ProxyError("Cannot connect to proxy.", e)
|
| 799 |
+
elif isinstance(e, (SocketError, HTTPException)):
|
| 800 |
+
e = ProtocolError("Connection aborted.", e)
|
| 801 |
+
|
| 802 |
+
retries = retries.increment(
|
| 803 |
+
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
|
| 804 |
+
)
|
| 805 |
+
retries.sleep()
|
| 806 |
+
|
| 807 |
+
# Keep track of the error for the retry warning.
|
| 808 |
+
err = e
|
| 809 |
+
|
| 810 |
+
finally:
|
| 811 |
+
if not clean_exit:
|
| 812 |
+
# We hit some kind of exception, handled or otherwise. We need
|
| 813 |
+
# to throw the connection away unless explicitly told not to.
|
| 814 |
+
# Close the connection, set the variable to None, and make sure
|
| 815 |
+
# we put the None back in the pool to avoid leaking it.
|
| 816 |
+
conn = conn and conn.close()
|
| 817 |
+
release_this_conn = True
|
| 818 |
+
|
| 819 |
+
if release_this_conn:
|
| 820 |
+
# Put the connection back to be reused. If the connection is
|
| 821 |
+
# expired then it will be None, which will get replaced with a
|
| 822 |
+
# fresh connection during _get_conn.
|
| 823 |
+
self._put_conn(conn)
|
| 824 |
+
|
| 825 |
+
if not conn:
|
| 826 |
+
# Try again
|
| 827 |
+
log.warning(
|
| 828 |
+
"Retrying (%r) after connection broken by '%r': %s", retries, err, url
|
| 829 |
+
)
|
| 830 |
+
return self.urlopen(
|
| 831 |
+
method,
|
| 832 |
+
url,
|
| 833 |
+
body,
|
| 834 |
+
headers,
|
| 835 |
+
retries,
|
| 836 |
+
redirect,
|
| 837 |
+
assert_same_host,
|
| 838 |
+
timeout=timeout,
|
| 839 |
+
pool_timeout=pool_timeout,
|
| 840 |
+
release_conn=release_conn,
|
| 841 |
+
chunked=chunked,
|
| 842 |
+
body_pos=body_pos,
|
| 843 |
+
**response_kw
|
| 844 |
+
)
|
| 845 |
+
|
| 846 |
+
# Handle redirect?
|
| 847 |
+
redirect_location = redirect and response.get_redirect_location()
|
| 848 |
+
if redirect_location:
|
| 849 |
+
if response.status == 303:
|
| 850 |
+
# Change the method according to RFC 9110, Section 15.4.4.
|
| 851 |
+
method = "GET"
|
| 852 |
+
# And lose the body not to transfer anything sensitive.
|
| 853 |
+
body = None
|
| 854 |
+
headers = HTTPHeaderDict(headers)._prepare_for_method_change()
|
| 855 |
+
|
| 856 |
+
try:
|
| 857 |
+
retries = retries.increment(method, url, response=response, _pool=self)
|
| 858 |
+
except MaxRetryError:
|
| 859 |
+
if retries.raise_on_redirect:
|
| 860 |
+
response.drain_conn()
|
| 861 |
+
raise
|
| 862 |
+
return response
|
| 863 |
+
|
| 864 |
+
response.drain_conn()
|
| 865 |
+
retries.sleep_for_retry(response)
|
| 866 |
+
log.debug("Redirecting %s -> %s", url, redirect_location)
|
| 867 |
+
return self.urlopen(
|
| 868 |
+
method,
|
| 869 |
+
redirect_location,
|
| 870 |
+
body,
|
| 871 |
+
headers,
|
| 872 |
+
retries=retries,
|
| 873 |
+
redirect=redirect,
|
| 874 |
+
assert_same_host=assert_same_host,
|
| 875 |
+
timeout=timeout,
|
| 876 |
+
pool_timeout=pool_timeout,
|
| 877 |
+
release_conn=release_conn,
|
| 878 |
+
chunked=chunked,
|
| 879 |
+
body_pos=body_pos,
|
| 880 |
+
**response_kw
|
| 881 |
+
)
|
| 882 |
+
|
| 883 |
+
# Check if we should retry the HTTP response.
|
| 884 |
+
has_retry_after = bool(response.headers.get("Retry-After"))
|
| 885 |
+
if retries.is_retry(method, response.status, has_retry_after):
|
| 886 |
+
try:
|
| 887 |
+
retries = retries.increment(method, url, response=response, _pool=self)
|
| 888 |
+
except MaxRetryError:
|
| 889 |
+
if retries.raise_on_status:
|
| 890 |
+
response.drain_conn()
|
| 891 |
+
raise
|
| 892 |
+
return response
|
| 893 |
+
|
| 894 |
+
response.drain_conn()
|
| 895 |
+
retries.sleep(response)
|
| 896 |
+
log.debug("Retry: %s", url)
|
| 897 |
+
return self.urlopen(
|
| 898 |
+
method,
|
| 899 |
+
url,
|
| 900 |
+
body,
|
| 901 |
+
headers,
|
| 902 |
+
retries=retries,
|
| 903 |
+
redirect=redirect,
|
| 904 |
+
assert_same_host=assert_same_host,
|
| 905 |
+
timeout=timeout,
|
| 906 |
+
pool_timeout=pool_timeout,
|
| 907 |
+
release_conn=release_conn,
|
| 908 |
+
chunked=chunked,
|
| 909 |
+
body_pos=body_pos,
|
| 910 |
+
**response_kw
|
| 911 |
+
)
|
| 912 |
+
|
| 913 |
+
return response
|
| 914 |
+
|
| 915 |
+
|
| 916 |
+
class HTTPSConnectionPool(HTTPConnectionPool):
|
| 917 |
+
"""
|
| 918 |
+
Same as :class:`.HTTPConnectionPool`, but HTTPS.
|
| 919 |
+
|
| 920 |
+
:class:`.HTTPSConnection` uses one of ``assert_fingerprint``,
|
| 921 |
+
``assert_hostname`` and ``host`` in this order to verify connections.
|
| 922 |
+
If ``assert_hostname`` is False, no verification is done.
|
| 923 |
+
|
| 924 |
+
The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs``,
|
| 925 |
+
``ca_cert_dir``, ``ssl_version``, ``key_password`` are only used if :mod:`ssl`
|
| 926 |
+
is available and are fed into :meth:`urllib3.util.ssl_wrap_socket` to upgrade
|
| 927 |
+
the connection socket into an SSL socket.
|
| 928 |
+
"""
|
| 929 |
+
|
| 930 |
+
scheme = "https"
|
| 931 |
+
ConnectionCls = HTTPSConnection
|
| 932 |
+
|
| 933 |
+
def __init__(
|
| 934 |
+
self,
|
| 935 |
+
host,
|
| 936 |
+
port=None,
|
| 937 |
+
strict=False,
|
| 938 |
+
timeout=Timeout.DEFAULT_TIMEOUT,
|
| 939 |
+
maxsize=1,
|
| 940 |
+
block=False,
|
| 941 |
+
headers=None,
|
| 942 |
+
retries=None,
|
| 943 |
+
_proxy=None,
|
| 944 |
+
_proxy_headers=None,
|
| 945 |
+
key_file=None,
|
| 946 |
+
cert_file=None,
|
| 947 |
+
cert_reqs=None,
|
| 948 |
+
key_password=None,
|
| 949 |
+
ca_certs=None,
|
| 950 |
+
ssl_version=None,
|
| 951 |
+
assert_hostname=None,
|
| 952 |
+
assert_fingerprint=None,
|
| 953 |
+
ca_cert_dir=None,
|
| 954 |
+
**conn_kw
|
| 955 |
+
):
|
| 956 |
+
|
| 957 |
+
HTTPConnectionPool.__init__(
|
| 958 |
+
self,
|
| 959 |
+
host,
|
| 960 |
+
port,
|
| 961 |
+
strict,
|
| 962 |
+
timeout,
|
| 963 |
+
maxsize,
|
| 964 |
+
block,
|
| 965 |
+
headers,
|
| 966 |
+
retries,
|
| 967 |
+
_proxy,
|
| 968 |
+
_proxy_headers,
|
| 969 |
+
**conn_kw
|
| 970 |
+
)
|
| 971 |
+
|
| 972 |
+
self.key_file = key_file
|
| 973 |
+
self.cert_file = cert_file
|
| 974 |
+
self.cert_reqs = cert_reqs
|
| 975 |
+
self.key_password = key_password
|
| 976 |
+
self.ca_certs = ca_certs
|
| 977 |
+
self.ca_cert_dir = ca_cert_dir
|
| 978 |
+
self.ssl_version = ssl_version
|
| 979 |
+
self.assert_hostname = assert_hostname
|
| 980 |
+
self.assert_fingerprint = assert_fingerprint
|
| 981 |
+
|
| 982 |
+
def _prepare_conn(self, conn):
|
| 983 |
+
"""
|
| 984 |
+
Prepare the ``connection`` for :meth:`urllib3.util.ssl_wrap_socket`
|
| 985 |
+
and establish the tunnel if proxy is used.
|
| 986 |
+
"""
|
| 987 |
+
|
| 988 |
+
if isinstance(conn, VerifiedHTTPSConnection):
|
| 989 |
+
conn.set_cert(
|
| 990 |
+
key_file=self.key_file,
|
| 991 |
+
key_password=self.key_password,
|
| 992 |
+
cert_file=self.cert_file,
|
| 993 |
+
cert_reqs=self.cert_reqs,
|
| 994 |
+
ca_certs=self.ca_certs,
|
| 995 |
+
ca_cert_dir=self.ca_cert_dir,
|
| 996 |
+
assert_hostname=self.assert_hostname,
|
| 997 |
+
assert_fingerprint=self.assert_fingerprint,
|
| 998 |
+
)
|
| 999 |
+
conn.ssl_version = self.ssl_version
|
| 1000 |
+
return conn
|
| 1001 |
+
|
| 1002 |
+
def _prepare_proxy(self, conn):
|
| 1003 |
+
"""
|
| 1004 |
+
Establishes a tunnel connection through HTTP CONNECT.
|
| 1005 |
+
|
| 1006 |
+
Tunnel connection is established early because otherwise httplib would
|
| 1007 |
+
improperly set Host: header to proxy's IP:port.
|
| 1008 |
+
"""
|
| 1009 |
+
|
| 1010 |
+
conn.set_tunnel(self._proxy_host, self.port, self.proxy_headers)
|
| 1011 |
+
|
| 1012 |
+
if self.proxy.scheme == "https":
|
| 1013 |
+
conn.tls_in_tls_required = True
|
| 1014 |
+
|
| 1015 |
+
conn.connect()
|
| 1016 |
+
|
| 1017 |
+
def _new_conn(self):
|
| 1018 |
+
"""
|
| 1019 |
+
Return a fresh :class:`http.client.HTTPSConnection`.
|
| 1020 |
+
"""
|
| 1021 |
+
self.num_connections += 1
|
| 1022 |
+
log.debug(
|
| 1023 |
+
"Starting new HTTPS connection (%d): %s:%s",
|
| 1024 |
+
self.num_connections,
|
| 1025 |
+
self.host,
|
| 1026 |
+
self.port or "443",
|
| 1027 |
+
)
|
| 1028 |
+
|
| 1029 |
+
if not self.ConnectionCls or self.ConnectionCls is DummyConnection:
|
| 1030 |
+
raise SSLError(
|
| 1031 |
+
"Can't connect to HTTPS URL because the SSL module is not available."
|
| 1032 |
+
)
|
| 1033 |
+
|
| 1034 |
+
actual_host = self.host
|
| 1035 |
+
actual_port = self.port
|
| 1036 |
+
if self.proxy is not None:
|
| 1037 |
+
actual_host = self.proxy.host
|
| 1038 |
+
actual_port = self.proxy.port
|
| 1039 |
+
|
| 1040 |
+
conn = self.ConnectionCls(
|
| 1041 |
+
host=actual_host,
|
| 1042 |
+
port=actual_port,
|
| 1043 |
+
timeout=self.timeout.connect_timeout,
|
| 1044 |
+
strict=self.strict,
|
| 1045 |
+
cert_file=self.cert_file,
|
| 1046 |
+
key_file=self.key_file,
|
| 1047 |
+
key_password=self.key_password,
|
| 1048 |
+
**self.conn_kw
|
| 1049 |
+
)
|
| 1050 |
+
|
| 1051 |
+
return self._prepare_conn(conn)
|
| 1052 |
+
|
| 1053 |
+
def _validate_conn(self, conn):
|
| 1054 |
+
"""
|
| 1055 |
+
Called right before a request is made, after the socket is created.
|
| 1056 |
+
"""
|
| 1057 |
+
super(HTTPSConnectionPool, self)._validate_conn(conn)
|
| 1058 |
+
|
| 1059 |
+
# Force connect early to allow us to validate the connection.
|
| 1060 |
+
if not getattr(conn, "sock", None): # AppEngine might not have `.sock`
|
| 1061 |
+
conn.connect()
|
| 1062 |
+
|
| 1063 |
+
if not conn.is_verified:
|
| 1064 |
+
warnings.warn(
|
| 1065 |
+
(
|
| 1066 |
+
"Unverified HTTPS request is being made to host '%s'. "
|
| 1067 |
+
"Adding certificate verification is strongly advised. See: "
|
| 1068 |
+
"https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html"
|
| 1069 |
+
"#ssl-warnings" % conn.host
|
| 1070 |
+
),
|
| 1071 |
+
InsecureRequestWarning,
|
| 1072 |
+
)
|
| 1073 |
+
|
| 1074 |
+
if getattr(conn, "proxy_is_verified", None) is False:
|
| 1075 |
+
warnings.warn(
|
| 1076 |
+
(
|
| 1077 |
+
"Unverified HTTPS connection done to an HTTPS proxy. "
|
| 1078 |
+
"Adding certificate verification is strongly advised. See: "
|
| 1079 |
+
"https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html"
|
| 1080 |
+
"#ssl-warnings"
|
| 1081 |
+
),
|
| 1082 |
+
InsecureRequestWarning,
|
| 1083 |
+
)
|
| 1084 |
+
|
| 1085 |
+
|
| 1086 |
+
def connection_from_url(url, **kw):
|
| 1087 |
+
"""
|
| 1088 |
+
Given a url, return an :class:`.ConnectionPool` instance of its host.
|
| 1089 |
+
|
| 1090 |
+
This is a shortcut for not having to parse out the scheme, host, and port
|
| 1091 |
+
of the url before creating an :class:`.ConnectionPool` instance.
|
| 1092 |
+
|
| 1093 |
+
:param url:
|
| 1094 |
+
Absolute URL string that must include the scheme. Port is optional.
|
| 1095 |
+
|
| 1096 |
+
:param \\**kw:
|
| 1097 |
+
Passes additional parameters to the constructor of the appropriate
|
| 1098 |
+
:class:`.ConnectionPool`. Useful for specifying things like
|
| 1099 |
+
timeout, maxsize, headers, etc.
|
| 1100 |
+
|
| 1101 |
+
Example::
|
| 1102 |
+
|
| 1103 |
+
>>> conn = connection_from_url('http://google.com/')
|
| 1104 |
+
>>> r = conn.request('GET', '/')
|
| 1105 |
+
"""
|
| 1106 |
+
scheme, host, port = get_host(url)
|
| 1107 |
+
port = port or port_by_scheme.get(scheme, 80)
|
| 1108 |
+
if scheme == "https":
|
| 1109 |
+
return HTTPSConnectionPool(host, port=port, **kw)
|
| 1110 |
+
else:
|
| 1111 |
+
return HTTPConnectionPool(host, port=port, **kw)
|
| 1112 |
+
|
| 1113 |
+
|
| 1114 |
+
def _normalize_host(host, scheme):
|
| 1115 |
+
"""
|
| 1116 |
+
Normalize hosts for comparisons and use with sockets.
|
| 1117 |
+
"""
|
| 1118 |
+
|
| 1119 |
+
host = normalize_host(host, scheme)
|
| 1120 |
+
|
| 1121 |
+
# httplib doesn't like it when we include brackets in IPv6 addresses
|
| 1122 |
+
# Specifically, if we include brackets but also pass the port then
|
| 1123 |
+
# httplib crazily doubles up the square brackets on the Host header.
|
| 1124 |
+
# Instead, we need to make sure we never pass ``None`` as the port.
|
| 1125 |
+
# However, for backward compatibility reasons we can't actually
|
| 1126 |
+
# *assert* that. See http://bugs.python.org/issue28539
|
| 1127 |
+
if host.startswith("[") and host.endswith("]"):
|
| 1128 |
+
host = host[1:-1]
|
| 1129 |
+
return host
|
| 1130 |
+
|
| 1131 |
+
|
| 1132 |
+
def _close_pool_connections(pool):
|
| 1133 |
+
"""Drains a queue of connections and closes each one."""
|
| 1134 |
+
try:
|
| 1135 |
+
while True:
|
| 1136 |
+
conn = pool.get(block=False)
|
| 1137 |
+
if conn:
|
| 1138 |
+
conn.close()
|
| 1139 |
+
except queue.Empty:
|
| 1140 |
+
pass # Done.
|
lib/python3.10/site-packages/urllib3/contrib/__init__.py
ADDED
|
File without changes
|
lib/python3.10/site-packages/urllib3/contrib/_appengine_environ.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module provides means to detect the App Engine environment.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def is_appengine():
|
| 9 |
+
return is_local_appengine() or is_prod_appengine()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def is_appengine_sandbox():
|
| 13 |
+
"""Reports if the app is running in the first generation sandbox.
|
| 14 |
+
|
| 15 |
+
The second generation runtimes are technically still in a sandbox, but it
|
| 16 |
+
is much less restrictive, so generally you shouldn't need to check for it.
|
| 17 |
+
see https://cloud.google.com/appengine/docs/standard/runtimes
|
| 18 |
+
"""
|
| 19 |
+
return is_appengine() and os.environ["APPENGINE_RUNTIME"] == "python27"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def is_local_appengine():
|
| 23 |
+
return "APPENGINE_RUNTIME" in os.environ and os.environ.get(
|
| 24 |
+
"SERVER_SOFTWARE", ""
|
| 25 |
+
).startswith("Development/")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def is_prod_appengine():
|
| 29 |
+
return "APPENGINE_RUNTIME" in os.environ and os.environ.get(
|
| 30 |
+
"SERVER_SOFTWARE", ""
|
| 31 |
+
).startswith("Google App Engine/")
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def is_prod_appengine_mvms():
|
| 35 |
+
"""Deprecated."""
|
| 36 |
+
return False
|
lib/python3.10/site-packages/urllib3/contrib/_securetransport/__init__.py
ADDED
|
File without changes
|
lib/python3.10/site-packages/urllib3/contrib/_securetransport/bindings.py
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module uses ctypes to bind a whole bunch of functions and constants from
|
| 3 |
+
SecureTransport. The goal here is to provide the low-level API to
|
| 4 |
+
SecureTransport. These are essentially the C-level functions and constants, and
|
| 5 |
+
they're pretty gross to work with.
|
| 6 |
+
|
| 7 |
+
This code is a bastardised version of the code found in Will Bond's oscrypto
|
| 8 |
+
library. An enormous debt is owed to him for blazing this trail for us. For
|
| 9 |
+
that reason, this code should be considered to be covered both by urllib3's
|
| 10 |
+
license and by oscrypto's:
|
| 11 |
+
|
| 12 |
+
Copyright (c) 2015-2016 Will Bond <will@wbond.net>
|
| 13 |
+
|
| 14 |
+
Permission is hereby granted, free of charge, to any person obtaining a
|
| 15 |
+
copy of this software and associated documentation files (the "Software"),
|
| 16 |
+
to deal in the Software without restriction, including without limitation
|
| 17 |
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
| 18 |
+
and/or sell copies of the Software, and to permit persons to whom the
|
| 19 |
+
Software is furnished to do so, subject to the following conditions:
|
| 20 |
+
|
| 21 |
+
The above copyright notice and this permission notice shall be included in
|
| 22 |
+
all copies or substantial portions of the Software.
|
| 23 |
+
|
| 24 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 25 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 26 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 27 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 28 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 29 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
| 30 |
+
DEALINGS IN THE SOFTWARE.
|
| 31 |
+
"""
|
| 32 |
+
from __future__ import absolute_import
|
| 33 |
+
|
| 34 |
+
import platform
|
| 35 |
+
from ctypes import (
|
| 36 |
+
CDLL,
|
| 37 |
+
CFUNCTYPE,
|
| 38 |
+
POINTER,
|
| 39 |
+
c_bool,
|
| 40 |
+
c_byte,
|
| 41 |
+
c_char_p,
|
| 42 |
+
c_int32,
|
| 43 |
+
c_long,
|
| 44 |
+
c_size_t,
|
| 45 |
+
c_uint32,
|
| 46 |
+
c_ulong,
|
| 47 |
+
c_void_p,
|
| 48 |
+
)
|
| 49 |
+
from ctypes.util import find_library
|
| 50 |
+
|
| 51 |
+
from ...packages.six import raise_from
|
| 52 |
+
|
| 53 |
+
if platform.system() != "Darwin":
|
| 54 |
+
raise ImportError("Only macOS is supported")
|
| 55 |
+
|
| 56 |
+
version = platform.mac_ver()[0]
|
| 57 |
+
version_info = tuple(map(int, version.split(".")))
|
| 58 |
+
if version_info < (10, 8):
|
| 59 |
+
raise OSError(
|
| 60 |
+
"Only OS X 10.8 and newer are supported, not %s.%s"
|
| 61 |
+
% (version_info[0], version_info[1])
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def load_cdll(name, macos10_16_path):
|
| 66 |
+
"""Loads a CDLL by name, falling back to known path on 10.16+"""
|
| 67 |
+
try:
|
| 68 |
+
# Big Sur is technically 11 but we use 10.16 due to the Big Sur
|
| 69 |
+
# beta being labeled as 10.16.
|
| 70 |
+
if version_info >= (10, 16):
|
| 71 |
+
path = macos10_16_path
|
| 72 |
+
else:
|
| 73 |
+
path = find_library(name)
|
| 74 |
+
if not path:
|
| 75 |
+
raise OSError # Caught and reraised as 'ImportError'
|
| 76 |
+
return CDLL(path, use_errno=True)
|
| 77 |
+
except OSError:
|
| 78 |
+
raise_from(ImportError("The library %s failed to load" % name), None)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
Security = load_cdll(
|
| 82 |
+
"Security", "/System/Library/Frameworks/Security.framework/Security"
|
| 83 |
+
)
|
| 84 |
+
CoreFoundation = load_cdll(
|
| 85 |
+
"CoreFoundation",
|
| 86 |
+
"/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation",
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
Boolean = c_bool
|
| 91 |
+
CFIndex = c_long
|
| 92 |
+
CFStringEncoding = c_uint32
|
| 93 |
+
CFData = c_void_p
|
| 94 |
+
CFString = c_void_p
|
| 95 |
+
CFArray = c_void_p
|
| 96 |
+
CFMutableArray = c_void_p
|
| 97 |
+
CFDictionary = c_void_p
|
| 98 |
+
CFError = c_void_p
|
| 99 |
+
CFType = c_void_p
|
| 100 |
+
CFTypeID = c_ulong
|
| 101 |
+
|
| 102 |
+
CFTypeRef = POINTER(CFType)
|
| 103 |
+
CFAllocatorRef = c_void_p
|
| 104 |
+
|
| 105 |
+
OSStatus = c_int32
|
| 106 |
+
|
| 107 |
+
CFDataRef = POINTER(CFData)
|
| 108 |
+
CFStringRef = POINTER(CFString)
|
| 109 |
+
CFArrayRef = POINTER(CFArray)
|
| 110 |
+
CFMutableArrayRef = POINTER(CFMutableArray)
|
| 111 |
+
CFDictionaryRef = POINTER(CFDictionary)
|
| 112 |
+
CFArrayCallBacks = c_void_p
|
| 113 |
+
CFDictionaryKeyCallBacks = c_void_p
|
| 114 |
+
CFDictionaryValueCallBacks = c_void_p
|
| 115 |
+
|
| 116 |
+
SecCertificateRef = POINTER(c_void_p)
|
| 117 |
+
SecExternalFormat = c_uint32
|
| 118 |
+
SecExternalItemType = c_uint32
|
| 119 |
+
SecIdentityRef = POINTER(c_void_p)
|
| 120 |
+
SecItemImportExportFlags = c_uint32
|
| 121 |
+
SecItemImportExportKeyParameters = c_void_p
|
| 122 |
+
SecKeychainRef = POINTER(c_void_p)
|
| 123 |
+
SSLProtocol = c_uint32
|
| 124 |
+
SSLCipherSuite = c_uint32
|
| 125 |
+
SSLContextRef = POINTER(c_void_p)
|
| 126 |
+
SecTrustRef = POINTER(c_void_p)
|
| 127 |
+
SSLConnectionRef = c_uint32
|
| 128 |
+
SecTrustResultType = c_uint32
|
| 129 |
+
SecTrustOptionFlags = c_uint32
|
| 130 |
+
SSLProtocolSide = c_uint32
|
| 131 |
+
SSLConnectionType = c_uint32
|
| 132 |
+
SSLSessionOption = c_uint32
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
try:
|
| 136 |
+
Security.SecItemImport.argtypes = [
|
| 137 |
+
CFDataRef,
|
| 138 |
+
CFStringRef,
|
| 139 |
+
POINTER(SecExternalFormat),
|
| 140 |
+
POINTER(SecExternalItemType),
|
| 141 |
+
SecItemImportExportFlags,
|
| 142 |
+
POINTER(SecItemImportExportKeyParameters),
|
| 143 |
+
SecKeychainRef,
|
| 144 |
+
POINTER(CFArrayRef),
|
| 145 |
+
]
|
| 146 |
+
Security.SecItemImport.restype = OSStatus
|
| 147 |
+
|
| 148 |
+
Security.SecCertificateGetTypeID.argtypes = []
|
| 149 |
+
Security.SecCertificateGetTypeID.restype = CFTypeID
|
| 150 |
+
|
| 151 |
+
Security.SecIdentityGetTypeID.argtypes = []
|
| 152 |
+
Security.SecIdentityGetTypeID.restype = CFTypeID
|
| 153 |
+
|
| 154 |
+
Security.SecKeyGetTypeID.argtypes = []
|
| 155 |
+
Security.SecKeyGetTypeID.restype = CFTypeID
|
| 156 |
+
|
| 157 |
+
Security.SecCertificateCreateWithData.argtypes = [CFAllocatorRef, CFDataRef]
|
| 158 |
+
Security.SecCertificateCreateWithData.restype = SecCertificateRef
|
| 159 |
+
|
| 160 |
+
Security.SecCertificateCopyData.argtypes = [SecCertificateRef]
|
| 161 |
+
Security.SecCertificateCopyData.restype = CFDataRef
|
| 162 |
+
|
| 163 |
+
Security.SecCopyErrorMessageString.argtypes = [OSStatus, c_void_p]
|
| 164 |
+
Security.SecCopyErrorMessageString.restype = CFStringRef
|
| 165 |
+
|
| 166 |
+
Security.SecIdentityCreateWithCertificate.argtypes = [
|
| 167 |
+
CFTypeRef,
|
| 168 |
+
SecCertificateRef,
|
| 169 |
+
POINTER(SecIdentityRef),
|
| 170 |
+
]
|
| 171 |
+
Security.SecIdentityCreateWithCertificate.restype = OSStatus
|
| 172 |
+
|
| 173 |
+
Security.SecKeychainCreate.argtypes = [
|
| 174 |
+
c_char_p,
|
| 175 |
+
c_uint32,
|
| 176 |
+
c_void_p,
|
| 177 |
+
Boolean,
|
| 178 |
+
c_void_p,
|
| 179 |
+
POINTER(SecKeychainRef),
|
| 180 |
+
]
|
| 181 |
+
Security.SecKeychainCreate.restype = OSStatus
|
| 182 |
+
|
| 183 |
+
Security.SecKeychainDelete.argtypes = [SecKeychainRef]
|
| 184 |
+
Security.SecKeychainDelete.restype = OSStatus
|
| 185 |
+
|
| 186 |
+
Security.SecPKCS12Import.argtypes = [
|
| 187 |
+
CFDataRef,
|
| 188 |
+
CFDictionaryRef,
|
| 189 |
+
POINTER(CFArrayRef),
|
| 190 |
+
]
|
| 191 |
+
Security.SecPKCS12Import.restype = OSStatus
|
| 192 |
+
|
| 193 |
+
SSLReadFunc = CFUNCTYPE(OSStatus, SSLConnectionRef, c_void_p, POINTER(c_size_t))
|
| 194 |
+
SSLWriteFunc = CFUNCTYPE(
|
| 195 |
+
OSStatus, SSLConnectionRef, POINTER(c_byte), POINTER(c_size_t)
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
Security.SSLSetIOFuncs.argtypes = [SSLContextRef, SSLReadFunc, SSLWriteFunc]
|
| 199 |
+
Security.SSLSetIOFuncs.restype = OSStatus
|
| 200 |
+
|
| 201 |
+
Security.SSLSetPeerID.argtypes = [SSLContextRef, c_char_p, c_size_t]
|
| 202 |
+
Security.SSLSetPeerID.restype = OSStatus
|
| 203 |
+
|
| 204 |
+
Security.SSLSetCertificate.argtypes = [SSLContextRef, CFArrayRef]
|
| 205 |
+
Security.SSLSetCertificate.restype = OSStatus
|
| 206 |
+
|
| 207 |
+
Security.SSLSetCertificateAuthorities.argtypes = [SSLContextRef, CFTypeRef, Boolean]
|
| 208 |
+
Security.SSLSetCertificateAuthorities.restype = OSStatus
|
| 209 |
+
|
| 210 |
+
Security.SSLSetConnection.argtypes = [SSLContextRef, SSLConnectionRef]
|
| 211 |
+
Security.SSLSetConnection.restype = OSStatus
|
| 212 |
+
|
| 213 |
+
Security.SSLSetPeerDomainName.argtypes = [SSLContextRef, c_char_p, c_size_t]
|
| 214 |
+
Security.SSLSetPeerDomainName.restype = OSStatus
|
| 215 |
+
|
| 216 |
+
Security.SSLHandshake.argtypes = [SSLContextRef]
|
| 217 |
+
Security.SSLHandshake.restype = OSStatus
|
| 218 |
+
|
| 219 |
+
Security.SSLRead.argtypes = [SSLContextRef, c_char_p, c_size_t, POINTER(c_size_t)]
|
| 220 |
+
Security.SSLRead.restype = OSStatus
|
| 221 |
+
|
| 222 |
+
Security.SSLWrite.argtypes = [SSLContextRef, c_char_p, c_size_t, POINTER(c_size_t)]
|
| 223 |
+
Security.SSLWrite.restype = OSStatus
|
| 224 |
+
|
| 225 |
+
Security.SSLClose.argtypes = [SSLContextRef]
|
| 226 |
+
Security.SSLClose.restype = OSStatus
|
| 227 |
+
|
| 228 |
+
Security.SSLGetNumberSupportedCiphers.argtypes = [SSLContextRef, POINTER(c_size_t)]
|
| 229 |
+
Security.SSLGetNumberSupportedCiphers.restype = OSStatus
|
| 230 |
+
|
| 231 |
+
Security.SSLGetSupportedCiphers.argtypes = [
|
| 232 |
+
SSLContextRef,
|
| 233 |
+
POINTER(SSLCipherSuite),
|
| 234 |
+
POINTER(c_size_t),
|
| 235 |
+
]
|
| 236 |
+
Security.SSLGetSupportedCiphers.restype = OSStatus
|
| 237 |
+
|
| 238 |
+
Security.SSLSetEnabledCiphers.argtypes = [
|
| 239 |
+
SSLContextRef,
|
| 240 |
+
POINTER(SSLCipherSuite),
|
| 241 |
+
c_size_t,
|
| 242 |
+
]
|
| 243 |
+
Security.SSLSetEnabledCiphers.restype = OSStatus
|
| 244 |
+
|
| 245 |
+
Security.SSLGetNumberEnabledCiphers.argtype = [SSLContextRef, POINTER(c_size_t)]
|
| 246 |
+
Security.SSLGetNumberEnabledCiphers.restype = OSStatus
|
| 247 |
+
|
| 248 |
+
Security.SSLGetEnabledCiphers.argtypes = [
|
| 249 |
+
SSLContextRef,
|
| 250 |
+
POINTER(SSLCipherSuite),
|
| 251 |
+
POINTER(c_size_t),
|
| 252 |
+
]
|
| 253 |
+
Security.SSLGetEnabledCiphers.restype = OSStatus
|
| 254 |
+
|
| 255 |
+
Security.SSLGetNegotiatedCipher.argtypes = [SSLContextRef, POINTER(SSLCipherSuite)]
|
| 256 |
+
Security.SSLGetNegotiatedCipher.restype = OSStatus
|
| 257 |
+
|
| 258 |
+
Security.SSLGetNegotiatedProtocolVersion.argtypes = [
|
| 259 |
+
SSLContextRef,
|
| 260 |
+
POINTER(SSLProtocol),
|
| 261 |
+
]
|
| 262 |
+
Security.SSLGetNegotiatedProtocolVersion.restype = OSStatus
|
| 263 |
+
|
| 264 |
+
Security.SSLCopyPeerTrust.argtypes = [SSLContextRef, POINTER(SecTrustRef)]
|
| 265 |
+
Security.SSLCopyPeerTrust.restype = OSStatus
|
| 266 |
+
|
| 267 |
+
Security.SecTrustSetAnchorCertificates.argtypes = [SecTrustRef, CFArrayRef]
|
| 268 |
+
Security.SecTrustSetAnchorCertificates.restype = OSStatus
|
| 269 |
+
|
| 270 |
+
Security.SecTrustSetAnchorCertificatesOnly.argstypes = [SecTrustRef, Boolean]
|
| 271 |
+
Security.SecTrustSetAnchorCertificatesOnly.restype = OSStatus
|
| 272 |
+
|
| 273 |
+
Security.SecTrustEvaluate.argtypes = [SecTrustRef, POINTER(SecTrustResultType)]
|
| 274 |
+
Security.SecTrustEvaluate.restype = OSStatus
|
| 275 |
+
|
| 276 |
+
Security.SecTrustGetCertificateCount.argtypes = [SecTrustRef]
|
| 277 |
+
Security.SecTrustGetCertificateCount.restype = CFIndex
|
| 278 |
+
|
| 279 |
+
Security.SecTrustGetCertificateAtIndex.argtypes = [SecTrustRef, CFIndex]
|
| 280 |
+
Security.SecTrustGetCertificateAtIndex.restype = SecCertificateRef
|
| 281 |
+
|
| 282 |
+
Security.SSLCreateContext.argtypes = [
|
| 283 |
+
CFAllocatorRef,
|
| 284 |
+
SSLProtocolSide,
|
| 285 |
+
SSLConnectionType,
|
| 286 |
+
]
|
| 287 |
+
Security.SSLCreateContext.restype = SSLContextRef
|
| 288 |
+
|
| 289 |
+
Security.SSLSetSessionOption.argtypes = [SSLContextRef, SSLSessionOption, Boolean]
|
| 290 |
+
Security.SSLSetSessionOption.restype = OSStatus
|
| 291 |
+
|
| 292 |
+
Security.SSLSetProtocolVersionMin.argtypes = [SSLContextRef, SSLProtocol]
|
| 293 |
+
Security.SSLSetProtocolVersionMin.restype = OSStatus
|
| 294 |
+
|
| 295 |
+
Security.SSLSetProtocolVersionMax.argtypes = [SSLContextRef, SSLProtocol]
|
| 296 |
+
Security.SSLSetProtocolVersionMax.restype = OSStatus
|
| 297 |
+
|
| 298 |
+
try:
|
| 299 |
+
Security.SSLSetALPNProtocols.argtypes = [SSLContextRef, CFArrayRef]
|
| 300 |
+
Security.SSLSetALPNProtocols.restype = OSStatus
|
| 301 |
+
except AttributeError:
|
| 302 |
+
# Supported only in 10.12+
|
| 303 |
+
pass
|
| 304 |
+
|
| 305 |
+
Security.SecCopyErrorMessageString.argtypes = [OSStatus, c_void_p]
|
| 306 |
+
Security.SecCopyErrorMessageString.restype = CFStringRef
|
| 307 |
+
|
| 308 |
+
Security.SSLReadFunc = SSLReadFunc
|
| 309 |
+
Security.SSLWriteFunc = SSLWriteFunc
|
| 310 |
+
Security.SSLContextRef = SSLContextRef
|
| 311 |
+
Security.SSLProtocol = SSLProtocol
|
| 312 |
+
Security.SSLCipherSuite = SSLCipherSuite
|
| 313 |
+
Security.SecIdentityRef = SecIdentityRef
|
| 314 |
+
Security.SecKeychainRef = SecKeychainRef
|
| 315 |
+
Security.SecTrustRef = SecTrustRef
|
| 316 |
+
Security.SecTrustResultType = SecTrustResultType
|
| 317 |
+
Security.SecExternalFormat = SecExternalFormat
|
| 318 |
+
Security.OSStatus = OSStatus
|
| 319 |
+
|
| 320 |
+
Security.kSecImportExportPassphrase = CFStringRef.in_dll(
|
| 321 |
+
Security, "kSecImportExportPassphrase"
|
| 322 |
+
)
|
| 323 |
+
Security.kSecImportItemIdentity = CFStringRef.in_dll(
|
| 324 |
+
Security, "kSecImportItemIdentity"
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
# CoreFoundation time!
|
| 328 |
+
CoreFoundation.CFRetain.argtypes = [CFTypeRef]
|
| 329 |
+
CoreFoundation.CFRetain.restype = CFTypeRef
|
| 330 |
+
|
| 331 |
+
CoreFoundation.CFRelease.argtypes = [CFTypeRef]
|
| 332 |
+
CoreFoundation.CFRelease.restype = None
|
| 333 |
+
|
| 334 |
+
CoreFoundation.CFGetTypeID.argtypes = [CFTypeRef]
|
| 335 |
+
CoreFoundation.CFGetTypeID.restype = CFTypeID
|
| 336 |
+
|
| 337 |
+
CoreFoundation.CFStringCreateWithCString.argtypes = [
|
| 338 |
+
CFAllocatorRef,
|
| 339 |
+
c_char_p,
|
| 340 |
+
CFStringEncoding,
|
| 341 |
+
]
|
| 342 |
+
CoreFoundation.CFStringCreateWithCString.restype = CFStringRef
|
| 343 |
+
|
| 344 |
+
CoreFoundation.CFStringGetCStringPtr.argtypes = [CFStringRef, CFStringEncoding]
|
| 345 |
+
CoreFoundation.CFStringGetCStringPtr.restype = c_char_p
|
| 346 |
+
|
| 347 |
+
CoreFoundation.CFStringGetCString.argtypes = [
|
| 348 |
+
CFStringRef,
|
| 349 |
+
c_char_p,
|
| 350 |
+
CFIndex,
|
| 351 |
+
CFStringEncoding,
|
| 352 |
+
]
|
| 353 |
+
CoreFoundation.CFStringGetCString.restype = c_bool
|
| 354 |
+
|
| 355 |
+
CoreFoundation.CFDataCreate.argtypes = [CFAllocatorRef, c_char_p, CFIndex]
|
| 356 |
+
CoreFoundation.CFDataCreate.restype = CFDataRef
|
| 357 |
+
|
| 358 |
+
CoreFoundation.CFDataGetLength.argtypes = [CFDataRef]
|
| 359 |
+
CoreFoundation.CFDataGetLength.restype = CFIndex
|
| 360 |
+
|
| 361 |
+
CoreFoundation.CFDataGetBytePtr.argtypes = [CFDataRef]
|
| 362 |
+
CoreFoundation.CFDataGetBytePtr.restype = c_void_p
|
| 363 |
+
|
| 364 |
+
CoreFoundation.CFDictionaryCreate.argtypes = [
|
| 365 |
+
CFAllocatorRef,
|
| 366 |
+
POINTER(CFTypeRef),
|
| 367 |
+
POINTER(CFTypeRef),
|
| 368 |
+
CFIndex,
|
| 369 |
+
CFDictionaryKeyCallBacks,
|
| 370 |
+
CFDictionaryValueCallBacks,
|
| 371 |
+
]
|
| 372 |
+
CoreFoundation.CFDictionaryCreate.restype = CFDictionaryRef
|
| 373 |
+
|
| 374 |
+
CoreFoundation.CFDictionaryGetValue.argtypes = [CFDictionaryRef, CFTypeRef]
|
| 375 |
+
CoreFoundation.CFDictionaryGetValue.restype = CFTypeRef
|
| 376 |
+
|
| 377 |
+
CoreFoundation.CFArrayCreate.argtypes = [
|
| 378 |
+
CFAllocatorRef,
|
| 379 |
+
POINTER(CFTypeRef),
|
| 380 |
+
CFIndex,
|
| 381 |
+
CFArrayCallBacks,
|
| 382 |
+
]
|
| 383 |
+
CoreFoundation.CFArrayCreate.restype = CFArrayRef
|
| 384 |
+
|
| 385 |
+
CoreFoundation.CFArrayCreateMutable.argtypes = [
|
| 386 |
+
CFAllocatorRef,
|
| 387 |
+
CFIndex,
|
| 388 |
+
CFArrayCallBacks,
|
| 389 |
+
]
|
| 390 |
+
CoreFoundation.CFArrayCreateMutable.restype = CFMutableArrayRef
|
| 391 |
+
|
| 392 |
+
CoreFoundation.CFArrayAppendValue.argtypes = [CFMutableArrayRef, c_void_p]
|
| 393 |
+
CoreFoundation.CFArrayAppendValue.restype = None
|
| 394 |
+
|
| 395 |
+
CoreFoundation.CFArrayGetCount.argtypes = [CFArrayRef]
|
| 396 |
+
CoreFoundation.CFArrayGetCount.restype = CFIndex
|
| 397 |
+
|
| 398 |
+
CoreFoundation.CFArrayGetValueAtIndex.argtypes = [CFArrayRef, CFIndex]
|
| 399 |
+
CoreFoundation.CFArrayGetValueAtIndex.restype = c_void_p
|
| 400 |
+
|
| 401 |
+
CoreFoundation.kCFAllocatorDefault = CFAllocatorRef.in_dll(
|
| 402 |
+
CoreFoundation, "kCFAllocatorDefault"
|
| 403 |
+
)
|
| 404 |
+
CoreFoundation.kCFTypeArrayCallBacks = c_void_p.in_dll(
|
| 405 |
+
CoreFoundation, "kCFTypeArrayCallBacks"
|
| 406 |
+
)
|
| 407 |
+
CoreFoundation.kCFTypeDictionaryKeyCallBacks = c_void_p.in_dll(
|
| 408 |
+
CoreFoundation, "kCFTypeDictionaryKeyCallBacks"
|
| 409 |
+
)
|
| 410 |
+
CoreFoundation.kCFTypeDictionaryValueCallBacks = c_void_p.in_dll(
|
| 411 |
+
CoreFoundation, "kCFTypeDictionaryValueCallBacks"
|
| 412 |
+
)
|
| 413 |
+
|
| 414 |
+
CoreFoundation.CFTypeRef = CFTypeRef
|
| 415 |
+
CoreFoundation.CFArrayRef = CFArrayRef
|
| 416 |
+
CoreFoundation.CFStringRef = CFStringRef
|
| 417 |
+
CoreFoundation.CFDictionaryRef = CFDictionaryRef
|
| 418 |
+
|
| 419 |
+
except (AttributeError):
|
| 420 |
+
raise ImportError("Error initializing ctypes")
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
class CFConst(object):
|
| 424 |
+
"""
|
| 425 |
+
A class object that acts as essentially a namespace for CoreFoundation
|
| 426 |
+
constants.
|
| 427 |
+
"""
|
| 428 |
+
|
| 429 |
+
kCFStringEncodingUTF8 = CFStringEncoding(0x08000100)
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
class SecurityConst(object):
|
| 433 |
+
"""
|
| 434 |
+
A class object that acts as essentially a namespace for Security constants.
|
| 435 |
+
"""
|
| 436 |
+
|
| 437 |
+
kSSLSessionOptionBreakOnServerAuth = 0
|
| 438 |
+
|
| 439 |
+
kSSLProtocol2 = 1
|
| 440 |
+
kSSLProtocol3 = 2
|
| 441 |
+
kTLSProtocol1 = 4
|
| 442 |
+
kTLSProtocol11 = 7
|
| 443 |
+
kTLSProtocol12 = 8
|
| 444 |
+
# SecureTransport does not support TLS 1.3 even if there's a constant for it
|
| 445 |
+
kTLSProtocol13 = 10
|
| 446 |
+
kTLSProtocolMaxSupported = 999
|
| 447 |
+
|
| 448 |
+
kSSLClientSide = 1
|
| 449 |
+
kSSLStreamType = 0
|
| 450 |
+
|
| 451 |
+
kSecFormatPEMSequence = 10
|
| 452 |
+
|
| 453 |
+
kSecTrustResultInvalid = 0
|
| 454 |
+
kSecTrustResultProceed = 1
|
| 455 |
+
# This gap is present on purpose: this was kSecTrustResultConfirm, which
|
| 456 |
+
# is deprecated.
|
| 457 |
+
kSecTrustResultDeny = 3
|
| 458 |
+
kSecTrustResultUnspecified = 4
|
| 459 |
+
kSecTrustResultRecoverableTrustFailure = 5
|
| 460 |
+
kSecTrustResultFatalTrustFailure = 6
|
| 461 |
+
kSecTrustResultOtherError = 7
|
| 462 |
+
|
| 463 |
+
errSSLProtocol = -9800
|
| 464 |
+
errSSLWouldBlock = -9803
|
| 465 |
+
errSSLClosedGraceful = -9805
|
| 466 |
+
errSSLClosedNoNotify = -9816
|
| 467 |
+
errSSLClosedAbort = -9806
|
| 468 |
+
|
| 469 |
+
errSSLXCertChainInvalid = -9807
|
| 470 |
+
errSSLCrypto = -9809
|
| 471 |
+
errSSLInternal = -9810
|
| 472 |
+
errSSLCertExpired = -9814
|
| 473 |
+
errSSLCertNotYetValid = -9815
|
| 474 |
+
errSSLUnknownRootCert = -9812
|
| 475 |
+
errSSLNoRootCert = -9813
|
| 476 |
+
errSSLHostNameMismatch = -9843
|
| 477 |
+
errSSLPeerHandshakeFail = -9824
|
| 478 |
+
errSSLPeerUserCancelled = -9839
|
| 479 |
+
errSSLWeakPeerEphemeralDHKey = -9850
|
| 480 |
+
errSSLServerAuthCompleted = -9841
|
| 481 |
+
errSSLRecordOverflow = -9847
|
| 482 |
+
|
| 483 |
+
errSecVerifyFailed = -67808
|
| 484 |
+
errSecNoTrustSettings = -25263
|
| 485 |
+
errSecItemNotFound = -25300
|
| 486 |
+
errSecInvalidTrustSettings = -25262
|
| 487 |
+
|
| 488 |
+
# Cipher suites. We only pick the ones our default cipher string allows.
|
| 489 |
+
# Source: https://developer.apple.com/documentation/security/1550981-ssl_cipher_suite_values
|
| 490 |
+
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xC02C
|
| 491 |
+
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xC030
|
| 492 |
+
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xC02B
|
| 493 |
+
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xC02F
|
| 494 |
+
TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA9
|
| 495 |
+
TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xCCA8
|
| 496 |
+
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = 0x009F
|
| 497 |
+
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = 0x009E
|
| 498 |
+
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = 0xC024
|
| 499 |
+
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = 0xC028
|
| 500 |
+
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xC00A
|
| 501 |
+
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xC014
|
| 502 |
+
TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = 0x006B
|
| 503 |
+
TLS_DHE_RSA_WITH_AES_256_CBC_SHA = 0x0039
|
| 504 |
+
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = 0xC023
|
| 505 |
+
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = 0xC027
|
| 506 |
+
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0xC009
|
| 507 |
+
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0xC013
|
| 508 |
+
TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = 0x0067
|
| 509 |
+
TLS_DHE_RSA_WITH_AES_128_CBC_SHA = 0x0033
|
| 510 |
+
TLS_RSA_WITH_AES_256_GCM_SHA384 = 0x009D
|
| 511 |
+
TLS_RSA_WITH_AES_128_GCM_SHA256 = 0x009C
|
| 512 |
+
TLS_RSA_WITH_AES_256_CBC_SHA256 = 0x003D
|
| 513 |
+
TLS_RSA_WITH_AES_128_CBC_SHA256 = 0x003C
|
| 514 |
+
TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035
|
| 515 |
+
TLS_RSA_WITH_AES_128_CBC_SHA = 0x002F
|
| 516 |
+
TLS_AES_128_GCM_SHA256 = 0x1301
|
| 517 |
+
TLS_AES_256_GCM_SHA384 = 0x1302
|
| 518 |
+
TLS_AES_128_CCM_8_SHA256 = 0x1305
|
| 519 |
+
TLS_AES_128_CCM_SHA256 = 0x1304
|
lib/python3.10/site-packages/urllib3/contrib/_securetransport/low_level.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Low-level helpers for the SecureTransport bindings.
|
| 3 |
+
|
| 4 |
+
These are Python functions that are not directly related to the high-level APIs
|
| 5 |
+
but are necessary to get them to work. They include a whole bunch of low-level
|
| 6 |
+
CoreFoundation messing about and memory management. The concerns in this module
|
| 7 |
+
are almost entirely about trying to avoid memory leaks and providing
|
| 8 |
+
appropriate and useful assistance to the higher-level code.
|
| 9 |
+
"""
|
| 10 |
+
import base64
|
| 11 |
+
import ctypes
|
| 12 |
+
import itertools
|
| 13 |
+
import os
|
| 14 |
+
import re
|
| 15 |
+
import ssl
|
| 16 |
+
import struct
|
| 17 |
+
import tempfile
|
| 18 |
+
|
| 19 |
+
from .bindings import CFConst, CoreFoundation, Security
|
| 20 |
+
|
| 21 |
+
# This regular expression is used to grab PEM data out of a PEM bundle.
|
| 22 |
+
_PEM_CERTS_RE = re.compile(
|
| 23 |
+
b"-----BEGIN CERTIFICATE-----\n(.*?)\n-----END CERTIFICATE-----", re.DOTALL
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _cf_data_from_bytes(bytestring):
|
| 28 |
+
"""
|
| 29 |
+
Given a bytestring, create a CFData object from it. This CFData object must
|
| 30 |
+
be CFReleased by the caller.
|
| 31 |
+
"""
|
| 32 |
+
return CoreFoundation.CFDataCreate(
|
| 33 |
+
CoreFoundation.kCFAllocatorDefault, bytestring, len(bytestring)
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _cf_dictionary_from_tuples(tuples):
|
| 38 |
+
"""
|
| 39 |
+
Given a list of Python tuples, create an associated CFDictionary.
|
| 40 |
+
"""
|
| 41 |
+
dictionary_size = len(tuples)
|
| 42 |
+
|
| 43 |
+
# We need to get the dictionary keys and values out in the same order.
|
| 44 |
+
keys = (t[0] for t in tuples)
|
| 45 |
+
values = (t[1] for t in tuples)
|
| 46 |
+
cf_keys = (CoreFoundation.CFTypeRef * dictionary_size)(*keys)
|
| 47 |
+
cf_values = (CoreFoundation.CFTypeRef * dictionary_size)(*values)
|
| 48 |
+
|
| 49 |
+
return CoreFoundation.CFDictionaryCreate(
|
| 50 |
+
CoreFoundation.kCFAllocatorDefault,
|
| 51 |
+
cf_keys,
|
| 52 |
+
cf_values,
|
| 53 |
+
dictionary_size,
|
| 54 |
+
CoreFoundation.kCFTypeDictionaryKeyCallBacks,
|
| 55 |
+
CoreFoundation.kCFTypeDictionaryValueCallBacks,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _cfstr(py_bstr):
|
| 60 |
+
"""
|
| 61 |
+
Given a Python binary data, create a CFString.
|
| 62 |
+
The string must be CFReleased by the caller.
|
| 63 |
+
"""
|
| 64 |
+
c_str = ctypes.c_char_p(py_bstr)
|
| 65 |
+
cf_str = CoreFoundation.CFStringCreateWithCString(
|
| 66 |
+
CoreFoundation.kCFAllocatorDefault,
|
| 67 |
+
c_str,
|
| 68 |
+
CFConst.kCFStringEncodingUTF8,
|
| 69 |
+
)
|
| 70 |
+
return cf_str
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def _create_cfstring_array(lst):
|
| 74 |
+
"""
|
| 75 |
+
Given a list of Python binary data, create an associated CFMutableArray.
|
| 76 |
+
The array must be CFReleased by the caller.
|
| 77 |
+
|
| 78 |
+
Raises an ssl.SSLError on failure.
|
| 79 |
+
"""
|
| 80 |
+
cf_arr = None
|
| 81 |
+
try:
|
| 82 |
+
cf_arr = CoreFoundation.CFArrayCreateMutable(
|
| 83 |
+
CoreFoundation.kCFAllocatorDefault,
|
| 84 |
+
0,
|
| 85 |
+
ctypes.byref(CoreFoundation.kCFTypeArrayCallBacks),
|
| 86 |
+
)
|
| 87 |
+
if not cf_arr:
|
| 88 |
+
raise MemoryError("Unable to allocate memory!")
|
| 89 |
+
for item in lst:
|
| 90 |
+
cf_str = _cfstr(item)
|
| 91 |
+
if not cf_str:
|
| 92 |
+
raise MemoryError("Unable to allocate memory!")
|
| 93 |
+
try:
|
| 94 |
+
CoreFoundation.CFArrayAppendValue(cf_arr, cf_str)
|
| 95 |
+
finally:
|
| 96 |
+
CoreFoundation.CFRelease(cf_str)
|
| 97 |
+
except BaseException as e:
|
| 98 |
+
if cf_arr:
|
| 99 |
+
CoreFoundation.CFRelease(cf_arr)
|
| 100 |
+
raise ssl.SSLError("Unable to allocate array: %s" % (e,))
|
| 101 |
+
return cf_arr
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def _cf_string_to_unicode(value):
|
| 105 |
+
"""
|
| 106 |
+
Creates a Unicode string from a CFString object. Used entirely for error
|
| 107 |
+
reporting.
|
| 108 |
+
|
| 109 |
+
Yes, it annoys me quite a lot that this function is this complex.
|
| 110 |
+
"""
|
| 111 |
+
value_as_void_p = ctypes.cast(value, ctypes.POINTER(ctypes.c_void_p))
|
| 112 |
+
|
| 113 |
+
string = CoreFoundation.CFStringGetCStringPtr(
|
| 114 |
+
value_as_void_p, CFConst.kCFStringEncodingUTF8
|
| 115 |
+
)
|
| 116 |
+
if string is None:
|
| 117 |
+
buffer = ctypes.create_string_buffer(1024)
|
| 118 |
+
result = CoreFoundation.CFStringGetCString(
|
| 119 |
+
value_as_void_p, buffer, 1024, CFConst.kCFStringEncodingUTF8
|
| 120 |
+
)
|
| 121 |
+
if not result:
|
| 122 |
+
raise OSError("Error copying C string from CFStringRef")
|
| 123 |
+
string = buffer.value
|
| 124 |
+
if string is not None:
|
| 125 |
+
string = string.decode("utf-8")
|
| 126 |
+
return string
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def _assert_no_error(error, exception_class=None):
|
| 130 |
+
"""
|
| 131 |
+
Checks the return code and throws an exception if there is an error to
|
| 132 |
+
report
|
| 133 |
+
"""
|
| 134 |
+
if error == 0:
|
| 135 |
+
return
|
| 136 |
+
|
| 137 |
+
cf_error_string = Security.SecCopyErrorMessageString(error, None)
|
| 138 |
+
output = _cf_string_to_unicode(cf_error_string)
|
| 139 |
+
CoreFoundation.CFRelease(cf_error_string)
|
| 140 |
+
|
| 141 |
+
if output is None or output == u"":
|
| 142 |
+
output = u"OSStatus %s" % error
|
| 143 |
+
|
| 144 |
+
if exception_class is None:
|
| 145 |
+
exception_class = ssl.SSLError
|
| 146 |
+
|
| 147 |
+
raise exception_class(output)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _cert_array_from_pem(pem_bundle):
|
| 151 |
+
"""
|
| 152 |
+
Given a bundle of certs in PEM format, turns them into a CFArray of certs
|
| 153 |
+
that can be used to validate a cert chain.
|
| 154 |
+
"""
|
| 155 |
+
# Normalize the PEM bundle's line endings.
|
| 156 |
+
pem_bundle = pem_bundle.replace(b"\r\n", b"\n")
|
| 157 |
+
|
| 158 |
+
der_certs = [
|
| 159 |
+
base64.b64decode(match.group(1)) for match in _PEM_CERTS_RE.finditer(pem_bundle)
|
| 160 |
+
]
|
| 161 |
+
if not der_certs:
|
| 162 |
+
raise ssl.SSLError("No root certificates specified")
|
| 163 |
+
|
| 164 |
+
cert_array = CoreFoundation.CFArrayCreateMutable(
|
| 165 |
+
CoreFoundation.kCFAllocatorDefault,
|
| 166 |
+
0,
|
| 167 |
+
ctypes.byref(CoreFoundation.kCFTypeArrayCallBacks),
|
| 168 |
+
)
|
| 169 |
+
if not cert_array:
|
| 170 |
+
raise ssl.SSLError("Unable to allocate memory!")
|
| 171 |
+
|
| 172 |
+
try:
|
| 173 |
+
for der_bytes in der_certs:
|
| 174 |
+
certdata = _cf_data_from_bytes(der_bytes)
|
| 175 |
+
if not certdata:
|
| 176 |
+
raise ssl.SSLError("Unable to allocate memory!")
|
| 177 |
+
cert = Security.SecCertificateCreateWithData(
|
| 178 |
+
CoreFoundation.kCFAllocatorDefault, certdata
|
| 179 |
+
)
|
| 180 |
+
CoreFoundation.CFRelease(certdata)
|
| 181 |
+
if not cert:
|
| 182 |
+
raise ssl.SSLError("Unable to build cert object!")
|
| 183 |
+
|
| 184 |
+
CoreFoundation.CFArrayAppendValue(cert_array, cert)
|
| 185 |
+
CoreFoundation.CFRelease(cert)
|
| 186 |
+
except Exception:
|
| 187 |
+
# We need to free the array before the exception bubbles further.
|
| 188 |
+
# We only want to do that if an error occurs: otherwise, the caller
|
| 189 |
+
# should free.
|
| 190 |
+
CoreFoundation.CFRelease(cert_array)
|
| 191 |
+
raise
|
| 192 |
+
|
| 193 |
+
return cert_array
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def _is_cert(item):
|
| 197 |
+
"""
|
| 198 |
+
Returns True if a given CFTypeRef is a certificate.
|
| 199 |
+
"""
|
| 200 |
+
expected = Security.SecCertificateGetTypeID()
|
| 201 |
+
return CoreFoundation.CFGetTypeID(item) == expected
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _is_identity(item):
|
| 205 |
+
"""
|
| 206 |
+
Returns True if a given CFTypeRef is an identity.
|
| 207 |
+
"""
|
| 208 |
+
expected = Security.SecIdentityGetTypeID()
|
| 209 |
+
return CoreFoundation.CFGetTypeID(item) == expected
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
def _temporary_keychain():
|
| 213 |
+
"""
|
| 214 |
+
This function creates a temporary Mac keychain that we can use to work with
|
| 215 |
+
credentials. This keychain uses a one-time password and a temporary file to
|
| 216 |
+
store the data. We expect to have one keychain per socket. The returned
|
| 217 |
+
SecKeychainRef must be freed by the caller, including calling
|
| 218 |
+
SecKeychainDelete.
|
| 219 |
+
|
| 220 |
+
Returns a tuple of the SecKeychainRef and the path to the temporary
|
| 221 |
+
directory that contains it.
|
| 222 |
+
"""
|
| 223 |
+
# Unfortunately, SecKeychainCreate requires a path to a keychain. This
|
| 224 |
+
# means we cannot use mkstemp to use a generic temporary file. Instead,
|
| 225 |
+
# we're going to create a temporary directory and a filename to use there.
|
| 226 |
+
# This filename will be 8 random bytes expanded into base64. We also need
|
| 227 |
+
# some random bytes to password-protect the keychain we're creating, so we
|
| 228 |
+
# ask for 40 random bytes.
|
| 229 |
+
random_bytes = os.urandom(40)
|
| 230 |
+
filename = base64.b16encode(random_bytes[:8]).decode("utf-8")
|
| 231 |
+
password = base64.b16encode(random_bytes[8:]) # Must be valid UTF-8
|
| 232 |
+
tempdirectory = tempfile.mkdtemp()
|
| 233 |
+
|
| 234 |
+
keychain_path = os.path.join(tempdirectory, filename).encode("utf-8")
|
| 235 |
+
|
| 236 |
+
# We now want to create the keychain itself.
|
| 237 |
+
keychain = Security.SecKeychainRef()
|
| 238 |
+
status = Security.SecKeychainCreate(
|
| 239 |
+
keychain_path, len(password), password, False, None, ctypes.byref(keychain)
|
| 240 |
+
)
|
| 241 |
+
_assert_no_error(status)
|
| 242 |
+
|
| 243 |
+
# Having created the keychain, we want to pass it off to the caller.
|
| 244 |
+
return keychain, tempdirectory
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def _load_items_from_file(keychain, path):
|
| 248 |
+
"""
|
| 249 |
+
Given a single file, loads all the trust objects from it into arrays and
|
| 250 |
+
the keychain.
|
| 251 |
+
Returns a tuple of lists: the first list is a list of identities, the
|
| 252 |
+
second a list of certs.
|
| 253 |
+
"""
|
| 254 |
+
certificates = []
|
| 255 |
+
identities = []
|
| 256 |
+
result_array = None
|
| 257 |
+
|
| 258 |
+
with open(path, "rb") as f:
|
| 259 |
+
raw_filedata = f.read()
|
| 260 |
+
|
| 261 |
+
try:
|
| 262 |
+
filedata = CoreFoundation.CFDataCreate(
|
| 263 |
+
CoreFoundation.kCFAllocatorDefault, raw_filedata, len(raw_filedata)
|
| 264 |
+
)
|
| 265 |
+
result_array = CoreFoundation.CFArrayRef()
|
| 266 |
+
result = Security.SecItemImport(
|
| 267 |
+
filedata, # cert data
|
| 268 |
+
None, # Filename, leaving it out for now
|
| 269 |
+
None, # What the type of the file is, we don't care
|
| 270 |
+
None, # what's in the file, we don't care
|
| 271 |
+
0, # import flags
|
| 272 |
+
None, # key params, can include passphrase in the future
|
| 273 |
+
keychain, # The keychain to insert into
|
| 274 |
+
ctypes.byref(result_array), # Results
|
| 275 |
+
)
|
| 276 |
+
_assert_no_error(result)
|
| 277 |
+
|
| 278 |
+
# A CFArray is not very useful to us as an intermediary
|
| 279 |
+
# representation, so we are going to extract the objects we want
|
| 280 |
+
# and then free the array. We don't need to keep hold of keys: the
|
| 281 |
+
# keychain already has them!
|
| 282 |
+
result_count = CoreFoundation.CFArrayGetCount(result_array)
|
| 283 |
+
for index in range(result_count):
|
| 284 |
+
item = CoreFoundation.CFArrayGetValueAtIndex(result_array, index)
|
| 285 |
+
item = ctypes.cast(item, CoreFoundation.CFTypeRef)
|
| 286 |
+
|
| 287 |
+
if _is_cert(item):
|
| 288 |
+
CoreFoundation.CFRetain(item)
|
| 289 |
+
certificates.append(item)
|
| 290 |
+
elif _is_identity(item):
|
| 291 |
+
CoreFoundation.CFRetain(item)
|
| 292 |
+
identities.append(item)
|
| 293 |
+
finally:
|
| 294 |
+
if result_array:
|
| 295 |
+
CoreFoundation.CFRelease(result_array)
|
| 296 |
+
|
| 297 |
+
CoreFoundation.CFRelease(filedata)
|
| 298 |
+
|
| 299 |
+
return (identities, certificates)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
def _load_client_cert_chain(keychain, *paths):
|
| 303 |
+
"""
|
| 304 |
+
Load certificates and maybe keys from a number of files. Has the end goal
|
| 305 |
+
of returning a CFArray containing one SecIdentityRef, and then zero or more
|
| 306 |
+
SecCertificateRef objects, suitable for use as a client certificate trust
|
| 307 |
+
chain.
|
| 308 |
+
"""
|
| 309 |
+
# Ok, the strategy.
|
| 310 |
+
#
|
| 311 |
+
# This relies on knowing that macOS will not give you a SecIdentityRef
|
| 312 |
+
# unless you have imported a key into a keychain. This is a somewhat
|
| 313 |
+
# artificial limitation of macOS (for example, it doesn't necessarily
|
| 314 |
+
# affect iOS), but there is nothing inside Security.framework that lets you
|
| 315 |
+
# get a SecIdentityRef without having a key in a keychain.
|
| 316 |
+
#
|
| 317 |
+
# So the policy here is we take all the files and iterate them in order.
|
| 318 |
+
# Each one will use SecItemImport to have one or more objects loaded from
|
| 319 |
+
# it. We will also point at a keychain that macOS can use to work with the
|
| 320 |
+
# private key.
|
| 321 |
+
#
|
| 322 |
+
# Once we have all the objects, we'll check what we actually have. If we
|
| 323 |
+
# already have a SecIdentityRef in hand, fab: we'll use that. Otherwise,
|
| 324 |
+
# we'll take the first certificate (which we assume to be our leaf) and
|
| 325 |
+
# ask the keychain to give us a SecIdentityRef with that cert's associated
|
| 326 |
+
# key.
|
| 327 |
+
#
|
| 328 |
+
# We'll then return a CFArray containing the trust chain: one
|
| 329 |
+
# SecIdentityRef and then zero-or-more SecCertificateRef objects. The
|
| 330 |
+
# responsibility for freeing this CFArray will be with the caller. This
|
| 331 |
+
# CFArray must remain alive for the entire connection, so in practice it
|
| 332 |
+
# will be stored with a single SSLSocket, along with the reference to the
|
| 333 |
+
# keychain.
|
| 334 |
+
certificates = []
|
| 335 |
+
identities = []
|
| 336 |
+
|
| 337 |
+
# Filter out bad paths.
|
| 338 |
+
paths = (path for path in paths if path)
|
| 339 |
+
|
| 340 |
+
try:
|
| 341 |
+
for file_path in paths:
|
| 342 |
+
new_identities, new_certs = _load_items_from_file(keychain, file_path)
|
| 343 |
+
identities.extend(new_identities)
|
| 344 |
+
certificates.extend(new_certs)
|
| 345 |
+
|
| 346 |
+
# Ok, we have everything. The question is: do we have an identity? If
|
| 347 |
+
# not, we want to grab one from the first cert we have.
|
| 348 |
+
if not identities:
|
| 349 |
+
new_identity = Security.SecIdentityRef()
|
| 350 |
+
status = Security.SecIdentityCreateWithCertificate(
|
| 351 |
+
keychain, certificates[0], ctypes.byref(new_identity)
|
| 352 |
+
)
|
| 353 |
+
_assert_no_error(status)
|
| 354 |
+
identities.append(new_identity)
|
| 355 |
+
|
| 356 |
+
# We now want to release the original certificate, as we no longer
|
| 357 |
+
# need it.
|
| 358 |
+
CoreFoundation.CFRelease(certificates.pop(0))
|
| 359 |
+
|
| 360 |
+
# We now need to build a new CFArray that holds the trust chain.
|
| 361 |
+
trust_chain = CoreFoundation.CFArrayCreateMutable(
|
| 362 |
+
CoreFoundation.kCFAllocatorDefault,
|
| 363 |
+
0,
|
| 364 |
+
ctypes.byref(CoreFoundation.kCFTypeArrayCallBacks),
|
| 365 |
+
)
|
| 366 |
+
for item in itertools.chain(identities, certificates):
|
| 367 |
+
# ArrayAppendValue does a CFRetain on the item. That's fine,
|
| 368 |
+
# because the finally block will release our other refs to them.
|
| 369 |
+
CoreFoundation.CFArrayAppendValue(trust_chain, item)
|
| 370 |
+
|
| 371 |
+
return trust_chain
|
| 372 |
+
finally:
|
| 373 |
+
for obj in itertools.chain(identities, certificates):
|
| 374 |
+
CoreFoundation.CFRelease(obj)
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
TLS_PROTOCOL_VERSIONS = {
|
| 378 |
+
"SSLv2": (0, 2),
|
| 379 |
+
"SSLv3": (3, 0),
|
| 380 |
+
"TLSv1": (3, 1),
|
| 381 |
+
"TLSv1.1": (3, 2),
|
| 382 |
+
"TLSv1.2": (3, 3),
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
def _build_tls_unknown_ca_alert(version):
|
| 387 |
+
"""
|
| 388 |
+
Builds a TLS alert record for an unknown CA.
|
| 389 |
+
"""
|
| 390 |
+
ver_maj, ver_min = TLS_PROTOCOL_VERSIONS[version]
|
| 391 |
+
severity_fatal = 0x02
|
| 392 |
+
description_unknown_ca = 0x30
|
| 393 |
+
msg = struct.pack(">BB", severity_fatal, description_unknown_ca)
|
| 394 |
+
msg_len = len(msg)
|
| 395 |
+
record_type_alert = 0x15
|
| 396 |
+
record = struct.pack(">BBBH", record_type_alert, ver_maj, ver_min, msg_len) + msg
|
| 397 |
+
return record
|
lib/python3.10/site-packages/urllib3/contrib/appengine.py
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
This module provides a pool manager that uses Google App Engine's
|
| 3 |
+
`URLFetch Service <https://cloud.google.com/appengine/docs/python/urlfetch>`_.
|
| 4 |
+
|
| 5 |
+
Example usage::
|
| 6 |
+
|
| 7 |
+
from urllib3 import PoolManager
|
| 8 |
+
from urllib3.contrib.appengine import AppEngineManager, is_appengine_sandbox
|
| 9 |
+
|
| 10 |
+
if is_appengine_sandbox():
|
| 11 |
+
# AppEngineManager uses AppEngine's URLFetch API behind the scenes
|
| 12 |
+
http = AppEngineManager()
|
| 13 |
+
else:
|
| 14 |
+
# PoolManager uses a socket-level API behind the scenes
|
| 15 |
+
http = PoolManager()
|
| 16 |
+
|
| 17 |
+
r = http.request('GET', 'https://google.com/')
|
| 18 |
+
|
| 19 |
+
There are `limitations <https://cloud.google.com/appengine/docs/python/\
|
| 20 |
+
urlfetch/#Python_Quotas_and_limits>`_ to the URLFetch service and it may not be
|
| 21 |
+
the best choice for your application. There are three options for using
|
| 22 |
+
urllib3 on Google App Engine:
|
| 23 |
+
|
| 24 |
+
1. You can use :class:`AppEngineManager` with URLFetch. URLFetch is
|
| 25 |
+
cost-effective in many circumstances as long as your usage is within the
|
| 26 |
+
limitations.
|
| 27 |
+
2. You can use a normal :class:`~urllib3.PoolManager` by enabling sockets.
|
| 28 |
+
Sockets also have `limitations and restrictions
|
| 29 |
+
<https://cloud.google.com/appengine/docs/python/sockets/\
|
| 30 |
+
#limitations-and-restrictions>`_ and have a lower free quota than URLFetch.
|
| 31 |
+
To use sockets, be sure to specify the following in your ``app.yaml``::
|
| 32 |
+
|
| 33 |
+
env_variables:
|
| 34 |
+
GAE_USE_SOCKETS_HTTPLIB : 'true'
|
| 35 |
+
|
| 36 |
+
3. If you are using `App Engine Flexible
|
| 37 |
+
<https://cloud.google.com/appengine/docs/flexible/>`_, you can use the standard
|
| 38 |
+
:class:`PoolManager` without any configuration or special environment variables.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
from __future__ import absolute_import
|
| 42 |
+
|
| 43 |
+
import io
|
| 44 |
+
import logging
|
| 45 |
+
import warnings
|
| 46 |
+
|
| 47 |
+
from ..exceptions import (
|
| 48 |
+
HTTPError,
|
| 49 |
+
HTTPWarning,
|
| 50 |
+
MaxRetryError,
|
| 51 |
+
ProtocolError,
|
| 52 |
+
SSLError,
|
| 53 |
+
TimeoutError,
|
| 54 |
+
)
|
| 55 |
+
from ..packages.six.moves.urllib.parse import urljoin
|
| 56 |
+
from ..request import RequestMethods
|
| 57 |
+
from ..response import HTTPResponse
|
| 58 |
+
from ..util.retry import Retry
|
| 59 |
+
from ..util.timeout import Timeout
|
| 60 |
+
from . import _appengine_environ
|
| 61 |
+
|
| 62 |
+
try:
|
| 63 |
+
from google.appengine.api import urlfetch
|
| 64 |
+
except ImportError:
|
| 65 |
+
urlfetch = None
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
log = logging.getLogger(__name__)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class AppEnginePlatformWarning(HTTPWarning):
|
| 72 |
+
pass
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class AppEnginePlatformError(HTTPError):
|
| 76 |
+
pass
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
class AppEngineManager(RequestMethods):
|
| 80 |
+
"""
|
| 81 |
+
Connection manager for Google App Engine sandbox applications.
|
| 82 |
+
|
| 83 |
+
This manager uses the URLFetch service directly instead of using the
|
| 84 |
+
emulated httplib, and is subject to URLFetch limitations as described in
|
| 85 |
+
the App Engine documentation `here
|
| 86 |
+
<https://cloud.google.com/appengine/docs/python/urlfetch>`_.
|
| 87 |
+
|
| 88 |
+
Notably it will raise an :class:`AppEnginePlatformError` if:
|
| 89 |
+
* URLFetch is not available.
|
| 90 |
+
* If you attempt to use this on App Engine Flexible, as full socket
|
| 91 |
+
support is available.
|
| 92 |
+
* If a request size is more than 10 megabytes.
|
| 93 |
+
* If a response size is more than 32 megabytes.
|
| 94 |
+
* If you use an unsupported request method such as OPTIONS.
|
| 95 |
+
|
| 96 |
+
Beyond those cases, it will raise normal urllib3 errors.
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
def __init__(
|
| 100 |
+
self,
|
| 101 |
+
headers=None,
|
| 102 |
+
retries=None,
|
| 103 |
+
validate_certificate=True,
|
| 104 |
+
urlfetch_retries=True,
|
| 105 |
+
):
|
| 106 |
+
if not urlfetch:
|
| 107 |
+
raise AppEnginePlatformError(
|
| 108 |
+
"URLFetch is not available in this environment."
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
warnings.warn(
|
| 112 |
+
"urllib3 is using URLFetch on Google App Engine sandbox instead "
|
| 113 |
+
"of sockets. To use sockets directly instead of URLFetch see "
|
| 114 |
+
"https://urllib3.readthedocs.io/en/1.26.x/reference/urllib3.contrib.html.",
|
| 115 |
+
AppEnginePlatformWarning,
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
RequestMethods.__init__(self, headers)
|
| 119 |
+
self.validate_certificate = validate_certificate
|
| 120 |
+
self.urlfetch_retries = urlfetch_retries
|
| 121 |
+
|
| 122 |
+
self.retries = retries or Retry.DEFAULT
|
| 123 |
+
|
| 124 |
+
def __enter__(self):
|
| 125 |
+
return self
|
| 126 |
+
|
| 127 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 128 |
+
# Return False to re-raise any potential exceptions
|
| 129 |
+
return False
|
| 130 |
+
|
| 131 |
+
def urlopen(
|
| 132 |
+
self,
|
| 133 |
+
method,
|
| 134 |
+
url,
|
| 135 |
+
body=None,
|
| 136 |
+
headers=None,
|
| 137 |
+
retries=None,
|
| 138 |
+
redirect=True,
|
| 139 |
+
timeout=Timeout.DEFAULT_TIMEOUT,
|
| 140 |
+
**response_kw
|
| 141 |
+
):
|
| 142 |
+
|
| 143 |
+
retries = self._get_retries(retries, redirect)
|
| 144 |
+
|
| 145 |
+
try:
|
| 146 |
+
follow_redirects = redirect and retries.redirect != 0 and retries.total
|
| 147 |
+
response = urlfetch.fetch(
|
| 148 |
+
url,
|
| 149 |
+
payload=body,
|
| 150 |
+
method=method,
|
| 151 |
+
headers=headers or {},
|
| 152 |
+
allow_truncated=False,
|
| 153 |
+
follow_redirects=self.urlfetch_retries and follow_redirects,
|
| 154 |
+
deadline=self._get_absolute_timeout(timeout),
|
| 155 |
+
validate_certificate=self.validate_certificate,
|
| 156 |
+
)
|
| 157 |
+
except urlfetch.DeadlineExceededError as e:
|
| 158 |
+
raise TimeoutError(self, e)
|
| 159 |
+
|
| 160 |
+
except urlfetch.InvalidURLError as e:
|
| 161 |
+
if "too large" in str(e):
|
| 162 |
+
raise AppEnginePlatformError(
|
| 163 |
+
"URLFetch request too large, URLFetch only "
|
| 164 |
+
"supports requests up to 10mb in size.",
|
| 165 |
+
e,
|
| 166 |
+
)
|
| 167 |
+
raise ProtocolError(e)
|
| 168 |
+
|
| 169 |
+
except urlfetch.DownloadError as e:
|
| 170 |
+
if "Too many redirects" in str(e):
|
| 171 |
+
raise MaxRetryError(self, url, reason=e)
|
| 172 |
+
raise ProtocolError(e)
|
| 173 |
+
|
| 174 |
+
except urlfetch.ResponseTooLargeError as e:
|
| 175 |
+
raise AppEnginePlatformError(
|
| 176 |
+
"URLFetch response too large, URLFetch only supports"
|
| 177 |
+
"responses up to 32mb in size.",
|
| 178 |
+
e,
|
| 179 |
+
)
|
| 180 |
+
|
| 181 |
+
except urlfetch.SSLCertificateError as e:
|
| 182 |
+
raise SSLError(e)
|
| 183 |
+
|
| 184 |
+
except urlfetch.InvalidMethodError as e:
|
| 185 |
+
raise AppEnginePlatformError(
|
| 186 |
+
"URLFetch does not support method: %s" % method, e
|
| 187 |
+
)
|
| 188 |
+
|
| 189 |
+
http_response = self._urlfetch_response_to_http_response(
|
| 190 |
+
response, retries=retries, **response_kw
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
# Handle redirect?
|
| 194 |
+
redirect_location = redirect and http_response.get_redirect_location()
|
| 195 |
+
if redirect_location:
|
| 196 |
+
# Check for redirect response
|
| 197 |
+
if self.urlfetch_retries and retries.raise_on_redirect:
|
| 198 |
+
raise MaxRetryError(self, url, "too many redirects")
|
| 199 |
+
else:
|
| 200 |
+
if http_response.status == 303:
|
| 201 |
+
method = "GET"
|
| 202 |
+
|
| 203 |
+
try:
|
| 204 |
+
retries = retries.increment(
|
| 205 |
+
method, url, response=http_response, _pool=self
|
| 206 |
+
)
|
| 207 |
+
except MaxRetryError:
|
| 208 |
+
if retries.raise_on_redirect:
|
| 209 |
+
raise MaxRetryError(self, url, "too many redirects")
|
| 210 |
+
return http_response
|
| 211 |
+
|
| 212 |
+
retries.sleep_for_retry(http_response)
|
| 213 |
+
log.debug("Redirecting %s -> %s", url, redirect_location)
|
| 214 |
+
redirect_url = urljoin(url, redirect_location)
|
| 215 |
+
return self.urlopen(
|
| 216 |
+
method,
|
| 217 |
+
redirect_url,
|
| 218 |
+
body,
|
| 219 |
+
headers,
|
| 220 |
+
retries=retries,
|
| 221 |
+
redirect=redirect,
|
| 222 |
+
timeout=timeout,
|
| 223 |
+
**response_kw
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
# Check if we should retry the HTTP response.
|
| 227 |
+
has_retry_after = bool(http_response.headers.get("Retry-After"))
|
| 228 |
+
if retries.is_retry(method, http_response.status, has_retry_after):
|
| 229 |
+
retries = retries.increment(method, url, response=http_response, _pool=self)
|
| 230 |
+
log.debug("Retry: %s", url)
|
| 231 |
+
retries.sleep(http_response)
|
| 232 |
+
return self.urlopen(
|
| 233 |
+
method,
|
| 234 |
+
url,
|
| 235 |
+
body=body,
|
| 236 |
+
headers=headers,
|
| 237 |
+
retries=retries,
|
| 238 |
+
redirect=redirect,
|
| 239 |
+
timeout=timeout,
|
| 240 |
+
**response_kw
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
return http_response
|
| 244 |
+
|
| 245 |
+
def _urlfetch_response_to_http_response(self, urlfetch_resp, **response_kw):
|
| 246 |
+
|
| 247 |
+
if is_prod_appengine():
|
| 248 |
+
# Production GAE handles deflate encoding automatically, but does
|
| 249 |
+
# not remove the encoding header.
|
| 250 |
+
content_encoding = urlfetch_resp.headers.get("content-encoding")
|
| 251 |
+
|
| 252 |
+
if content_encoding == "deflate":
|
| 253 |
+
del urlfetch_resp.headers["content-encoding"]
|
| 254 |
+
|
| 255 |
+
transfer_encoding = urlfetch_resp.headers.get("transfer-encoding")
|
| 256 |
+
# We have a full response's content,
|
| 257 |
+
# so let's make sure we don't report ourselves as chunked data.
|
| 258 |
+
if transfer_encoding == "chunked":
|
| 259 |
+
encodings = transfer_encoding.split(",")
|
| 260 |
+
encodings.remove("chunked")
|
| 261 |
+
urlfetch_resp.headers["transfer-encoding"] = ",".join(encodings)
|
| 262 |
+
|
| 263 |
+
original_response = HTTPResponse(
|
| 264 |
+
# In order for decoding to work, we must present the content as
|
| 265 |
+
# a file-like object.
|
| 266 |
+
body=io.BytesIO(urlfetch_resp.content),
|
| 267 |
+
msg=urlfetch_resp.header_msg,
|
| 268 |
+
headers=urlfetch_resp.headers,
|
| 269 |
+
status=urlfetch_resp.status_code,
|
| 270 |
+
**response_kw
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
return HTTPResponse(
|
| 274 |
+
body=io.BytesIO(urlfetch_resp.content),
|
| 275 |
+
headers=urlfetch_resp.headers,
|
| 276 |
+
status=urlfetch_resp.status_code,
|
| 277 |
+
original_response=original_response,
|
| 278 |
+
**response_kw
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
def _get_absolute_timeout(self, timeout):
|
| 282 |
+
if timeout is Timeout.DEFAULT_TIMEOUT:
|
| 283 |
+
return None # Defer to URLFetch's default.
|
| 284 |
+
if isinstance(timeout, Timeout):
|
| 285 |
+
if timeout._read is not None or timeout._connect is not None:
|
| 286 |
+
warnings.warn(
|
| 287 |
+
"URLFetch does not support granular timeout settings, "
|
| 288 |
+
"reverting to total or default URLFetch timeout.",
|
| 289 |
+
AppEnginePlatformWarning,
|
| 290 |
+
)
|
| 291 |
+
return timeout.total
|
| 292 |
+
return timeout
|
| 293 |
+
|
| 294 |
+
def _get_retries(self, retries, redirect):
|
| 295 |
+
if not isinstance(retries, Retry):
|
| 296 |
+
retries = Retry.from_int(retries, redirect=redirect, default=self.retries)
|
| 297 |
+
|
| 298 |
+
if retries.connect or retries.read or retries.redirect:
|
| 299 |
+
warnings.warn(
|
| 300 |
+
"URLFetch only supports total retries and does not "
|
| 301 |
+
"recognize connect, read, or redirect retry parameters.",
|
| 302 |
+
AppEnginePlatformWarning,
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
return retries
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
# Alias methods from _appengine_environ to maintain public API interface.
|
| 309 |
+
|
| 310 |
+
is_appengine = _appengine_environ.is_appengine
|
| 311 |
+
is_appengine_sandbox = _appengine_environ.is_appengine_sandbox
|
| 312 |
+
is_local_appengine = _appengine_environ.is_local_appengine
|
| 313 |
+
is_prod_appengine = _appengine_environ.is_prod_appengine
|
| 314 |
+
is_prod_appengine_mvms = _appengine_environ.is_prod_appengine_mvms
|
lib/python3.10/site-packages/urllib3/contrib/ntlmpool.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
NTLM authenticating pool, contributed by erikcederstran
|
| 3 |
+
|
| 4 |
+
Issue #10, see: http://code.google.com/p/urllib3/issues/detail?id=10
|
| 5 |
+
"""
|
| 6 |
+
from __future__ import absolute_import
|
| 7 |
+
|
| 8 |
+
import warnings
|
| 9 |
+
from logging import getLogger
|
| 10 |
+
|
| 11 |
+
from ntlm import ntlm
|
| 12 |
+
|
| 13 |
+
from .. import HTTPSConnectionPool
|
| 14 |
+
from ..packages.six.moves.http_client import HTTPSConnection
|
| 15 |
+
|
| 16 |
+
warnings.warn(
|
| 17 |
+
"The 'urllib3.contrib.ntlmpool' module is deprecated and will be removed "
|
| 18 |
+
"in urllib3 v2.0 release, urllib3 is not able to support it properly due "
|
| 19 |
+
"to reasons listed in issue: https://github.com/urllib3/urllib3/issues/2282. "
|
| 20 |
+
"If you are a user of this module please comment in the mentioned issue.",
|
| 21 |
+
DeprecationWarning,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
log = getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class NTLMConnectionPool(HTTPSConnectionPool):
|
| 28 |
+
"""
|
| 29 |
+
Implements an NTLM authentication version of an urllib3 connection pool
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
scheme = "https"
|
| 33 |
+
|
| 34 |
+
def __init__(self, user, pw, authurl, *args, **kwargs):
|
| 35 |
+
"""
|
| 36 |
+
authurl is a random URL on the server that is protected by NTLM.
|
| 37 |
+
user is the Windows user, probably in the DOMAIN\\username format.
|
| 38 |
+
pw is the password for the user.
|
| 39 |
+
"""
|
| 40 |
+
super(NTLMConnectionPool, self).__init__(*args, **kwargs)
|
| 41 |
+
self.authurl = authurl
|
| 42 |
+
self.rawuser = user
|
| 43 |
+
user_parts = user.split("\\", 1)
|
| 44 |
+
self.domain = user_parts[0].upper()
|
| 45 |
+
self.user = user_parts[1]
|
| 46 |
+
self.pw = pw
|
| 47 |
+
|
| 48 |
+
def _new_conn(self):
|
| 49 |
+
# Performs the NTLM handshake that secures the connection. The socket
|
| 50 |
+
# must be kept open while requests are performed.
|
| 51 |
+
self.num_connections += 1
|
| 52 |
+
log.debug(
|
| 53 |
+
"Starting NTLM HTTPS connection no. %d: https://%s%s",
|
| 54 |
+
self.num_connections,
|
| 55 |
+
self.host,
|
| 56 |
+
self.authurl,
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
headers = {"Connection": "Keep-Alive"}
|
| 60 |
+
req_header = "Authorization"
|
| 61 |
+
resp_header = "www-authenticate"
|
| 62 |
+
|
| 63 |
+
conn = HTTPSConnection(host=self.host, port=self.port)
|
| 64 |
+
|
| 65 |
+
# Send negotiation message
|
| 66 |
+
headers[req_header] = "NTLM %s" % ntlm.create_NTLM_NEGOTIATE_MESSAGE(
|
| 67 |
+
self.rawuser
|
| 68 |
+
)
|
| 69 |
+
log.debug("Request headers: %s", headers)
|
| 70 |
+
conn.request("GET", self.authurl, None, headers)
|
| 71 |
+
res = conn.getresponse()
|
| 72 |
+
reshdr = dict(res.headers)
|
| 73 |
+
log.debug("Response status: %s %s", res.status, res.reason)
|
| 74 |
+
log.debug("Response headers: %s", reshdr)
|
| 75 |
+
log.debug("Response data: %s [...]", res.read(100))
|
| 76 |
+
|
| 77 |
+
# Remove the reference to the socket, so that it can not be closed by
|
| 78 |
+
# the response object (we want to keep the socket open)
|
| 79 |
+
res.fp = None
|
| 80 |
+
|
| 81 |
+
# Server should respond with a challenge message
|
| 82 |
+
auth_header_values = reshdr[resp_header].split(", ")
|
| 83 |
+
auth_header_value = None
|
| 84 |
+
for s in auth_header_values:
|
| 85 |
+
if s[:5] == "NTLM ":
|
| 86 |
+
auth_header_value = s[5:]
|
| 87 |
+
if auth_header_value is None:
|
| 88 |
+
raise Exception(
|
| 89 |
+
"Unexpected %s response header: %s" % (resp_header, reshdr[resp_header])
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
# Send authentication message
|
| 93 |
+
ServerChallenge, NegotiateFlags = ntlm.parse_NTLM_CHALLENGE_MESSAGE(
|
| 94 |
+
auth_header_value
|
| 95 |
+
)
|
| 96 |
+
auth_msg = ntlm.create_NTLM_AUTHENTICATE_MESSAGE(
|
| 97 |
+
ServerChallenge, self.user, self.domain, self.pw, NegotiateFlags
|
| 98 |
+
)
|
| 99 |
+
headers[req_header] = "NTLM %s" % auth_msg
|
| 100 |
+
log.debug("Request headers: %s", headers)
|
| 101 |
+
conn.request("GET", self.authurl, None, headers)
|
| 102 |
+
res = conn.getresponse()
|
| 103 |
+
log.debug("Response status: %s %s", res.status, res.reason)
|
| 104 |
+
log.debug("Response headers: %s", dict(res.headers))
|
| 105 |
+
log.debug("Response data: %s [...]", res.read()[:100])
|
| 106 |
+
if res.status != 200:
|
| 107 |
+
if res.status == 401:
|
| 108 |
+
raise Exception("Server rejected request: wrong username or password")
|
| 109 |
+
raise Exception("Wrong server response: %s %s" % (res.status, res.reason))
|
| 110 |
+
|
| 111 |
+
res.fp = None
|
| 112 |
+
log.debug("Connection established")
|
| 113 |
+
return conn
|
| 114 |
+
|
| 115 |
+
def urlopen(
|
| 116 |
+
self,
|
| 117 |
+
method,
|
| 118 |
+
url,
|
| 119 |
+
body=None,
|
| 120 |
+
headers=None,
|
| 121 |
+
retries=3,
|
| 122 |
+
redirect=True,
|
| 123 |
+
assert_same_host=True,
|
| 124 |
+
):
|
| 125 |
+
if headers is None:
|
| 126 |
+
headers = {}
|
| 127 |
+
headers["Connection"] = "Keep-Alive"
|
| 128 |
+
return super(NTLMConnectionPool, self).urlopen(
|
| 129 |
+
method, url, body, headers, retries, redirect, assert_same_host
|
| 130 |
+
)
|