ayousanz commited on
Commit
a902c8a
·
verified ·
1 Parent(s): 3d3578a

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. .venv/Lib/site-packages/torch/lib/cusparse64_12.dll +3 -0
  3. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Lisbon +0 -0
  4. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Ljubljana +0 -0
  5. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/London +0 -0
  6. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Luxembourg +0 -0
  7. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Madrid +0 -0
  8. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Malta +0 -0
  9. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Mariehamn +0 -0
  10. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Minsk +0 -0
  11. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Monaco +0 -0
  12. .venv/Lib/site-packages/tzdata/zoneinfo/Europe/Moscow +0 -0
  13. .venv/Lib/site-packages/unidic-1.1.0.dist-info/INSTALLER +1 -0
  14. .venv/Lib/site-packages/unidic-1.1.0.dist-info/LICENSE +21 -0
  15. .venv/Lib/site-packages/unidic-1.1.0.dist-info/METADATA +100 -0
  16. .venv/Lib/site-packages/unidic-1.1.0.dist-info/RECORD +11 -0
  17. .venv/Lib/site-packages/unidic-1.1.0.dist-info/REQUESTED +0 -0
  18. .venv/Lib/site-packages/unidic-1.1.0.dist-info/WHEEL +5 -0
  19. .venv/Lib/site-packages/unidic-1.1.0.dist-info/top_level.txt +1 -0
  20. .venv/Lib/site-packages/unidic/__pycache__/__init__.cpython-39.pyc +0 -0
  21. .venv/Lib/site-packages/unidic/__pycache__/__main__.cpython-39.pyc +0 -0
  22. .venv/Lib/site-packages/unidic/__pycache__/unidic.cpython-39.pyc +0 -0
  23. .venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/METADATA +44 -0
  24. .venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/RECORD +29 -0
  25. .venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/REQUESTED +0 -0
  26. .venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/WHEEL +5 -0
  27. .venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/top_level.txt +1 -0
  28. .venv/Lib/site-packages/unidic_lite/__init__.py +1 -0
  29. .venv/Lib/site-packages/unidic_lite/dicdir/AUTHORS +1 -0
  30. .venv/Lib/site-packages/unidic_lite/dicdir/BSD +30 -0
  31. .venv/Lib/site-packages/unidic_lite/dicdir/COPYING +4 -0
  32. .venv/Lib/site-packages/unidic_lite/dicdir/ChangeLog +43 -0
  33. .venv/Lib/site-packages/unidic_lite/dicdir/GPL +340 -0
  34. .venv/Lib/site-packages/unidic_lite/dicdir/INSTALL +1 -0
  35. .venv/Lib/site-packages/unidic_lite/dicdir/LGPL +504 -0
  36. .venv/Lib/site-packages/unidic_lite/dicdir/README.md +14 -0
  37. .venv/Lib/site-packages/unidic_lite/dicdir/dicrc +58 -0
  38. .venv/Lib/site-packages/unidic_lite/dicdir/left-id.def +0 -0
  39. .venv/Lib/site-packages/unidic_lite/dicdir/mecabrc +2 -0
  40. .venv/Lib/site-packages/unidic_lite/dicdir/rewrite.def +60 -0
  41. .venv/Lib/site-packages/unidic_lite/unidic.py +13 -0
  42. .venv/Lib/site-packages/urllib3/__init__.py +211 -0
  43. .venv/Lib/site-packages/urllib3/_base_connection.py +172 -0
  44. .venv/Lib/site-packages/urllib3/_collections.py +483 -0
  45. .venv/Lib/site-packages/urllib3/_request_methods.py +278 -0
  46. .venv/Lib/site-packages/urllib3/_version.py +16 -0
  47. .venv/Lib/site-packages/urllib3/connection.py +1033 -0
  48. .venv/Lib/site-packages/urllib3/connectionpool.py +1182 -0
  49. .venv/Lib/site-packages/urllib3/contrib/__pycache__/__init__.cpython-39.pyc +0 -0
  50. .venv/Lib/site-packages/urllib3/contrib/pyopenssl.py +552 -0
.gitattributes CHANGED
@@ -125,3 +125,4 @@ reference_sample_wavs/syuukovoice_200918_3_01.wav filter=lfs diff=lfs merge=lfs
125
  .venv/Lib/site-packages/torch/lib/kineto.lib filter=lfs diff=lfs merge=lfs -text
126
  .venv/Lib/site-packages/torch/lib/libprotobuf.lib filter=lfs diff=lfs merge=lfs -text
127
  .venv/Lib/site-packages/torch/lib/torch_cpu.dll filter=lfs diff=lfs merge=lfs -text
 
 
125
  .venv/Lib/site-packages/torch/lib/kineto.lib filter=lfs diff=lfs merge=lfs -text
126
  .venv/Lib/site-packages/torch/lib/libprotobuf.lib filter=lfs diff=lfs merge=lfs -text
127
  .venv/Lib/site-packages/torch/lib/torch_cpu.dll filter=lfs diff=lfs merge=lfs -text
128
+ .venv/Lib/site-packages/torch/lib/cusparse64_12.dll filter=lfs diff=lfs merge=lfs -text
.venv/Lib/site-packages/torch/lib/cusparse64_12.dll ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:89f444f56433e5d0fed2084adedc5d575c3d05b025626d4bada46fe559be2c54
3
+ size 262348288
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Lisbon ADDED
Binary file (1.46 kB). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Ljubljana ADDED
Binary file (478 Bytes). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/London ADDED
Binary file (1.6 kB). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Luxembourg ADDED
Binary file (1.1 kB). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Madrid ADDED
Binary file (897 Bytes). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Malta ADDED
Binary file (928 Bytes). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Mariehamn ADDED
Binary file (481 Bytes). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Minsk ADDED
Binary file (808 Bytes). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Monaco ADDED
Binary file (1.11 kB). View file
 
.venv/Lib/site-packages/tzdata/zoneinfo/Europe/Moscow ADDED
Binary file (908 Bytes). View file
 
.venv/Lib/site-packages/unidic-1.1.0.dist-info/INSTALLER ADDED
@@ -0,0 +1 @@
 
 
1
+ uv
.venv/Lib/site-packages/unidic-1.1.0.dist-info/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Paul O'Leary McCann
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
.venv/Lib/site-packages/unidic-1.1.0.dist-info/METADATA ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: unidic
3
+ Version: 1.1.0
4
+ Summary: UniDic packaged for Python
5
+ Home-page: https://github.com/polm/unidic-py
6
+ Author: Paul O'Leary McCann
7
+ Author-email: [email protected]
8
+ License: MIT
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Natural Language :: Japanese
11
+ Requires-Python: >=3.5
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests<3.0.0,>=2.22.0
15
+ Requires-Dist: tqdm<5.0.0,>=4.41.1
16
+ Requires-Dist: wasabi<1.0.0,>=0.6.0
17
+ Requires-Dist: plac<2.0.0,>=1.1.3
18
+
19
+ # unidic-py
20
+
21
+ This is a version of [UniDic](https://unidic.ninjal.ac.jp/) packaged for use
22
+ with pip.
23
+
24
+ Currently it supports 2.3.0, the latest version of UniDic. **Note this will
25
+ take up 1GB on disk after install.** If you want a small package, try
26
+ [unidic-lite](https://github.com/polm/unidic-lite).
27
+
28
+ The data for this dictionary is hosted as part of the AWS Open Data
29
+ Sponsorship Program. You can read the announcement
30
+ [here](https://aws.amazon.com/jp/blogs/news/published-unidic-mecab-on-aws-open-data/).
31
+
32
+ After installing via pip, you need to download the dictionary using the
33
+ following command:
34
+
35
+ python -m unidic download
36
+
37
+ With [fugashi](https://github.com/polm/fugashi) or
38
+ [mecab-python3](https://github.com/samurait/mecab-python3) unidic will be used
39
+ automatically when installed, though if you want you can manually pass the
40
+ MeCab arguments:
41
+
42
+ import fugashi
43
+ import unidic
44
+ tagger = fugashi.Tagger('-d "{}"'.format(unidic.DICDIR))
45
+ # that's it!
46
+
47
+ ## Differences from the Official UniDic Release
48
+
49
+ This has a few changes from the official UniDic release to make it easier to use.
50
+
51
+ - entries for 令和 have been added
52
+ - single-character numeric and alphabetic words have been deleted
53
+ - `unk.def` has been modified so unknown punctuation won't be marked as a noun
54
+
55
+ See the `extras` directory for details on how to replicate the build process.
56
+
57
+ ## Fields
58
+
59
+ Here is a list of fields included in this edition of UniDic. For more information see the [UniDic FAQ](https://unidic.ninjal.ac.jp/faq#col_name), though not all fields are included. For fields in the UniDic FAQ the name given there is included.
60
+
61
+ Fields which are not applicable are usually marked with an asterisk (`*`).
62
+
63
+ - **pos1, pos2, pos3, pos4**: Part of speech fields. The earlier fields are more general, the later fields are more specific.
64
+ - **cType:** 活用型, conjugation type. Will have a value like `五段-ラ行`.
65
+ - **cForm:** 活用形, conjugation shape. Will have a value like `連用形-促音便`.
66
+ - **lForm:** 語彙素読み, lemma reading. The reading of the lemma in katakana, this uses the same format as the `kana` field, not `pron`.
67
+ - **lemma:** 語彙素(+語彙素細分類). The lemma is a non-inflected "dictionary form" of a word. UniDic lemmas sometimes include extra info or have unusual forms, like using katakana for some place names.
68
+ - **orth:** 書字形出現形, the word as it appears in text, this appears to be identical to the surface.
69
+ - **pron:** 発音形出現形, pronunciation. This is similar to kana except that long vowels are indicated with a ー, so 講師 is こーし.
70
+ - **orthBase:** 書字形基本形, the uninflected form of the word using its current written form. For example, for 彷徨った the lemma is さ迷う but the orthBase is 彷徨う.
71
+ - **pronBase:** 発音形基本形, the pronunciation of the base form. Like `pron` for the `lemma` or `orthBase`.
72
+ - **goshu:** 語種, word type. Etymological category. In order of frequency, 和, 固, 漢, 外, 混, 記号, 不明. Defined for all dictionary words, blank for unks.
73
+ - **iType:** 語頭変化化型, "i" is for "initial". This is the type of initial transformation the word undergoes when combining, for example 兵 is へ半濁 because it can be read as べい in combination. This is available for <2% of entries.
74
+ - **iForm:** 語頭変化形, this is the initial form of the word in context, such as 基本形 or 半濁音形.
75
+ - **fType:** 語末変化化型, "f" is for "final", but otherwise as iType. For example 医学 is ク促 because it can change to いがっ (apparently). This is available for <0.1% of entries.
76
+ - **fForm:** 語末変化形, as iForm but for final transformations.
77
+ - **iConType:** 語頭変化結合型, initial change fusion type. Describes phonetic change at the start of the word in counting expressions. Only available for a few hundred entries, mostly numbers. Values are N followed by a letter or number; most entries with this value are numeric.
78
+ - **fConType:** 語末変化結合型, final change fusion type. This is also used for counting expressions, and like iConType it is only available for a few hundred entries. Unlike iConType the values are very complicated, like `B1S6SjShS,B1S6S8SjShS`.
79
+ - **type:** Not entirely clear what this is, seems to have some overlap with POS.
80
+ - **kana:** 読みがな, this is the typical representation of a word in kana, unlike pron. 講師 is こうし.
81
+ - **kanaBase:** 仮名形基本形, this is the typical kana representation of the lemma.
82
+ - **form:** 語形出現形, seems to be the same as `pron`.
83
+ - **formBase:** 語形基本形 seems to be the same as `pronBase`.
84
+ - **aType:** Accent type. This is a (potentially) comma-separated field which has the number of the mora taking the accent in 標準語 (standard language). When there are multiple values, more common accent patterns come first.
85
+ - **aConType:** This describes how the accent shifts when the word is used in a counter expression. It uses complicated notation.
86
+ - **aModType:** Presumably accent related but unclear use. Available for <25% of entries and only has 6 non-default values.
87
+ - **lid:** 語彙表ID. A long lemma ID. This seems to be a kind of GUID. There is usually one entry per line in the CSV, except that half-width and full-width variations can be combined.
88
+ - **lemma_id:** 語彙素ID. A shorter lemma id, starting from 1. This seems to be as unique as the `lemma` field, so many CSV lines can share this value.
89
+
90
+ # License
91
+
92
+ The modern Japanese UniDic is available under the GPL, LGPL, or BSD license,
93
+ [see here](https://unidic.ninjal.ac.jp/download#unidic_bccwj). UniDic is
94
+ developed by [NINJAL](https://www.ninjal.ac.jp/), the National Institute for
95
+ Japanese Language and Linguistics. UniDic is copyrighted by the UniDic
96
+ Consortium and is distributed here under the terms of the [BSD
97
+ License](./LICENSE.unidic).
98
+
99
+ The code in this repository is not written or maintained by NINJAL. The code is
100
+ available under the MIT or WTFPL License, as you prefer.
.venv/Lib/site-packages/unidic-1.1.0.dist-info/RECORD ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ unidic-1.1.0.dist-info/LICENSE,sha256=hzatDUY2y22rrj6X6ZwI9cDAi4xFHx1Imymg1jvr8HQ,1076
2
+ unidic-1.1.0.dist-info/METADATA,sha256=QpBzpNFSurXRSzcpxxSZt6fync7GBvSu48M40goxcKM,6661
3
+ unidic-1.1.0.dist-info/RECORD,,
4
+ unidic-1.1.0.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
+ unidic-1.1.0.dist-info/top_level.txt,sha256=Rrt9OcSUZ5g2Cp-gZkC3EEUwWyurf_jm-k9UyM4BQxQ,7
6
+ unidic-1.1.0.dist-info\INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
7
+ unidic-1.1.0.dist-info\REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ unidic/__init__.py,sha256=ij55hIkxnef3Mrj2Nf6YDC0DF3Oe2TgoyQmV0IPaXp4,36
9
+ unidic/__main__.py,sha256=sNrhnmvgmndJflis5BeyJnObhynGqjQMDVHFhV7h8_Y,511
10
+ unidic/download.py,sha256=ehUHLc4f2dJpuonqy0PkTtfVpW1pDidL_QFp1iKBrb4,3536
11
+ unidic/unidic.py,sha256=emlkiIhLqiEqBJS6KtvsItpZ7ts1vhznTkgiEzirjE0,416
.venv/Lib/site-packages/unidic-1.1.0.dist-info/REQUESTED ADDED
File without changes
.venv/Lib/site-packages/unidic-1.1.0.dist-info/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
.venv/Lib/site-packages/unidic-1.1.0.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ unidic
.venv/Lib/site-packages/unidic/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (233 Bytes). View file
 
.venv/Lib/site-packages/unidic/__pycache__/__main__.cpython-39.pyc ADDED
Binary file (555 Bytes). View file
 
.venv/Lib/site-packages/unidic/__pycache__/unidic.cpython-39.pyc ADDED
Binary file (632 Bytes). View file
 
.venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/METADATA ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: unidic-lite
3
+ Version: 1.0.8
4
+ Summary: A small version of UniDic packaged for Python
5
+ Home-page: https://github.com/polm/unidic-lite
6
+ Author: Paul O'Leary McCann
7
+ Author-email: [email protected]
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Natural Language :: Japanese
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ License-File: LICENSE.unidic
15
+
16
+ [![Current PyPI packages](https://badge.fury.io/py/unidic-lite.svg)](https://pypi.org/project/unidic-lite/)
17
+
18
+ # Unidic Lite
19
+
20
+ This is a version of [unidic-py](https://github.com/polm/unidic-py) that is
21
+ designed to be installable with pip alone, not requiring any extra downloads.
22
+
23
+ At the moment it uses Unidic 2.1.2, from 2013, which is the most recent release
24
+ of UniDic that's small enough to be distributed via PyPI.
25
+
26
+ **Note this package takes roughly 250MB on disk after being installed.**
27
+
28
+ In order to use this you will need to install a MeCab wrapper such as
29
+ [mecab-python3](https://github.com/SamuraiT/mecab-python3) or
30
+ [fugashi](https://github.com/polm/fugashi).
31
+
32
+ ## Differences from the Official UniDic Release
33
+
34
+ This has a few changes from the official UniDic release to make it easier to use.
35
+
36
+ - entries for 令和 have been added
37
+ - single-character numeric and alphabetic words have been deleted
38
+ - `unk.def` has been modified so unknown punctuation won't be marked as a noun
39
+
40
+ ## License
41
+
42
+ This code is licensed under the MIT or WTFPL license, as you prefer. Unidic
43
+ 2.1.2 is copyright the UniDic Consortium and distributed under the terms of the
44
+ [BSD license](./LICENSE.unidic).
.venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/RECORD ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ unidic_lite-1.0.8.dist-info/LICENSE,sha256=NFZZNt-P9QcVtynAZdCypHUjHaee_EwieeK8zuXwKjM,1051
2
+ unidic_lite-1.0.8.dist-info/LICENSE.unidic,sha256=0s_ewl16y1m3ruLJs2_VJHB3PO5YosNAwXn0NasFO_I,1515
3
+ unidic_lite-1.0.8.dist-info/METADATA,sha256=ZHKDtnDqHShWmyWQQjvQ9B-_jq3Xmrfnl5npr9KeCg4,1730
4
+ unidic_lite-1.0.8.dist-info/RECORD,,
5
+ unidic_lite-1.0.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
6
+ unidic_lite-1.0.8.dist-info/top_level.txt,sha256=mslJM-63kzGdb13nggWmhM3CsWY7906BOXYufdrBREk,12
7
+ unidic_lite-1.0.8.dist-info\INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
8
+ unidic_lite-1.0.8.dist-info\REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ unidic_lite/__init__.py,sha256=ij55hIkxnef3Mrj2Nf6YDC0DF3Oe2TgoyQmV0IPaXp4,36
10
+ unidic_lite/dicdir/AUTHORS,sha256=oFv906nbNtnGRJX0o9GCTQW5X7tPxtwHxmDpG8GRxIE,22
11
+ unidic_lite/dicdir/BSD,sha256=eRfs-vlaW6e09FqpqEWskx15yQ85t-cRRC28IcYSVg8,1515
12
+ unidic_lite/dicdir/COPYING,sha256=F4_7fLwr6tsLh6FEl-WCIrSEB2unz8iTigesdif6IsQ,195
13
+ unidic_lite/dicdir/ChangeLog,sha256=SANZd6MI-7ZTJuTYHxUYbMJBATs2CtFh2Cx6FRpb2KA,947
14
+ unidic_lite/dicdir/GPL,sha256=oTdDQZb1452INt6JWGb8_qB0rRsoJDF0yhxKWFoSKbA,17991
15
+ unidic_lite/dicdir/INSTALL,sha256=e0-YCojp4z6Wzle3Ws5gvJNhOOx-2sCwPrvZyeO-clA,22
16
+ unidic_lite/dicdir/LGPL,sha256=US0tIbazOEumR4GrsCCKG4d0C8MeLfSOKyBt235NV3k,26428
17
+ unidic_lite/dicdir/README.md,sha256=wnl9G7QW2csvTy1H4_-Os-kaa8NZdKAuzE_81EQWB_c,402
18
+ unidic_lite/dicdir/char.bin,sha256=3TE5ZWPYkkZFuA_Tyap7E8oInXdI8lVToda8P5tRGug,262496
19
+ unidic_lite/dicdir/dicrc,sha256=_NF_NXUt4UF4WaFeLh8EPWZtoD823GMujA7UaIeIOlk,1444
20
+ unidic_lite/dicdir/left-id.def,sha256=xez75Hp9LZ8EBLb5dG5KuW_H8vN-FiJPAyWlMKtnrfc,449526
21
+ unidic_lite/dicdir/matrix.bin,sha256=iPuZ7-EHXZuLQOAbsnUeQJXxYSYY8kkK93brXtORkKk,71544726
22
+ unidic_lite/dicdir/mecabrc,sha256=cgIa4X5WgLtLs7Vw5-eStWfkxnWMexezn7x8jEmSKbM,62
23
+ unidic_lite/dicdir/rewrite.def,sha256=HlAZPy-MPg--8nWc14y3Vu47k7_fUctmyF_dwkMpi9s,4061
24
+ unidic_lite/dicdir/right-id.def,sha256=xez75Hp9LZ8EBLb5dG5KuW_H8vN-FiJPAyWlMKtnrfc,449526
25
+ unidic_lite/dicdir/sys.dic,sha256=EixMkfAmv0tlu-Lf2Ln47rarVtjrKnKHpovKdXCLpRM,187680870
26
+ unidic_lite/dicdir/unidic-mecab.pdf,sha256=bl7MR3CIHP4rymw7dLog8bB7unV8hkVIy3n2KwVQzFs,21462
27
+ unidic_lite/dicdir/unk.dic,sha256=47koA_7rbCcSx5a5BTF-wZKllynSwekrJyjUVBaVQcQ,5475
28
+ unidic_lite/dicdir/version,sha256=n2JxlR7coC4MimaaeZMGJnF7d_BEOtijJ7k6UuQZSCk,6
29
+ unidic_lite/unidic.py,sha256=jbDy755H1lfdoPqmNxwfUmhZRZJxo8ptnCLmVO-xgUw,322
.venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/REQUESTED ADDED
File without changes
.venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
.venv/Lib/site-packages/unidic_lite-1.0.8.dist-info/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ unidic_lite
.venv/Lib/site-packages/unidic_lite/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .unidic import DICDIR, VERSION
.venv/Lib/site-packages/unidic_lite/dicdir/AUTHORS ADDED
@@ -0,0 +1 @@
 
 
1
+ The UniDic Consortium
.venv/Lib/site-packages/unidic_lite/dicdir/BSD ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2011-2013, The UniDic Consortium
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the
14
+ distribution.
15
+
16
+ * Neither the name of the UniDic Consortium nor the names of its
17
+ contributors may be used to endorse or promote products derived
18
+ from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.venv/Lib/site-packages/unidic_lite/dicdir/COPYING ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ unidic-mecab is copyrighted free software by the UniDic Consortium,
2
+ and is released under any of the GPL (see the file GPL), the LGPL (see
3
+ the file LGPL), or the BSD License (see the file BSD).
4
+
.venv/Lib/site-packages/unidic_lite/dicdir/ChangeLog ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 2013-01-26 Yasuharu DEN <[email protected]>
2
+
3
+ * ver. 2.1.2 release
4
+ Customized lex.csv for kana and accent information added
5
+
6
+ 2012-12-12 Yasuharu DEN <[email protected]>
7
+
8
+ * ver. 2.1.1 release
9
+ Adjusted to MeCab-0.994
10
+
11
+ 2011-02-27 Yasuharu DEN <[email protected]>
12
+
13
+ * ver. 2.1.0 release
14
+ New release based on UniDic2
15
+
16
+ 2009-07-31 Yasuharu DEN <[email protected]>
17
+
18
+ * ver. 1.3.12 release
19
+ Some minor changes
20
+
21
+ 2009-04-30 Yasuharu DEN <[email protected]>
22
+
23
+ * ver. 1.3.11 release
24
+ New POS tag `Ascii-Art' added
25
+
26
+ 2008-07-15 Yasuharu DEN <[email protected]>
27
+
28
+ * ver. 1.3.9 release
29
+ Bug fix
30
+
31
+ 2008-04-25 Yasuharu DEN <[email protected]>
32
+
33
+ * ver. 1.3.8 release
34
+ Goshu information added
35
+
36
+ 2007-10-12 Yasuharu DEN <[email protected]>
37
+
38
+ * ver. 1.3.5 release
39
+ The conjugation system changed: Kihon -> Syusi/Rentai
40
+
41
+ 2007-04-06 Yasuharu DEN <[email protected]>
42
+
43
+ * ver. 1.3.0 release
.venv/Lib/site-packages/unidic_lite/dicdir/GPL ADDED
@@ -0,0 +1,340 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ Preamble
10
+
11
+ The licenses for most software are designed to take away your
12
+ freedom to share and change it. By contrast, the GNU General Public
13
+ License is intended to guarantee your freedom to share and change free
14
+ software--to make sure the software is free for all its users. This
15
+ General Public License applies to most of the Free Software
16
+ Foundation's software and to any other program whose authors commit to
17
+ using it. (Some other Free Software Foundation software is covered by
18
+ the GNU Library General Public License instead.) You can apply it to
19
+ your programs, too.
20
+
21
+ When we speak of free software, we are referring to freedom, not
22
+ price. Our General Public Licenses are designed to make sure that you
23
+ have the freedom to distribute copies of free software (and charge for
24
+ this service if you wish), that you receive source code or can get it
25
+ if you want it, that you can change the software or use pieces of it
26
+ in new free programs; and that you know you can do these things.
27
+
28
+ To protect your rights, we need to make restrictions that forbid
29
+ anyone to deny you these rights or to ask you to surrender the rights.
30
+ These restrictions translate to certain responsibilities for you if you
31
+ distribute copies of the software, or if you modify it.
32
+
33
+ For example, if you distribute copies of such a program, whether
34
+ gratis or for a fee, you must give the recipients all the rights that
35
+ you have. You must make sure that they, too, receive or can get the
36
+ source code. And you must show them these terms so they know their
37
+ rights.
38
+
39
+ We protect your rights with two steps: (1) copyright the software, and
40
+ (2) offer you this license which gives you legal permission to copy,
41
+ distribute and/or modify the software.
42
+
43
+ Also, for each author's protection and ours, we want to make certain
44
+ that everyone understands that there is no warranty for this free
45
+ software. If the software is modified by someone else and passed on, we
46
+ want its recipients to know that what they have is not the original, so
47
+ that any problems introduced by others will not reflect on the original
48
+ authors' reputations.
49
+
50
+ Finally, any free program is threatened constantly by software
51
+ patents. We wish to avoid the danger that redistributors of a free
52
+ program will individually obtain patent licenses, in effect making the
53
+ program proprietary. To prevent this, we have made it clear that any
54
+ patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+ The precise terms and conditions for copying, distribution and
57
+ modification follow.
58
+
59
+ GNU GENERAL PUBLIC LICENSE
60
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+ 0. This License applies to any program or other work which contains
63
+ a notice placed by the copyright holder saying it may be distributed
64
+ under the terms of this General Public License. The "Program", below,
65
+ refers to any such program or work, and a "work based on the Program"
66
+ means either the Program or any derivative work under copyright law:
67
+ that is to say, a work containing the Program or a portion of it,
68
+ either verbatim or with modifications and/or translated into another
69
+ language. (Hereinafter, translation is included without limitation in
70
+ the term "modification".) Each licensee is addressed as "you".
71
+
72
+ Activities other than copying, distribution and modification are not
73
+ covered by this License; they are outside its scope. The act of
74
+ running the Program is not restricted, and the output from the Program
75
+ is covered only if its contents constitute a work based on the
76
+ Program (independent of having been made by running the Program).
77
+ Whether that is true depends on what the Program does.
78
+
79
+ 1. You may copy and distribute verbatim copies of the Program's
80
+ source code as you receive it, in any medium, provided that you
81
+ conspicuously and appropriately publish on each copy an appropriate
82
+ copyright notice and disclaimer of warranty; keep intact all the
83
+ notices that refer to this License and to the absence of any warranty;
84
+ and give any other recipients of the Program a copy of this License
85
+ along with the Program.
86
+
87
+ You may charge a fee for the physical act of transferring a copy, and
88
+ you may at your option offer warranty protection in exchange for a fee.
89
+
90
+ 2. You may modify your copy or copies of the Program or any portion
91
+ of it, thus forming a work based on the Program, and copy and
92
+ distribute such modifications or work under the terms of Section 1
93
+ above, provided that you also meet all of these conditions:
94
+
95
+ a) You must cause the modified files to carry prominent notices
96
+ stating that you changed the files and the date of any change.
97
+
98
+ b) You must cause any work that you distribute or publish, that in
99
+ whole or in part contains or is derived from the Program or any
100
+ part thereof, to be licensed as a whole at no charge to all third
101
+ parties under the terms of this License.
102
+
103
+ c) If the modified program normally reads commands interactively
104
+ when run, you must cause it, when started running for such
105
+ interactive use in the most ordinary way, to print or display an
106
+ announcement including an appropriate copyright notice and a
107
+ notice that there is no warranty (or else, saying that you provide
108
+ a warranty) and that users may redistribute the program under
109
+ these conditions, and telling the user how to view a copy of this
110
+ License. (Exception: if the Program itself is interactive but
111
+ does not normally print such an announcement, your work based on
112
+ the Program is not required to print an announcement.)
113
+
114
+ These requirements apply to the modified work as a whole. If
115
+ identifiable sections of that work are not derived from the Program,
116
+ and can be reasonably considered independent and separate works in
117
+ themselves, then this License, and its terms, do not apply to those
118
+ sections when you distribute them as separate works. But when you
119
+ distribute the same sections as part of a whole which is a work based
120
+ on the Program, the distribution of the whole must be on the terms of
121
+ this License, whose permissions for other licensees extend to the
122
+ entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+ Thus, it is not the intent of this section to claim rights or contest
125
+ your rights to work written entirely by you; rather, the intent is to
126
+ exercise the right to control the distribution of derivative or
127
+ collective works based on the Program.
128
+
129
+ In addition, mere aggregation of another work not based on the Program
130
+ with the Program (or with a work based on the Program) on a volume of
131
+ a storage or distribution medium does not bring the other work under
132
+ the scope of this License.
133
+
134
+ 3. You may copy and distribute the Program (or a work based on it,
135
+ under Section 2) in object code or executable form under the terms of
136
+ Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+ a) Accompany it with the complete corresponding machine-readable
139
+ source code, which must be distributed under the terms of Sections
140
+ 1 and 2 above on a medium customarily used for software interchange; or,
141
+
142
+ b) Accompany it with a written offer, valid for at least three
143
+ years, to give any third party, for a charge no more than your
144
+ cost of physically performing source distribution, a complete
145
+ machine-readable copy of the corresponding source code, to be
146
+ distributed under the terms of Sections 1 and 2 above on a medium
147
+ customarily used for software interchange; or,
148
+
149
+ c) Accompany it with the information you received as to the offer
150
+ to distribute corresponding source code. (This alternative is
151
+ allowed only for noncommercial distribution and only if you
152
+ received the program in object code or executable form with such
153
+ an offer, in accord with Subsection b above.)
154
+
155
+ The source code for a work means the preferred form of the work for
156
+ making modifications to it. For an executable work, complete source
157
+ code means all the source code for all modules it contains, plus any
158
+ associated interface definition files, plus the scripts used to
159
+ control compilation and installation of the executable. However, as a
160
+ special exception, the source code distributed need not include
161
+ anything that is normally distributed (in either source or binary
162
+ form) with the major components (compiler, kernel, and so on) of the
163
+ operating system on which the executable runs, unless that component
164
+ itself accompanies the executable.
165
+
166
+ If distribution of executable or object code is made by offering
167
+ access to copy from a designated place, then offering equivalent
168
+ access to copy the source code from the same place counts as
169
+ distribution of the source code, even though third parties are not
170
+ compelled to copy the source along with the object code.
171
+
172
+ 4. You may not copy, modify, sublicense, or distribute the Program
173
+ except as expressly provided under this License. Any attempt
174
+ otherwise to copy, modify, sublicense or distribute the Program is
175
+ void, and will automatically terminate your rights under this License.
176
+ However, parties who have received copies, or rights, from you under
177
+ this License will not have their licenses terminated so long as such
178
+ parties remain in full compliance.
179
+
180
+ 5. You are not required to accept this License, since you have not
181
+ signed it. However, nothing else grants you permission to modify or
182
+ distribute the Program or its derivative works. These actions are
183
+ prohibited by law if you do not accept this License. Therefore, by
184
+ modifying or distributing the Program (or any work based on the
185
+ Program), you indicate your acceptance of this License to do so, and
186
+ all its terms and conditions for copying, distributing or modifying
187
+ the Program or works based on it.
188
+
189
+ 6. Each time you redistribute the Program (or any work based on the
190
+ Program), the recipient automatically receives a license from the
191
+ original licensor to copy, distribute or modify the Program subject to
192
+ these terms and conditions. You may not impose any further
193
+ restrictions on the recipients' exercise of the rights granted herein.
194
+ You are not responsible for enforcing compliance by third parties to
195
+ this License.
196
+
197
+ 7. If, as a consequence of a court judgment or allegation of patent
198
+ infringement or for any other reason (not limited to patent issues),
199
+ conditions are imposed on you (whether by court order, agreement or
200
+ otherwise) that contradict the conditions of this License, they do not
201
+ excuse you from the conditions of this License. If you cannot
202
+ distribute so as to satisfy simultaneously your obligations under this
203
+ License and any other pertinent obligations, then as a consequence you
204
+ may not distribute the Program at all. For example, if a patent
205
+ license would not permit royalty-free redistribution of the Program by
206
+ all those who receive copies directly or indirectly through you, then
207
+ the only way you could satisfy both it and this License would be to
208
+ refrain entirely from distribution of the Program.
209
+
210
+ If any portion of this section is held invalid or unenforceable under
211
+ any particular circumstance, the balance of the section is intended to
212
+ apply and the section as a whole is intended to apply in other
213
+ circumstances.
214
+
215
+ It is not the purpose of this section to induce you to infringe any
216
+ patents or other property right claims or to contest validity of any
217
+ such claims; this section has the sole purpose of protecting the
218
+ integrity of the free software distribution system, which is
219
+ implemented by public license practices. Many people have made
220
+ generous contributions to the wide range of software distributed
221
+ through that system in reliance on consistent application of that
222
+ system; it is up to the author/donor to decide if he or she is willing
223
+ to distribute software through any other system and a licensee cannot
224
+ impose that choice.
225
+
226
+ This section is intended to make thoroughly clear what is believed to
227
+ be a consequence of the rest of this License.
228
+
229
+ 8. If the distribution and/or use of the Program is restricted in
230
+ certain countries either by patents or by copyrighted interfaces, the
231
+ original copyright holder who places the Program under this License
232
+ may add an explicit geographical distribution limitation excluding
233
+ those countries, so that distribution is permitted only in or among
234
+ countries not thus excluded. In such case, this License incorporates
235
+ the limitation as if written in the body of this License.
236
+
237
+ 9. The Free Software Foundation may publish revised and/or new versions
238
+ of the General Public License from time to time. Such new versions will
239
+ be similar in spirit to the present version, but may differ in detail to
240
+ address new problems or concerns.
241
+
242
+ Each version is given a distinguishing version number. If the Program
243
+ specifies a version number of this License which applies to it and "any
244
+ later version", you have the option of following the terms and conditions
245
+ either of that version or of any later version published by the Free
246
+ Software Foundation. If the Program does not specify a version number of
247
+ this License, you may choose any version ever published by the Free Software
248
+ Foundation.
249
+
250
+ 10. If you wish to incorporate parts of the Program into other free
251
+ programs whose distribution conditions are different, write to the author
252
+ to ask for permission. For software which is copyrighted by the Free
253
+ Software Foundation, write to the Free Software Foundation; we sometimes
254
+ make exceptions for this. Our decision will be guided by the two goals
255
+ of preserving the free status of all derivatives of our free software and
256
+ of promoting the sharing and reuse of software generally.
257
+
258
+ NO WARRANTY
259
+
260
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
+ REPAIR OR CORRECTION.
269
+
270
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
+ POSSIBILITY OF SUCH DAMAGES.
279
+
280
+ END OF TERMS AND CONDITIONS
281
+
282
+ How to Apply These Terms to Your New Programs
283
+
284
+ If you develop a new program, and you want it to be of the greatest
285
+ possible use to the public, the best way to achieve this is to make it
286
+ free software which everyone can redistribute and change under these terms.
287
+
288
+ To do so, attach the following notices to the program. It is safest
289
+ to attach them to the start of each source file to most effectively
290
+ convey the exclusion of warranty; and each file should have at least
291
+ the "copyright" line and a pointer to where the full notice is found.
292
+
293
+ <one line to give the program's name and a brief idea of what it does.>
294
+ Copyright (C) <year> <name of author>
295
+
296
+ This program is free software; you can redistribute it and/or modify
297
+ it under the terms of the GNU General Public License as published by
298
+ the Free Software Foundation; either version 2 of the License, or
299
+ (at your option) any later version.
300
+
301
+ This program is distributed in the hope that it will be useful,
302
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304
+ GNU General Public License for more details.
305
+
306
+ You should have received a copy of the GNU General Public License
307
+ along with this program; if not, write to the Free Software
308
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
+
310
+
311
+ Also add information on how to contact you by electronic and paper mail.
312
+
313
+ If the program is interactive, make it output a short notice like this
314
+ when it starts in an interactive mode:
315
+
316
+ Gnomovision version 69, Copyright (C) year name of author
317
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318
+ This is free software, and you are welcome to redistribute it
319
+ under certain conditions; type `show c' for details.
320
+
321
+ The hypothetical commands `show w' and `show c' should show the appropriate
322
+ parts of the General Public License. Of course, the commands you use may
323
+ be called something other than `show w' and `show c'; they could even be
324
+ mouse-clicks or menu items--whatever suits your program.
325
+
326
+ You should also get your employer (if you work as a programmer) or your
327
+ school, if any, to sign a "copyright disclaimer" for the program, if
328
+ necessary. Here is a sample; alter the names:
329
+
330
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
+
333
+ <signature of Ty Coon>, 1 April 1989
334
+ Ty Coon, President of Vice
335
+
336
+ This General Public License does not permit incorporating your program into
337
+ proprietary programs. If your program is a subroutine library, you may
338
+ consider it more useful to permit linking proprietary applications with the
339
+ library. If this is what you want to do, use the GNU Library General
340
+ Public License instead of this License.
.venv/Lib/site-packages/unidic_lite/dicdir/INSTALL ADDED
@@ -0,0 +1 @@
 
 
1
+ see unidic-mecab.pdf
.venv/Lib/site-packages/unidic_lite/dicdir/LGPL ADDED
@@ -0,0 +1,504 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 2.1, February 1999
3
+
4
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
5
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+ [This is the first released version of the Lesser GPL. It also counts
10
+ as the successor of the GNU Library Public License, version 2, hence
11
+ the version number 2.1.]
12
+
13
+ Preamble
14
+
15
+ The licenses for most software are designed to take away your
16
+ freedom to share and change it. By contrast, the GNU General Public
17
+ Licenses are intended to guarantee your freedom to share and change
18
+ free software--to make sure the software is free for all its users.
19
+
20
+ This license, the Lesser General Public License, applies to some
21
+ specially designated software packages--typically libraries--of the
22
+ Free Software Foundation and other authors who decide to use it. You
23
+ can use it too, but we suggest you first think carefully about whether
24
+ this license or the ordinary General Public License is the better
25
+ strategy to use in any particular case, based on the explanations below.
26
+
27
+ When we speak of free software, we are referring to freedom of use,
28
+ not price. Our General Public Licenses are designed to make sure that
29
+ you have the freedom to distribute copies of free software (and charge
30
+ for this service if you wish); that you receive source code or can get
31
+ it if you want it; that you can change the software and use pieces of
32
+ it in new free programs; and that you are informed that you can do
33
+ these things.
34
+
35
+ To protect your rights, we need to make restrictions that forbid
36
+ distributors to deny you these rights or to ask you to surrender these
37
+ rights. These restrictions translate to certain responsibilities for
38
+ you if you distribute copies of the library or if you modify it.
39
+
40
+ For example, if you distribute copies of the library, whether gratis
41
+ or for a fee, you must give the recipients all the rights that we gave
42
+ you. You must make sure that they, too, receive or can get the source
43
+ code. If you link other code with the library, you must provide
44
+ complete object files to the recipients, so that they can relink them
45
+ with the library after making changes to the library and recompiling
46
+ it. And you must show them these terms so they know their rights.
47
+
48
+ We protect your rights with a two-step method: (1) we copyright the
49
+ library, and (2) we offer you this license, which gives you legal
50
+ permission to copy, distribute and/or modify the library.
51
+
52
+ To protect each distributor, we want to make it very clear that
53
+ there is no warranty for the free library. Also, if the library is
54
+ modified by someone else and passed on, the recipients should know
55
+ that what they have is not the original version, so that the original
56
+ author's reputation will not be affected by problems that might be
57
+ introduced by others.
58
+
59
+ Finally, software patents pose a constant threat to the existence of
60
+ any free program. We wish to make sure that a company cannot
61
+ effectively restrict the users of a free program by obtaining a
62
+ restrictive license from a patent holder. Therefore, we insist that
63
+ any patent license obtained for a version of the library must be
64
+ consistent with the full freedom of use specified in this license.
65
+
66
+ Most GNU software, including some libraries, is covered by the
67
+ ordinary GNU General Public License. This license, the GNU Lesser
68
+ General Public License, applies to certain designated libraries, and
69
+ is quite different from the ordinary General Public License. We use
70
+ this license for certain libraries in order to permit linking those
71
+ libraries into non-free programs.
72
+
73
+ When a program is linked with a library, whether statically or using
74
+ a shared library, the combination of the two is legally speaking a
75
+ combined work, a derivative of the original library. The ordinary
76
+ General Public License therefore permits such linking only if the
77
+ entire combination fits its criteria of freedom. The Lesser General
78
+ Public License permits more lax criteria for linking other code with
79
+ the library.
80
+
81
+ We call this license the "Lesser" General Public License because it
82
+ does Less to protect the user's freedom than the ordinary General
83
+ Public License. It also provides other free software developers Less
84
+ of an advantage over competing non-free programs. These disadvantages
85
+ are the reason we use the ordinary General Public License for many
86
+ libraries. However, the Lesser license provides advantages in certain
87
+ special circumstances.
88
+
89
+ For example, on rare occasions, there may be a special need to
90
+ encourage the widest possible use of a certain library, so that it becomes
91
+ a de-facto standard. To achieve this, non-free programs must be
92
+ allowed to use the library. A more frequent case is that a free
93
+ library does the same job as widely used non-free libraries. In this
94
+ case, there is little to gain by limiting the free library to free
95
+ software only, so we use the Lesser General Public License.
96
+
97
+ In other cases, permission to use a particular library in non-free
98
+ programs enables a greater number of people to use a large body of
99
+ free software. For example, permission to use the GNU C Library in
100
+ non-free programs enables many more people to use the whole GNU
101
+ operating system, as well as its variant, the GNU/Linux operating
102
+ system.
103
+
104
+ Although the Lesser General Public License is Less protective of the
105
+ users' freedom, it does ensure that the user of a program that is
106
+ linked with the Library has the freedom and the wherewithal to run
107
+ that program using a modified version of the Library.
108
+
109
+ The precise terms and conditions for copying, distribution and
110
+ modification follow. Pay close attention to the difference between a
111
+ "work based on the library" and a "work that uses the library". The
112
+ former contains code derived from the library, whereas the latter must
113
+ be combined with the library in order to run.
114
+
115
+ GNU LESSER GENERAL PUBLIC LICENSE
116
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
117
+
118
+ 0. This License Agreement applies to any software library or other
119
+ program which contains a notice placed by the copyright holder or
120
+ other authorized party saying it may be distributed under the terms of
121
+ this Lesser General Public License (also called "this License").
122
+ Each licensee is addressed as "you".
123
+
124
+ A "library" means a collection of software functions and/or data
125
+ prepared so as to be conveniently linked with application programs
126
+ (which use some of those functions and data) to form executables.
127
+
128
+ The "Library", below, refers to any such software library or work
129
+ which has been distributed under these terms. A "work based on the
130
+ Library" means either the Library or any derivative work under
131
+ copyright law: that is to say, a work containing the Library or a
132
+ portion of it, either verbatim or with modifications and/or translated
133
+ straightforwardly into another language. (Hereinafter, translation is
134
+ included without limitation in the term "modification".)
135
+
136
+ "Source code" for a work means the preferred form of the work for
137
+ making modifications to it. For a library, complete source code means
138
+ all the source code for all modules it contains, plus any associated
139
+ interface definition files, plus the scripts used to control compilation
140
+ and installation of the library.
141
+
142
+ Activities other than copying, distribution and modification are not
143
+ covered by this License; they are outside its scope. The act of
144
+ running a program using the Library is not restricted, and output from
145
+ such a program is covered only if its contents constitute a work based
146
+ on the Library (independent of the use of the Library in a tool for
147
+ writing it). Whether that is true depends on what the Library does
148
+ and what the program that uses the Library does.
149
+
150
+ 1. You may copy and distribute verbatim copies of the Library's
151
+ complete source code as you receive it, in any medium, provided that
152
+ you conspicuously and appropriately publish on each copy an
153
+ appropriate copyright notice and disclaimer of warranty; keep intact
154
+ all the notices that refer to this License and to the absence of any
155
+ warranty; and distribute a copy of this License along with the
156
+ Library.
157
+
158
+ You may charge a fee for the physical act of transferring a copy,
159
+ and you may at your option offer warranty protection in exchange for a
160
+ fee.
161
+
162
+ 2. You may modify your copy or copies of the Library or any portion
163
+ of it, thus forming a work based on the Library, and copy and
164
+ distribute such modifications or work under the terms of Section 1
165
+ above, provided that you also meet all of these conditions:
166
+
167
+ a) The modified work must itself be a software library.
168
+
169
+ b) You must cause the files modified to carry prominent notices
170
+ stating that you changed the files and the date of any change.
171
+
172
+ c) You must cause the whole of the work to be licensed at no
173
+ charge to all third parties under the terms of this License.
174
+
175
+ d) If a facility in the modified Library refers to a function or a
176
+ table of data to be supplied by an application program that uses
177
+ the facility, other than as an argument passed when the facility
178
+ is invoked, then you must make a good faith effort to ensure that,
179
+ in the event an application does not supply such function or
180
+ table, the facility still operates, and performs whatever part of
181
+ its purpose remains meaningful.
182
+
183
+ (For example, a function in a library to compute square roots has
184
+ a purpose that is entirely well-defined independent of the
185
+ application. Therefore, Subsection 2d requires that any
186
+ application-supplied function or table used by this function must
187
+ be optional: if the application does not supply it, the square
188
+ root function must still compute square roots.)
189
+
190
+ These requirements apply to the modified work as a whole. If
191
+ identifiable sections of that work are not derived from the Library,
192
+ and can be reasonably considered independent and separate works in
193
+ themselves, then this License, and its terms, do not apply to those
194
+ sections when you distribute them as separate works. But when you
195
+ distribute the same sections as part of a whole which is a work based
196
+ on the Library, the distribution of the whole must be on the terms of
197
+ this License, whose permissions for other licensees extend to the
198
+ entire whole, and thus to each and every part regardless of who wrote
199
+ it.
200
+
201
+ Thus, it is not the intent of this section to claim rights or contest
202
+ your rights to work written entirely by you; rather, the intent is to
203
+ exercise the right to control the distribution of derivative or
204
+ collective works based on the Library.
205
+
206
+ In addition, mere aggregation of another work not based on the Library
207
+ with the Library (or with a work based on the Library) on a volume of
208
+ a storage or distribution medium does not bring the other work under
209
+ the scope of this License.
210
+
211
+ 3. You may opt to apply the terms of the ordinary GNU General Public
212
+ License instead of this License to a given copy of the Library. To do
213
+ this, you must alter all the notices that refer to this License, so
214
+ that they refer to the ordinary GNU General Public License, version 2,
215
+ instead of to this License. (If a newer version than version 2 of the
216
+ ordinary GNU General Public License has appeared, then you can specify
217
+ that version instead if you wish.) Do not make any other change in
218
+ these notices.
219
+
220
+ Once this change is made in a given copy, it is irreversible for
221
+ that copy, so the ordinary GNU General Public License applies to all
222
+ subsequent copies and derivative works made from that copy.
223
+
224
+ This option is useful when you wish to copy part of the code of
225
+ the Library into a program that is not a library.
226
+
227
+ 4. You may copy and distribute the Library (or a portion or
228
+ derivative of it, under Section 2) in object code or executable form
229
+ under the terms of Sections 1 and 2 above provided that you accompany
230
+ it with the complete corresponding machine-readable source code, which
231
+ must be distributed under the terms of Sections 1 and 2 above on a
232
+ medium customarily used for software interchange.
233
+
234
+ If distribution of object code is made by offering access to copy
235
+ from a designated place, then offering equivalent access to copy the
236
+ source code from the same place satisfies the requirement to
237
+ distribute the source code, even though third parties are not
238
+ compelled to copy the source along with the object code.
239
+
240
+ 5. A program that contains no derivative of any portion of the
241
+ Library, but is designed to work with the Library by being compiled or
242
+ linked with it, is called a "work that uses the Library". Such a
243
+ work, in isolation, is not a derivative work of the Library, and
244
+ therefore falls outside the scope of this License.
245
+
246
+ However, linking a "work that uses the Library" with the Library
247
+ creates an executable that is a derivative of the Library (because it
248
+ contains portions of the Library), rather than a "work that uses the
249
+ library". The executable is therefore covered by this License.
250
+ Section 6 states terms for distribution of such executables.
251
+
252
+ When a "work that uses the Library" uses material from a header file
253
+ that is part of the Library, the object code for the work may be a
254
+ derivative work of the Library even though the source code is not.
255
+ Whether this is true is especially significant if the work can be
256
+ linked without the Library, or if the work is itself a library. The
257
+ threshold for this to be true is not precisely defined by law.
258
+
259
+ If such an object file uses only numerical parameters, data
260
+ structure layouts and accessors, and small macros and small inline
261
+ functions (ten lines or less in length), then the use of the object
262
+ file is unrestricted, regardless of whether it is legally a derivative
263
+ work. (Executables containing this object code plus portions of the
264
+ Library will still fall under Section 6.)
265
+
266
+ Otherwise, if the work is a derivative of the Library, you may
267
+ distribute the object code for the work under the terms of Section 6.
268
+ Any executables containing that work also fall under Section 6,
269
+ whether or not they are linked directly with the Library itself.
270
+
271
+ 6. As an exception to the Sections above, you may also combine or
272
+ link a "work that uses the Library" with the Library to produce a
273
+ work containing portions of the Library, and distribute that work
274
+ under terms of your choice, provided that the terms permit
275
+ modification of the work for the customer's own use and reverse
276
+ engineering for debugging such modifications.
277
+
278
+ You must give prominent notice with each copy of the work that the
279
+ Library is used in it and that the Library and its use are covered by
280
+ this License. You must supply a copy of this License. If the work
281
+ during execution displays copyright notices, you must include the
282
+ copyright notice for the Library among them, as well as a reference
283
+ directing the user to the copy of this License. Also, you must do one
284
+ of these things:
285
+
286
+ a) Accompany the work with the complete corresponding
287
+ machine-readable source code for the Library including whatever
288
+ changes were used in the work (which must be distributed under
289
+ Sections 1 and 2 above); and, if the work is an executable linked
290
+ with the Library, with the complete machine-readable "work that
291
+ uses the Library", as object code and/or source code, so that the
292
+ user can modify the Library and then relink to produce a modified
293
+ executable containing the modified Library. (It is understood
294
+ that the user who changes the contents of definitions files in the
295
+ Library will not necessarily be able to recompile the application
296
+ to use the modified definitions.)
297
+
298
+ b) Use a suitable shared library mechanism for linking with the
299
+ Library. A suitable mechanism is one that (1) uses at run time a
300
+ copy of the library already present on the user's computer system,
301
+ rather than copying library functions into the executable, and (2)
302
+ will operate properly with a modified version of the library, if
303
+ the user installs one, as long as the modified version is
304
+ interface-compatible with the version that the work was made with.
305
+
306
+ c) Accompany the work with a written offer, valid for at
307
+ least three years, to give the same user the materials
308
+ specified in Subsection 6a, above, for a charge no more
309
+ than the cost of performing this distribution.
310
+
311
+ d) If distribution of the work is made by offering access to copy
312
+ from a designated place, offer equivalent access to copy the above
313
+ specified materials from the same place.
314
+
315
+ e) Verify that the user has already received a copy of these
316
+ materials or that you have already sent this user a copy.
317
+
318
+ For an executable, the required form of the "work that uses the
319
+ Library" must include any data and utility programs needed for
320
+ reproducing the executable from it. However, as a special exception,
321
+ the materials to be distributed need not include anything that is
322
+ normally distributed (in either source or binary form) with the major
323
+ components (compiler, kernel, and so on) of the operating system on
324
+ which the executable runs, unless that component itself accompanies
325
+ the executable.
326
+
327
+ It may happen that this requirement contradicts the license
328
+ restrictions of other proprietary libraries that do not normally
329
+ accompany the operating system. Such a contradiction means you cannot
330
+ use both them and the Library together in an executable that you
331
+ distribute.
332
+
333
+ 7. You may place library facilities that are a work based on the
334
+ Library side-by-side in a single library together with other library
335
+ facilities not covered by this License, and distribute such a combined
336
+ library, provided that the separate distribution of the work based on
337
+ the Library and of the other library facilities is otherwise
338
+ permitted, and provided that you do these two things:
339
+
340
+ a) Accompany the combined library with a copy of the same work
341
+ based on the Library, uncombined with any other library
342
+ facilities. This must be distributed under the terms of the
343
+ Sections above.
344
+
345
+ b) Give prominent notice with the combined library of the fact
346
+ that part of it is a work based on the Library, and explaining
347
+ where to find the accompanying uncombined form of the same work.
348
+
349
+ 8. You may not copy, modify, sublicense, link with, or distribute
350
+ the Library except as expressly provided under this License. Any
351
+ attempt otherwise to copy, modify, sublicense, link with, or
352
+ distribute the Library is void, and will automatically terminate your
353
+ rights under this License. However, parties who have received copies,
354
+ or rights, from you under this License will not have their licenses
355
+ terminated so long as such parties remain in full compliance.
356
+
357
+ 9. You are not required to accept this License, since you have not
358
+ signed it. However, nothing else grants you permission to modify or
359
+ distribute the Library or its derivative works. These actions are
360
+ prohibited by law if you do not accept this License. Therefore, by
361
+ modifying or distributing the Library (or any work based on the
362
+ Library), you indicate your acceptance of this License to do so, and
363
+ all its terms and conditions for copying, distributing or modifying
364
+ the Library or works based on it.
365
+
366
+ 10. Each time you redistribute the Library (or any work based on the
367
+ Library), the recipient automatically receives a license from the
368
+ original licensor to copy, distribute, link with or modify the Library
369
+ subject to these terms and conditions. You may not impose any further
370
+ restrictions on the recipients' exercise of the rights granted herein.
371
+ You are not responsible for enforcing compliance by third parties with
372
+ this License.
373
+
374
+ 11. If, as a consequence of a court judgment or allegation of patent
375
+ infringement or for any other reason (not limited to patent issues),
376
+ conditions are imposed on you (whether by court order, agreement or
377
+ otherwise) that contradict the conditions of this License, they do not
378
+ excuse you from the conditions of this License. If you cannot
379
+ distribute so as to satisfy simultaneously your obligations under this
380
+ License and any other pertinent obligations, then as a consequence you
381
+ may not distribute the Library at all. For example, if a patent
382
+ license would not permit royalty-free redistribution of the Library by
383
+ all those who receive copies directly or indirectly through you, then
384
+ the only way you could satisfy both it and this License would be to
385
+ refrain entirely from distribution of the Library.
386
+
387
+ If any portion of this section is held invalid or unenforceable under any
388
+ particular circumstance, the balance of the section is intended to apply,
389
+ and the section as a whole is intended to apply in other circumstances.
390
+
391
+ It is not the purpose of this section to induce you to infringe any
392
+ patents or other property right claims or to contest validity of any
393
+ such claims; this section has the sole purpose of protecting the
394
+ integrity of the free software distribution system which is
395
+ implemented by public license practices. Many people have made
396
+ generous contributions to the wide range of software distributed
397
+ through that system in reliance on consistent application of that
398
+ system; it is up to the author/donor to decide if he or she is willing
399
+ to distribute software through any other system and a licensee cannot
400
+ impose that choice.
401
+
402
+ This section is intended to make thoroughly clear what is believed to
403
+ be a consequence of the rest of this License.
404
+
405
+ 12. If the distribution and/or use of the Library is restricted in
406
+ certain countries either by patents or by copyrighted interfaces, the
407
+ original copyright holder who places the Library under this License may add
408
+ an explicit geographical distribution limitation excluding those countries,
409
+ so that distribution is permitted only in or among countries not thus
410
+ excluded. In such case, this License incorporates the limitation as if
411
+ written in the body of this License.
412
+
413
+ 13. The Free Software Foundation may publish revised and/or new
414
+ versions of the Lesser General Public License from time to time.
415
+ Such new versions will be similar in spirit to the present version,
416
+ but may differ in detail to address new problems or concerns.
417
+
418
+ Each version is given a distinguishing version number. If the Library
419
+ specifies a version number of this License which applies to it and
420
+ "any later version", you have the option of following the terms and
421
+ conditions either of that version or of any later version published by
422
+ the Free Software Foundation. If the Library does not specify a
423
+ license version number, you may choose any version ever published by
424
+ the Free Software Foundation.
425
+
426
+ 14. If you wish to incorporate parts of the Library into other free
427
+ programs whose distribution conditions are incompatible with these,
428
+ write to the author to ask for permission. For software which is
429
+ copyrighted by the Free Software Foundation, write to the Free
430
+ Software Foundation; we sometimes make exceptions for this. Our
431
+ decision will be guided by the two goals of preserving the free status
432
+ of all derivatives of our free software and of promoting the sharing
433
+ and reuse of software generally.
434
+
435
+ NO WARRANTY
436
+
437
+ 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
438
+ WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
439
+ EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
440
+ OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
441
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
442
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
443
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
444
+ LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
445
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
446
+
447
+ 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
448
+ WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
449
+ AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
450
+ FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
451
+ CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
452
+ LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
453
+ RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
454
+ FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
455
+ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
456
+ DAMAGES.
457
+
458
+ END OF TERMS AND CONDITIONS
459
+
460
+ How to Apply These Terms to Your New Libraries
461
+
462
+ If you develop a new library, and you want it to be of the greatest
463
+ possible use to the public, we recommend making it free software that
464
+ everyone can redistribute and change. You can do so by permitting
465
+ redistribution under these terms (or, alternatively, under the terms of the
466
+ ordinary General Public License).
467
+
468
+ To apply these terms, attach the following notices to the library. It is
469
+ safest to attach them to the start of each source file to most effectively
470
+ convey the exclusion of warranty; and each file should have at least the
471
+ "copyright" line and a pointer to where the full notice is found.
472
+
473
+ <one line to give the library's name and a brief idea of what it does.>
474
+ Copyright (C) <year> <name of author>
475
+
476
+ This library is free software; you can redistribute it and/or
477
+ modify it under the terms of the GNU Lesser General Public
478
+ License as published by the Free Software Foundation; either
479
+ version 2 of the License, or (at your option) any later version.
480
+
481
+ This library is distributed in the hope that it will be useful,
482
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
483
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
484
+ Lesser General Public License for more details.
485
+
486
+ You should have received a copy of the GNU Lesser General Public
487
+ License along with this library; if not, write to the Free Software
488
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
489
+
490
+ Also add information on how to contact you by electronic and paper mail.
491
+
492
+ You should also get your employer (if you work as a programmer) or your
493
+ school, if any, to sign a "copyright disclaimer" for the library, if
494
+ necessary. Here is a sample; alter the names:
495
+
496
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the
497
+ library `Frob' (a library for tweaking knobs) written by James Random Hacker.
498
+
499
+ <signature of Ty Coon>, 1 April 1990
500
+ Ty Coon, President of Vice
501
+
502
+ That's all there is to it!
503
+
504
+
.venv/Lib/site-packages/unidic_lite/dicdir/README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # UniDic 2.1.2
2
+
3
+ Note the files included here are the unmodified files provided in the Unidic 2.1.2 binary distribution.
4
+
5
+ They were originally acquired from this link:
6
+
7
+ https://unidic.ninjal.ac.jp/back_number
8
+
9
+ Specifically:
10
+
11
+ https://unidic.ninjal.ac.jp/unidic_archive/cwj/2.1.2/unidic-mecab-2.1.2_bin.zip
12
+
13
+ Because they are large these files are not included in the git source for unidic-lite.
14
+
.venv/Lib/site-packages/unidic_lite/dicdir/dicrc ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ; List of features
2
+ ; f[0]: pos1
3
+ ; f[1]: pos2
4
+ ; f[2]: pos3
5
+ ; f[3]: pos4
6
+ ; f[4]: cType
7
+ ; f[5]: cForm
8
+ ; f[6]: lForm
9
+ ; f[7]: lemma
10
+ ; f[8]: orth
11
+ ; f[9]: pron
12
+ ; f[10]: orthBase
13
+ ; f[11]: pronBase
14
+ ; f[12]: goshu
15
+ ; f[13]: iType
16
+ ; f[14]: iForm
17
+ ; f[15]: fType
18
+ ; f[16]: fForm
19
+ ; f[17]: kana
20
+ ; f[18]: kanaBase
21
+ ; f[19]: form
22
+ ; f[20]: formBase
23
+ ; f[21]: iConType
24
+ ; f[22]: fConType
25
+ ; f[23]: aType
26
+ ; f[24]: aConType
27
+ ; f[25]: aModType
28
+
29
+ ;dictionary-charset = utf8
30
+ ;config-charset = utf8
31
+
32
+ cost-factor = 700
33
+ ;max-grouping-size = 10
34
+ ;eval-size = 10
35
+ ;unk-eval-size = 4
36
+
37
+ bos-feature = BOS/EOS,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*
38
+
39
+ output-format-type = unidic
40
+
41
+ ; output aType
42
+ ;node-format-unidic = %m\t%f[9]\t%f[6]\t%f[7]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\n
43
+ node-format-unidic = %m\t%f[9]\t%f[6]\t%f[7]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\t%f[23]\n
44
+ ; default aType is 0
45
+ ;unk-format-unidic = %m\t%m\t%m\t%m\t%F-[0,1,2,3]\t%f[4]\t%f[5]\n
46
+ unk-format-unidic = %m\t%m\t%m\t%m\t%F-[0,1,2,3]\t%f[4]\t%f[5]\t0\n
47
+ bos-format-unidic =
48
+ eos-format-unidic = EOS\n
49
+
50
+ ; output aType
51
+ node-format-chamame = \t%m\t%f[9]\t%f[6]\t%f[7]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\n
52
+ node-format-chamame = \t%m\t%f[9]\t%f[6]\t%f[7]\t%F-[0,1,2,3]\t%f[4]\t%f[5]\t%f[23]\n
53
+ ; default aType is 0
54
+ ;unk-format-chamame = \t%m\t\t\t%m\tUNK\t\t\n
55
+ ;unk-format-chamame = \t%m\t\t\t%m\t%F-[0,1,2,3]\t\t\n
56
+ unk-format-chamame = \t%m\t\t\t%m\t%F-[0,1,2,3]\t\t\t0\n
57
+ bos-format-chamame = B
58
+ eos-format-chamame =
.venv/Lib/site-packages/unidic_lite/dicdir/left-id.def ADDED
The diff for this file is too large to render. See raw diff
 
.venv/Lib/site-packages/unidic_lite/dicdir/mecabrc ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # This is a dummy file
2
+ # It has to exist, but it can be empty
.venv/Lib/site-packages/unidic_lite/dicdir/rewrite.def ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # node:
2
+ # $1: pos1
3
+ # $2: pos2
4
+ # $3: pos3
5
+ # $4: pos4
6
+ # $5: cType
7
+ # $6: cForm
8
+ # $7: lForm
9
+ # $8: lemma
10
+ # $9: orth
11
+ # $10: pron
12
+ # $11: orthBase
13
+ # $12: pronBase
14
+ # $13: goshu
15
+ # $14: iType
16
+ # $15: iForm
17
+ # $16: fType
18
+ # $17: fForm
19
+ # unk:
20
+ # $1: pos1
21
+ # $2: pos2
22
+ # $3: pos3
23
+ # $4: pos4
24
+ # $5: cType
25
+ # $6: cForm
26
+
27
+ [unigram rewrite]
28
+ BOS/EOS,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,*,*,*,*,*,*,BOS/EOS,BOS/EOS,*,BOS/EOS,*,BOS/EOS,*,*,*,*
29
+ *,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17
30
+ *,*,*,*,*,* $1,$2,$3,$4,$5,$6,*,*,*,*,*,*,*,*,*,*,*
31
+
32
+ [left rewrite]
33
+ BOS/EOS,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,*,*,*,*,*,BOS/EOS,BOS/EOS,BOS/EOS
34
+ 助詞,*,*,*,*,*,*,(の|に|を|て|は|と|が|で|も|の|から|か|が|ね|か|けれど|など|って|と|ば|や|まで|へ|から|より|だけ|な|たり|よ|くらい|ながら|し|ほど|しか),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
35
+ 助動詞,*,*,*,*,*,*,(だ|た|ます|です|れる|ず|ない|てる|られる|べし|たい|り|せる|ちゃう),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
36
+ 名詞,助動詞語幹,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
37
+ 形状詞,助動詞語幹,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
38
+ 動詞,非自立可能,*,*,*,*,*,(為る|居る|有る|成る|見る|行く|来る|出来る|得る|遣る|仕舞う|呉れる|出す|置く|致す|付く|頂く|付ける|貰う|掛ける|続く|始める|続ける|御座る|終わる),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
39
+ 形容詞,非自立可能,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
40
+ 接尾辞,*,*,*,*,*,*,(的|年|者|月|さん|日|パーセント|人|つ|等|日|円|等|化|達|人|さ|性|回|時|氏|所|生|方|分|長|党|目|中|省|歳|内|年度|国|家|後|部|上|車|権|度|力|員|費|書|用|物|型|業|間|メートル|庁|箇月|番|局|機|年間|館|件|時間|社),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
41
+ 接頭辞,*,*,*,*,*,*,(第|御|約|不|大|新|各|小|御|非),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
42
+ 名詞,数詞,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
43
+ 補助記号,*,*,*,*,*,*,*,.,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
44
+ *,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,*,*,$13
45
+ *,*,*,*,*,* $1,$2,$3,$4,$5,$6,*,*,*
46
+
47
+ [right rewrite]
48
+ BOS/EOS,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,*,*,*,*,*,BOS/EOS,BOS/EOS,BOS/EOS
49
+ 助詞,*,*,*,*,*,*,(の|に|を|て|は|と|が|で|も|の|から|か|が|ね|か|けれど|など|って|と|ば|や|まで|へ|から|より|だけ|な|たり|よ|くらい|ながら|し|ほど|しか),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
50
+ 助動詞,*,*,*,*,*,*,(だ|た|ます|です|れる|ず|ない|てる|られる|べし|たい|り|せる|ちゃう),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
51
+ 名詞,助動詞語幹,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
52
+ 形状詞,助動詞語幹,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
53
+ 動詞,非自立可能,*,*,*,*,*,(為る|居る|有る|成る|見る|行く|来る|出来る|得る|遣る|仕舞う|呉れる|出す|置く|致す|付く|頂く|付ける|貰う|掛ける|続く|始める|続ける|御座る|終わる),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
54
+ 形容詞,非自立可能,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
55
+ 接尾辞,*,*,*,*,*,*,(的|年|者|月|さん|日|パーセント|人|つ|等|日|円|等|化|達|人|さ|性|回|時|氏|所|生|方|分|長|党|目|中|省|歳|内|年度|国|家|後|部|上|車|権|度|力|員|費|書|用|物|型|業|間|メートル|庁|箇月|番|局|機|年間|館|件|時間|社),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
56
+ 接頭辞,*,*,*,*,*,*,(第|御|約|不|大|新|各|小|御|非),*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
57
+ 名詞,数詞,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
58
+ 補助記号,*,*,*,*,*,*,*,.,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,$9,$11,$13
59
+ *,*,*,*,*,*,*,*,*,*,*,*,*,*,*,*,* $1,$2,$3,$4,$5,$6,*,*,$13
60
+ *,*,*,*,*,* $1,$2,$3,$4,$5,$6,*,*,*
.venv/Lib/site-packages/unidic_lite/unidic.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+
4
+ def get_version(dicdir):
5
+ vpath = os.path.join(dicdir, 'version')
6
+ with open(vpath) as vfile:
7
+ return vfile.read().strip()
8
+
9
+ _curdir = os.path.dirname(__file__)
10
+
11
+ # This will be used elsewhere to initialize the tagger
12
+ DICDIR = os.path.join(_curdir, 'dicdir')
13
+ VERSION = get_version(DICDIR)
.venv/Lib/site-packages/urllib3/__init__.py ADDED
@@ -0,0 +1,211 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Python HTTP library with thread-safe connection pooling, file post support, user friendly, and more
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ # Set default logging handler to avoid "No handler found" warnings.
8
+ import logging
9
+ import sys
10
+ import typing
11
+ import warnings
12
+ from logging import NullHandler
13
+
14
+ from . import exceptions
15
+ from ._base_connection import _TYPE_BODY
16
+ from ._collections import HTTPHeaderDict
17
+ from ._version import __version__
18
+ from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, connection_from_url
19
+ from .filepost import _TYPE_FIELDS, encode_multipart_formdata
20
+ from .poolmanager import PoolManager, ProxyManager, proxy_from_url
21
+ from .response import BaseHTTPResponse, HTTPResponse
22
+ from .util.request import make_headers
23
+ from .util.retry import Retry
24
+ from .util.timeout import Timeout
25
+
26
+ # Ensure that Python is compiled with OpenSSL 1.1.1+
27
+ # If the 'ssl' module isn't available at all that's
28
+ # fine, we only care if the module is available.
29
+ try:
30
+ import ssl
31
+ except ImportError:
32
+ pass
33
+ else:
34
+ if not ssl.OPENSSL_VERSION.startswith("OpenSSL "): # Defensive:
35
+ warnings.warn(
36
+ "urllib3 v2 only supports OpenSSL 1.1.1+, currently "
37
+ f"the 'ssl' module is compiled with {ssl.OPENSSL_VERSION!r}. "
38
+ "See: https://github.com/urllib3/urllib3/issues/3020",
39
+ exceptions.NotOpenSSLWarning,
40
+ )
41
+ elif ssl.OPENSSL_VERSION_INFO < (1, 1, 1): # Defensive:
42
+ raise ImportError(
43
+ "urllib3 v2 only supports OpenSSL 1.1.1+, currently "
44
+ f"the 'ssl' module is compiled with {ssl.OPENSSL_VERSION!r}. "
45
+ "See: https://github.com/urllib3/urllib3/issues/2168"
46
+ )
47
+
48
+ __author__ = "Andrey Petrov ([email protected])"
49
+ __license__ = "MIT"
50
+ __version__ = __version__
51
+
52
+ __all__ = (
53
+ "HTTPConnectionPool",
54
+ "HTTPHeaderDict",
55
+ "HTTPSConnectionPool",
56
+ "PoolManager",
57
+ "ProxyManager",
58
+ "HTTPResponse",
59
+ "Retry",
60
+ "Timeout",
61
+ "add_stderr_logger",
62
+ "connection_from_url",
63
+ "disable_warnings",
64
+ "encode_multipart_formdata",
65
+ "make_headers",
66
+ "proxy_from_url",
67
+ "request",
68
+ "BaseHTTPResponse",
69
+ )
70
+
71
+ logging.getLogger(__name__).addHandler(NullHandler())
72
+
73
+
74
+ def add_stderr_logger(
75
+ level: int = logging.DEBUG,
76
+ ) -> logging.StreamHandler[typing.TextIO]:
77
+ """
78
+ Helper for quickly adding a StreamHandler to the logger. Useful for
79
+ debugging.
80
+
81
+ Returns the handler after adding it.
82
+ """
83
+ # This method needs to be in this __init__.py to get the __name__ correct
84
+ # even if urllib3 is vendored within another package.
85
+ logger = logging.getLogger(__name__)
86
+ handler = logging.StreamHandler()
87
+ handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))
88
+ logger.addHandler(handler)
89
+ logger.setLevel(level)
90
+ logger.debug("Added a stderr logging handler to logger: %s", __name__)
91
+ return handler
92
+
93
+
94
+ # ... Clean up.
95
+ del NullHandler
96
+
97
+
98
+ # All warning filters *must* be appended unless you're really certain that they
99
+ # shouldn't be: otherwise, it's very hard for users to use most Python
100
+ # mechanisms to silence them.
101
+ # SecurityWarning's always go off by default.
102
+ warnings.simplefilter("always", exceptions.SecurityWarning, append=True)
103
+ # InsecurePlatformWarning's don't vary between requests, so we keep it default.
104
+ warnings.simplefilter("default", exceptions.InsecurePlatformWarning, append=True)
105
+
106
+
107
+ def disable_warnings(category: type[Warning] = exceptions.HTTPWarning) -> None:
108
+ """
109
+ Helper for quickly disabling all urllib3 warnings.
110
+ """
111
+ warnings.simplefilter("ignore", category)
112
+
113
+
114
+ _DEFAULT_POOL = PoolManager()
115
+
116
+
117
+ def request(
118
+ method: str,
119
+ url: str,
120
+ *,
121
+ body: _TYPE_BODY | None = None,
122
+ fields: _TYPE_FIELDS | None = None,
123
+ headers: typing.Mapping[str, str] | None = None,
124
+ preload_content: bool | None = True,
125
+ decode_content: bool | None = True,
126
+ redirect: bool | None = True,
127
+ retries: Retry | bool | int | None = None,
128
+ timeout: Timeout | float | int | None = 3,
129
+ json: typing.Any | None = None,
130
+ ) -> BaseHTTPResponse:
131
+ """
132
+ A convenience, top-level request method. It uses a module-global ``PoolManager`` instance.
133
+ Therefore, its side effects could be shared across dependencies relying on it.
134
+ To avoid side effects create a new ``PoolManager`` instance and use it instead.
135
+ The method does not accept low-level ``**urlopen_kw`` keyword arguments.
136
+
137
+ :param method:
138
+ HTTP request method (such as GET, POST, PUT, etc.)
139
+
140
+ :param url:
141
+ The URL to perform the request on.
142
+
143
+ :param body:
144
+ Data to send in the request body, either :class:`str`, :class:`bytes`,
145
+ an iterable of :class:`str`/:class:`bytes`, or a file-like object.
146
+
147
+ :param fields:
148
+ Data to encode and send in the request body.
149
+
150
+ :param headers:
151
+ Dictionary of custom headers to send, such as User-Agent,
152
+ If-None-Match, etc.
153
+
154
+ :param bool preload_content:
155
+ If True, the response's body will be preloaded into memory.
156
+
157
+ :param bool decode_content:
158
+ If True, will attempt to decode the body based on the
159
+ 'content-encoding' header.
160
+
161
+ :param redirect:
162
+ If True, automatically handle redirects (status codes 301, 302,
163
+ 303, 307, 308). Each redirect counts as a retry. Disabling retries
164
+ will disable redirect, too.
165
+
166
+ :param retries:
167
+ Configure the number of retries to allow before raising a
168
+ :class:`~urllib3.exceptions.MaxRetryError` exception.
169
+
170
+ If ``None`` (default) will retry 3 times, see ``Retry.DEFAULT``. Pass a
171
+ :class:`~urllib3.util.retry.Retry` object for fine-grained control
172
+ over different types of retries.
173
+ Pass an integer number to retry connection errors that many times,
174
+ but no other types of errors. Pass zero to never retry.
175
+
176
+ If ``False``, then retries are disabled and any exception is raised
177
+ immediately. Also, instead of raising a MaxRetryError on redirects,
178
+ the redirect response will be returned.
179
+
180
+ :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
181
+
182
+ :param timeout:
183
+ If specified, overrides the default timeout for this one
184
+ request. It may be a float (in seconds) or an instance of
185
+ :class:`urllib3.util.Timeout`.
186
+
187
+ :param json:
188
+ Data to encode and send as JSON with UTF-encoded in the request body.
189
+ The ``"Content-Type"`` header will be set to ``"application/json"``
190
+ unless specified otherwise.
191
+ """
192
+
193
+ return _DEFAULT_POOL.request(
194
+ method,
195
+ url,
196
+ body=body,
197
+ fields=fields,
198
+ headers=headers,
199
+ preload_content=preload_content,
200
+ decode_content=decode_content,
201
+ redirect=redirect,
202
+ retries=retries,
203
+ timeout=timeout,
204
+ json=json,
205
+ )
206
+
207
+
208
+ if sys.platform == "emscripten":
209
+ from .contrib.emscripten import inject_into_urllib3 # noqa: 401
210
+
211
+ inject_into_urllib3()
.venv/Lib/site-packages/urllib3/_base_connection.py ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+
5
+ from .util.connection import _TYPE_SOCKET_OPTIONS
6
+ from .util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT
7
+ from .util.url import Url
8
+
9
+ _TYPE_BODY = typing.Union[bytes, typing.IO[typing.Any], typing.Iterable[bytes], str]
10
+
11
+
12
+ class ProxyConfig(typing.NamedTuple):
13
+ ssl_context: ssl.SSLContext | None
14
+ use_forwarding_for_https: bool
15
+ assert_hostname: None | str | typing.Literal[False]
16
+ assert_fingerprint: str | None
17
+
18
+
19
+ class _ResponseOptions(typing.NamedTuple):
20
+ # TODO: Remove this in favor of a better
21
+ # HTTP request/response lifecycle tracking.
22
+ request_method: str
23
+ request_url: str
24
+ preload_content: bool
25
+ decode_content: bool
26
+ enforce_content_length: bool
27
+
28
+
29
+ if typing.TYPE_CHECKING:
30
+ import ssl
31
+ from typing import Protocol
32
+
33
+ from .response import BaseHTTPResponse
34
+
35
+ class BaseHTTPConnection(Protocol):
36
+ default_port: typing.ClassVar[int]
37
+ default_socket_options: typing.ClassVar[_TYPE_SOCKET_OPTIONS]
38
+
39
+ host: str
40
+ port: int
41
+ timeout: None | (
42
+ float
43
+ ) # Instance doesn't store _DEFAULT_TIMEOUT, must be resolved.
44
+ blocksize: int
45
+ source_address: tuple[str, int] | None
46
+ socket_options: _TYPE_SOCKET_OPTIONS | None
47
+
48
+ proxy: Url | None
49
+ proxy_config: ProxyConfig | None
50
+
51
+ is_verified: bool
52
+ proxy_is_verified: bool | None
53
+
54
+ def __init__(
55
+ self,
56
+ host: str,
57
+ port: int | None = None,
58
+ *,
59
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
60
+ source_address: tuple[str, int] | None = None,
61
+ blocksize: int = 8192,
62
+ socket_options: _TYPE_SOCKET_OPTIONS | None = ...,
63
+ proxy: Url | None = None,
64
+ proxy_config: ProxyConfig | None = None,
65
+ ) -> None:
66
+ ...
67
+
68
+ def set_tunnel(
69
+ self,
70
+ host: str,
71
+ port: int | None = None,
72
+ headers: typing.Mapping[str, str] | None = None,
73
+ scheme: str = "http",
74
+ ) -> None:
75
+ ...
76
+
77
+ def connect(self) -> None:
78
+ ...
79
+
80
+ def request(
81
+ self,
82
+ method: str,
83
+ url: str,
84
+ body: _TYPE_BODY | None = None,
85
+ headers: typing.Mapping[str, str] | None = None,
86
+ # We know *at least* botocore is depending on the order of the
87
+ # first 3 parameters so to be safe we only mark the later ones
88
+ # as keyword-only to ensure we have space to extend.
89
+ *,
90
+ chunked: bool = False,
91
+ preload_content: bool = True,
92
+ decode_content: bool = True,
93
+ enforce_content_length: bool = True,
94
+ ) -> None:
95
+ ...
96
+
97
+ def getresponse(self) -> BaseHTTPResponse:
98
+ ...
99
+
100
+ def close(self) -> None:
101
+ ...
102
+
103
+ @property
104
+ def is_closed(self) -> bool:
105
+ """Whether the connection either is brand new or has been previously closed.
106
+ If this property is True then both ``is_connected`` and ``has_connected_to_proxy``
107
+ properties must be False.
108
+ """
109
+
110
+ @property
111
+ def is_connected(self) -> bool:
112
+ """Whether the connection is actively connected to any origin (proxy or target)"""
113
+
114
+ @property
115
+ def has_connected_to_proxy(self) -> bool:
116
+ """Whether the connection has successfully connected to its proxy.
117
+ This returns False if no proxy is in use. Used to determine whether
118
+ errors are coming from the proxy layer or from tunnelling to the target origin.
119
+ """
120
+
121
+ class BaseHTTPSConnection(BaseHTTPConnection, Protocol):
122
+ default_port: typing.ClassVar[int]
123
+ default_socket_options: typing.ClassVar[_TYPE_SOCKET_OPTIONS]
124
+
125
+ # Certificate verification methods
126
+ cert_reqs: int | str | None
127
+ assert_hostname: None | str | typing.Literal[False]
128
+ assert_fingerprint: str | None
129
+ ssl_context: ssl.SSLContext | None
130
+
131
+ # Trusted CAs
132
+ ca_certs: str | None
133
+ ca_cert_dir: str | None
134
+ ca_cert_data: None | str | bytes
135
+
136
+ # TLS version
137
+ ssl_minimum_version: int | None
138
+ ssl_maximum_version: int | None
139
+ ssl_version: int | str | None # Deprecated
140
+
141
+ # Client certificates
142
+ cert_file: str | None
143
+ key_file: str | None
144
+ key_password: str | None
145
+
146
+ def __init__(
147
+ self,
148
+ host: str,
149
+ port: int | None = None,
150
+ *,
151
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
152
+ source_address: tuple[str, int] | None = None,
153
+ blocksize: int = 16384,
154
+ socket_options: _TYPE_SOCKET_OPTIONS | None = ...,
155
+ proxy: Url | None = None,
156
+ proxy_config: ProxyConfig | None = None,
157
+ cert_reqs: int | str | None = None,
158
+ assert_hostname: None | str | typing.Literal[False] = None,
159
+ assert_fingerprint: str | None = None,
160
+ server_hostname: str | None = None,
161
+ ssl_context: ssl.SSLContext | None = None,
162
+ ca_certs: str | None = None,
163
+ ca_cert_dir: str | None = None,
164
+ ca_cert_data: None | str | bytes = None,
165
+ ssl_minimum_version: int | None = None,
166
+ ssl_maximum_version: int | None = None,
167
+ ssl_version: int | str | None = None, # Deprecated
168
+ cert_file: str | None = None,
169
+ key_file: str | None = None,
170
+ key_password: str | None = None,
171
+ ) -> None:
172
+ ...
.venv/Lib/site-packages/urllib3/_collections.py ADDED
@@ -0,0 +1,483 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import typing
4
+ from collections import OrderedDict
5
+ from enum import Enum, auto
6
+ from threading import RLock
7
+
8
+ if typing.TYPE_CHECKING:
9
+ # We can only import Protocol if TYPE_CHECKING because it's a development
10
+ # dependency, and is not available at runtime.
11
+ from typing import Protocol
12
+
13
+ from typing_extensions import Self
14
+
15
+ class HasGettableStringKeys(Protocol):
16
+ def keys(self) -> typing.Iterator[str]:
17
+ ...
18
+
19
+ def __getitem__(self, key: str) -> str:
20
+ ...
21
+
22
+
23
+ __all__ = ["RecentlyUsedContainer", "HTTPHeaderDict"]
24
+
25
+
26
+ # Key type
27
+ _KT = typing.TypeVar("_KT")
28
+ # Value type
29
+ _VT = typing.TypeVar("_VT")
30
+ # Default type
31
+ _DT = typing.TypeVar("_DT")
32
+
33
+ ValidHTTPHeaderSource = typing.Union[
34
+ "HTTPHeaderDict",
35
+ typing.Mapping[str, str],
36
+ typing.Iterable[typing.Tuple[str, str]],
37
+ "HasGettableStringKeys",
38
+ ]
39
+
40
+
41
+ class _Sentinel(Enum):
42
+ not_passed = auto()
43
+
44
+
45
+ def ensure_can_construct_http_header_dict(
46
+ potential: object,
47
+ ) -> ValidHTTPHeaderSource | None:
48
+ if isinstance(potential, HTTPHeaderDict):
49
+ return potential
50
+ elif isinstance(potential, typing.Mapping):
51
+ # Full runtime checking of the contents of a Mapping is expensive, so for the
52
+ # purposes of typechecking, we assume that any Mapping is the right shape.
53
+ return typing.cast(typing.Mapping[str, str], potential)
54
+ elif isinstance(potential, typing.Iterable):
55
+ # Similarly to Mapping, full runtime checking of the contents of an Iterable is
56
+ # expensive, so for the purposes of typechecking, we assume that any Iterable
57
+ # is the right shape.
58
+ return typing.cast(typing.Iterable[typing.Tuple[str, str]], potential)
59
+ elif hasattr(potential, "keys") and hasattr(potential, "__getitem__"):
60
+ return typing.cast("HasGettableStringKeys", potential)
61
+ else:
62
+ return None
63
+
64
+
65
+ class RecentlyUsedContainer(typing.Generic[_KT, _VT], typing.MutableMapping[_KT, _VT]):
66
+ """
67
+ Provides a thread-safe dict-like container which maintains up to
68
+ ``maxsize`` keys while throwing away the least-recently-used keys beyond
69
+ ``maxsize``.
70
+
71
+ :param maxsize:
72
+ Maximum number of recent elements to retain.
73
+
74
+ :param dispose_func:
75
+ Every time an item is evicted from the container,
76
+ ``dispose_func(value)`` is called. Callback which will get called
77
+ """
78
+
79
+ _container: typing.OrderedDict[_KT, _VT]
80
+ _maxsize: int
81
+ dispose_func: typing.Callable[[_VT], None] | None
82
+ lock: RLock
83
+
84
+ def __init__(
85
+ self,
86
+ maxsize: int = 10,
87
+ dispose_func: typing.Callable[[_VT], None] | None = None,
88
+ ) -> None:
89
+ super().__init__()
90
+ self._maxsize = maxsize
91
+ self.dispose_func = dispose_func
92
+ self._container = OrderedDict()
93
+ self.lock = RLock()
94
+
95
+ def __getitem__(self, key: _KT) -> _VT:
96
+ # Re-insert the item, moving it to the end of the eviction line.
97
+ with self.lock:
98
+ item = self._container.pop(key)
99
+ self._container[key] = item
100
+ return item
101
+
102
+ def __setitem__(self, key: _KT, value: _VT) -> None:
103
+ evicted_item = None
104
+ with self.lock:
105
+ # Possibly evict the existing value of 'key'
106
+ try:
107
+ # If the key exists, we'll overwrite it, which won't change the
108
+ # size of the pool. Because accessing a key should move it to
109
+ # the end of the eviction line, we pop it out first.
110
+ evicted_item = key, self._container.pop(key)
111
+ self._container[key] = value
112
+ except KeyError:
113
+ # When the key does not exist, we insert the value first so that
114
+ # evicting works in all cases, including when self._maxsize is 0
115
+ self._container[key] = value
116
+ if len(self._container) > self._maxsize:
117
+ # If we didn't evict an existing value, and we've hit our maximum
118
+ # size, then we have to evict the least recently used item from
119
+ # the beginning of the container.
120
+ evicted_item = self._container.popitem(last=False)
121
+
122
+ # After releasing the lock on the pool, dispose of any evicted value.
123
+ if evicted_item is not None and self.dispose_func:
124
+ _, evicted_value = evicted_item
125
+ self.dispose_func(evicted_value)
126
+
127
+ def __delitem__(self, key: _KT) -> None:
128
+ with self.lock:
129
+ value = self._container.pop(key)
130
+
131
+ if self.dispose_func:
132
+ self.dispose_func(value)
133
+
134
+ def __len__(self) -> int:
135
+ with self.lock:
136
+ return len(self._container)
137
+
138
+ def __iter__(self) -> typing.NoReturn:
139
+ raise NotImplementedError(
140
+ "Iteration over this class is unlikely to be threadsafe."
141
+ )
142
+
143
+ def clear(self) -> None:
144
+ with self.lock:
145
+ # Copy pointers to all values, then wipe the mapping
146
+ values = list(self._container.values())
147
+ self._container.clear()
148
+
149
+ if self.dispose_func:
150
+ for value in values:
151
+ self.dispose_func(value)
152
+
153
+ def keys(self) -> set[_KT]: # type: ignore[override]
154
+ with self.lock:
155
+ return set(self._container.keys())
156
+
157
+
158
+ class HTTPHeaderDictItemView(typing.Set[typing.Tuple[str, str]]):
159
+ """
160
+ HTTPHeaderDict is unusual for a Mapping[str, str] in that it has two modes of
161
+ address.
162
+
163
+ If we directly try to get an item with a particular name, we will get a string
164
+ back that is the concatenated version of all the values:
165
+
166
+ >>> d['X-Header-Name']
167
+ 'Value1, Value2, Value3'
168
+
169
+ However, if we iterate over an HTTPHeaderDict's items, we will optionally combine
170
+ these values based on whether combine=True was called when building up the dictionary
171
+
172
+ >>> d = HTTPHeaderDict({"A": "1", "B": "foo"})
173
+ >>> d.add("A", "2", combine=True)
174
+ >>> d.add("B", "bar")
175
+ >>> list(d.items())
176
+ [
177
+ ('A', '1, 2'),
178
+ ('B', 'foo'),
179
+ ('B', 'bar'),
180
+ ]
181
+
182
+ This class conforms to the interface required by the MutableMapping ABC while
183
+ also giving us the nonstandard iteration behavior we want; items with duplicate
184
+ keys, ordered by time of first insertion.
185
+ """
186
+
187
+ _headers: HTTPHeaderDict
188
+
189
+ def __init__(self, headers: HTTPHeaderDict) -> None:
190
+ self._headers = headers
191
+
192
+ def __len__(self) -> int:
193
+ return len(list(self._headers.iteritems()))
194
+
195
+ def __iter__(self) -> typing.Iterator[tuple[str, str]]:
196
+ return self._headers.iteritems()
197
+
198
+ def __contains__(self, item: object) -> bool:
199
+ if isinstance(item, tuple) and len(item) == 2:
200
+ passed_key, passed_val = item
201
+ if isinstance(passed_key, str) and isinstance(passed_val, str):
202
+ return self._headers._has_value_for_header(passed_key, passed_val)
203
+ return False
204
+
205
+
206
+ class HTTPHeaderDict(typing.MutableMapping[str, str]):
207
+ """
208
+ :param headers:
209
+ An iterable of field-value pairs. Must not contain multiple field names
210
+ when compared case-insensitively.
211
+
212
+ :param kwargs:
213
+ Additional field-value pairs to pass in to ``dict.update``.
214
+
215
+ A ``dict`` like container for storing HTTP Headers.
216
+
217
+ Field names are stored and compared case-insensitively in compliance with
218
+ RFC 7230. Iteration provides the first case-sensitive key seen for each
219
+ case-insensitive pair.
220
+
221
+ Using ``__setitem__`` syntax overwrites fields that compare equal
222
+ case-insensitively in order to maintain ``dict``'s api. For fields that
223
+ compare equal, instead create a new ``HTTPHeaderDict`` and use ``.add``
224
+ in a loop.
225
+
226
+ If multiple fields that are equal case-insensitively are passed to the
227
+ constructor or ``.update``, the behavior is undefined and some will be
228
+ lost.
229
+
230
+ >>> headers = HTTPHeaderDict()
231
+ >>> headers.add('Set-Cookie', 'foo=bar')
232
+ >>> headers.add('set-cookie', 'baz=quxx')
233
+ >>> headers['content-length'] = '7'
234
+ >>> headers['SET-cookie']
235
+ 'foo=bar, baz=quxx'
236
+ >>> headers['Content-Length']
237
+ '7'
238
+ """
239
+
240
+ _container: typing.MutableMapping[str, list[str]]
241
+
242
+ def __init__(self, headers: ValidHTTPHeaderSource | None = None, **kwargs: str):
243
+ super().__init__()
244
+ self._container = {} # 'dict' is insert-ordered
245
+ if headers is not None:
246
+ if isinstance(headers, HTTPHeaderDict):
247
+ self._copy_from(headers)
248
+ else:
249
+ self.extend(headers)
250
+ if kwargs:
251
+ self.extend(kwargs)
252
+
253
+ def __setitem__(self, key: str, val: str) -> None:
254
+ # avoid a bytes/str comparison by decoding before httplib
255
+ if isinstance(key, bytes):
256
+ key = key.decode("latin-1")
257
+ self._container[key.lower()] = [key, val]
258
+
259
+ def __getitem__(self, key: str) -> str:
260
+ val = self._container[key.lower()]
261
+ return ", ".join(val[1:])
262
+
263
+ def __delitem__(self, key: str) -> None:
264
+ del self._container[key.lower()]
265
+
266
+ def __contains__(self, key: object) -> bool:
267
+ if isinstance(key, str):
268
+ return key.lower() in self._container
269
+ return False
270
+
271
+ def setdefault(self, key: str, default: str = "") -> str:
272
+ return super().setdefault(key, default)
273
+
274
+ def __eq__(self, other: object) -> bool:
275
+ maybe_constructable = ensure_can_construct_http_header_dict(other)
276
+ if maybe_constructable is None:
277
+ return False
278
+ else:
279
+ other_as_http_header_dict = type(self)(maybe_constructable)
280
+
281
+ return {k.lower(): v for k, v in self.itermerged()} == {
282
+ k.lower(): v for k, v in other_as_http_header_dict.itermerged()
283
+ }
284
+
285
+ def __ne__(self, other: object) -> bool:
286
+ return not self.__eq__(other)
287
+
288
+ def __len__(self) -> int:
289
+ return len(self._container)
290
+
291
+ def __iter__(self) -> typing.Iterator[str]:
292
+ # Only provide the originally cased names
293
+ for vals in self._container.values():
294
+ yield vals[0]
295
+
296
+ def discard(self, key: str) -> None:
297
+ try:
298
+ del self[key]
299
+ except KeyError:
300
+ pass
301
+
302
+ def add(self, key: str, val: str, *, combine: bool = False) -> None:
303
+ """Adds a (name, value) pair, doesn't overwrite the value if it already
304
+ exists.
305
+
306
+ If this is called with combine=True, instead of adding a new header value
307
+ as a distinct item during iteration, this will instead append the value to
308
+ any existing header value with a comma. If no existing header value exists
309
+ for the key, then the value will simply be added, ignoring the combine parameter.
310
+
311
+ >>> headers = HTTPHeaderDict(foo='bar')
312
+ >>> headers.add('Foo', 'baz')
313
+ >>> headers['foo']
314
+ 'bar, baz'
315
+ >>> list(headers.items())
316
+ [('foo', 'bar'), ('foo', 'baz')]
317
+ >>> headers.add('foo', 'quz', combine=True)
318
+ >>> list(headers.items())
319
+ [('foo', 'bar, baz, quz')]
320
+ """
321
+ # avoid a bytes/str comparison by decoding before httplib
322
+ if isinstance(key, bytes):
323
+ key = key.decode("latin-1")
324
+ key_lower = key.lower()
325
+ new_vals = [key, val]
326
+ # Keep the common case aka no item present as fast as possible
327
+ vals = self._container.setdefault(key_lower, new_vals)
328
+ if new_vals is not vals:
329
+ # if there are values here, then there is at least the initial
330
+ # key/value pair
331
+ assert len(vals) >= 2
332
+ if combine:
333
+ vals[-1] = vals[-1] + ", " + val
334
+ else:
335
+ vals.append(val)
336
+
337
+ def extend(self, *args: ValidHTTPHeaderSource, **kwargs: str) -> None:
338
+ """Generic import function for any type of header-like object.
339
+ Adapted version of MutableMapping.update in order to insert items
340
+ with self.add instead of self.__setitem__
341
+ """
342
+ if len(args) > 1:
343
+ raise TypeError(
344
+ f"extend() takes at most 1 positional arguments ({len(args)} given)"
345
+ )
346
+ other = args[0] if len(args) >= 1 else ()
347
+
348
+ if isinstance(other, HTTPHeaderDict):
349
+ for key, val in other.iteritems():
350
+ self.add(key, val)
351
+ elif isinstance(other, typing.Mapping):
352
+ for key, val in other.items():
353
+ self.add(key, val)
354
+ elif isinstance(other, typing.Iterable):
355
+ other = typing.cast(typing.Iterable[typing.Tuple[str, str]], other)
356
+ for key, value in other:
357
+ self.add(key, value)
358
+ elif hasattr(other, "keys") and hasattr(other, "__getitem__"):
359
+ # THIS IS NOT A TYPESAFE BRANCH
360
+ # In this branch, the object has a `keys` attr but is not a Mapping or any of
361
+ # the other types indicated in the method signature. We do some stuff with
362
+ # it as though it partially implements the Mapping interface, but we're not
363
+ # doing that stuff safely AT ALL.
364
+ for key in other.keys():
365
+ self.add(key, other[key])
366
+
367
+ for key, value in kwargs.items():
368
+ self.add(key, value)
369
+
370
+ @typing.overload
371
+ def getlist(self, key: str) -> list[str]:
372
+ ...
373
+
374
+ @typing.overload
375
+ def getlist(self, key: str, default: _DT) -> list[str] | _DT:
376
+ ...
377
+
378
+ def getlist(
379
+ self, key: str, default: _Sentinel | _DT = _Sentinel.not_passed
380
+ ) -> list[str] | _DT:
381
+ """Returns a list of all the values for the named field. Returns an
382
+ empty list if the key doesn't exist."""
383
+ try:
384
+ vals = self._container[key.lower()]
385
+ except KeyError:
386
+ if default is _Sentinel.not_passed:
387
+ # _DT is unbound; empty list is instance of List[str]
388
+ return []
389
+ # _DT is bound; default is instance of _DT
390
+ return default
391
+ else:
392
+ # _DT may or may not be bound; vals[1:] is instance of List[str], which
393
+ # meets our external interface requirement of `Union[List[str], _DT]`.
394
+ return vals[1:]
395
+
396
+ def _prepare_for_method_change(self) -> Self:
397
+ """
398
+ Remove content-specific header fields before changing the request
399
+ method to GET or HEAD according to RFC 9110, Section 15.4.
400
+ """
401
+ content_specific_headers = [
402
+ "Content-Encoding",
403
+ "Content-Language",
404
+ "Content-Location",
405
+ "Content-Type",
406
+ "Content-Length",
407
+ "Digest",
408
+ "Last-Modified",
409
+ ]
410
+ for header in content_specific_headers:
411
+ self.discard(header)
412
+ return self
413
+
414
+ # Backwards compatibility for httplib
415
+ getheaders = getlist
416
+ getallmatchingheaders = getlist
417
+ iget = getlist
418
+
419
+ # Backwards compatibility for http.cookiejar
420
+ get_all = getlist
421
+
422
+ def __repr__(self) -> str:
423
+ return f"{type(self).__name__}({dict(self.itermerged())})"
424
+
425
+ def _copy_from(self, other: HTTPHeaderDict) -> None:
426
+ for key in other:
427
+ val = other.getlist(key)
428
+ self._container[key.lower()] = [key, *val]
429
+
430
+ def copy(self) -> Self:
431
+ clone = type(self)()
432
+ clone._copy_from(self)
433
+ return clone
434
+
435
+ def iteritems(self) -> typing.Iterator[tuple[str, str]]:
436
+ """Iterate over all header lines, including duplicate ones."""
437
+ for key in self:
438
+ vals = self._container[key.lower()]
439
+ for val in vals[1:]:
440
+ yield vals[0], val
441
+
442
+ def itermerged(self) -> typing.Iterator[tuple[str, str]]:
443
+ """Iterate over all headers, merging duplicate ones together."""
444
+ for key in self:
445
+ val = self._container[key.lower()]
446
+ yield val[0], ", ".join(val[1:])
447
+
448
+ def items(self) -> HTTPHeaderDictItemView: # type: ignore[override]
449
+ return HTTPHeaderDictItemView(self)
450
+
451
+ def _has_value_for_header(self, header_name: str, potential_value: str) -> bool:
452
+ if header_name in self:
453
+ return potential_value in self._container[header_name.lower()][1:]
454
+ return False
455
+
456
+ def __ior__(self, other: object) -> HTTPHeaderDict:
457
+ # Supports extending a header dict in-place using operator |=
458
+ # combining items with add instead of __setitem__
459
+ maybe_constructable = ensure_can_construct_http_header_dict(other)
460
+ if maybe_constructable is None:
461
+ return NotImplemented
462
+ self.extend(maybe_constructable)
463
+ return self
464
+
465
+ def __or__(self, other: object) -> Self:
466
+ # Supports merging header dicts using operator |
467
+ # combining items with add instead of __setitem__
468
+ maybe_constructable = ensure_can_construct_http_header_dict(other)
469
+ if maybe_constructable is None:
470
+ return NotImplemented
471
+ result = self.copy()
472
+ result.extend(maybe_constructable)
473
+ return result
474
+
475
+ def __ror__(self, other: object) -> Self:
476
+ # Supports merging header dicts using operator | when other is on left side
477
+ # combining items with add instead of __setitem__
478
+ maybe_constructable = ensure_can_construct_http_header_dict(other)
479
+ if maybe_constructable is None:
480
+ return NotImplemented
481
+ result = type(self)(maybe_constructable)
482
+ result.extend(self)
483
+ return result
.venv/Lib/site-packages/urllib3/_request_methods.py ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import json as _json
4
+ import typing
5
+ from urllib.parse import urlencode
6
+
7
+ from ._base_connection import _TYPE_BODY
8
+ from ._collections import HTTPHeaderDict
9
+ from .filepost import _TYPE_FIELDS, encode_multipart_formdata
10
+ from .response import BaseHTTPResponse
11
+
12
+ __all__ = ["RequestMethods"]
13
+
14
+ _TYPE_ENCODE_URL_FIELDS = typing.Union[
15
+ typing.Sequence[typing.Tuple[str, typing.Union[str, bytes]]],
16
+ typing.Mapping[str, typing.Union[str, bytes]],
17
+ ]
18
+
19
+
20
+ class RequestMethods:
21
+ """
22
+ Convenience mixin for classes who implement a :meth:`urlopen` method, such
23
+ as :class:`urllib3.HTTPConnectionPool` and
24
+ :class:`urllib3.PoolManager`.
25
+
26
+ Provides behavior for making common types of HTTP request methods and
27
+ decides which type of request field encoding to use.
28
+
29
+ Specifically,
30
+
31
+ :meth:`.request_encode_url` is for sending requests whose fields are
32
+ encoded in the URL (such as GET, HEAD, DELETE).
33
+
34
+ :meth:`.request_encode_body` is for sending requests whose fields are
35
+ encoded in the *body* of the request using multipart or www-form-urlencoded
36
+ (such as for POST, PUT, PATCH).
37
+
38
+ :meth:`.request` is for making any kind of request, it will look up the
39
+ appropriate encoding format and use one of the above two methods to make
40
+ the request.
41
+
42
+ Initializer parameters:
43
+
44
+ :param headers:
45
+ Headers to include with all requests, unless other headers are given
46
+ explicitly.
47
+ """
48
+
49
+ _encode_url_methods = {"DELETE", "GET", "HEAD", "OPTIONS"}
50
+
51
+ def __init__(self, headers: typing.Mapping[str, str] | None = None) -> None:
52
+ self.headers = headers or {}
53
+
54
+ def urlopen(
55
+ self,
56
+ method: str,
57
+ url: str,
58
+ body: _TYPE_BODY | None = None,
59
+ headers: typing.Mapping[str, str] | None = None,
60
+ encode_multipart: bool = True,
61
+ multipart_boundary: str | None = None,
62
+ **kw: typing.Any,
63
+ ) -> BaseHTTPResponse: # Abstract
64
+ raise NotImplementedError(
65
+ "Classes extending RequestMethods must implement "
66
+ "their own ``urlopen`` method."
67
+ )
68
+
69
+ def request(
70
+ self,
71
+ method: str,
72
+ url: str,
73
+ body: _TYPE_BODY | None = None,
74
+ fields: _TYPE_FIELDS | None = None,
75
+ headers: typing.Mapping[str, str] | None = None,
76
+ json: typing.Any | None = None,
77
+ **urlopen_kw: typing.Any,
78
+ ) -> BaseHTTPResponse:
79
+ """
80
+ Make a request using :meth:`urlopen` with the appropriate encoding of
81
+ ``fields`` based on the ``method`` used.
82
+
83
+ This is a convenience method that requires the least amount of manual
84
+ effort. It can be used in most situations, while still having the
85
+ option to drop down to more specific methods when necessary, such as
86
+ :meth:`request_encode_url`, :meth:`request_encode_body`,
87
+ or even the lowest level :meth:`urlopen`.
88
+
89
+ :param method:
90
+ HTTP request method (such as GET, POST, PUT, etc.)
91
+
92
+ :param url:
93
+ The URL to perform the request on.
94
+
95
+ :param body:
96
+ Data to send in the request body, either :class:`str`, :class:`bytes`,
97
+ an iterable of :class:`str`/:class:`bytes`, or a file-like object.
98
+
99
+ :param fields:
100
+ Data to encode and send in the URL or request body, depending on ``method``.
101
+
102
+ :param headers:
103
+ Dictionary of custom headers to send, such as User-Agent,
104
+ If-None-Match, etc. If None, pool headers are used. If provided,
105
+ these headers completely replace any pool-specific headers.
106
+
107
+ :param json:
108
+ Data to encode and send as JSON with UTF-encoded in the request body.
109
+ The ``"Content-Type"`` header will be set to ``"application/json"``
110
+ unless specified otherwise.
111
+ """
112
+ method = method.upper()
113
+
114
+ if json is not None and body is not None:
115
+ raise TypeError(
116
+ "request got values for both 'body' and 'json' parameters which are mutually exclusive"
117
+ )
118
+
119
+ if json is not None:
120
+ if headers is None:
121
+ headers = self.headers
122
+
123
+ if not ("content-type" in map(str.lower, headers.keys())):
124
+ headers = HTTPHeaderDict(headers)
125
+ headers["Content-Type"] = "application/json"
126
+
127
+ body = _json.dumps(json, separators=(",", ":"), ensure_ascii=False).encode(
128
+ "utf-8"
129
+ )
130
+
131
+ if body is not None:
132
+ urlopen_kw["body"] = body
133
+
134
+ if method in self._encode_url_methods:
135
+ return self.request_encode_url(
136
+ method,
137
+ url,
138
+ fields=fields, # type: ignore[arg-type]
139
+ headers=headers,
140
+ **urlopen_kw,
141
+ )
142
+ else:
143
+ return self.request_encode_body(
144
+ method, url, fields=fields, headers=headers, **urlopen_kw
145
+ )
146
+
147
+ def request_encode_url(
148
+ self,
149
+ method: str,
150
+ url: str,
151
+ fields: _TYPE_ENCODE_URL_FIELDS | None = None,
152
+ headers: typing.Mapping[str, str] | None = None,
153
+ **urlopen_kw: str,
154
+ ) -> BaseHTTPResponse:
155
+ """
156
+ Make a request using :meth:`urlopen` with the ``fields`` encoded in
157
+ the url. This is useful for request methods like GET, HEAD, DELETE, etc.
158
+
159
+ :param method:
160
+ HTTP request method (such as GET, POST, PUT, etc.)
161
+
162
+ :param url:
163
+ The URL to perform the request on.
164
+
165
+ :param fields:
166
+ Data to encode and send in the URL.
167
+
168
+ :param headers:
169
+ Dictionary of custom headers to send, such as User-Agent,
170
+ If-None-Match, etc. If None, pool headers are used. If provided,
171
+ these headers completely replace any pool-specific headers.
172
+ """
173
+ if headers is None:
174
+ headers = self.headers
175
+
176
+ extra_kw: dict[str, typing.Any] = {"headers": headers}
177
+ extra_kw.update(urlopen_kw)
178
+
179
+ if fields:
180
+ url += "?" + urlencode(fields)
181
+
182
+ return self.urlopen(method, url, **extra_kw)
183
+
184
+ def request_encode_body(
185
+ self,
186
+ method: str,
187
+ url: str,
188
+ fields: _TYPE_FIELDS | None = None,
189
+ headers: typing.Mapping[str, str] | None = None,
190
+ encode_multipart: bool = True,
191
+ multipart_boundary: str | None = None,
192
+ **urlopen_kw: str,
193
+ ) -> BaseHTTPResponse:
194
+ """
195
+ Make a request using :meth:`urlopen` with the ``fields`` encoded in
196
+ the body. This is useful for request methods like POST, PUT, PATCH, etc.
197
+
198
+ When ``encode_multipart=True`` (default), then
199
+ :func:`urllib3.encode_multipart_formdata` is used to encode
200
+ the payload with the appropriate content type. Otherwise
201
+ :func:`urllib.parse.urlencode` is used with the
202
+ 'application/x-www-form-urlencoded' content type.
203
+
204
+ Multipart encoding must be used when posting files, and it's reasonably
205
+ safe to use it in other times too. However, it may break request
206
+ signing, such as with OAuth.
207
+
208
+ Supports an optional ``fields`` parameter of key/value strings AND
209
+ key/filetuple. A filetuple is a (filename, data, MIME type) tuple where
210
+ the MIME type is optional. For example::
211
+
212
+ fields = {
213
+ 'foo': 'bar',
214
+ 'fakefile': ('foofile.txt', 'contents of foofile'),
215
+ 'realfile': ('barfile.txt', open('realfile').read()),
216
+ 'typedfile': ('bazfile.bin', open('bazfile').read(),
217
+ 'image/jpeg'),
218
+ 'nonamefile': 'contents of nonamefile field',
219
+ }
220
+
221
+ When uploading a file, providing a filename (the first parameter of the
222
+ tuple) is optional but recommended to best mimic behavior of browsers.
223
+
224
+ Note that if ``headers`` are supplied, the 'Content-Type' header will
225
+ be overwritten because it depends on the dynamic random boundary string
226
+ which is used to compose the body of the request. The random boundary
227
+ string can be explicitly set with the ``multipart_boundary`` parameter.
228
+
229
+ :param method:
230
+ HTTP request method (such as GET, POST, PUT, etc.)
231
+
232
+ :param url:
233
+ The URL to perform the request on.
234
+
235
+ :param fields:
236
+ Data to encode and send in the request body.
237
+
238
+ :param headers:
239
+ Dictionary of custom headers to send, such as User-Agent,
240
+ If-None-Match, etc. If None, pool headers are used. If provided,
241
+ these headers completely replace any pool-specific headers.
242
+
243
+ :param encode_multipart:
244
+ If True, encode the ``fields`` using the multipart/form-data MIME
245
+ format.
246
+
247
+ :param multipart_boundary:
248
+ If not specified, then a random boundary will be generated using
249
+ :func:`urllib3.filepost.choose_boundary`.
250
+ """
251
+ if headers is None:
252
+ headers = self.headers
253
+
254
+ extra_kw: dict[str, typing.Any] = {"headers": HTTPHeaderDict(headers)}
255
+ body: bytes | str
256
+
257
+ if fields:
258
+ if "body" in urlopen_kw:
259
+ raise TypeError(
260
+ "request got values for both 'fields' and 'body', can only specify one."
261
+ )
262
+
263
+ if encode_multipart:
264
+ body, content_type = encode_multipart_formdata(
265
+ fields, boundary=multipart_boundary
266
+ )
267
+ else:
268
+ body, content_type = (
269
+ urlencode(fields), # type: ignore[arg-type]
270
+ "application/x-www-form-urlencoded",
271
+ )
272
+
273
+ extra_kw["body"] = body
274
+ extra_kw["headers"].setdefault("Content-Type", content_type)
275
+
276
+ extra_kw.update(urlopen_kw)
277
+
278
+ return self.urlopen(method, url, **extra_kw)
.venv/Lib/site-packages/urllib3/_version.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '2.2.3'
16
+ __version_tuple__ = version_tuple = (2, 2, 3)
.venv/Lib/site-packages/urllib3/connection.py ADDED
@@ -0,0 +1,1033 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import datetime
4
+ import http.client
5
+ import logging
6
+ import os
7
+ import re
8
+ import socket
9
+ import sys
10
+ import threading
11
+ import typing
12
+ import warnings
13
+ from http.client import HTTPConnection as _HTTPConnection
14
+ from http.client import HTTPException as HTTPException # noqa: F401
15
+ from http.client import ResponseNotReady
16
+ from socket import timeout as SocketTimeout
17
+
18
+ if typing.TYPE_CHECKING:
19
+ from .response import HTTPResponse
20
+ from .util.ssl_ import _TYPE_PEER_CERT_RET_DICT
21
+ from .util.ssltransport import SSLTransport
22
+
23
+ from ._collections import HTTPHeaderDict
24
+ from .http2 import probe as http2_probe
25
+ from .util.response import assert_header_parsing
26
+ from .util.timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT, Timeout
27
+ from .util.util import to_str
28
+ from .util.wait import wait_for_read
29
+
30
+ try: # Compiled with SSL?
31
+ import ssl
32
+
33
+ BaseSSLError = ssl.SSLError
34
+ except (ImportError, AttributeError):
35
+ ssl = None # type: ignore[assignment]
36
+
37
+ class BaseSSLError(BaseException): # type: ignore[no-redef]
38
+ pass
39
+
40
+
41
+ from ._base_connection import _TYPE_BODY
42
+ from ._base_connection import ProxyConfig as ProxyConfig
43
+ from ._base_connection import _ResponseOptions as _ResponseOptions
44
+ from ._version import __version__
45
+ from .exceptions import (
46
+ ConnectTimeoutError,
47
+ HeaderParsingError,
48
+ NameResolutionError,
49
+ NewConnectionError,
50
+ ProxyError,
51
+ SystemTimeWarning,
52
+ )
53
+ from .util import SKIP_HEADER, SKIPPABLE_HEADERS, connection, ssl_
54
+ from .util.request import body_to_chunks
55
+ from .util.ssl_ import assert_fingerprint as _assert_fingerprint
56
+ from .util.ssl_ import (
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
+ from .util.url import Url
65
+
66
+ # Not a no-op, we're adding this to the namespace so it can be imported.
67
+ ConnectionError = ConnectionError
68
+ BrokenPipeError = BrokenPipeError
69
+
70
+
71
+ log = logging.getLogger(__name__)
72
+
73
+ port_by_scheme = {"http": 80, "https": 443}
74
+
75
+ # When it comes time to update this value as a part of regular maintenance
76
+ # (ie test_recent_date is failing) update it to ~6 months before the current date.
77
+ RECENT_DATE = datetime.date(2023, 6, 1)
78
+
79
+ _CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")
80
+
81
+ _HAS_SYS_AUDIT = hasattr(sys, "audit")
82
+
83
+
84
+ class HTTPConnection(_HTTPConnection):
85
+ """
86
+ Based on :class:`http.client.HTTPConnection` but provides an extra constructor
87
+ backwards-compatibility layer between older and newer Pythons.
88
+
89
+ Additional keyword parameters are used to configure attributes of the connection.
90
+ Accepted parameters include:
91
+
92
+ - ``source_address``: Set the source address for the current connection.
93
+ - ``socket_options``: Set specific options on the underlying socket. If not specified, then
94
+ defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
95
+ Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.
96
+
97
+ For example, if you wish to enable TCP Keep Alive in addition to the defaults,
98
+ you might pass:
99
+
100
+ .. code-block:: python
101
+
102
+ HTTPConnection.default_socket_options + [
103
+ (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
104
+ ]
105
+
106
+ Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
107
+ """
108
+
109
+ default_port: typing.ClassVar[int] = port_by_scheme["http"] # type: ignore[misc]
110
+
111
+ #: Disable Nagle's algorithm by default.
112
+ #: ``[(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)]``
113
+ default_socket_options: typing.ClassVar[connection._TYPE_SOCKET_OPTIONS] = [
114
+ (socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
115
+ ]
116
+
117
+ #: Whether this connection verifies the host's certificate.
118
+ is_verified: bool = False
119
+
120
+ #: Whether this proxy connection verified the proxy host's certificate.
121
+ # If no proxy is currently connected to the value will be ``None``.
122
+ proxy_is_verified: bool | None = None
123
+
124
+ blocksize: int
125
+ source_address: tuple[str, int] | None
126
+ socket_options: connection._TYPE_SOCKET_OPTIONS | None
127
+
128
+ _has_connected_to_proxy: bool
129
+ _response_options: _ResponseOptions | None
130
+ _tunnel_host: str | None
131
+ _tunnel_port: int | None
132
+ _tunnel_scheme: str | None
133
+
134
+ def __init__(
135
+ self,
136
+ host: str,
137
+ port: int | None = None,
138
+ *,
139
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
140
+ source_address: tuple[str, int] | None = None,
141
+ blocksize: int = 16384,
142
+ socket_options: None
143
+ | (connection._TYPE_SOCKET_OPTIONS) = default_socket_options,
144
+ proxy: Url | None = None,
145
+ proxy_config: ProxyConfig | None = None,
146
+ ) -> None:
147
+ super().__init__(
148
+ host=host,
149
+ port=port,
150
+ timeout=Timeout.resolve_default_timeout(timeout),
151
+ source_address=source_address,
152
+ blocksize=blocksize,
153
+ )
154
+ self.socket_options = socket_options
155
+ self.proxy = proxy
156
+ self.proxy_config = proxy_config
157
+
158
+ self._has_connected_to_proxy = False
159
+ self._response_options = None
160
+ self._tunnel_host: str | None = None
161
+ self._tunnel_port: int | None = None
162
+ self._tunnel_scheme: str | None = None
163
+
164
+ @property
165
+ def host(self) -> str:
166
+ """
167
+ Getter method to remove any trailing dots that indicate the hostname is an FQDN.
168
+
169
+ In general, SSL certificates don't include the trailing dot indicating a
170
+ fully-qualified domain name, and thus, they don't validate properly when
171
+ checked against a domain name that includes the dot. In addition, some
172
+ servers may not expect to receive the trailing dot when provided.
173
+
174
+ However, the hostname with trailing dot is critical to DNS resolution; doing a
175
+ lookup with the trailing dot will properly only resolve the appropriate FQDN,
176
+ whereas a lookup without a trailing dot will search the system's search domain
177
+ list. Thus, it's important to keep the original host around for use only in
178
+ those cases where it's appropriate (i.e., when doing DNS lookup to establish the
179
+ actual TCP connection across which we're going to send HTTP requests).
180
+ """
181
+ return self._dns_host.rstrip(".")
182
+
183
+ @host.setter
184
+ def host(self, value: str) -> None:
185
+ """
186
+ Setter for the `host` property.
187
+
188
+ We assume that only urllib3 uses the _dns_host attribute; httplib itself
189
+ only uses `host`, and it seems reasonable that other libraries follow suit.
190
+ """
191
+ self._dns_host = value
192
+
193
+ def _new_conn(self) -> socket.socket:
194
+ """Establish a socket connection and set nodelay settings on it.
195
+
196
+ :return: New socket connection.
197
+ """
198
+ try:
199
+ sock = connection.create_connection(
200
+ (self._dns_host, self.port),
201
+ self.timeout,
202
+ source_address=self.source_address,
203
+ socket_options=self.socket_options,
204
+ )
205
+ except socket.gaierror as e:
206
+ raise NameResolutionError(self.host, self, e) from e
207
+ except SocketTimeout as e:
208
+ raise ConnectTimeoutError(
209
+ self,
210
+ f"Connection to {self.host} timed out. (connect timeout={self.timeout})",
211
+ ) from e
212
+
213
+ except OSError as e:
214
+ raise NewConnectionError(
215
+ self, f"Failed to establish a new connection: {e}"
216
+ ) from e
217
+
218
+ # Audit hooks are only available in Python 3.8+
219
+ if _HAS_SYS_AUDIT:
220
+ sys.audit("http.client.connect", self, self.host, self.port)
221
+
222
+ return sock
223
+
224
+ def set_tunnel(
225
+ self,
226
+ host: str,
227
+ port: int | None = None,
228
+ headers: typing.Mapping[str, str] | None = None,
229
+ scheme: str = "http",
230
+ ) -> None:
231
+ if scheme not in ("http", "https"):
232
+ raise ValueError(
233
+ f"Invalid proxy scheme for tunneling: {scheme!r}, must be either 'http' or 'https'"
234
+ )
235
+ super().set_tunnel(host, port=port, headers=headers)
236
+ self._tunnel_scheme = scheme
237
+
238
+ if sys.version_info < (3, 11, 4):
239
+
240
+ def _tunnel(self) -> None:
241
+ _MAXLINE = http.client._MAXLINE # type: ignore[attr-defined]
242
+ connect = b"CONNECT %s:%d HTTP/1.0\r\n" % ( # type: ignore[str-format]
243
+ self._tunnel_host.encode("ascii"), # type: ignore[union-attr]
244
+ self._tunnel_port,
245
+ )
246
+ headers = [connect]
247
+ for header, value in self._tunnel_headers.items(): # type: ignore[attr-defined]
248
+ headers.append(f"{header}: {value}\r\n".encode("latin-1"))
249
+ headers.append(b"\r\n")
250
+ # Making a single send() call instead of one per line encourages
251
+ # the host OS to use a more optimal packet size instead of
252
+ # potentially emitting a series of small packets.
253
+ self.send(b"".join(headers))
254
+ del headers
255
+
256
+ response = self.response_class(self.sock, method=self._method) # type: ignore[attr-defined]
257
+ try:
258
+ (version, code, message) = response._read_status() # type: ignore[attr-defined]
259
+
260
+ if code != http.HTTPStatus.OK:
261
+ self.close()
262
+ raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
263
+ while True:
264
+ line = response.fp.readline(_MAXLINE + 1)
265
+ if len(line) > _MAXLINE:
266
+ raise http.client.LineTooLong("header line")
267
+ if not line:
268
+ # for sites which EOF without sending a trailer
269
+ break
270
+ if line in (b"\r\n", b"\n", b""):
271
+ break
272
+
273
+ if self.debuglevel > 0:
274
+ print("header:", line.decode())
275
+ finally:
276
+ response.close()
277
+
278
+ def connect(self) -> None:
279
+ self.sock = self._new_conn()
280
+ if self._tunnel_host:
281
+ # If we're tunneling it means we're connected to our proxy.
282
+ self._has_connected_to_proxy = True
283
+
284
+ # TODO: Fix tunnel so it doesn't depend on self.sock state.
285
+ self._tunnel()
286
+
287
+ # If there's a proxy to be connected to we are fully connected.
288
+ # This is set twice (once above and here) due to forwarding proxies
289
+ # not using tunnelling.
290
+ self._has_connected_to_proxy = bool(self.proxy)
291
+
292
+ if self._has_connected_to_proxy:
293
+ self.proxy_is_verified = False
294
+
295
+ @property
296
+ def is_closed(self) -> bool:
297
+ return self.sock is None
298
+
299
+ @property
300
+ def is_connected(self) -> bool:
301
+ if self.sock is None:
302
+ return False
303
+ return not wait_for_read(self.sock, timeout=0.0)
304
+
305
+ @property
306
+ def has_connected_to_proxy(self) -> bool:
307
+ return self._has_connected_to_proxy
308
+
309
+ @property
310
+ def proxy_is_forwarding(self) -> bool:
311
+ """
312
+ Return True if a forwarding proxy is configured, else return False
313
+ """
314
+ return bool(self.proxy) and self._tunnel_host is None
315
+
316
+ def close(self) -> None:
317
+ try:
318
+ super().close()
319
+ finally:
320
+ # Reset all stateful properties so connection
321
+ # can be re-used without leaking prior configs.
322
+ self.sock = None
323
+ self.is_verified = False
324
+ self.proxy_is_verified = None
325
+ self._has_connected_to_proxy = False
326
+ self._response_options = None
327
+ self._tunnel_host = None
328
+ self._tunnel_port = None
329
+ self._tunnel_scheme = None
330
+
331
+ def putrequest(
332
+ self,
333
+ method: str,
334
+ url: str,
335
+ skip_host: bool = False,
336
+ skip_accept_encoding: bool = False,
337
+ ) -> None:
338
+ """"""
339
+ # Empty docstring because the indentation of CPython's implementation
340
+ # is broken but we don't want this method in our documentation.
341
+ match = _CONTAINS_CONTROL_CHAR_RE.search(method)
342
+ if match:
343
+ raise ValueError(
344
+ f"Method cannot contain non-token characters {method!r} (found at least {match.group()!r})"
345
+ )
346
+
347
+ return super().putrequest(
348
+ method, url, skip_host=skip_host, skip_accept_encoding=skip_accept_encoding
349
+ )
350
+
351
+ def putheader(self, header: str, *values: str) -> None: # type: ignore[override]
352
+ """"""
353
+ if not any(isinstance(v, str) and v == SKIP_HEADER for v in values):
354
+ super().putheader(header, *values)
355
+ elif to_str(header.lower()) not in SKIPPABLE_HEADERS:
356
+ skippable_headers = "', '".join(
357
+ [str.title(header) for header in sorted(SKIPPABLE_HEADERS)]
358
+ )
359
+ raise ValueError(
360
+ f"urllib3.util.SKIP_HEADER only supports '{skippable_headers}'"
361
+ )
362
+
363
+ # `request` method's signature intentionally violates LSP.
364
+ # urllib3's API is different from `http.client.HTTPConnection` and the subclassing is only incidental.
365
+ def request( # type: ignore[override]
366
+ self,
367
+ method: str,
368
+ url: str,
369
+ body: _TYPE_BODY | None = None,
370
+ headers: typing.Mapping[str, str] | None = None,
371
+ *,
372
+ chunked: bool = False,
373
+ preload_content: bool = True,
374
+ decode_content: bool = True,
375
+ enforce_content_length: bool = True,
376
+ ) -> None:
377
+ # Update the inner socket's timeout value to send the request.
378
+ # This only triggers if the connection is re-used.
379
+ if self.sock is not None:
380
+ self.sock.settimeout(self.timeout)
381
+
382
+ # Store these values to be fed into the HTTPResponse
383
+ # object later. TODO: Remove this in favor of a real
384
+ # HTTP lifecycle mechanism.
385
+
386
+ # We have to store these before we call .request()
387
+ # because sometimes we can still salvage a response
388
+ # off the wire even if we aren't able to completely
389
+ # send the request body.
390
+ self._response_options = _ResponseOptions(
391
+ request_method=method,
392
+ request_url=url,
393
+ preload_content=preload_content,
394
+ decode_content=decode_content,
395
+ enforce_content_length=enforce_content_length,
396
+ )
397
+
398
+ if headers is None:
399
+ headers = {}
400
+ header_keys = frozenset(to_str(k.lower()) for k in headers)
401
+ skip_accept_encoding = "accept-encoding" in header_keys
402
+ skip_host = "host" in header_keys
403
+ self.putrequest(
404
+ method, url, skip_accept_encoding=skip_accept_encoding, skip_host=skip_host
405
+ )
406
+
407
+ # Transform the body into an iterable of sendall()-able chunks
408
+ # and detect if an explicit Content-Length is doable.
409
+ chunks_and_cl = body_to_chunks(body, method=method, blocksize=self.blocksize)
410
+ chunks = chunks_and_cl.chunks
411
+ content_length = chunks_and_cl.content_length
412
+
413
+ # When chunked is explicit set to 'True' we respect that.
414
+ if chunked:
415
+ if "transfer-encoding" not in header_keys:
416
+ self.putheader("Transfer-Encoding", "chunked")
417
+ else:
418
+ # Detect whether a framing mechanism is already in use. If so
419
+ # we respect that value, otherwise we pick chunked vs content-length
420
+ # depending on the type of 'body'.
421
+ if "content-length" in header_keys:
422
+ chunked = False
423
+ elif "transfer-encoding" in header_keys:
424
+ chunked = True
425
+
426
+ # Otherwise we go off the recommendation of 'body_to_chunks()'.
427
+ else:
428
+ chunked = False
429
+ if content_length is None:
430
+ if chunks is not None:
431
+ chunked = True
432
+ self.putheader("Transfer-Encoding", "chunked")
433
+ else:
434
+ self.putheader("Content-Length", str(content_length))
435
+
436
+ # Now that framing headers are out of the way we send all the other headers.
437
+ if "user-agent" not in header_keys:
438
+ self.putheader("User-Agent", _get_default_user_agent())
439
+ for header, value in headers.items():
440
+ self.putheader(header, value)
441
+ self.endheaders()
442
+
443
+ # If we're given a body we start sending that in chunks.
444
+ if chunks is not None:
445
+ for chunk in chunks:
446
+ # Sending empty chunks isn't allowed for TE: chunked
447
+ # as it indicates the end of the body.
448
+ if not chunk:
449
+ continue
450
+ if isinstance(chunk, str):
451
+ chunk = chunk.encode("utf-8")
452
+ if chunked:
453
+ self.send(b"%x\r\n%b\r\n" % (len(chunk), chunk))
454
+ else:
455
+ self.send(chunk)
456
+
457
+ # Regardless of whether we have a body or not, if we're in
458
+ # chunked mode we want to send an explicit empty chunk.
459
+ if chunked:
460
+ self.send(b"0\r\n\r\n")
461
+
462
+ def request_chunked(
463
+ self,
464
+ method: str,
465
+ url: str,
466
+ body: _TYPE_BODY | None = None,
467
+ headers: typing.Mapping[str, str] | None = None,
468
+ ) -> None:
469
+ """
470
+ Alternative to the common request method, which sends the
471
+ body with chunked encoding and not as one block
472
+ """
473
+ warnings.warn(
474
+ "HTTPConnection.request_chunked() is deprecated and will be removed "
475
+ "in urllib3 v2.1.0. Instead use HTTPConnection.request(..., chunked=True).",
476
+ category=DeprecationWarning,
477
+ stacklevel=2,
478
+ )
479
+ self.request(method, url, body=body, headers=headers, chunked=True)
480
+
481
+ def getresponse( # type: ignore[override]
482
+ self,
483
+ ) -> HTTPResponse:
484
+ """
485
+ Get the response from the server.
486
+
487
+ If the HTTPConnection is in the correct state, returns an instance of HTTPResponse or of whatever object is returned by the response_class variable.
488
+
489
+ If a request has not been sent or if a previous response has not be handled, ResponseNotReady is raised. If the HTTP response indicates that the connection should be closed, then it will be closed before the response is returned. When the connection is closed, the underlying socket is closed.
490
+ """
491
+ # Raise the same error as http.client.HTTPConnection
492
+ if self._response_options is None:
493
+ raise ResponseNotReady()
494
+
495
+ # Reset this attribute for being used again.
496
+ resp_options = self._response_options
497
+ self._response_options = None
498
+
499
+ # Since the connection's timeout value may have been updated
500
+ # we need to set the timeout on the socket.
501
+ self.sock.settimeout(self.timeout)
502
+
503
+ # This is needed here to avoid circular import errors
504
+ from .response import HTTPResponse
505
+
506
+ # Get the response from http.client.HTTPConnection
507
+ httplib_response = super().getresponse()
508
+
509
+ try:
510
+ assert_header_parsing(httplib_response.msg)
511
+ except (HeaderParsingError, TypeError) as hpe:
512
+ log.warning(
513
+ "Failed to parse headers (url=%s): %s",
514
+ _url_from_connection(self, resp_options.request_url),
515
+ hpe,
516
+ exc_info=True,
517
+ )
518
+
519
+ headers = HTTPHeaderDict(httplib_response.msg.items())
520
+
521
+ response = HTTPResponse(
522
+ body=httplib_response,
523
+ headers=headers,
524
+ status=httplib_response.status,
525
+ version=httplib_response.version,
526
+ version_string=getattr(self, "_http_vsn_str", "HTTP/?"),
527
+ reason=httplib_response.reason,
528
+ preload_content=resp_options.preload_content,
529
+ decode_content=resp_options.decode_content,
530
+ original_response=httplib_response,
531
+ enforce_content_length=resp_options.enforce_content_length,
532
+ request_method=resp_options.request_method,
533
+ request_url=resp_options.request_url,
534
+ )
535
+ return response
536
+
537
+
538
+ class HTTPSConnection(HTTPConnection):
539
+ """
540
+ Many of the parameters to this constructor are passed to the underlying SSL
541
+ socket by means of :py:func:`urllib3.util.ssl_wrap_socket`.
542
+ """
543
+
544
+ default_port = port_by_scheme["https"] # type: ignore[misc]
545
+
546
+ cert_reqs: int | str | None = None
547
+ ca_certs: str | None = None
548
+ ca_cert_dir: str | None = None
549
+ ca_cert_data: None | str | bytes = None
550
+ ssl_version: int | str | None = None
551
+ ssl_minimum_version: int | None = None
552
+ ssl_maximum_version: int | None = None
553
+ assert_fingerprint: str | None = None
554
+ _connect_callback: typing.Callable[..., None] | None = None
555
+
556
+ def __init__(
557
+ self,
558
+ host: str,
559
+ port: int | None = None,
560
+ *,
561
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
562
+ source_address: tuple[str, int] | None = None,
563
+ blocksize: int = 16384,
564
+ socket_options: None
565
+ | (connection._TYPE_SOCKET_OPTIONS) = HTTPConnection.default_socket_options,
566
+ proxy: Url | None = None,
567
+ proxy_config: ProxyConfig | None = None,
568
+ cert_reqs: int | str | None = None,
569
+ assert_hostname: None | str | typing.Literal[False] = None,
570
+ assert_fingerprint: str | None = None,
571
+ server_hostname: str | None = None,
572
+ ssl_context: ssl.SSLContext | None = None,
573
+ ca_certs: str | None = None,
574
+ ca_cert_dir: str | None = None,
575
+ ca_cert_data: None | str | bytes = None,
576
+ ssl_minimum_version: int | None = None,
577
+ ssl_maximum_version: int | None = None,
578
+ ssl_version: int | str | None = None, # Deprecated
579
+ cert_file: str | None = None,
580
+ key_file: str | None = None,
581
+ key_password: str | None = None,
582
+ ) -> None:
583
+ super().__init__(
584
+ host,
585
+ port=port,
586
+ timeout=timeout,
587
+ source_address=source_address,
588
+ blocksize=blocksize,
589
+ socket_options=socket_options,
590
+ proxy=proxy,
591
+ proxy_config=proxy_config,
592
+ )
593
+
594
+ self.key_file = key_file
595
+ self.cert_file = cert_file
596
+ self.key_password = key_password
597
+ self.ssl_context = ssl_context
598
+ self.server_hostname = server_hostname
599
+ self.assert_hostname = assert_hostname
600
+ self.assert_fingerprint = assert_fingerprint
601
+ self.ssl_version = ssl_version
602
+ self.ssl_minimum_version = ssl_minimum_version
603
+ self.ssl_maximum_version = ssl_maximum_version
604
+ self.ca_certs = ca_certs and os.path.expanduser(ca_certs)
605
+ self.ca_cert_dir = ca_cert_dir and os.path.expanduser(ca_cert_dir)
606
+ self.ca_cert_data = ca_cert_data
607
+
608
+ # cert_reqs depends on ssl_context so calculate last.
609
+ if cert_reqs is None:
610
+ if self.ssl_context is not None:
611
+ cert_reqs = self.ssl_context.verify_mode
612
+ else:
613
+ cert_reqs = resolve_cert_reqs(None)
614
+ self.cert_reqs = cert_reqs
615
+ self._connect_callback = None
616
+
617
+ def set_cert(
618
+ self,
619
+ key_file: str | None = None,
620
+ cert_file: str | None = None,
621
+ cert_reqs: int | str | None = None,
622
+ key_password: str | None = None,
623
+ ca_certs: str | None = None,
624
+ assert_hostname: None | str | typing.Literal[False] = None,
625
+ assert_fingerprint: str | None = None,
626
+ ca_cert_dir: str | None = None,
627
+ ca_cert_data: None | str | bytes = None,
628
+ ) -> None:
629
+ """
630
+ This method should only be called once, before the connection is used.
631
+ """
632
+ warnings.warn(
633
+ "HTTPSConnection.set_cert() is deprecated and will be removed "
634
+ "in urllib3 v2.1.0. Instead provide the parameters to the "
635
+ "HTTPSConnection constructor.",
636
+ category=DeprecationWarning,
637
+ stacklevel=2,
638
+ )
639
+
640
+ # If cert_reqs is not provided we'll assume CERT_REQUIRED unless we also
641
+ # have an SSLContext object in which case we'll use its verify_mode.
642
+ if cert_reqs is None:
643
+ if self.ssl_context is not None:
644
+ cert_reqs = self.ssl_context.verify_mode
645
+ else:
646
+ cert_reqs = resolve_cert_reqs(None)
647
+
648
+ self.key_file = key_file
649
+ self.cert_file = cert_file
650
+ self.cert_reqs = cert_reqs
651
+ self.key_password = key_password
652
+ self.assert_hostname = assert_hostname
653
+ self.assert_fingerprint = assert_fingerprint
654
+ self.ca_certs = ca_certs and os.path.expanduser(ca_certs)
655
+ self.ca_cert_dir = ca_cert_dir and os.path.expanduser(ca_cert_dir)
656
+ self.ca_cert_data = ca_cert_data
657
+
658
+ def connect(self) -> None:
659
+ # Today we don't need to be doing this step before the /actual/ socket
660
+ # connection, however in the future we'll need to decide whether to
661
+ # create a new socket or re-use an existing "shared" socket as a part
662
+ # of the HTTP/2 handshake dance.
663
+ if self._tunnel_host is not None and self._tunnel_port is not None:
664
+ probe_http2_host = self._tunnel_host
665
+ probe_http2_port = self._tunnel_port
666
+ else:
667
+ probe_http2_host = self.host
668
+ probe_http2_port = self.port
669
+
670
+ # Check if the target origin supports HTTP/2.
671
+ # If the value comes back as 'None' it means that the current thread
672
+ # is probing for HTTP/2 support. Otherwise, we're waiting for another
673
+ # probe to complete, or we get a value right away.
674
+ target_supports_http2: bool | None
675
+ if "h2" in ssl_.ALPN_PROTOCOLS:
676
+ target_supports_http2 = http2_probe.acquire_and_get(
677
+ host=probe_http2_host, port=probe_http2_port
678
+ )
679
+ else:
680
+ # If HTTP/2 isn't going to be offered it doesn't matter if
681
+ # the target supports HTTP/2. Don't want to make a probe.
682
+ target_supports_http2 = False
683
+
684
+ if self._connect_callback is not None:
685
+ self._connect_callback(
686
+ "before connect",
687
+ thread_id=threading.get_ident(),
688
+ target_supports_http2=target_supports_http2,
689
+ )
690
+
691
+ try:
692
+ sock: socket.socket | ssl.SSLSocket
693
+ self.sock = sock = self._new_conn()
694
+ server_hostname: str = self.host
695
+ tls_in_tls = False
696
+
697
+ # Do we need to establish a tunnel?
698
+ if self._tunnel_host is not None:
699
+ # We're tunneling to an HTTPS origin so need to do TLS-in-TLS.
700
+ if self._tunnel_scheme == "https":
701
+ # _connect_tls_proxy will verify and assign proxy_is_verified
702
+ self.sock = sock = self._connect_tls_proxy(self.host, sock)
703
+ tls_in_tls = True
704
+ elif self._tunnel_scheme == "http":
705
+ self.proxy_is_verified = False
706
+
707
+ # If we're tunneling it means we're connected to our proxy.
708
+ self._has_connected_to_proxy = True
709
+
710
+ self._tunnel()
711
+ # Override the host with the one we're requesting data from.
712
+ server_hostname = self._tunnel_host
713
+
714
+ if self.server_hostname is not None:
715
+ server_hostname = self.server_hostname
716
+
717
+ is_time_off = datetime.date.today() < RECENT_DATE
718
+ if is_time_off:
719
+ warnings.warn(
720
+ (
721
+ f"System time is way off (before {RECENT_DATE}). This will probably "
722
+ "lead to SSL verification errors"
723
+ ),
724
+ SystemTimeWarning,
725
+ )
726
+
727
+ # Remove trailing '.' from fqdn hostnames to allow certificate validation
728
+ server_hostname_rm_dot = server_hostname.rstrip(".")
729
+
730
+ sock_and_verified = _ssl_wrap_socket_and_match_hostname(
731
+ sock=sock,
732
+ cert_reqs=self.cert_reqs,
733
+ ssl_version=self.ssl_version,
734
+ ssl_minimum_version=self.ssl_minimum_version,
735
+ ssl_maximum_version=self.ssl_maximum_version,
736
+ ca_certs=self.ca_certs,
737
+ ca_cert_dir=self.ca_cert_dir,
738
+ ca_cert_data=self.ca_cert_data,
739
+ cert_file=self.cert_file,
740
+ key_file=self.key_file,
741
+ key_password=self.key_password,
742
+ server_hostname=server_hostname_rm_dot,
743
+ ssl_context=self.ssl_context,
744
+ tls_in_tls=tls_in_tls,
745
+ assert_hostname=self.assert_hostname,
746
+ assert_fingerprint=self.assert_fingerprint,
747
+ )
748
+ self.sock = sock_and_verified.socket
749
+
750
+ # If an error occurs during connection/handshake we may need to release
751
+ # our lock so another connection can probe the origin.
752
+ except BaseException:
753
+ if self._connect_callback is not None:
754
+ self._connect_callback(
755
+ "after connect failure",
756
+ thread_id=threading.get_ident(),
757
+ target_supports_http2=target_supports_http2,
758
+ )
759
+
760
+ if target_supports_http2 is None:
761
+ http2_probe.set_and_release(
762
+ host=probe_http2_host, port=probe_http2_port, supports_http2=None
763
+ )
764
+ raise
765
+
766
+ # If this connection doesn't know if the origin supports HTTP/2
767
+ # we report back to the HTTP/2 probe our result.
768
+ if target_supports_http2 is None:
769
+ supports_http2 = sock_and_verified.socket.selected_alpn_protocol() == "h2"
770
+ http2_probe.set_and_release(
771
+ host=probe_http2_host,
772
+ port=probe_http2_port,
773
+ supports_http2=supports_http2,
774
+ )
775
+
776
+ # Forwarding proxies can never have a verified target since
777
+ # the proxy is the one doing the verification. Should instead
778
+ # use a CONNECT tunnel in order to verify the target.
779
+ # See: https://github.com/urllib3/urllib3/issues/3267.
780
+ if self.proxy_is_forwarding:
781
+ self.is_verified = False
782
+ else:
783
+ self.is_verified = sock_and_verified.is_verified
784
+
785
+ # If there's a proxy to be connected to we are fully connected.
786
+ # This is set twice (once above and here) due to forwarding proxies
787
+ # not using tunnelling.
788
+ self._has_connected_to_proxy = bool(self.proxy)
789
+
790
+ # Set `self.proxy_is_verified` unless it's already set while
791
+ # establishing a tunnel.
792
+ if self._has_connected_to_proxy and self.proxy_is_verified is None:
793
+ self.proxy_is_verified = sock_and_verified.is_verified
794
+
795
+ def _connect_tls_proxy(self, hostname: str, sock: socket.socket) -> ssl.SSLSocket:
796
+ """
797
+ Establish a TLS connection to the proxy using the provided SSL context.
798
+ """
799
+ # `_connect_tls_proxy` is called when self._tunnel_host is truthy.
800
+ proxy_config = typing.cast(ProxyConfig, self.proxy_config)
801
+ ssl_context = proxy_config.ssl_context
802
+ sock_and_verified = _ssl_wrap_socket_and_match_hostname(
803
+ sock,
804
+ cert_reqs=self.cert_reqs,
805
+ ssl_version=self.ssl_version,
806
+ ssl_minimum_version=self.ssl_minimum_version,
807
+ ssl_maximum_version=self.ssl_maximum_version,
808
+ ca_certs=self.ca_certs,
809
+ ca_cert_dir=self.ca_cert_dir,
810
+ ca_cert_data=self.ca_cert_data,
811
+ server_hostname=hostname,
812
+ ssl_context=ssl_context,
813
+ assert_hostname=proxy_config.assert_hostname,
814
+ assert_fingerprint=proxy_config.assert_fingerprint,
815
+ # Features that aren't implemented for proxies yet:
816
+ cert_file=None,
817
+ key_file=None,
818
+ key_password=None,
819
+ tls_in_tls=False,
820
+ )
821
+ self.proxy_is_verified = sock_and_verified.is_verified
822
+ return sock_and_verified.socket # type: ignore[return-value]
823
+
824
+
825
+ class _WrappedAndVerifiedSocket(typing.NamedTuple):
826
+ """
827
+ Wrapped socket and whether the connection is
828
+ verified after the TLS handshake
829
+ """
830
+
831
+ socket: ssl.SSLSocket | SSLTransport
832
+ is_verified: bool
833
+
834
+
835
+ def _ssl_wrap_socket_and_match_hostname(
836
+ sock: socket.socket,
837
+ *,
838
+ cert_reqs: None | str | int,
839
+ ssl_version: None | str | int,
840
+ ssl_minimum_version: int | None,
841
+ ssl_maximum_version: int | None,
842
+ cert_file: str | None,
843
+ key_file: str | None,
844
+ key_password: str | None,
845
+ ca_certs: str | None,
846
+ ca_cert_dir: str | None,
847
+ ca_cert_data: None | str | bytes,
848
+ assert_hostname: None | str | typing.Literal[False],
849
+ assert_fingerprint: str | None,
850
+ server_hostname: str | None,
851
+ ssl_context: ssl.SSLContext | None,
852
+ tls_in_tls: bool = False,
853
+ ) -> _WrappedAndVerifiedSocket:
854
+ """Logic for constructing an SSLContext from all TLS parameters, passing
855
+ that down into ssl_wrap_socket, and then doing certificate verification
856
+ either via hostname or fingerprint. This function exists to guarantee
857
+ that both proxies and targets have the same behavior when connecting via TLS.
858
+ """
859
+ default_ssl_context = False
860
+ if ssl_context is None:
861
+ default_ssl_context = True
862
+ context = create_urllib3_context(
863
+ ssl_version=resolve_ssl_version(ssl_version),
864
+ ssl_minimum_version=ssl_minimum_version,
865
+ ssl_maximum_version=ssl_maximum_version,
866
+ cert_reqs=resolve_cert_reqs(cert_reqs),
867
+ )
868
+ else:
869
+ context = ssl_context
870
+
871
+ context.verify_mode = resolve_cert_reqs(cert_reqs)
872
+
873
+ # In some cases, we want to verify hostnames ourselves
874
+ if (
875
+ # `ssl` can't verify fingerprints or alternate hostnames
876
+ assert_fingerprint
877
+ or assert_hostname
878
+ # assert_hostname can be set to False to disable hostname checking
879
+ or assert_hostname is False
880
+ # We still support OpenSSL 1.0.2, which prevents us from verifying
881
+ # hostnames easily: https://github.com/pyca/pyopenssl/pull/933
882
+ or ssl_.IS_PYOPENSSL
883
+ or not ssl_.HAS_NEVER_CHECK_COMMON_NAME
884
+ ):
885
+ context.check_hostname = False
886
+
887
+ # Try to load OS default certs if none are given. We need to do the hasattr() check
888
+ # for custom pyOpenSSL SSLContext objects because they don't support
889
+ # load_default_certs().
890
+ if (
891
+ not ca_certs
892
+ and not ca_cert_dir
893
+ and not ca_cert_data
894
+ and default_ssl_context
895
+ and hasattr(context, "load_default_certs")
896
+ ):
897
+ context.load_default_certs()
898
+
899
+ # Ensure that IPv6 addresses are in the proper format and don't have a
900
+ # scope ID. Python's SSL module fails to recognize scoped IPv6 addresses
901
+ # and interprets them as DNS hostnames.
902
+ if server_hostname is not None:
903
+ normalized = server_hostname.strip("[]")
904
+ if "%" in normalized:
905
+ normalized = normalized[: normalized.rfind("%")]
906
+ if is_ipaddress(normalized):
907
+ server_hostname = normalized
908
+
909
+ ssl_sock = ssl_wrap_socket(
910
+ sock=sock,
911
+ keyfile=key_file,
912
+ certfile=cert_file,
913
+ key_password=key_password,
914
+ ca_certs=ca_certs,
915
+ ca_cert_dir=ca_cert_dir,
916
+ ca_cert_data=ca_cert_data,
917
+ server_hostname=server_hostname,
918
+ ssl_context=context,
919
+ tls_in_tls=tls_in_tls,
920
+ )
921
+
922
+ try:
923
+ if assert_fingerprint:
924
+ _assert_fingerprint(
925
+ ssl_sock.getpeercert(binary_form=True), assert_fingerprint
926
+ )
927
+ elif (
928
+ context.verify_mode != ssl.CERT_NONE
929
+ and not context.check_hostname
930
+ and assert_hostname is not False
931
+ ):
932
+ cert: _TYPE_PEER_CERT_RET_DICT = ssl_sock.getpeercert() # type: ignore[assignment]
933
+
934
+ # Need to signal to our match_hostname whether to use 'commonName' or not.
935
+ # If we're using our own constructed SSLContext we explicitly set 'False'
936
+ # because PyPy hard-codes 'True' from SSLContext.hostname_checks_common_name.
937
+ if default_ssl_context:
938
+ hostname_checks_common_name = False
939
+ else:
940
+ hostname_checks_common_name = (
941
+ getattr(context, "hostname_checks_common_name", False) or False
942
+ )
943
+
944
+ _match_hostname(
945
+ cert,
946
+ assert_hostname or server_hostname, # type: ignore[arg-type]
947
+ hostname_checks_common_name,
948
+ )
949
+
950
+ return _WrappedAndVerifiedSocket(
951
+ socket=ssl_sock,
952
+ is_verified=context.verify_mode == ssl.CERT_REQUIRED
953
+ or bool(assert_fingerprint),
954
+ )
955
+ except BaseException:
956
+ ssl_sock.close()
957
+ raise
958
+
959
+
960
+ def _match_hostname(
961
+ cert: _TYPE_PEER_CERT_RET_DICT | None,
962
+ asserted_hostname: str,
963
+ hostname_checks_common_name: bool = False,
964
+ ) -> None:
965
+ # Our upstream implementation of ssl.match_hostname()
966
+ # only applies this normalization to IP addresses so it doesn't
967
+ # match DNS SANs so we do the same thing!
968
+ stripped_hostname = asserted_hostname.strip("[]")
969
+ if is_ipaddress(stripped_hostname):
970
+ asserted_hostname = stripped_hostname
971
+
972
+ try:
973
+ match_hostname(cert, asserted_hostname, hostname_checks_common_name)
974
+ except CertificateError as e:
975
+ log.warning(
976
+ "Certificate did not match expected hostname: %s. Certificate: %s",
977
+ asserted_hostname,
978
+ cert,
979
+ )
980
+ # Add cert to exception and reraise so client code can inspect
981
+ # the cert when catching the exception, if they want to
982
+ e._peer_cert = cert # type: ignore[attr-defined]
983
+ raise
984
+
985
+
986
+ def _wrap_proxy_error(err: Exception, proxy_scheme: str | None) -> ProxyError:
987
+ # Look for the phrase 'wrong version number', if found
988
+ # then we should warn the user that we're very sure that
989
+ # this proxy is HTTP-only and they have a configuration issue.
990
+ error_normalized = " ".join(re.split("[^a-z]", str(err).lower()))
991
+ is_likely_http_proxy = (
992
+ "wrong version number" in error_normalized
993
+ or "unknown protocol" in error_normalized
994
+ or "record layer failure" in error_normalized
995
+ )
996
+ http_proxy_warning = (
997
+ ". Your proxy appears to only use HTTP and not HTTPS, "
998
+ "try changing your proxy URL to be HTTP. See: "
999
+ "https://urllib3.readthedocs.io/en/latest/advanced-usage.html"
1000
+ "#https-proxy-error-http-proxy"
1001
+ )
1002
+ new_err = ProxyError(
1003
+ f"Unable to connect to proxy"
1004
+ f"{http_proxy_warning if is_likely_http_proxy and proxy_scheme == 'https' else ''}",
1005
+ err,
1006
+ )
1007
+ new_err.__cause__ = err
1008
+ return new_err
1009
+
1010
+
1011
+ def _get_default_user_agent() -> str:
1012
+ return f"python-urllib3/{__version__}"
1013
+
1014
+
1015
+ class DummyConnection:
1016
+ """Used to detect a failed ConnectionCls import."""
1017
+
1018
+
1019
+ if not ssl:
1020
+ HTTPSConnection = DummyConnection # type: ignore[misc, assignment] # noqa: F811
1021
+
1022
+
1023
+ VerifiedHTTPSConnection = HTTPSConnection
1024
+
1025
+
1026
+ def _url_from_connection(
1027
+ conn: HTTPConnection | HTTPSConnection, path: str | None = None
1028
+ ) -> str:
1029
+ """Returns the URL from a given connection. This is mainly used for testing and logging."""
1030
+
1031
+ scheme = "https" if isinstance(conn, HTTPSConnection) else "http"
1032
+
1033
+ return Url(scheme=scheme, host=conn.host, port=conn.port, path=path).url
.venv/Lib/site-packages/urllib3/connectionpool.py ADDED
@@ -0,0 +1,1182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import errno
4
+ import logging
5
+ import queue
6
+ import sys
7
+ import typing
8
+ import warnings
9
+ import weakref
10
+ from socket import timeout as SocketTimeout
11
+ from types import TracebackType
12
+
13
+ from ._base_connection import _TYPE_BODY
14
+ from ._collections import HTTPHeaderDict
15
+ from ._request_methods import RequestMethods
16
+ from .connection import (
17
+ BaseSSLError,
18
+ BrokenPipeError,
19
+ DummyConnection,
20
+ HTTPConnection,
21
+ HTTPException,
22
+ HTTPSConnection,
23
+ ProxyConfig,
24
+ _wrap_proxy_error,
25
+ )
26
+ from .connection import port_by_scheme as port_by_scheme
27
+ from .exceptions import (
28
+ ClosedPoolError,
29
+ EmptyPoolError,
30
+ FullPoolError,
31
+ HostChangedError,
32
+ InsecureRequestWarning,
33
+ LocationValueError,
34
+ MaxRetryError,
35
+ NewConnectionError,
36
+ ProtocolError,
37
+ ProxyError,
38
+ ReadTimeoutError,
39
+ SSLError,
40
+ TimeoutError,
41
+ )
42
+ from .response import BaseHTTPResponse
43
+ from .util.connection import is_connection_dropped
44
+ from .util.proxy import connection_requires_http_tunnel
45
+ from .util.request import _TYPE_BODY_POSITION, set_file_position
46
+ from .util.retry import Retry
47
+ from .util.ssl_match_hostname import CertificateError
48
+ from .util.timeout import _DEFAULT_TIMEOUT, _TYPE_DEFAULT, Timeout
49
+ from .util.url import Url, _encode_target
50
+ from .util.url import _normalize_host as normalize_host
51
+ from .util.url import parse_url
52
+ from .util.util import to_str
53
+
54
+ if typing.TYPE_CHECKING:
55
+ import ssl
56
+
57
+ from typing_extensions import Self
58
+
59
+ from ._base_connection import BaseHTTPConnection, BaseHTTPSConnection
60
+
61
+ log = logging.getLogger(__name__)
62
+
63
+ _TYPE_TIMEOUT = typing.Union[Timeout, float, _TYPE_DEFAULT, None]
64
+
65
+
66
+ # Pool objects
67
+ class ConnectionPool:
68
+ """
69
+ Base class for all connection pools, such as
70
+ :class:`.HTTPConnectionPool` and :class:`.HTTPSConnectionPool`.
71
+
72
+ .. note::
73
+ ConnectionPool.urlopen() does not normalize or percent-encode target URIs
74
+ which is useful if your target server doesn't support percent-encoded
75
+ target URIs.
76
+ """
77
+
78
+ scheme: str | None = None
79
+ QueueCls = queue.LifoQueue
80
+
81
+ def __init__(self, host: str, port: int | None = None) -> None:
82
+ if not host:
83
+ raise LocationValueError("No host specified.")
84
+
85
+ self.host = _normalize_host(host, scheme=self.scheme)
86
+ self.port = port
87
+
88
+ # This property uses 'normalize_host()' (not '_normalize_host()')
89
+ # to avoid removing square braces around IPv6 addresses.
90
+ # This value is sent to `HTTPConnection.set_tunnel()` if called
91
+ # because square braces are required for HTTP CONNECT tunneling.
92
+ self._tunnel_host = normalize_host(host, scheme=self.scheme).lower()
93
+
94
+ def __str__(self) -> str:
95
+ return f"{type(self).__name__}(host={self.host!r}, port={self.port!r})"
96
+
97
+ def __enter__(self) -> Self:
98
+ return self
99
+
100
+ def __exit__(
101
+ self,
102
+ exc_type: type[BaseException] | None,
103
+ exc_val: BaseException | None,
104
+ exc_tb: TracebackType | None,
105
+ ) -> typing.Literal[False]:
106
+ self.close()
107
+ # Return False to re-raise any potential exceptions
108
+ return False
109
+
110
+ def close(self) -> None:
111
+ """
112
+ Close all pooled connections and disable the pool.
113
+ """
114
+
115
+
116
+ # This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l252
117
+ _blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}
118
+
119
+
120
+ class HTTPConnectionPool(ConnectionPool, RequestMethods):
121
+ """
122
+ Thread-safe connection pool for one host.
123
+
124
+ :param host:
125
+ Host used for this HTTP Connection (e.g. "localhost"), passed into
126
+ :class:`http.client.HTTPConnection`.
127
+
128
+ :param port:
129
+ Port used for this HTTP Connection (None is equivalent to 80), passed
130
+ into :class:`http.client.HTTPConnection`.
131
+
132
+ :param timeout:
133
+ Socket timeout in seconds for each individual connection. This can
134
+ be a float or integer, which sets the timeout for the HTTP request,
135
+ or an instance of :class:`urllib3.util.Timeout` which gives you more
136
+ fine-grained control over request timeouts. After the constructor has
137
+ been parsed, this is always a `urllib3.util.Timeout` object.
138
+
139
+ :param maxsize:
140
+ Number of connections to save that can be reused. More than 1 is useful
141
+ in multithreaded situations. If ``block`` is set to False, more
142
+ connections will be created but they will not be saved once they've
143
+ been used.
144
+
145
+ :param block:
146
+ If set to True, no more than ``maxsize`` connections will be used at
147
+ a time. When no free connections are available, the call will block
148
+ until a connection has been released. This is a useful side effect for
149
+ particular multithreaded situations where one does not want to use more
150
+ than maxsize connections per host to prevent flooding.
151
+
152
+ :param headers:
153
+ Headers to include with all requests, unless other headers are given
154
+ explicitly.
155
+
156
+ :param retries:
157
+ Retry configuration to use by default with requests in this pool.
158
+
159
+ :param _proxy:
160
+ Parsed proxy URL, should not be used directly, instead, see
161
+ :class:`urllib3.ProxyManager`
162
+
163
+ :param _proxy_headers:
164
+ A dictionary with proxy headers, should not be used directly,
165
+ instead, see :class:`urllib3.ProxyManager`
166
+
167
+ :param \\**conn_kw:
168
+ Additional parameters are used to create fresh :class:`urllib3.connection.HTTPConnection`,
169
+ :class:`urllib3.connection.HTTPSConnection` instances.
170
+ """
171
+
172
+ scheme = "http"
173
+ ConnectionCls: (
174
+ type[BaseHTTPConnection] | type[BaseHTTPSConnection]
175
+ ) = HTTPConnection
176
+
177
+ def __init__(
178
+ self,
179
+ host: str,
180
+ port: int | None = None,
181
+ timeout: _TYPE_TIMEOUT | None = _DEFAULT_TIMEOUT,
182
+ maxsize: int = 1,
183
+ block: bool = False,
184
+ headers: typing.Mapping[str, str] | None = None,
185
+ retries: Retry | bool | int | None = None,
186
+ _proxy: Url | None = None,
187
+ _proxy_headers: typing.Mapping[str, str] | None = None,
188
+ _proxy_config: ProxyConfig | None = None,
189
+ **conn_kw: typing.Any,
190
+ ):
191
+ ConnectionPool.__init__(self, host, port)
192
+ RequestMethods.__init__(self, headers)
193
+
194
+ if not isinstance(timeout, Timeout):
195
+ timeout = Timeout.from_float(timeout)
196
+
197
+ if retries is None:
198
+ retries = Retry.DEFAULT
199
+
200
+ self.timeout = timeout
201
+ self.retries = retries
202
+
203
+ self.pool: queue.LifoQueue[typing.Any] | None = self.QueueCls(maxsize)
204
+ self.block = block
205
+
206
+ self.proxy = _proxy
207
+ self.proxy_headers = _proxy_headers or {}
208
+ self.proxy_config = _proxy_config
209
+
210
+ # Fill the queue up so that doing get() on it will block properly
211
+ for _ in range(maxsize):
212
+ self.pool.put(None)
213
+
214
+ # These are mostly for testing and debugging purposes.
215
+ self.num_connections = 0
216
+ self.num_requests = 0
217
+ self.conn_kw = conn_kw
218
+
219
+ if self.proxy:
220
+ # Enable Nagle's algorithm for proxies, to avoid packet fragmentation.
221
+ # We cannot know if the user has added default socket options, so we cannot replace the
222
+ # list.
223
+ self.conn_kw.setdefault("socket_options", [])
224
+
225
+ self.conn_kw["proxy"] = self.proxy
226
+ self.conn_kw["proxy_config"] = self.proxy_config
227
+
228
+ # Do not pass 'self' as callback to 'finalize'.
229
+ # Then the 'finalize' would keep an endless living (leak) to self.
230
+ # By just passing a reference to the pool allows the garbage collector
231
+ # to free self if nobody else has a reference to it.
232
+ pool = self.pool
233
+
234
+ # Close all the HTTPConnections in the pool before the
235
+ # HTTPConnectionPool object is garbage collected.
236
+ weakref.finalize(self, _close_pool_connections, pool)
237
+
238
+ def _new_conn(self) -> BaseHTTPConnection:
239
+ """
240
+ Return a fresh :class:`HTTPConnection`.
241
+ """
242
+ self.num_connections += 1
243
+ log.debug(
244
+ "Starting new HTTP connection (%d): %s:%s",
245
+ self.num_connections,
246
+ self.host,
247
+ self.port or "80",
248
+ )
249
+
250
+ conn = self.ConnectionCls(
251
+ host=self.host,
252
+ port=self.port,
253
+ timeout=self.timeout.connect_timeout,
254
+ **self.conn_kw,
255
+ )
256
+ return conn
257
+
258
+ def _get_conn(self, timeout: float | None = None) -> BaseHTTPConnection:
259
+ """
260
+ Get a connection. Will return a pooled connection if one is available.
261
+
262
+ If no connections are available and :prop:`.block` is ``False``, then a
263
+ fresh connection is returned.
264
+
265
+ :param timeout:
266
+ Seconds to wait before giving up and raising
267
+ :class:`urllib3.exceptions.EmptyPoolError` if the pool is empty and
268
+ :prop:`.block` is ``True``.
269
+ """
270
+ conn = None
271
+
272
+ if self.pool is None:
273
+ raise ClosedPoolError(self, "Pool is closed.")
274
+
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.") from None # Defensive:
280
+
281
+ except queue.Empty:
282
+ if self.block:
283
+ raise EmptyPoolError(
284
+ self,
285
+ "Pool is empty and a new connection can't be opened due to blocking mode.",
286
+ ) from None
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
+
294
+ return conn or self._new_conn()
295
+
296
+ def _put_conn(self, conn: BaseHTTPConnection | None) -> None:
297
+ """
298
+ Put a connection back into the pool.
299
+
300
+ :param conn:
301
+ Connection object for the current host and port as returned by
302
+ :meth:`._new_conn` or :meth:`._get_conn`.
303
+
304
+ If the pool is already full, the connection is closed and discarded
305
+ because we exceeded maxsize. If connections are discarded frequently,
306
+ then maxsize should be increased.
307
+
308
+ If the pool is closed, then the connection will be closed and discarded.
309
+ """
310
+ if self.pool is not None:
311
+ try:
312
+ self.pool.put(conn, block=False)
313
+ return # Everything is dandy, done.
314
+ except AttributeError:
315
+ # self.pool is None.
316
+ pass
317
+ except queue.Full:
318
+ # Connection never got put back into the pool, close it.
319
+ if conn:
320
+ conn.close()
321
+
322
+ if self.block:
323
+ # This should never happen if you got the conn from self._get_conn
324
+ raise FullPoolError(
325
+ self,
326
+ "Pool reached maximum size and no more connections are allowed.",
327
+ ) from None
328
+
329
+ log.warning(
330
+ "Connection pool is full, discarding connection: %s. Connection pool size: %s",
331
+ self.host,
332
+ self.pool.qsize(),
333
+ )
334
+
335
+ # Connection never got put back into the pool, close it.
336
+ if conn:
337
+ conn.close()
338
+
339
+ def _validate_conn(self, conn: BaseHTTPConnection) -> None:
340
+ """
341
+ Called right before a request is made, after the socket is created.
342
+ """
343
+
344
+ def _prepare_proxy(self, conn: BaseHTTPConnection) -> None:
345
+ # Nothing to do for HTTP connections.
346
+ pass
347
+
348
+ def _get_timeout(self, timeout: _TYPE_TIMEOUT) -> Timeout:
349
+ """Helper that always returns a :class:`urllib3.util.Timeout`"""
350
+ if timeout is _DEFAULT_TIMEOUT:
351
+ return self.timeout.clone()
352
+
353
+ if isinstance(timeout, Timeout):
354
+ return timeout.clone()
355
+ else:
356
+ # User passed us an int/float. This is for backwards compatibility,
357
+ # can be removed later
358
+ return Timeout.from_float(timeout)
359
+
360
+ def _raise_timeout(
361
+ self,
362
+ err: BaseSSLError | OSError | SocketTimeout,
363
+ url: str,
364
+ timeout_value: _TYPE_TIMEOUT | None,
365
+ ) -> None:
366
+ """Is the error actually a timeout? Will raise a ReadTimeout or pass"""
367
+
368
+ if isinstance(err, SocketTimeout):
369
+ raise ReadTimeoutError(
370
+ self, url, f"Read timed out. (read timeout={timeout_value})"
371
+ ) from err
372
+
373
+ # See the above comment about EAGAIN in Python 3.
374
+ if hasattr(err, "errno") and err.errno in _blocking_errnos:
375
+ raise ReadTimeoutError(
376
+ self, url, f"Read timed out. (read timeout={timeout_value})"
377
+ ) from err
378
+
379
+ def _make_request(
380
+ self,
381
+ conn: BaseHTTPConnection,
382
+ method: str,
383
+ url: str,
384
+ body: _TYPE_BODY | None = None,
385
+ headers: typing.Mapping[str, str] | None = None,
386
+ retries: Retry | None = None,
387
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
388
+ chunked: bool = False,
389
+ response_conn: BaseHTTPConnection | None = None,
390
+ preload_content: bool = True,
391
+ decode_content: bool = True,
392
+ enforce_content_length: bool = True,
393
+ ) -> BaseHTTPResponse:
394
+ """
395
+ Perform a request on a given urllib connection object taken from our
396
+ pool.
397
+
398
+ :param conn:
399
+ a connection from one of our connection pools
400
+
401
+ :param method:
402
+ HTTP request method (such as GET, POST, PUT, etc.)
403
+
404
+ :param url:
405
+ The URL to perform the request on.
406
+
407
+ :param body:
408
+ Data to send in the request body, either :class:`str`, :class:`bytes`,
409
+ an iterable of :class:`str`/:class:`bytes`, or a file-like object.
410
+
411
+ :param headers:
412
+ Dictionary of custom headers to send, such as User-Agent,
413
+ If-None-Match, etc. If None, pool headers are used. If provided,
414
+ these headers completely replace any pool-specific headers.
415
+
416
+ :param retries:
417
+ Configure the number of retries to allow before raising a
418
+ :class:`~urllib3.exceptions.MaxRetryError` exception.
419
+
420
+ Pass ``None`` to retry until you receive a response. Pass a
421
+ :class:`~urllib3.util.retry.Retry` object for fine-grained control
422
+ over different types of retries.
423
+ Pass an integer number to retry connection errors that many times,
424
+ but no other types of errors. Pass zero to never retry.
425
+
426
+ If ``False``, then retries are disabled and any exception is raised
427
+ immediately. Also, instead of raising a MaxRetryError on redirects,
428
+ the redirect response will be returned.
429
+
430
+ :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
431
+
432
+ :param timeout:
433
+ If specified, overrides the default timeout for this one
434
+ request. It may be a float (in seconds) or an instance of
435
+ :class:`urllib3.util.Timeout`.
436
+
437
+ :param chunked:
438
+ If True, urllib3 will send the body using chunked transfer
439
+ encoding. Otherwise, urllib3 will send the body using the standard
440
+ content-length form. Defaults to False.
441
+
442
+ :param response_conn:
443
+ Set this to ``None`` if you will handle releasing the connection or
444
+ set the connection to have the response release it.
445
+
446
+ :param preload_content:
447
+ If True, the response's body will be preloaded during construction.
448
+
449
+ :param decode_content:
450
+ If True, will attempt to decode the body based on the
451
+ 'content-encoding' header.
452
+
453
+ :param enforce_content_length:
454
+ Enforce content length checking. Body returned by server must match
455
+ value of Content-Length header, if present. Otherwise, raise error.
456
+ """
457
+ self.num_requests += 1
458
+
459
+ timeout_obj = self._get_timeout(timeout)
460
+ timeout_obj.start_connect()
461
+ conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)
462
+
463
+ try:
464
+ # Trigger any extra validation we need to do.
465
+ try:
466
+ self._validate_conn(conn)
467
+ except (SocketTimeout, BaseSSLError) as e:
468
+ self._raise_timeout(err=e, url=url, timeout_value=conn.timeout)
469
+ raise
470
+
471
+ # _validate_conn() starts the connection to an HTTPS proxy
472
+ # so we need to wrap errors with 'ProxyError' here too.
473
+ except (
474
+ OSError,
475
+ NewConnectionError,
476
+ TimeoutError,
477
+ BaseSSLError,
478
+ CertificateError,
479
+ SSLError,
480
+ ) as e:
481
+ new_e: Exception = e
482
+ if isinstance(e, (BaseSSLError, CertificateError)):
483
+ new_e = SSLError(e)
484
+ # If the connection didn't successfully connect to it's proxy
485
+ # then there
486
+ if isinstance(
487
+ new_e, (OSError, NewConnectionError, TimeoutError, SSLError)
488
+ ) and (conn and conn.proxy and not conn.has_connected_to_proxy):
489
+ new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
490
+ raise new_e
491
+
492
+ # conn.request() calls http.client.*.request, not the method in
493
+ # urllib3.request. It also calls makefile (recv) on the socket.
494
+ try:
495
+ conn.request(
496
+ method,
497
+ url,
498
+ body=body,
499
+ headers=headers,
500
+ chunked=chunked,
501
+ preload_content=preload_content,
502
+ decode_content=decode_content,
503
+ enforce_content_length=enforce_content_length,
504
+ )
505
+
506
+ # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
507
+ # legitimately able to close the connection after sending a valid response.
508
+ # With this behaviour, the received response is still readable.
509
+ except BrokenPipeError:
510
+ pass
511
+ except OSError as e:
512
+ # MacOS/Linux
513
+ # EPROTOTYPE and ECONNRESET are needed on macOS
514
+ # https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
515
+ # Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
516
+ if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
517
+ raise
518
+
519
+ # Reset the timeout for the recv() on the socket
520
+ read_timeout = timeout_obj.read_timeout
521
+
522
+ if not conn.is_closed:
523
+ # In Python 3 socket.py will catch EAGAIN and return None when you
524
+ # try and read into the file pointer created by http.client, which
525
+ # instead raises a BadStatusLine exception. Instead of catching
526
+ # the exception and assuming all BadStatusLine exceptions are read
527
+ # timeouts, check for a zero timeout before making the request.
528
+ if read_timeout == 0:
529
+ raise ReadTimeoutError(
530
+ self, url, f"Read timed out. (read timeout={read_timeout})"
531
+ )
532
+ conn.timeout = read_timeout
533
+
534
+ # Receive the response from the server
535
+ try:
536
+ response = conn.getresponse()
537
+ except (BaseSSLError, OSError) as e:
538
+ self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
539
+ raise
540
+
541
+ # Set properties that are used by the pooling layer.
542
+ response.retries = retries
543
+ response._connection = response_conn # type: ignore[attr-defined]
544
+ response._pool = self # type: ignore[attr-defined]
545
+
546
+ log.debug(
547
+ '%s://%s:%s "%s %s HTTP/%s" %s %s',
548
+ self.scheme,
549
+ self.host,
550
+ self.port,
551
+ method,
552
+ url,
553
+ response.version,
554
+ response.status,
555
+ response.length_remaining,
556
+ )
557
+
558
+ return response
559
+
560
+ def close(self) -> None:
561
+ """
562
+ Close all pooled connections and disable the pool.
563
+ """
564
+ if self.pool is None:
565
+ return
566
+ # Disable access to the pool
567
+ old_pool, self.pool = self.pool, None
568
+
569
+ # Close all the HTTPConnections in the pool.
570
+ _close_pool_connections(old_pool)
571
+
572
+ def is_same_host(self, url: str) -> bool:
573
+ """
574
+ Check if the given ``url`` is a member of the same host as this
575
+ connection pool.
576
+ """
577
+ if url.startswith("/"):
578
+ return True
579
+
580
+ # TODO: Add optional support for socket.gethostbyname checking.
581
+ scheme, _, host, port, *_ = parse_url(url)
582
+ scheme = scheme or "http"
583
+ if host is not None:
584
+ host = _normalize_host(host, scheme=scheme)
585
+
586
+ # Use explicit default port for comparison when none is given
587
+ if self.port and not port:
588
+ port = port_by_scheme.get(scheme)
589
+ elif not self.port and port == port_by_scheme.get(scheme):
590
+ port = None
591
+
592
+ return (scheme, host, port) == (self.scheme, self.host, self.port)
593
+
594
+ def urlopen( # type: ignore[override]
595
+ self,
596
+ method: str,
597
+ url: str,
598
+ body: _TYPE_BODY | None = None,
599
+ headers: typing.Mapping[str, str] | None = None,
600
+ retries: Retry | bool | int | None = None,
601
+ redirect: bool = True,
602
+ assert_same_host: bool = True,
603
+ timeout: _TYPE_TIMEOUT = _DEFAULT_TIMEOUT,
604
+ pool_timeout: int | None = None,
605
+ release_conn: bool | None = None,
606
+ chunked: bool = False,
607
+ body_pos: _TYPE_BODY_POSITION | None = None,
608
+ preload_content: bool = True,
609
+ decode_content: bool = True,
610
+ **response_kw: typing.Any,
611
+ ) -> BaseHTTPResponse:
612
+ """
613
+ Get a connection from the pool and perform an HTTP request. This is the
614
+ lowest level call for making a request, so you'll need to specify all
615
+ the raw details.
616
+
617
+ .. note::
618
+
619
+ More commonly, it's appropriate to use a convenience method
620
+ such as :meth:`request`.
621
+
622
+ .. note::
623
+
624
+ `release_conn` will only behave as expected if
625
+ `preload_content=False` because we want to make
626
+ `preload_content=False` the default behaviour someday soon without
627
+ breaking backwards compatibility.
628
+
629
+ :param method:
630
+ HTTP request method (such as GET, POST, PUT, etc.)
631
+
632
+ :param url:
633
+ The URL to perform the request on.
634
+
635
+ :param body:
636
+ Data to send in the request body, either :class:`str`, :class:`bytes`,
637
+ an iterable of :class:`str`/:class:`bytes`, or a file-like object.
638
+
639
+ :param headers:
640
+ Dictionary of custom headers to send, such as User-Agent,
641
+ If-None-Match, etc. If None, pool headers are used. If provided,
642
+ these headers completely replace any pool-specific headers.
643
+
644
+ :param retries:
645
+ Configure the number of retries to allow before raising a
646
+ :class:`~urllib3.exceptions.MaxRetryError` exception.
647
+
648
+ If ``None`` (default) will retry 3 times, see ``Retry.DEFAULT``. Pass a
649
+ :class:`~urllib3.util.retry.Retry` object for fine-grained control
650
+ over different types of retries.
651
+ Pass an integer number to retry connection errors that many times,
652
+ but no other types of errors. Pass zero to never retry.
653
+
654
+ If ``False``, then retries are disabled and any exception is raised
655
+ immediately. Also, instead of raising a MaxRetryError on redirects,
656
+ the redirect response will be returned.
657
+
658
+ :type retries: :class:`~urllib3.util.retry.Retry`, False, or an int.
659
+
660
+ :param redirect:
661
+ If True, automatically handle redirects (status codes 301, 302,
662
+ 303, 307, 308). Each redirect counts as a retry. Disabling retries
663
+ will disable redirect, too.
664
+
665
+ :param assert_same_host:
666
+ If ``True``, will make sure that the host of the pool requests is
667
+ consistent else will raise HostChangedError. When ``False``, you can
668
+ use the pool on an HTTP proxy and request foreign hosts.
669
+
670
+ :param timeout:
671
+ If specified, overrides the default timeout for this one
672
+ request. It may be a float (in seconds) or an instance of
673
+ :class:`urllib3.util.Timeout`.
674
+
675
+ :param pool_timeout:
676
+ If set and the pool is set to block=True, then this method will
677
+ block for ``pool_timeout`` seconds and raise EmptyPoolError if no
678
+ connection is available within the time period.
679
+
680
+ :param bool preload_content:
681
+ If True, the response's body will be preloaded into memory.
682
+
683
+ :param bool decode_content:
684
+ If True, will attempt to decode the body based on the
685
+ 'content-encoding' header.
686
+
687
+ :param release_conn:
688
+ If False, then the urlopen call will not release the connection
689
+ back into the pool once a response is received (but will release if
690
+ you read the entire contents of the response such as when
691
+ `preload_content=True`). This is useful if you're not preloading
692
+ the response's content immediately. You will need to call
693
+ ``r.release_conn()`` on the response ``r`` to return the connection
694
+ back into the pool. If None, it takes the value of ``preload_content``
695
+ which defaults to ``True``.
696
+
697
+ :param bool chunked:
698
+ If True, urllib3 will send the body using chunked transfer
699
+ encoding. Otherwise, urllib3 will send the body using the standard
700
+ content-length form. Defaults to False.
701
+
702
+ :param int body_pos:
703
+ Position to seek to in file-like body in the event of a retry or
704
+ redirect. Typically this won't need to be set because urllib3 will
705
+ auto-populate the value when needed.
706
+ """
707
+ parsed_url = parse_url(url)
708
+ destination_scheme = parsed_url.scheme
709
+
710
+ if headers is None:
711
+ headers = self.headers
712
+
713
+ if not isinstance(retries, Retry):
714
+ retries = Retry.from_int(retries, redirect=redirect, default=self.retries)
715
+
716
+ if release_conn is None:
717
+ release_conn = preload_content
718
+
719
+ # Check host
720
+ if assert_same_host and not self.is_same_host(url):
721
+ raise HostChangedError(self, url, retries)
722
+
723
+ # Ensure that the URL we're connecting to is properly encoded
724
+ if url.startswith("/"):
725
+ url = to_str(_encode_target(url))
726
+ else:
727
+ url = to_str(parsed_url.url)
728
+
729
+ conn = None
730
+
731
+ # Track whether `conn` needs to be released before
732
+ # returning/raising/recursing. Update this variable if necessary, and
733
+ # leave `release_conn` constant throughout the function. That way, if
734
+ # the function recurses, the original value of `release_conn` will be
735
+ # passed down into the recursive call, and its value will be respected.
736
+ #
737
+ # See issue #651 [1] for details.
738
+ #
739
+ # [1] <https://github.com/urllib3/urllib3/issues/651>
740
+ release_this_conn = release_conn
741
+
742
+ http_tunnel_required = connection_requires_http_tunnel(
743
+ self.proxy, self.proxy_config, destination_scheme
744
+ )
745
+
746
+ # Merge the proxy headers. Only done when not using HTTP CONNECT. We
747
+ # have to copy the headers dict so we can safely change it without those
748
+ # changes being reflected in anyone else's copy.
749
+ if not http_tunnel_required:
750
+ headers = headers.copy() # type: ignore[attr-defined]
751
+ headers.update(self.proxy_headers) # type: ignore[union-attr]
752
+
753
+ # Must keep the exception bound to a separate variable or else Python 3
754
+ # complains about UnboundLocalError.
755
+ err = None
756
+
757
+ # Keep track of whether we cleanly exited the except block. This
758
+ # ensures we do proper cleanup in finally.
759
+ clean_exit = False
760
+
761
+ # Rewind body position, if needed. Record current position
762
+ # for future rewinds in the event of a redirect/retry.
763
+ body_pos = set_file_position(body, body_pos)
764
+
765
+ try:
766
+ # Request a connection from the queue.
767
+ timeout_obj = self._get_timeout(timeout)
768
+ conn = self._get_conn(timeout=pool_timeout)
769
+
770
+ conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment]
771
+
772
+ # Is this a closed/new connection that requires CONNECT tunnelling?
773
+ if self.proxy is not None and http_tunnel_required and conn.is_closed:
774
+ try:
775
+ self._prepare_proxy(conn)
776
+ except (BaseSSLError, OSError, SocketTimeout) as e:
777
+ self._raise_timeout(
778
+ err=e, url=self.proxy.url, timeout_value=conn.timeout
779
+ )
780
+ raise
781
+
782
+ # If we're going to release the connection in ``finally:``, then
783
+ # the response doesn't need to know about the connection. Otherwise
784
+ # it will also try to release it and we'll have a double-release
785
+ # mess.
786
+ response_conn = conn if not release_conn else None
787
+
788
+ # Make the request on the HTTPConnection object
789
+ response = self._make_request(
790
+ conn,
791
+ method,
792
+ url,
793
+ timeout=timeout_obj,
794
+ body=body,
795
+ headers=headers,
796
+ chunked=chunked,
797
+ retries=retries,
798
+ response_conn=response_conn,
799
+ preload_content=preload_content,
800
+ decode_content=decode_content,
801
+ **response_kw,
802
+ )
803
+
804
+ # Everything went great!
805
+ clean_exit = True
806
+
807
+ except EmptyPoolError:
808
+ # Didn't get a connection from the pool, no need to clean up
809
+ clean_exit = True
810
+ release_this_conn = False
811
+ raise
812
+
813
+ except (
814
+ TimeoutError,
815
+ HTTPException,
816
+ OSError,
817
+ ProtocolError,
818
+ BaseSSLError,
819
+ SSLError,
820
+ CertificateError,
821
+ ProxyError,
822
+ ) as e:
823
+ # Discard the connection for these exceptions. It will be
824
+ # replaced during the next _get_conn() call.
825
+ clean_exit = False
826
+ new_e: Exception = e
827
+ if isinstance(e, (BaseSSLError, CertificateError)):
828
+ new_e = SSLError(e)
829
+ if isinstance(
830
+ new_e,
831
+ (
832
+ OSError,
833
+ NewConnectionError,
834
+ TimeoutError,
835
+ SSLError,
836
+ HTTPException,
837
+ ),
838
+ ) and (conn and conn.proxy and not conn.has_connected_to_proxy):
839
+ new_e = _wrap_proxy_error(new_e, conn.proxy.scheme)
840
+ elif isinstance(new_e, (OSError, HTTPException)):
841
+ new_e = ProtocolError("Connection aborted.", new_e)
842
+
843
+ retries = retries.increment(
844
+ method, url, error=new_e, _pool=self, _stacktrace=sys.exc_info()[2]
845
+ )
846
+ retries.sleep()
847
+
848
+ # Keep track of the error for the retry warning.
849
+ err = e
850
+
851
+ finally:
852
+ if not clean_exit:
853
+ # We hit some kind of exception, handled or otherwise. We need
854
+ # to throw the connection away unless explicitly told not to.
855
+ # Close the connection, set the variable to None, and make sure
856
+ # we put the None back in the pool to avoid leaking it.
857
+ if conn:
858
+ conn.close()
859
+ conn = None
860
+ release_this_conn = True
861
+
862
+ if release_this_conn:
863
+ # Put the connection back to be reused. If the connection is
864
+ # expired then it will be None, which will get replaced with a
865
+ # fresh connection during _get_conn.
866
+ self._put_conn(conn)
867
+
868
+ if not conn:
869
+ # Try again
870
+ log.warning(
871
+ "Retrying (%r) after connection broken by '%r': %s", retries, err, url
872
+ )
873
+ return self.urlopen(
874
+ method,
875
+ url,
876
+ body,
877
+ headers,
878
+ retries,
879
+ redirect,
880
+ assert_same_host,
881
+ timeout=timeout,
882
+ pool_timeout=pool_timeout,
883
+ release_conn=release_conn,
884
+ chunked=chunked,
885
+ body_pos=body_pos,
886
+ preload_content=preload_content,
887
+ decode_content=decode_content,
888
+ **response_kw,
889
+ )
890
+
891
+ # Handle redirect?
892
+ redirect_location = redirect and response.get_redirect_location()
893
+ if redirect_location:
894
+ if response.status == 303:
895
+ # Change the method according to RFC 9110, Section 15.4.4.
896
+ method = "GET"
897
+ # And lose the body not to transfer anything sensitive.
898
+ body = None
899
+ headers = HTTPHeaderDict(headers)._prepare_for_method_change()
900
+
901
+ try:
902
+ retries = retries.increment(method, url, response=response, _pool=self)
903
+ except MaxRetryError:
904
+ if retries.raise_on_redirect:
905
+ response.drain_conn()
906
+ raise
907
+ return response
908
+
909
+ response.drain_conn()
910
+ retries.sleep_for_retry(response)
911
+ log.debug("Redirecting %s -> %s", url, redirect_location)
912
+ return self.urlopen(
913
+ method,
914
+ redirect_location,
915
+ body,
916
+ headers,
917
+ retries=retries,
918
+ redirect=redirect,
919
+ assert_same_host=assert_same_host,
920
+ timeout=timeout,
921
+ pool_timeout=pool_timeout,
922
+ release_conn=release_conn,
923
+ chunked=chunked,
924
+ body_pos=body_pos,
925
+ preload_content=preload_content,
926
+ decode_content=decode_content,
927
+ **response_kw,
928
+ )
929
+
930
+ # Check if we should retry the HTTP response.
931
+ has_retry_after = bool(response.headers.get("Retry-After"))
932
+ if retries.is_retry(method, response.status, has_retry_after):
933
+ try:
934
+ retries = retries.increment(method, url, response=response, _pool=self)
935
+ except MaxRetryError:
936
+ if retries.raise_on_status:
937
+ response.drain_conn()
938
+ raise
939
+ return response
940
+
941
+ response.drain_conn()
942
+ retries.sleep(response)
943
+ log.debug("Retry: %s", url)
944
+ return self.urlopen(
945
+ method,
946
+ url,
947
+ body,
948
+ headers,
949
+ retries=retries,
950
+ redirect=redirect,
951
+ assert_same_host=assert_same_host,
952
+ timeout=timeout,
953
+ pool_timeout=pool_timeout,
954
+ release_conn=release_conn,
955
+ chunked=chunked,
956
+ body_pos=body_pos,
957
+ preload_content=preload_content,
958
+ decode_content=decode_content,
959
+ **response_kw,
960
+ )
961
+
962
+ return response
963
+
964
+
965
+ class HTTPSConnectionPool(HTTPConnectionPool):
966
+ """
967
+ Same as :class:`.HTTPConnectionPool`, but HTTPS.
968
+
969
+ :class:`.HTTPSConnection` uses one of ``assert_fingerprint``,
970
+ ``assert_hostname`` and ``host`` in this order to verify connections.
971
+ If ``assert_hostname`` is False, no verification is done.
972
+
973
+ The ``key_file``, ``cert_file``, ``cert_reqs``, ``ca_certs``,
974
+ ``ca_cert_dir``, ``ssl_version``, ``key_password`` are only used if :mod:`ssl`
975
+ is available and are fed into :meth:`urllib3.util.ssl_wrap_socket` to upgrade
976
+ the connection socket into an SSL socket.
977
+ """
978
+
979
+ scheme = "https"
980
+ ConnectionCls: type[BaseHTTPSConnection] = HTTPSConnection
981
+
982
+ def __init__(
983
+ self,
984
+ host: str,
985
+ port: int | None = None,
986
+ timeout: _TYPE_TIMEOUT | None = _DEFAULT_TIMEOUT,
987
+ maxsize: int = 1,
988
+ block: bool = False,
989
+ headers: typing.Mapping[str, str] | None = None,
990
+ retries: Retry | bool | int | None = None,
991
+ _proxy: Url | None = None,
992
+ _proxy_headers: typing.Mapping[str, str] | None = None,
993
+ key_file: str | None = None,
994
+ cert_file: str | None = None,
995
+ cert_reqs: int | str | None = None,
996
+ key_password: str | None = None,
997
+ ca_certs: str | None = None,
998
+ ssl_version: int | str | None = None,
999
+ ssl_minimum_version: ssl.TLSVersion | None = None,
1000
+ ssl_maximum_version: ssl.TLSVersion | None = None,
1001
+ assert_hostname: str | typing.Literal[False] | None = None,
1002
+ assert_fingerprint: str | None = None,
1003
+ ca_cert_dir: str | None = None,
1004
+ **conn_kw: typing.Any,
1005
+ ) -> None:
1006
+ super().__init__(
1007
+ host,
1008
+ port,
1009
+ timeout,
1010
+ maxsize,
1011
+ block,
1012
+ headers,
1013
+ retries,
1014
+ _proxy,
1015
+ _proxy_headers,
1016
+ **conn_kw,
1017
+ )
1018
+
1019
+ self.key_file = key_file
1020
+ self.cert_file = cert_file
1021
+ self.cert_reqs = cert_reqs
1022
+ self.key_password = key_password
1023
+ self.ca_certs = ca_certs
1024
+ self.ca_cert_dir = ca_cert_dir
1025
+ self.ssl_version = ssl_version
1026
+ self.ssl_minimum_version = ssl_minimum_version
1027
+ self.ssl_maximum_version = ssl_maximum_version
1028
+ self.assert_hostname = assert_hostname
1029
+ self.assert_fingerprint = assert_fingerprint
1030
+
1031
+ def _prepare_proxy(self, conn: HTTPSConnection) -> None: # type: ignore[override]
1032
+ """Establishes a tunnel connection through HTTP CONNECT."""
1033
+ if self.proxy and self.proxy.scheme == "https":
1034
+ tunnel_scheme = "https"
1035
+ else:
1036
+ tunnel_scheme = "http"
1037
+
1038
+ conn.set_tunnel(
1039
+ scheme=tunnel_scheme,
1040
+ host=self._tunnel_host,
1041
+ port=self.port,
1042
+ headers=self.proxy_headers,
1043
+ )
1044
+ conn.connect()
1045
+
1046
+ def _new_conn(self) -> BaseHTTPSConnection:
1047
+ """
1048
+ Return a fresh :class:`urllib3.connection.HTTPConnection`.
1049
+ """
1050
+ self.num_connections += 1
1051
+ log.debug(
1052
+ "Starting new HTTPS connection (%d): %s:%s",
1053
+ self.num_connections,
1054
+ self.host,
1055
+ self.port or "443",
1056
+ )
1057
+
1058
+ if not self.ConnectionCls or self.ConnectionCls is DummyConnection: # type: ignore[comparison-overlap]
1059
+ raise ImportError(
1060
+ "Can't connect to HTTPS URL because the SSL module is not available."
1061
+ )
1062
+
1063
+ actual_host: str = self.host
1064
+ actual_port = self.port
1065
+ if self.proxy is not None and self.proxy.host is not None:
1066
+ actual_host = self.proxy.host
1067
+ actual_port = self.proxy.port
1068
+
1069
+ return self.ConnectionCls(
1070
+ host=actual_host,
1071
+ port=actual_port,
1072
+ timeout=self.timeout.connect_timeout,
1073
+ cert_file=self.cert_file,
1074
+ key_file=self.key_file,
1075
+ key_password=self.key_password,
1076
+ cert_reqs=self.cert_reqs,
1077
+ ca_certs=self.ca_certs,
1078
+ ca_cert_dir=self.ca_cert_dir,
1079
+ assert_hostname=self.assert_hostname,
1080
+ assert_fingerprint=self.assert_fingerprint,
1081
+ ssl_version=self.ssl_version,
1082
+ ssl_minimum_version=self.ssl_minimum_version,
1083
+ ssl_maximum_version=self.ssl_maximum_version,
1084
+ **self.conn_kw,
1085
+ )
1086
+
1087
+ def _validate_conn(self, conn: BaseHTTPConnection) -> None:
1088
+ """
1089
+ Called right before a request is made, after the socket is created.
1090
+ """
1091
+ super()._validate_conn(conn)
1092
+
1093
+ # Force connect early to allow us to validate the connection.
1094
+ if conn.is_closed:
1095
+ conn.connect()
1096
+
1097
+ # TODO revise this, see https://github.com/urllib3/urllib3/issues/2791
1098
+ if not conn.is_verified and not conn.proxy_is_verified:
1099
+ warnings.warn(
1100
+ (
1101
+ f"Unverified HTTPS request is being made to host '{conn.host}'. "
1102
+ "Adding certificate verification is strongly advised. See: "
1103
+ "https://urllib3.readthedocs.io/en/latest/advanced-usage.html"
1104
+ "#tls-warnings"
1105
+ ),
1106
+ InsecureRequestWarning,
1107
+ )
1108
+
1109
+
1110
+ def connection_from_url(url: str, **kw: typing.Any) -> HTTPConnectionPool:
1111
+ """
1112
+ Given a url, return an :class:`.ConnectionPool` instance of its host.
1113
+
1114
+ This is a shortcut for not having to parse out the scheme, host, and port
1115
+ of the url before creating an :class:`.ConnectionPool` instance.
1116
+
1117
+ :param url:
1118
+ Absolute URL string that must include the scheme. Port is optional.
1119
+
1120
+ :param \\**kw:
1121
+ Passes additional parameters to the constructor of the appropriate
1122
+ :class:`.ConnectionPool`. Useful for specifying things like
1123
+ timeout, maxsize, headers, etc.
1124
+
1125
+ Example::
1126
+
1127
+ >>> conn = connection_from_url('http://google.com/')
1128
+ >>> r = conn.request('GET', '/')
1129
+ """
1130
+ scheme, _, host, port, *_ = parse_url(url)
1131
+ scheme = scheme or "http"
1132
+ port = port or port_by_scheme.get(scheme, 80)
1133
+ if scheme == "https":
1134
+ return HTTPSConnectionPool(host, port=port, **kw) # type: ignore[arg-type]
1135
+ else:
1136
+ return HTTPConnectionPool(host, port=port, **kw) # type: ignore[arg-type]
1137
+
1138
+
1139
+ @typing.overload
1140
+ def _normalize_host(host: None, scheme: str | None) -> None:
1141
+ ...
1142
+
1143
+
1144
+ @typing.overload
1145
+ def _normalize_host(host: str, scheme: str | None) -> str:
1146
+ ...
1147
+
1148
+
1149
+ def _normalize_host(host: str | None, scheme: str | None) -> str | None:
1150
+ """
1151
+ Normalize hosts for comparisons and use with sockets.
1152
+ """
1153
+
1154
+ host = normalize_host(host, scheme)
1155
+
1156
+ # httplib doesn't like it when we include brackets in IPv6 addresses
1157
+ # Specifically, if we include brackets but also pass the port then
1158
+ # httplib crazily doubles up the square brackets on the Host header.
1159
+ # Instead, we need to make sure we never pass ``None`` as the port.
1160
+ # However, for backward compatibility reasons we can't actually
1161
+ # *assert* that. See http://bugs.python.org/issue28539
1162
+ if host and host.startswith("[") and host.endswith("]"):
1163
+ host = host[1:-1]
1164
+ return host
1165
+
1166
+
1167
+ def _url_from_pool(
1168
+ pool: HTTPConnectionPool | HTTPSConnectionPool, path: str | None = None
1169
+ ) -> str:
1170
+ """Returns the URL from a given connection pool. This is mainly used for testing and logging."""
1171
+ return Url(scheme=pool.scheme, host=pool.host, port=pool.port, path=path).url
1172
+
1173
+
1174
+ def _close_pool_connections(pool: queue.LifoQueue[typing.Any]) -> None:
1175
+ """Drains a queue of connections and closes each one."""
1176
+ try:
1177
+ while True:
1178
+ conn = pool.get(block=False)
1179
+ if conn:
1180
+ conn.close()
1181
+ except queue.Empty:
1182
+ pass # Done.
.venv/Lib/site-packages/urllib3/contrib/__pycache__/__init__.cpython-39.pyc ADDED
Binary file (187 Bytes). View file
 
.venv/Lib/site-packages/urllib3/contrib/pyopenssl.py ADDED
@@ -0,0 +1,552 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Module for using pyOpenSSL as a TLS backend. This module was relevant before
3
+ the standard library ``ssl`` module supported SNI, but now that we've dropped
4
+ support for Python 2.7 all relevant Python versions support SNI so
5
+ **this module is no longer recommended**.
6
+
7
+ This needs the following packages installed:
8
+
9
+ * `pyOpenSSL`_ (tested with 16.0.0)
10
+ * `cryptography`_ (minimum 1.3.4, from pyopenssl)
11
+ * `idna`_ (minimum 2.0)
12
+
13
+ However, pyOpenSSL depends on cryptography, so while we use all three directly here we
14
+ end up having relatively few packages required.
15
+
16
+ You can install them with the following command:
17
+
18
+ .. code-block:: bash
19
+
20
+ $ python -m pip install pyopenssl cryptography idna
21
+
22
+ To activate certificate checking, call
23
+ :func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code
24
+ before you begin making HTTP requests. This can be done in a ``sitecustomize``
25
+ module, or at any other time before your application begins using ``urllib3``,
26
+ like this:
27
+
28
+ .. code-block:: python
29
+
30
+ try:
31
+ import urllib3.contrib.pyopenssl
32
+ urllib3.contrib.pyopenssl.inject_into_urllib3()
33
+ except ImportError:
34
+ pass
35
+
36
+ .. _pyopenssl: https://www.pyopenssl.org
37
+ .. _cryptography: https://cryptography.io
38
+ .. _idna: https://github.com/kjd/idna
39
+ """
40
+
41
+ from __future__ import annotations
42
+
43
+ import OpenSSL.SSL # type: ignore[import-untyped]
44
+ from cryptography import x509
45
+
46
+ try:
47
+ from cryptography.x509 import UnsupportedExtension # type: ignore[attr-defined]
48
+ except ImportError:
49
+ # UnsupportedExtension is gone in cryptography >= 2.1.0
50
+ class UnsupportedExtension(Exception): # type: ignore[no-redef]
51
+ pass
52
+
53
+
54
+ import logging
55
+ import ssl
56
+ import typing
57
+ from io import BytesIO
58
+ from socket import socket as socket_cls
59
+ from socket import timeout
60
+
61
+ from .. import util
62
+
63
+ if typing.TYPE_CHECKING:
64
+ from OpenSSL.crypto import X509 # type: ignore[import-untyped]
65
+
66
+
67
+ __all__ = ["inject_into_urllib3", "extract_from_urllib3"]
68
+
69
+ # Map from urllib3 to PyOpenSSL compatible parameter-values.
70
+ _openssl_versions: dict[int, int] = {
71
+ util.ssl_.PROTOCOL_TLS: OpenSSL.SSL.SSLv23_METHOD, # type: ignore[attr-defined]
72
+ util.ssl_.PROTOCOL_TLS_CLIENT: OpenSSL.SSL.SSLv23_METHOD, # type: ignore[attr-defined]
73
+ ssl.PROTOCOL_TLSv1: OpenSSL.SSL.TLSv1_METHOD,
74
+ }
75
+
76
+ if hasattr(ssl, "PROTOCOL_TLSv1_1") and hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"):
77
+ _openssl_versions[ssl.PROTOCOL_TLSv1_1] = OpenSSL.SSL.TLSv1_1_METHOD
78
+
79
+ if hasattr(ssl, "PROTOCOL_TLSv1_2") and hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"):
80
+ _openssl_versions[ssl.PROTOCOL_TLSv1_2] = OpenSSL.SSL.TLSv1_2_METHOD
81
+
82
+
83
+ _stdlib_to_openssl_verify = {
84
+ ssl.CERT_NONE: OpenSSL.SSL.VERIFY_NONE,
85
+ ssl.CERT_OPTIONAL: OpenSSL.SSL.VERIFY_PEER,
86
+ ssl.CERT_REQUIRED: OpenSSL.SSL.VERIFY_PEER
87
+ + OpenSSL.SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
88
+ }
89
+ _openssl_to_stdlib_verify = {v: k for k, v in _stdlib_to_openssl_verify.items()}
90
+
91
+ # The SSLvX values are the most likely to be missing in the future
92
+ # but we check them all just to be sure.
93
+ _OP_NO_SSLv2_OR_SSLv3: int = getattr(OpenSSL.SSL, "OP_NO_SSLv2", 0) | getattr(
94
+ OpenSSL.SSL, "OP_NO_SSLv3", 0
95
+ )
96
+ _OP_NO_TLSv1: int = getattr(OpenSSL.SSL, "OP_NO_TLSv1", 0)
97
+ _OP_NO_TLSv1_1: int = getattr(OpenSSL.SSL, "OP_NO_TLSv1_1", 0)
98
+ _OP_NO_TLSv1_2: int = getattr(OpenSSL.SSL, "OP_NO_TLSv1_2", 0)
99
+ _OP_NO_TLSv1_3: int = getattr(OpenSSL.SSL, "OP_NO_TLSv1_3", 0)
100
+
101
+ _openssl_to_ssl_minimum_version: dict[int, int] = {
102
+ ssl.TLSVersion.MINIMUM_SUPPORTED: _OP_NO_SSLv2_OR_SSLv3,
103
+ ssl.TLSVersion.TLSv1: _OP_NO_SSLv2_OR_SSLv3,
104
+ ssl.TLSVersion.TLSv1_1: _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1,
105
+ ssl.TLSVersion.TLSv1_2: _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1 | _OP_NO_TLSv1_1,
106
+ ssl.TLSVersion.TLSv1_3: (
107
+ _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1 | _OP_NO_TLSv1_1 | _OP_NO_TLSv1_2
108
+ ),
109
+ ssl.TLSVersion.MAXIMUM_SUPPORTED: (
110
+ _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1 | _OP_NO_TLSv1_1 | _OP_NO_TLSv1_2
111
+ ),
112
+ }
113
+ _openssl_to_ssl_maximum_version: dict[int, int] = {
114
+ ssl.TLSVersion.MINIMUM_SUPPORTED: (
115
+ _OP_NO_SSLv2_OR_SSLv3
116
+ | _OP_NO_TLSv1
117
+ | _OP_NO_TLSv1_1
118
+ | _OP_NO_TLSv1_2
119
+ | _OP_NO_TLSv1_3
120
+ ),
121
+ ssl.TLSVersion.TLSv1: (
122
+ _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1_1 | _OP_NO_TLSv1_2 | _OP_NO_TLSv1_3
123
+ ),
124
+ ssl.TLSVersion.TLSv1_1: _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1_2 | _OP_NO_TLSv1_3,
125
+ ssl.TLSVersion.TLSv1_2: _OP_NO_SSLv2_OR_SSLv3 | _OP_NO_TLSv1_3,
126
+ ssl.TLSVersion.TLSv1_3: _OP_NO_SSLv2_OR_SSLv3,
127
+ ssl.TLSVersion.MAXIMUM_SUPPORTED: _OP_NO_SSLv2_OR_SSLv3,
128
+ }
129
+
130
+ # OpenSSL will only write 16K at a time
131
+ SSL_WRITE_BLOCKSIZE = 16384
132
+
133
+ orig_util_SSLContext = util.ssl_.SSLContext
134
+
135
+
136
+ log = logging.getLogger(__name__)
137
+
138
+
139
+ def inject_into_urllib3() -> None:
140
+ "Monkey-patch urllib3 with PyOpenSSL-backed SSL-support."
141
+
142
+ _validate_dependencies_met()
143
+
144
+ util.SSLContext = PyOpenSSLContext # type: ignore[assignment]
145
+ util.ssl_.SSLContext = PyOpenSSLContext # type: ignore[assignment]
146
+ util.IS_PYOPENSSL = True
147
+ util.ssl_.IS_PYOPENSSL = True
148
+
149
+
150
+ def extract_from_urllib3() -> None:
151
+ "Undo monkey-patching by :func:`inject_into_urllib3`."
152
+
153
+ util.SSLContext = orig_util_SSLContext
154
+ util.ssl_.SSLContext = orig_util_SSLContext
155
+ util.IS_PYOPENSSL = False
156
+ util.ssl_.IS_PYOPENSSL = False
157
+
158
+
159
+ def _validate_dependencies_met() -> None:
160
+ """
161
+ Verifies that PyOpenSSL's package-level dependencies have been met.
162
+ Throws `ImportError` if they are not met.
163
+ """
164
+ # Method added in `cryptography==1.1`; not available in older versions
165
+ from cryptography.x509.extensions import Extensions
166
+
167
+ if getattr(Extensions, "get_extension_for_class", None) is None:
168
+ raise ImportError(
169
+ "'cryptography' module missing required functionality. "
170
+ "Try upgrading to v1.3.4 or newer."
171
+ )
172
+
173
+ # pyOpenSSL 0.14 and above use cryptography for OpenSSL bindings. The _x509
174
+ # attribute is only present on those versions.
175
+ from OpenSSL.crypto import X509
176
+
177
+ x509 = X509()
178
+ if getattr(x509, "_x509", None) is None:
179
+ raise ImportError(
180
+ "'pyOpenSSL' module missing required functionality. "
181
+ "Try upgrading to v0.14 or newer."
182
+ )
183
+
184
+
185
+ def _dnsname_to_stdlib(name: str) -> str | None:
186
+ """
187
+ Converts a dNSName SubjectAlternativeName field to the form used by the
188
+ standard library on the given Python version.
189
+
190
+ Cryptography produces a dNSName as a unicode string that was idna-decoded
191
+ from ASCII bytes. We need to idna-encode that string to get it back, and
192
+ then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib
193
+ uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8).
194
+
195
+ If the name cannot be idna-encoded then we return None signalling that
196
+ the name given should be skipped.
197
+ """
198
+
199
+ def idna_encode(name: str) -> bytes | None:
200
+ """
201
+ Borrowed wholesale from the Python Cryptography Project. It turns out
202
+ that we can't just safely call `idna.encode`: it can explode for
203
+ wildcard names. This avoids that problem.
204
+ """
205
+ import idna
206
+
207
+ try:
208
+ for prefix in ["*.", "."]:
209
+ if name.startswith(prefix):
210
+ name = name[len(prefix) :]
211
+ return prefix.encode("ascii") + idna.encode(name)
212
+ return idna.encode(name)
213
+ except idna.core.IDNAError:
214
+ return None
215
+
216
+ # Don't send IPv6 addresses through the IDNA encoder.
217
+ if ":" in name:
218
+ return name
219
+
220
+ encoded_name = idna_encode(name)
221
+ if encoded_name is None:
222
+ return None
223
+ return encoded_name.decode("utf-8")
224
+
225
+
226
+ def get_subj_alt_name(peer_cert: X509) -> list[tuple[str, str]]:
227
+ """
228
+ Given an PyOpenSSL certificate, provides all the subject alternative names.
229
+ """
230
+ cert = peer_cert.to_cryptography()
231
+
232
+ # We want to find the SAN extension. Ask Cryptography to locate it (it's
233
+ # faster than looping in Python)
234
+ try:
235
+ ext = cert.extensions.get_extension_for_class(x509.SubjectAlternativeName).value
236
+ except x509.ExtensionNotFound:
237
+ # No such extension, return the empty list.
238
+ return []
239
+ except (
240
+ x509.DuplicateExtension,
241
+ UnsupportedExtension,
242
+ x509.UnsupportedGeneralNameType,
243
+ UnicodeError,
244
+ ) as e:
245
+ # A problem has been found with the quality of the certificate. Assume
246
+ # no SAN field is present.
247
+ log.warning(
248
+ "A problem was encountered with the certificate that prevented "
249
+ "urllib3 from finding the SubjectAlternativeName field. This can "
250
+ "affect certificate validation. The error was %s",
251
+ e,
252
+ )
253
+ return []
254
+
255
+ # We want to return dNSName and iPAddress fields. We need to cast the IPs
256
+ # back to strings because the match_hostname function wants them as
257
+ # strings.
258
+ # Sadly the DNS names need to be idna encoded and then, on Python 3, UTF-8
259
+ # decoded. This is pretty frustrating, but that's what the standard library
260
+ # does with certificates, and so we need to attempt to do the same.
261
+ # We also want to skip over names which cannot be idna encoded.
262
+ names = [
263
+ ("DNS", name)
264
+ for name in map(_dnsname_to_stdlib, ext.get_values_for_type(x509.DNSName))
265
+ if name is not None
266
+ ]
267
+ names.extend(
268
+ ("IP Address", str(name)) for name in ext.get_values_for_type(x509.IPAddress)
269
+ )
270
+
271
+ return names
272
+
273
+
274
+ class WrappedSocket:
275
+ """API-compatibility wrapper for Python OpenSSL's Connection-class."""
276
+
277
+ def __init__(
278
+ self,
279
+ connection: OpenSSL.SSL.Connection,
280
+ socket: socket_cls,
281
+ suppress_ragged_eofs: bool = True,
282
+ ) -> None:
283
+ self.connection = connection
284
+ self.socket = socket
285
+ self.suppress_ragged_eofs = suppress_ragged_eofs
286
+ self._io_refs = 0
287
+ self._closed = False
288
+
289
+ def fileno(self) -> int:
290
+ return self.socket.fileno()
291
+
292
+ # Copy-pasted from Python 3.5 source code
293
+ def _decref_socketios(self) -> None:
294
+ if self._io_refs > 0:
295
+ self._io_refs -= 1
296
+ if self._closed:
297
+ self.close()
298
+
299
+ def recv(self, *args: typing.Any, **kwargs: typing.Any) -> bytes:
300
+ try:
301
+ data = self.connection.recv(*args, **kwargs)
302
+ except OpenSSL.SSL.SysCallError as e:
303
+ if self.suppress_ragged_eofs and e.args == (-1, "Unexpected EOF"):
304
+ return b""
305
+ else:
306
+ raise OSError(e.args[0], str(e)) from e
307
+ except OpenSSL.SSL.ZeroReturnError:
308
+ if self.connection.get_shutdown() == OpenSSL.SSL.RECEIVED_SHUTDOWN:
309
+ return b""
310
+ else:
311
+ raise
312
+ except OpenSSL.SSL.WantReadError as e:
313
+ if not util.wait_for_read(self.socket, self.socket.gettimeout()):
314
+ raise timeout("The read operation timed out") from e
315
+ else:
316
+ return self.recv(*args, **kwargs)
317
+
318
+ # TLS 1.3 post-handshake authentication
319
+ except OpenSSL.SSL.Error as e:
320
+ raise ssl.SSLError(f"read error: {e!r}") from e
321
+ else:
322
+ return data # type: ignore[no-any-return]
323
+
324
+ def recv_into(self, *args: typing.Any, **kwargs: typing.Any) -> int:
325
+ try:
326
+ return self.connection.recv_into(*args, **kwargs) # type: ignore[no-any-return]
327
+ except OpenSSL.SSL.SysCallError as e:
328
+ if self.suppress_ragged_eofs and e.args == (-1, "Unexpected EOF"):
329
+ return 0
330
+ else:
331
+ raise OSError(e.args[0], str(e)) from e
332
+ except OpenSSL.SSL.ZeroReturnError:
333
+ if self.connection.get_shutdown() == OpenSSL.SSL.RECEIVED_SHUTDOWN:
334
+ return 0
335
+ else:
336
+ raise
337
+ except OpenSSL.SSL.WantReadError as e:
338
+ if not util.wait_for_read(self.socket, self.socket.gettimeout()):
339
+ raise timeout("The read operation timed out") from e
340
+ else:
341
+ return self.recv_into(*args, **kwargs)
342
+
343
+ # TLS 1.3 post-handshake authentication
344
+ except OpenSSL.SSL.Error as e:
345
+ raise ssl.SSLError(f"read error: {e!r}") from e
346
+
347
+ def settimeout(self, timeout: float) -> None:
348
+ return self.socket.settimeout(timeout)
349
+
350
+ def _send_until_done(self, data: bytes) -> int:
351
+ while True:
352
+ try:
353
+ return self.connection.send(data) # type: ignore[no-any-return]
354
+ except OpenSSL.SSL.WantWriteError as e:
355
+ if not util.wait_for_write(self.socket, self.socket.gettimeout()):
356
+ raise timeout() from e
357
+ continue
358
+ except OpenSSL.SSL.SysCallError as e:
359
+ raise OSError(e.args[0], str(e)) from e
360
+
361
+ def sendall(self, data: bytes) -> None:
362
+ total_sent = 0
363
+ while total_sent < len(data):
364
+ sent = self._send_until_done(
365
+ data[total_sent : total_sent + SSL_WRITE_BLOCKSIZE]
366
+ )
367
+ total_sent += sent
368
+
369
+ def shutdown(self) -> None:
370
+ # FIXME rethrow compatible exceptions should we ever use this
371
+ self.connection.shutdown()
372
+
373
+ def close(self) -> None:
374
+ self._closed = True
375
+ if self._io_refs <= 0:
376
+ self._real_close()
377
+
378
+ def _real_close(self) -> None:
379
+ try:
380
+ return self.connection.close() # type: ignore[no-any-return]
381
+ except OpenSSL.SSL.Error:
382
+ return
383
+
384
+ def getpeercert(
385
+ self, binary_form: bool = False
386
+ ) -> dict[str, list[typing.Any]] | None:
387
+ x509 = self.connection.get_peer_certificate()
388
+
389
+ if not x509:
390
+ return x509 # type: ignore[no-any-return]
391
+
392
+ if binary_form:
393
+ return OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, x509) # type: ignore[no-any-return]
394
+
395
+ return {
396
+ "subject": ((("commonName", x509.get_subject().CN),),), # type: ignore[dict-item]
397
+ "subjectAltName": get_subj_alt_name(x509),
398
+ }
399
+
400
+ def version(self) -> str:
401
+ return self.connection.get_protocol_version_name() # type: ignore[no-any-return]
402
+
403
+ def selected_alpn_protocol(self) -> str | None:
404
+ alpn_proto = self.connection.get_alpn_proto_negotiated()
405
+ return alpn_proto.decode() if alpn_proto else None
406
+
407
+
408
+ WrappedSocket.makefile = socket_cls.makefile # type: ignore[attr-defined]
409
+
410
+
411
+ class PyOpenSSLContext:
412
+ """
413
+ I am a wrapper class for the PyOpenSSL ``Context`` object. I am responsible
414
+ for translating the interface of the standard library ``SSLContext`` object
415
+ to calls into PyOpenSSL.
416
+ """
417
+
418
+ def __init__(self, protocol: int) -> None:
419
+ self.protocol = _openssl_versions[protocol]
420
+ self._ctx = OpenSSL.SSL.Context(self.protocol)
421
+ self._options = 0
422
+ self.check_hostname = False
423
+ self._minimum_version: int = ssl.TLSVersion.MINIMUM_SUPPORTED
424
+ self._maximum_version: int = ssl.TLSVersion.MAXIMUM_SUPPORTED
425
+
426
+ @property
427
+ def options(self) -> int:
428
+ return self._options
429
+
430
+ @options.setter
431
+ def options(self, value: int) -> None:
432
+ self._options = value
433
+ self._set_ctx_options()
434
+
435
+ @property
436
+ def verify_mode(self) -> int:
437
+ return _openssl_to_stdlib_verify[self._ctx.get_verify_mode()]
438
+
439
+ @verify_mode.setter
440
+ def verify_mode(self, value: ssl.VerifyMode) -> None:
441
+ self._ctx.set_verify(_stdlib_to_openssl_verify[value], _verify_callback)
442
+
443
+ def set_default_verify_paths(self) -> None:
444
+ self._ctx.set_default_verify_paths()
445
+
446
+ def set_ciphers(self, ciphers: bytes | str) -> None:
447
+ if isinstance(ciphers, str):
448
+ ciphers = ciphers.encode("utf-8")
449
+ self._ctx.set_cipher_list(ciphers)
450
+
451
+ def load_verify_locations(
452
+ self,
453
+ cafile: str | None = None,
454
+ capath: str | None = None,
455
+ cadata: bytes | None = None,
456
+ ) -> None:
457
+ if cafile is not None:
458
+ cafile = cafile.encode("utf-8") # type: ignore[assignment]
459
+ if capath is not None:
460
+ capath = capath.encode("utf-8") # type: ignore[assignment]
461
+ try:
462
+ self._ctx.load_verify_locations(cafile, capath)
463
+ if cadata is not None:
464
+ self._ctx.load_verify_locations(BytesIO(cadata))
465
+ except OpenSSL.SSL.Error as e:
466
+ raise ssl.SSLError(f"unable to load trusted certificates: {e!r}") from e
467
+
468
+ def load_cert_chain(
469
+ self,
470
+ certfile: str,
471
+ keyfile: str | None = None,
472
+ password: str | None = None,
473
+ ) -> None:
474
+ try:
475
+ self._ctx.use_certificate_chain_file(certfile)
476
+ if password is not None:
477
+ if not isinstance(password, bytes):
478
+ password = password.encode("utf-8") # type: ignore[assignment]
479
+ self._ctx.set_passwd_cb(lambda *_: password)
480
+ self._ctx.use_privatekey_file(keyfile or certfile)
481
+ except OpenSSL.SSL.Error as e:
482
+ raise ssl.SSLError(f"Unable to load certificate chain: {e!r}") from e
483
+
484
+ def set_alpn_protocols(self, protocols: list[bytes | str]) -> None:
485
+ protocols = [util.util.to_bytes(p, "ascii") for p in protocols]
486
+ return self._ctx.set_alpn_protos(protocols) # type: ignore[no-any-return]
487
+
488
+ def wrap_socket(
489
+ self,
490
+ sock: socket_cls,
491
+ server_side: bool = False,
492
+ do_handshake_on_connect: bool = True,
493
+ suppress_ragged_eofs: bool = True,
494
+ server_hostname: bytes | str | None = None,
495
+ ) -> WrappedSocket:
496
+ cnx = OpenSSL.SSL.Connection(self._ctx, sock)
497
+
498
+ # If server_hostname is an IP, don't use it for SNI, per RFC6066 Section 3
499
+ if server_hostname and not util.ssl_.is_ipaddress(server_hostname):
500
+ if isinstance(server_hostname, str):
501
+ server_hostname = server_hostname.encode("utf-8")
502
+ cnx.set_tlsext_host_name(server_hostname)
503
+
504
+ cnx.set_connect_state()
505
+
506
+ while True:
507
+ try:
508
+ cnx.do_handshake()
509
+ except OpenSSL.SSL.WantReadError as e:
510
+ if not util.wait_for_read(sock, sock.gettimeout()):
511
+ raise timeout("select timed out") from e
512
+ continue
513
+ except OpenSSL.SSL.Error as e:
514
+ raise ssl.SSLError(f"bad handshake: {e!r}") from e
515
+ break
516
+
517
+ return WrappedSocket(cnx, sock)
518
+
519
+ def _set_ctx_options(self) -> None:
520
+ self._ctx.set_options(
521
+ self._options
522
+ | _openssl_to_ssl_minimum_version[self._minimum_version]
523
+ | _openssl_to_ssl_maximum_version[self._maximum_version]
524
+ )
525
+
526
+ @property
527
+ def minimum_version(self) -> int:
528
+ return self._minimum_version
529
+
530
+ @minimum_version.setter
531
+ def minimum_version(self, minimum_version: int) -> None:
532
+ self._minimum_version = minimum_version
533
+ self._set_ctx_options()
534
+
535
+ @property
536
+ def maximum_version(self) -> int:
537
+ return self._maximum_version
538
+
539
+ @maximum_version.setter
540
+ def maximum_version(self, maximum_version: int) -> None:
541
+ self._maximum_version = maximum_version
542
+ self._set_ctx_options()
543
+
544
+
545
+ def _verify_callback(
546
+ cnx: OpenSSL.SSL.Connection,
547
+ x509: X509,
548
+ err_no: int,
549
+ err_depth: int,
550
+ return_code: int,
551
+ ) -> bool:
552
+ return err_no == 0