@rowstile/cli-linux-x64 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (565) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +5 -0
  3. package/package.json +26 -0
  4. package/python/bin/python3.13 +0 -0
  5. package/python/bin/python3.13-config +122 -0
  6. package/python/lib/libpython3.13.so.1.0 +0 -0
  7. package/python/lib/libpython3.so +0 -0
  8. package/python/lib/python3.13/LICENSE.txt +277 -0
  9. package/python/lib/python3.13/__future__.py +147 -0
  10. package/python/lib/python3.13/__hello__.py +16 -0
  11. package/python/lib/python3.13/_aix_support.py +108 -0
  12. package/python/lib/python3.13/_android_support.py +192 -0
  13. package/python/lib/python3.13/_apple_support.py +66 -0
  14. package/python/lib/python3.13/_collections_abc.py +1187 -0
  15. package/python/lib/python3.13/_colorize.py +119 -0
  16. package/python/lib/python3.13/_compat_pickle.py +251 -0
  17. package/python/lib/python3.13/_compression.py +162 -0
  18. package/python/lib/python3.13/_ios_support.py +71 -0
  19. package/python/lib/python3.13/_markupbase.py +396 -0
  20. package/python/lib/python3.13/_opcode_metadata.py +343 -0
  21. package/python/lib/python3.13/_osx_support.py +579 -0
  22. package/python/lib/python3.13/_py_abc.py +147 -0
  23. package/python/lib/python3.13/_pydatetime.py +2640 -0
  24. package/python/lib/python3.13/_pydecimal.py +6356 -0
  25. package/python/lib/python3.13/_pyio.py +2714 -0
  26. package/python/lib/python3.13/_pylong.py +363 -0
  27. package/python/lib/python3.13/_pyrepl/__init__.py +19 -0
  28. package/python/lib/python3.13/_pyrepl/__main__.py +10 -0
  29. package/python/lib/python3.13/_pyrepl/_minimal_curses.py +68 -0
  30. package/python/lib/python3.13/_pyrepl/_threading_handler.py +74 -0
  31. package/python/lib/python3.13/_pyrepl/base_eventqueue.py +110 -0
  32. package/python/lib/python3.13/_pyrepl/commands.py +492 -0
  33. package/python/lib/python3.13/_pyrepl/completing_reader.py +295 -0
  34. package/python/lib/python3.13/_pyrepl/console.py +229 -0
  35. package/python/lib/python3.13/_pyrepl/curses.py +33 -0
  36. package/python/lib/python3.13/_pyrepl/fancy_termios.py +82 -0
  37. package/python/lib/python3.13/_pyrepl/historical_reader.py +419 -0
  38. package/python/lib/python3.13/_pyrepl/input.py +114 -0
  39. package/python/lib/python3.13/_pyrepl/keymap.py +213 -0
  40. package/python/lib/python3.13/_pyrepl/main.py +59 -0
  41. package/python/lib/python3.13/_pyrepl/mypy.ini +29 -0
  42. package/python/lib/python3.13/_pyrepl/pager.py +175 -0
  43. package/python/lib/python3.13/_pyrepl/reader.py +764 -0
  44. package/python/lib/python3.13/_pyrepl/readline.py +599 -0
  45. package/python/lib/python3.13/_pyrepl/simple_interact.py +180 -0
  46. package/python/lib/python3.13/_pyrepl/trace.py +21 -0
  47. package/python/lib/python3.13/_pyrepl/types.py +10 -0
  48. package/python/lib/python3.13/_pyrepl/unix_console.py +852 -0
  49. package/python/lib/python3.13/_pyrepl/unix_eventqueue.py +76 -0
  50. package/python/lib/python3.13/_pyrepl/utils.py +83 -0
  51. package/python/lib/python3.13/_pyrepl/windows_console.py +687 -0
  52. package/python/lib/python3.13/_pyrepl/windows_eventqueue.py +42 -0
  53. package/python/lib/python3.13/_sitebuiltins.py +91 -0
  54. package/python/lib/python3.13/_strptime.py +800 -0
  55. package/python/lib/python3.13/_sysconfigdata__linux_x86_64-linux-gnu.py +1079 -0
  56. package/python/lib/python3.13/_threading_local.py +120 -0
  57. package/python/lib/python3.13/_weakrefset.py +205 -0
  58. package/python/lib/python3.13/abc.py +188 -0
  59. package/python/lib/python3.13/antigravity.py +17 -0
  60. package/python/lib/python3.13/argparse.py +2690 -0
  61. package/python/lib/python3.13/ast.py +1865 -0
  62. package/python/lib/python3.13/asyncio/__init__.py +47 -0
  63. package/python/lib/python3.13/asyncio/__main__.py +211 -0
  64. package/python/lib/python3.13/asyncio/base_events.py +2086 -0
  65. package/python/lib/python3.13/asyncio/base_futures.py +67 -0
  66. package/python/lib/python3.13/asyncio/base_subprocess.py +312 -0
  67. package/python/lib/python3.13/asyncio/base_tasks.py +94 -0
  68. package/python/lib/python3.13/asyncio/constants.py +41 -0
  69. package/python/lib/python3.13/asyncio/coroutines.py +109 -0
  70. package/python/lib/python3.13/asyncio/events.py +885 -0
  71. package/python/lib/python3.13/asyncio/exceptions.py +62 -0
  72. package/python/lib/python3.13/asyncio/format_helpers.py +84 -0
  73. package/python/lib/python3.13/asyncio/futures.py +425 -0
  74. package/python/lib/python3.13/asyncio/locks.py +617 -0
  75. package/python/lib/python3.13/asyncio/log.py +7 -0
  76. package/python/lib/python3.13/asyncio/mixins.py +21 -0
  77. package/python/lib/python3.13/asyncio/proactor_events.py +891 -0
  78. package/python/lib/python3.13/asyncio/protocols.py +216 -0
  79. package/python/lib/python3.13/asyncio/queues.py +309 -0
  80. package/python/lib/python3.13/asyncio/runners.py +217 -0
  81. package/python/lib/python3.13/asyncio/selector_events.py +1328 -0
  82. package/python/lib/python3.13/asyncio/sslproto.py +929 -0
  83. package/python/lib/python3.13/asyncio/staggered.py +174 -0
  84. package/python/lib/python3.13/asyncio/streams.py +787 -0
  85. package/python/lib/python3.13/asyncio/subprocess.py +229 -0
  86. package/python/lib/python3.13/asyncio/taskgroups.py +278 -0
  87. package/python/lib/python3.13/asyncio/tasks.py +1121 -0
  88. package/python/lib/python3.13/asyncio/threads.py +26 -0
  89. package/python/lib/python3.13/asyncio/timeouts.py +185 -0
  90. package/python/lib/python3.13/asyncio/transports.py +337 -0
  91. package/python/lib/python3.13/asyncio/trsock.py +98 -0
  92. package/python/lib/python3.13/asyncio/unix_events.py +1550 -0
  93. package/python/lib/python3.13/asyncio/windows_events.py +906 -0
  94. package/python/lib/python3.13/asyncio/windows_utils.py +181 -0
  95. package/python/lib/python3.13/base64.py +628 -0
  96. package/python/lib/python3.13/bdb.py +973 -0
  97. package/python/lib/python3.13/bisect.py +118 -0
  98. package/python/lib/python3.13/bz2.py +352 -0
  99. package/python/lib/python3.13/cProfile.py +197 -0
  100. package/python/lib/python3.13/calendar.py +813 -0
  101. package/python/lib/python3.13/cmd.py +409 -0
  102. package/python/lib/python3.13/code.py +386 -0
  103. package/python/lib/python3.13/codecs.py +1132 -0
  104. package/python/lib/python3.13/codeop.py +155 -0
  105. package/python/lib/python3.13/collections/__init__.py +1603 -0
  106. package/python/lib/python3.13/colorsys.py +166 -0
  107. package/python/lib/python3.13/compileall.py +470 -0
  108. package/python/lib/python3.13/concurrent/__init__.py +1 -0
  109. package/python/lib/python3.13/concurrent/futures/__init__.py +54 -0
  110. package/python/lib/python3.13/concurrent/futures/_base.py +660 -0
  111. package/python/lib/python3.13/concurrent/futures/process.py +892 -0
  112. package/python/lib/python3.13/concurrent/futures/thread.py +240 -0
  113. package/python/lib/python3.13/configparser.py +1396 -0
  114. package/python/lib/python3.13/contextlib.py +814 -0
  115. package/python/lib/python3.13/contextvars.py +4 -0
  116. package/python/lib/python3.13/copy.py +306 -0
  117. package/python/lib/python3.13/copyreg.py +217 -0
  118. package/python/lib/python3.13/csv.py +527 -0
  119. package/python/lib/python3.13/ctypes/__init__.py +605 -0
  120. package/python/lib/python3.13/ctypes/_aix.py +327 -0
  121. package/python/lib/python3.13/ctypes/_endian.py +78 -0
  122. package/python/lib/python3.13/ctypes/macholib/README.ctypes +7 -0
  123. package/python/lib/python3.13/ctypes/macholib/__init__.py +9 -0
  124. package/python/lib/python3.13/ctypes/macholib/dyld.py +165 -0
  125. package/python/lib/python3.13/ctypes/macholib/dylib.py +42 -0
  126. package/python/lib/python3.13/ctypes/macholib/fetch_macholib +2 -0
  127. package/python/lib/python3.13/ctypes/macholib/fetch_macholib.bat +1 -0
  128. package/python/lib/python3.13/ctypes/macholib/framework.py +42 -0
  129. package/python/lib/python3.13/ctypes/util.py +387 -0
  130. package/python/lib/python3.13/ctypes/wintypes.py +202 -0
  131. package/python/lib/python3.13/curses/__init__.py +101 -0
  132. package/python/lib/python3.13/curses/ascii.py +99 -0
  133. package/python/lib/python3.13/curses/has_key.py +192 -0
  134. package/python/lib/python3.13/curses/panel.py +6 -0
  135. package/python/lib/python3.13/curses/textpad.py +236 -0
  136. package/python/lib/python3.13/dataclasses.py +1679 -0
  137. package/python/lib/python3.13/datetime.py +9 -0
  138. package/python/lib/python3.13/dbm/__init__.py +194 -0
  139. package/python/lib/python3.13/dbm/dumb.py +319 -0
  140. package/python/lib/python3.13/dbm/gnu.py +3 -0
  141. package/python/lib/python3.13/dbm/ndbm.py +3 -0
  142. package/python/lib/python3.13/dbm/sqlite3.py +144 -0
  143. package/python/lib/python3.13/decimal.py +109 -0
  144. package/python/lib/python3.13/difflib.py +2058 -0
  145. package/python/lib/python3.13/dis.py +1075 -0
  146. package/python/lib/python3.13/doctest.py +2919 -0
  147. package/python/lib/python3.13/email/__init__.py +61 -0
  148. package/python/lib/python3.13/email/_encoded_words.py +233 -0
  149. package/python/lib/python3.13/email/_header_value_parser.py +3153 -0
  150. package/python/lib/python3.13/email/_parseaddr.py +563 -0
  151. package/python/lib/python3.13/email/_policybase.py +382 -0
  152. package/python/lib/python3.13/email/architecture.rst +216 -0
  153. package/python/lib/python3.13/email/base64mime.py +115 -0
  154. package/python/lib/python3.13/email/charset.py +396 -0
  155. package/python/lib/python3.13/email/contentmanager.py +254 -0
  156. package/python/lib/python3.13/email/encoders.py +65 -0
  157. package/python/lib/python3.13/email/errors.py +117 -0
  158. package/python/lib/python3.13/email/feedparser.py +536 -0
  159. package/python/lib/python3.13/email/generator.py +530 -0
  160. package/python/lib/python3.13/email/header.py +582 -0
  161. package/python/lib/python3.13/email/headerregistry.py +618 -0
  162. package/python/lib/python3.13/email/iterators.py +68 -0
  163. package/python/lib/python3.13/email/message.py +1217 -0
  164. package/python/lib/python3.13/email/mime/__init__.py +0 -0
  165. package/python/lib/python3.13/email/mime/application.py +37 -0
  166. package/python/lib/python3.13/email/mime/audio.py +97 -0
  167. package/python/lib/python3.13/email/mime/base.py +29 -0
  168. package/python/lib/python3.13/email/mime/image.py +152 -0
  169. package/python/lib/python3.13/email/mime/message.py +33 -0
  170. package/python/lib/python3.13/email/mime/multipart.py +47 -0
  171. package/python/lib/python3.13/email/mime/nonmultipart.py +21 -0
  172. package/python/lib/python3.13/email/mime/text.py +40 -0
  173. package/python/lib/python3.13/email/parser.py +127 -0
  174. package/python/lib/python3.13/email/policy.py +232 -0
  175. package/python/lib/python3.13/email/quoprimime.py +300 -0
  176. package/python/lib/python3.13/email/utils.py +497 -0
  177. package/python/lib/python3.13/encodings/__init__.py +179 -0
  178. package/python/lib/python3.13/encodings/__pycache__/__init__.cpython-313.pyc +0 -0
  179. package/python/lib/python3.13/encodings/__pycache__/aliases.cpython-313.pyc +0 -0
  180. package/python/lib/python3.13/encodings/__pycache__/utf_8.cpython-313.pyc +0 -0
  181. package/python/lib/python3.13/encodings/aliases.py +560 -0
  182. package/python/lib/python3.13/encodings/ascii.py +50 -0
  183. package/python/lib/python3.13/encodings/base64_codec.py +55 -0
  184. package/python/lib/python3.13/encodings/big5.py +39 -0
  185. package/python/lib/python3.13/encodings/big5hkscs.py +39 -0
  186. package/python/lib/python3.13/encodings/bz2_codec.py +78 -0
  187. package/python/lib/python3.13/encodings/charmap.py +69 -0
  188. package/python/lib/python3.13/encodings/cp037.py +307 -0
  189. package/python/lib/python3.13/encodings/cp1006.py +307 -0
  190. package/python/lib/python3.13/encodings/cp1026.py +307 -0
  191. package/python/lib/python3.13/encodings/cp1125.py +698 -0
  192. package/python/lib/python3.13/encodings/cp1140.py +307 -0
  193. package/python/lib/python3.13/encodings/cp1250.py +307 -0
  194. package/python/lib/python3.13/encodings/cp1251.py +307 -0
  195. package/python/lib/python3.13/encodings/cp1252.py +307 -0
  196. package/python/lib/python3.13/encodings/cp1253.py +307 -0
  197. package/python/lib/python3.13/encodings/cp1254.py +307 -0
  198. package/python/lib/python3.13/encodings/cp1255.py +307 -0
  199. package/python/lib/python3.13/encodings/cp1256.py +307 -0
  200. package/python/lib/python3.13/encodings/cp1257.py +307 -0
  201. package/python/lib/python3.13/encodings/cp1258.py +307 -0
  202. package/python/lib/python3.13/encodings/cp273.py +307 -0
  203. package/python/lib/python3.13/encodings/cp424.py +307 -0
  204. package/python/lib/python3.13/encodings/cp437.py +698 -0
  205. package/python/lib/python3.13/encodings/cp500.py +307 -0
  206. package/python/lib/python3.13/encodings/cp720.py +309 -0
  207. package/python/lib/python3.13/encodings/cp737.py +698 -0
  208. package/python/lib/python3.13/encodings/cp775.py +697 -0
  209. package/python/lib/python3.13/encodings/cp850.py +698 -0
  210. package/python/lib/python3.13/encodings/cp852.py +698 -0
  211. package/python/lib/python3.13/encodings/cp855.py +698 -0
  212. package/python/lib/python3.13/encodings/cp856.py +307 -0
  213. package/python/lib/python3.13/encodings/cp857.py +694 -0
  214. package/python/lib/python3.13/encodings/cp858.py +698 -0
  215. package/python/lib/python3.13/encodings/cp860.py +698 -0
  216. package/python/lib/python3.13/encodings/cp861.py +698 -0
  217. package/python/lib/python3.13/encodings/cp862.py +698 -0
  218. package/python/lib/python3.13/encodings/cp863.py +698 -0
  219. package/python/lib/python3.13/encodings/cp864.py +690 -0
  220. package/python/lib/python3.13/encodings/cp865.py +698 -0
  221. package/python/lib/python3.13/encodings/cp866.py +698 -0
  222. package/python/lib/python3.13/encodings/cp869.py +689 -0
  223. package/python/lib/python3.13/encodings/cp874.py +307 -0
  224. package/python/lib/python3.13/encodings/cp875.py +307 -0
  225. package/python/lib/python3.13/encodings/cp932.py +39 -0
  226. package/python/lib/python3.13/encodings/cp949.py +39 -0
  227. package/python/lib/python3.13/encodings/cp950.py +39 -0
  228. package/python/lib/python3.13/encodings/euc_jis_2004.py +39 -0
  229. package/python/lib/python3.13/encodings/euc_jisx0213.py +39 -0
  230. package/python/lib/python3.13/encodings/euc_jp.py +39 -0
  231. package/python/lib/python3.13/encodings/euc_kr.py +39 -0
  232. package/python/lib/python3.13/encodings/gb18030.py +39 -0
  233. package/python/lib/python3.13/encodings/gb2312.py +39 -0
  234. package/python/lib/python3.13/encodings/gbk.py +39 -0
  235. package/python/lib/python3.13/encodings/hex_codec.py +55 -0
  236. package/python/lib/python3.13/encodings/hp_roman8.py +314 -0
  237. package/python/lib/python3.13/encodings/hz.py +39 -0
  238. package/python/lib/python3.13/encodings/idna.py +387 -0
  239. package/python/lib/python3.13/encodings/iso2022_jp.py +39 -0
  240. package/python/lib/python3.13/encodings/iso2022_jp_1.py +39 -0
  241. package/python/lib/python3.13/encodings/iso2022_jp_2.py +39 -0
  242. package/python/lib/python3.13/encodings/iso2022_jp_2004.py +39 -0
  243. package/python/lib/python3.13/encodings/iso2022_jp_3.py +39 -0
  244. package/python/lib/python3.13/encodings/iso2022_jp_ext.py +39 -0
  245. package/python/lib/python3.13/encodings/iso2022_kr.py +39 -0
  246. package/python/lib/python3.13/encodings/iso8859_1.py +307 -0
  247. package/python/lib/python3.13/encodings/iso8859_10.py +307 -0
  248. package/python/lib/python3.13/encodings/iso8859_11.py +307 -0
  249. package/python/lib/python3.13/encodings/iso8859_13.py +307 -0
  250. package/python/lib/python3.13/encodings/iso8859_14.py +307 -0
  251. package/python/lib/python3.13/encodings/iso8859_15.py +307 -0
  252. package/python/lib/python3.13/encodings/iso8859_16.py +307 -0
  253. package/python/lib/python3.13/encodings/iso8859_2.py +307 -0
  254. package/python/lib/python3.13/encodings/iso8859_3.py +307 -0
  255. package/python/lib/python3.13/encodings/iso8859_4.py +307 -0
  256. package/python/lib/python3.13/encodings/iso8859_5.py +307 -0
  257. package/python/lib/python3.13/encodings/iso8859_6.py +307 -0
  258. package/python/lib/python3.13/encodings/iso8859_7.py +307 -0
  259. package/python/lib/python3.13/encodings/iso8859_8.py +307 -0
  260. package/python/lib/python3.13/encodings/iso8859_9.py +307 -0
  261. package/python/lib/python3.13/encodings/johab.py +39 -0
  262. package/python/lib/python3.13/encodings/koi8_r.py +307 -0
  263. package/python/lib/python3.13/encodings/koi8_t.py +308 -0
  264. package/python/lib/python3.13/encodings/koi8_u.py +307 -0
  265. package/python/lib/python3.13/encodings/kz1048.py +307 -0
  266. package/python/lib/python3.13/encodings/latin_1.py +50 -0
  267. package/python/lib/python3.13/encodings/mac_arabic.py +698 -0
  268. package/python/lib/python3.13/encodings/mac_croatian.py +307 -0
  269. package/python/lib/python3.13/encodings/mac_cyrillic.py +307 -0
  270. package/python/lib/python3.13/encodings/mac_farsi.py +307 -0
  271. package/python/lib/python3.13/encodings/mac_greek.py +307 -0
  272. package/python/lib/python3.13/encodings/mac_iceland.py +307 -0
  273. package/python/lib/python3.13/encodings/mac_latin2.py +312 -0
  274. package/python/lib/python3.13/encodings/mac_roman.py +307 -0
  275. package/python/lib/python3.13/encodings/mac_romanian.py +307 -0
  276. package/python/lib/python3.13/encodings/mac_turkish.py +307 -0
  277. package/python/lib/python3.13/encodings/mbcs.py +47 -0
  278. package/python/lib/python3.13/encodings/oem.py +41 -0
  279. package/python/lib/python3.13/encodings/palmos.py +308 -0
  280. package/python/lib/python3.13/encodings/ptcp154.py +312 -0
  281. package/python/lib/python3.13/encodings/punycode.py +253 -0
  282. package/python/lib/python3.13/encodings/quopri_codec.py +56 -0
  283. package/python/lib/python3.13/encodings/raw_unicode_escape.py +46 -0
  284. package/python/lib/python3.13/encodings/rot_13.py +113 -0
  285. package/python/lib/python3.13/encodings/shift_jis.py +39 -0
  286. package/python/lib/python3.13/encodings/shift_jis_2004.py +39 -0
  287. package/python/lib/python3.13/encodings/shift_jisx0213.py +39 -0
  288. package/python/lib/python3.13/encodings/tis_620.py +307 -0
  289. package/python/lib/python3.13/encodings/undefined.py +49 -0
  290. package/python/lib/python3.13/encodings/unicode_escape.py +46 -0
  291. package/python/lib/python3.13/encodings/utf_16.py +155 -0
  292. package/python/lib/python3.13/encodings/utf_16_be.py +42 -0
  293. package/python/lib/python3.13/encodings/utf_16_le.py +42 -0
  294. package/python/lib/python3.13/encodings/utf_32.py +150 -0
  295. package/python/lib/python3.13/encodings/utf_32_be.py +37 -0
  296. package/python/lib/python3.13/encodings/utf_32_le.py +37 -0
  297. package/python/lib/python3.13/encodings/utf_7.py +38 -0
  298. package/python/lib/python3.13/encodings/utf_8.py +42 -0
  299. package/python/lib/python3.13/encodings/utf_8_sig.py +130 -0
  300. package/python/lib/python3.13/encodings/uu_codec.py +103 -0
  301. package/python/lib/python3.13/encodings/zlib_codec.py +77 -0
  302. package/python/lib/python3.13/enum.py +2183 -0
  303. package/python/lib/python3.13/filecmp.py +320 -0
  304. package/python/lib/python3.13/fileinput.py +442 -0
  305. package/python/lib/python3.13/fnmatch.py +192 -0
  306. package/python/lib/python3.13/fractions.py +1043 -0
  307. package/python/lib/python3.13/ftplib.py +975 -0
  308. package/python/lib/python3.13/functools.py +1036 -0
  309. package/python/lib/python3.13/genericpath.py +200 -0
  310. package/python/lib/python3.13/getopt.py +215 -0
  311. package/python/lib/python3.13/getpass.py +192 -0
  312. package/python/lib/python3.13/gettext.py +657 -0
  313. package/python/lib/python3.13/glob.py +572 -0
  314. package/python/lib/python3.13/graphlib.py +250 -0
  315. package/python/lib/python3.13/gzip.py +693 -0
  316. package/python/lib/python3.13/hashlib.py +255 -0
  317. package/python/lib/python3.13/heapq.py +603 -0
  318. package/python/lib/python3.13/hmac.py +220 -0
  319. package/python/lib/python3.13/html/__init__.py +132 -0
  320. package/python/lib/python3.13/html/entities.py +2513 -0
  321. package/python/lib/python3.13/html/parser.py +583 -0
  322. package/python/lib/python3.13/http/__init__.py +202 -0
  323. package/python/lib/python3.13/http/client.py +1598 -0
  324. package/python/lib/python3.13/http/cookiejar.py +2122 -0
  325. package/python/lib/python3.13/http/cookies.py +635 -0
  326. package/python/lib/python3.13/http/server.py +1355 -0
  327. package/python/lib/python3.13/imaplib.py +1769 -0
  328. package/python/lib/python3.13/importlib/__init__.py +136 -0
  329. package/python/lib/python3.13/importlib/_abc.py +39 -0
  330. package/python/lib/python3.13/importlib/_bootstrap.py +1559 -0
  331. package/python/lib/python3.13/importlib/_bootstrap_external.py +1826 -0
  332. package/python/lib/python3.13/importlib/abc.py +243 -0
  333. package/python/lib/python3.13/importlib/machinery.py +21 -0
  334. package/python/lib/python3.13/importlib/metadata/__init__.py +1093 -0
  335. package/python/lib/python3.13/importlib/metadata/_adapters.py +89 -0
  336. package/python/lib/python3.13/importlib/metadata/_collections.py +30 -0
  337. package/python/lib/python3.13/importlib/metadata/_functools.py +104 -0
  338. package/python/lib/python3.13/importlib/metadata/_itertools.py +73 -0
  339. package/python/lib/python3.13/importlib/metadata/_meta.py +67 -0
  340. package/python/lib/python3.13/importlib/metadata/_text.py +99 -0
  341. package/python/lib/python3.13/importlib/metadata/diagnose.py +21 -0
  342. package/python/lib/python3.13/importlib/readers.py +12 -0
  343. package/python/lib/python3.13/importlib/resources/__init__.py +43 -0
  344. package/python/lib/python3.13/importlib/resources/_adapters.py +168 -0
  345. package/python/lib/python3.13/importlib/resources/_common.py +211 -0
  346. package/python/lib/python3.13/importlib/resources/_functional.py +81 -0
  347. package/python/lib/python3.13/importlib/resources/_itertools.py +38 -0
  348. package/python/lib/python3.13/importlib/resources/abc.py +173 -0
  349. package/python/lib/python3.13/importlib/resources/readers.py +203 -0
  350. package/python/lib/python3.13/importlib/resources/simple.py +106 -0
  351. package/python/lib/python3.13/importlib/simple.py +14 -0
  352. package/python/lib/python3.13/importlib/util.py +274 -0
  353. package/python/lib/python3.13/inspect.py +3479 -0
  354. package/python/lib/python3.13/io.py +99 -0
  355. package/python/lib/python3.13/ipaddress.py +2440 -0
  356. package/python/lib/python3.13/json/__init__.py +365 -0
  357. package/python/lib/python3.13/json/decoder.py +364 -0
  358. package/python/lib/python3.13/json/encoder.py +446 -0
  359. package/python/lib/python3.13/json/scanner.py +73 -0
  360. package/python/lib/python3.13/json/tool.py +90 -0
  361. package/python/lib/python3.13/keyword.py +64 -0
  362. package/python/lib/python3.13/lib-dynload/.empty +0 -0
  363. package/python/lib/python3.13/lib-dynload/_dbm.cpython-313-x86_64-linux-gnu.so +0 -0
  364. package/python/lib/python3.13/linecache.py +236 -0
  365. package/python/lib/python3.13/locale.py +1987 -0
  366. package/python/lib/python3.13/logging/__init__.py +2330 -0
  367. package/python/lib/python3.13/logging/config.py +1080 -0
  368. package/python/lib/python3.13/logging/handlers.py +1629 -0
  369. package/python/lib/python3.13/lzma.py +364 -0
  370. package/python/lib/python3.13/mailbox.py +2219 -0
  371. package/python/lib/python3.13/mimetypes.py +679 -0
  372. package/python/lib/python3.13/modulefinder.py +671 -0
  373. package/python/lib/python3.13/multiprocessing/__init__.py +37 -0
  374. package/python/lib/python3.13/multiprocessing/connection.py +1216 -0
  375. package/python/lib/python3.13/multiprocessing/context.py +383 -0
  376. package/python/lib/python3.13/multiprocessing/dummy/__init__.py +126 -0
  377. package/python/lib/python3.13/multiprocessing/dummy/connection.py +75 -0
  378. package/python/lib/python3.13/multiprocessing/forkserver.py +373 -0
  379. package/python/lib/python3.13/multiprocessing/heap.py +337 -0
  380. package/python/lib/python3.13/multiprocessing/managers.py +1397 -0
  381. package/python/lib/python3.13/multiprocessing/pool.py +957 -0
  382. package/python/lib/python3.13/multiprocessing/popen_fork.py +97 -0
  383. package/python/lib/python3.13/multiprocessing/popen_forkserver.py +74 -0
  384. package/python/lib/python3.13/multiprocessing/popen_spawn_posix.py +76 -0
  385. package/python/lib/python3.13/multiprocessing/popen_spawn_win32.py +147 -0
  386. package/python/lib/python3.13/multiprocessing/process.py +436 -0
  387. package/python/lib/python3.13/multiprocessing/queues.py +399 -0
  388. package/python/lib/python3.13/multiprocessing/reduction.py +281 -0
  389. package/python/lib/python3.13/multiprocessing/resource_sharer.py +154 -0
  390. package/python/lib/python3.13/multiprocessing/resource_tracker.py +499 -0
  391. package/python/lib/python3.13/multiprocessing/shared_memory.py +544 -0
  392. package/python/lib/python3.13/multiprocessing/sharedctypes.py +240 -0
  393. package/python/lib/python3.13/multiprocessing/spawn.py +307 -0
  394. package/python/lib/python3.13/multiprocessing/synchronize.py +404 -0
  395. package/python/lib/python3.13/multiprocessing/util.py +562 -0
  396. package/python/lib/python3.13/netrc.py +199 -0
  397. package/python/lib/python3.13/ntpath.py +872 -0
  398. package/python/lib/python3.13/nturl2path.py +69 -0
  399. package/python/lib/python3.13/numbers.py +427 -0
  400. package/python/lib/python3.13/opcode.py +115 -0
  401. package/python/lib/python3.13/operator.py +467 -0
  402. package/python/lib/python3.13/optparse.py +1681 -0
  403. package/python/lib/python3.13/os.py +1184 -0
  404. package/python/lib/python3.13/pathlib/__init__.py +12 -0
  405. package/python/lib/python3.13/pathlib/_abc.py +930 -0
  406. package/python/lib/python3.13/pathlib/_local.py +861 -0
  407. package/python/lib/python3.13/pdb.py +2550 -0
  408. package/python/lib/python3.13/pickle.py +1860 -0
  409. package/python/lib/python3.13/pickletools.py +2904 -0
  410. package/python/lib/python3.13/pkgutil.py +529 -0
  411. package/python/lib/python3.13/platform.py +1454 -0
  412. package/python/lib/python3.13/plistlib.py +948 -0
  413. package/python/lib/python3.13/poplib.py +477 -0
  414. package/python/lib/python3.13/posixpath.py +578 -0
  415. package/python/lib/python3.13/pprint.py +658 -0
  416. package/python/lib/python3.13/profile.py +616 -0
  417. package/python/lib/python3.13/pstats.py +778 -0
  418. package/python/lib/python3.13/pty.py +211 -0
  419. package/python/lib/python3.13/py_compile.py +212 -0
  420. package/python/lib/python3.13/pyclbr.py +314 -0
  421. package/python/lib/python3.13/pydoc.py +2861 -0
  422. package/python/lib/python3.13/queue.py +383 -0
  423. package/python/lib/python3.13/quopri.py +237 -0
  424. package/python/lib/python3.13/random.py +1078 -0
  425. package/python/lib/python3.13/re/__init__.py +428 -0
  426. package/python/lib/python3.13/re/_casefix.py +106 -0
  427. package/python/lib/python3.13/re/_compiler.py +768 -0
  428. package/python/lib/python3.13/re/_constants.py +222 -0
  429. package/python/lib/python3.13/re/_parser.py +1081 -0
  430. package/python/lib/python3.13/reprlib.py +230 -0
  431. package/python/lib/python3.13/rlcompleter.py +222 -0
  432. package/python/lib/python3.13/runpy.py +326 -0
  433. package/python/lib/python3.13/sched.py +167 -0
  434. package/python/lib/python3.13/secrets.py +71 -0
  435. package/python/lib/python3.13/selectors.py +603 -0
  436. package/python/lib/python3.13/shelve.py +250 -0
  437. package/python/lib/python3.13/shlex.py +345 -0
  438. package/python/lib/python3.13/shutil.py +1569 -0
  439. package/python/lib/python3.13/signal.py +94 -0
  440. package/python/lib/python3.13/site.py +773 -0
  441. package/python/lib/python3.13/smtplib.py +1123 -0
  442. package/python/lib/python3.13/socket.py +988 -0
  443. package/python/lib/python3.13/socketserver.py +863 -0
  444. package/python/lib/python3.13/sqlite3/__init__.py +70 -0
  445. package/python/lib/python3.13/sqlite3/__main__.py +139 -0
  446. package/python/lib/python3.13/sqlite3/dbapi2.py +108 -0
  447. package/python/lib/python3.13/sqlite3/dump.py +118 -0
  448. package/python/lib/python3.13/sre_compile.py +7 -0
  449. package/python/lib/python3.13/sre_constants.py +7 -0
  450. package/python/lib/python3.13/sre_parse.py +7 -0
  451. package/python/lib/python3.13/ssl.py +1541 -0
  452. package/python/lib/python3.13/stat.py +212 -0
  453. package/python/lib/python3.13/statistics.py +1817 -0
  454. package/python/lib/python3.13/string.py +314 -0
  455. package/python/lib/python3.13/stringprep.py +272 -0
  456. package/python/lib/python3.13/struct.py +15 -0
  457. package/python/lib/python3.13/subprocess.py +2258 -0
  458. package/python/lib/python3.13/symtable.py +414 -0
  459. package/python/lib/python3.13/sysconfig/__init__.py +734 -0
  460. package/python/lib/python3.13/sysconfig/__main__.py +248 -0
  461. package/python/lib/python3.13/tabnanny.py +340 -0
  462. package/python/lib/python3.13/tarfile.py +3136 -0
  463. package/python/lib/python3.13/tempfile.py +958 -0
  464. package/python/lib/python3.13/textwrap.py +497 -0
  465. package/python/lib/python3.13/this.py +28 -0
  466. package/python/lib/python3.13/threading.py +1602 -0
  467. package/python/lib/python3.13/timeit.py +381 -0
  468. package/python/lib/python3.13/token.py +141 -0
  469. package/python/lib/python3.13/tokenize.py +592 -0
  470. package/python/lib/python3.13/tomllib/__init__.py +10 -0
  471. package/python/lib/python3.13/tomllib/_parser.py +703 -0
  472. package/python/lib/python3.13/tomllib/_re.py +107 -0
  473. package/python/lib/python3.13/tomllib/_types.py +10 -0
  474. package/python/lib/python3.13/tomllib/mypy.ini +15 -0
  475. package/python/lib/python3.13/trace.py +754 -0
  476. package/python/lib/python3.13/traceback.py +1639 -0
  477. package/python/lib/python3.13/tracemalloc.py +560 -0
  478. package/python/lib/python3.13/tty.py +73 -0
  479. package/python/lib/python3.13/types.py +346 -0
  480. package/python/lib/python3.13/typing.py +3846 -0
  481. package/python/lib/python3.13/unittest/__init__.py +80 -0
  482. package/python/lib/python3.13/unittest/__main__.py +18 -0
  483. package/python/lib/python3.13/unittest/_log.py +86 -0
  484. package/python/lib/python3.13/unittest/async_case.py +146 -0
  485. package/python/lib/python3.13/unittest/case.py +1478 -0
  486. package/python/lib/python3.13/unittest/loader.py +460 -0
  487. package/python/lib/python3.13/unittest/main.py +280 -0
  488. package/python/lib/python3.13/unittest/mock.py +3189 -0
  489. package/python/lib/python3.13/unittest/result.py +256 -0
  490. package/python/lib/python3.13/unittest/runner.py +292 -0
  491. package/python/lib/python3.13/unittest/signals.py +71 -0
  492. package/python/lib/python3.13/unittest/suite.py +379 -0
  493. package/python/lib/python3.13/unittest/util.py +170 -0
  494. package/python/lib/python3.13/urllib/__init__.py +0 -0
  495. package/python/lib/python3.13/urllib/error.py +74 -0
  496. package/python/lib/python3.13/urllib/parse.py +1264 -0
  497. package/python/lib/python3.13/urllib/request.py +2796 -0
  498. package/python/lib/python3.13/urllib/response.py +84 -0
  499. package/python/lib/python3.13/urllib/robotparser.py +363 -0
  500. package/python/lib/python3.13/uuid.py +784 -0
  501. package/python/lib/python3.13/warnings.py +735 -0
  502. package/python/lib/python3.13/wave.py +665 -0
  503. package/python/lib/python3.13/weakref.py +674 -0
  504. package/python/lib/python3.13/webbrowser.py +724 -0
  505. package/python/lib/python3.13/wsgiref/__init__.py +25 -0
  506. package/python/lib/python3.13/wsgiref/handlers.py +575 -0
  507. package/python/lib/python3.13/wsgiref/headers.py +192 -0
  508. package/python/lib/python3.13/wsgiref/simple_server.py +161 -0
  509. package/python/lib/python3.13/wsgiref/types.py +54 -0
  510. package/python/lib/python3.13/wsgiref/util.py +159 -0
  511. package/python/lib/python3.13/wsgiref/validate.py +438 -0
  512. package/python/lib/python3.13/xml/__init__.py +20 -0
  513. package/python/lib/python3.13/xml/dom/NodeFilter.py +27 -0
  514. package/python/lib/python3.13/xml/dom/__init__.py +140 -0
  515. package/python/lib/python3.13/xml/dom/domreg.py +99 -0
  516. package/python/lib/python3.13/xml/dom/expatbuilder.py +962 -0
  517. package/python/lib/python3.13/xml/dom/minicompat.py +109 -0
  518. package/python/lib/python3.13/xml/dom/minidom.py +2024 -0
  519. package/python/lib/python3.13/xml/dom/pulldom.py +336 -0
  520. package/python/lib/python3.13/xml/dom/xmlbuilder.py +389 -0
  521. package/python/lib/python3.13/xml/etree/ElementInclude.py +186 -0
  522. package/python/lib/python3.13/xml/etree/ElementPath.py +430 -0
  523. package/python/lib/python3.13/xml/etree/ElementTree.py +2116 -0
  524. package/python/lib/python3.13/xml/etree/__init__.py +33 -0
  525. package/python/lib/python3.13/xml/etree/cElementTree.py +3 -0
  526. package/python/lib/python3.13/xml/parsers/__init__.py +8 -0
  527. package/python/lib/python3.13/xml/parsers/expat.py +8 -0
  528. package/python/lib/python3.13/xml/sax/__init__.py +94 -0
  529. package/python/lib/python3.13/xml/sax/_exceptions.py +127 -0
  530. package/python/lib/python3.13/xml/sax/expatreader.py +454 -0
  531. package/python/lib/python3.13/xml/sax/handler.py +387 -0
  532. package/python/lib/python3.13/xml/sax/saxutils.py +369 -0
  533. package/python/lib/python3.13/xml/sax/xmlreader.py +378 -0
  534. package/python/lib/python3.13/xmlrpc/__init__.py +1 -0
  535. package/python/lib/python3.13/xmlrpc/client.py +1503 -0
  536. package/python/lib/python3.13/xmlrpc/server.py +1002 -0
  537. package/python/lib/python3.13/zipapp.py +229 -0
  538. package/python/lib/python3.13/zipfile/__init__.py +2391 -0
  539. package/python/lib/python3.13/zipfile/__main__.py +4 -0
  540. package/python/lib/python3.13/zipfile/_path/__init__.py +452 -0
  541. package/python/lib/python3.13/zipfile/_path/glob.py +113 -0
  542. package/python/lib/python3.13/zipimport.py +803 -0
  543. package/python/lib/python3.13/zoneinfo/__init__.py +34 -0
  544. package/python/lib/python3.13/zoneinfo/_common.py +172 -0
  545. package/python/lib/python3.13/zoneinfo/_tzpath.py +189 -0
  546. package/python/lib/python3.13/zoneinfo/_zoneinfo.py +779 -0
  547. package/python/licenses/LICENSE.bdb.txt +126 -0
  548. package/python/licenses/LICENSE.bzip2.txt +37 -0
  549. package/python/licenses/LICENSE.cpython.txt +771 -0
  550. package/python/licenses/LICENSE.expat.txt +21 -0
  551. package/python/licenses/LICENSE.libX11.txt +942 -0
  552. package/python/licenses/LICENSE.libXau.txt +21 -0
  553. package/python/licenses/LICENSE.libedit.txt +29 -0
  554. package/python/licenses/LICENSE.libffi.txt +21 -0
  555. package/python/licenses/LICENSE.liblzma.txt +13 -0
  556. package/python/licenses/LICENSE.libuuid.txt +27 -0
  557. package/python/licenses/LICENSE.libxcb.txt +30 -0
  558. package/python/licenses/LICENSE.mpdecimal.txt +24 -0
  559. package/python/licenses/LICENSE.ncurses.txt +29 -0
  560. package/python/licenses/LICENSE.openssl-1.1.txt +124 -0
  561. package/python/licenses/LICENSE.openssl-3.txt +177 -0
  562. package/python/licenses/LICENSE.sqlite.txt +23 -0
  563. package/python/licenses/LICENSE.tcl.txt +40 -0
  564. package/python/licenses/LICENSE.tix.txt +54 -0
  565. package/python/licenses/LICENSE.zlib.txt +21 -0
@@ -0,0 +1,1598 @@
1
+ r"""HTTP/1.1 client library
2
+
3
+ <intro stuff goes here>
4
+ <other stuff, too>
5
+
6
+ HTTPConnection goes through a number of "states", which define when a client
7
+ may legally make another request or fetch the response for a particular
8
+ request. This diagram details these state transitions:
9
+
10
+ (null)
11
+ |
12
+ | HTTPConnection()
13
+ v
14
+ Idle
15
+ |
16
+ | putrequest()
17
+ v
18
+ Request-started
19
+ |
20
+ | ( putheader() )* endheaders()
21
+ v
22
+ Request-sent
23
+ |\_____________________________
24
+ | | getresponse() raises
25
+ | response = getresponse() | ConnectionError
26
+ v v
27
+ Unread-response Idle
28
+ [Response-headers-read]
29
+ |\____________________
30
+ | |
31
+ | response.read() | putrequest()
32
+ v v
33
+ Idle Req-started-unread-response
34
+ ______/|
35
+ / |
36
+ response.read() | | ( putheader() )* endheaders()
37
+ v v
38
+ Request-started Req-sent-unread-response
39
+ |
40
+ | response.read()
41
+ v
42
+ Request-sent
43
+
44
+ This diagram presents the following rules:
45
+ -- a second request may not be started until {response-headers-read}
46
+ -- a response [object] cannot be retrieved until {request-sent}
47
+ -- there is no differentiation between an unread response body and a
48
+ partially read response body
49
+
50
+ Note: this enforcement is applied by the HTTPConnection class. The
51
+ HTTPResponse class does not enforce this state machine, which
52
+ implies sophisticated clients may accelerate the request/response
53
+ pipeline. Caution should be taken, though: accelerating the states
54
+ beyond the above pattern may imply knowledge of the server's
55
+ connection-close behavior for certain requests. For example, it
56
+ is impossible to tell whether the server will close the connection
57
+ UNTIL the response headers have been read; this means that further
58
+ requests cannot be placed into the pipeline until it is known that
59
+ the server will NOT be closing the connection.
60
+
61
+ Logical State __state __response
62
+ ------------- ------- ----------
63
+ Idle _CS_IDLE None
64
+ Request-started _CS_REQ_STARTED None
65
+ Request-sent _CS_REQ_SENT None
66
+ Unread-response _CS_IDLE <response_class>
67
+ Req-started-unread-response _CS_REQ_STARTED <response_class>
68
+ Req-sent-unread-response _CS_REQ_SENT <response_class>
69
+ """
70
+
71
+ import email.parser
72
+ import email.message
73
+ import errno
74
+ import http
75
+ import io
76
+ import re
77
+ import socket
78
+ import sys
79
+ import collections.abc
80
+ from urllib.parse import urlsplit
81
+
82
+ # HTTPMessage, parse_headers(), and the HTTP status code constants are
83
+ # intentionally omitted for simplicity
84
+ __all__ = ["HTTPResponse", "HTTPConnection",
85
+ "HTTPException", "NotConnected", "UnknownProtocol",
86
+ "UnknownTransferEncoding", "UnimplementedFileMode",
87
+ "IncompleteRead", "InvalidURL", "ImproperConnectionState",
88
+ "CannotSendRequest", "CannotSendHeader", "ResponseNotReady",
89
+ "BadStatusLine", "LineTooLong", "RemoteDisconnected", "error",
90
+ "responses"]
91
+
92
+ HTTP_PORT = 80
93
+ HTTPS_PORT = 443
94
+
95
+ _UNKNOWN = 'UNKNOWN'
96
+
97
+ # connection states
98
+ _CS_IDLE = 'Idle'
99
+ _CS_REQ_STARTED = 'Request-started'
100
+ _CS_REQ_SENT = 'Request-sent'
101
+
102
+
103
+ # hack to maintain backwards compatibility
104
+ globals().update(http.HTTPStatus.__members__)
105
+
106
+ # another hack to maintain backwards compatibility
107
+ # Mapping status codes to official W3C names
108
+ responses = {v: v.phrase for v in http.HTTPStatus.__members__.values()}
109
+
110
+ # maximal line length when calling readline().
111
+ _MAXLINE = 65536
112
+ _MAXHEADERS = 100
113
+
114
+ # maximal number of interim (1xx) responses tolerated before the final
115
+ # response. Real servers send at most a few; without a bound, a server
116
+ # streaming "100 Continue" responses would hang getresponse() forever.
117
+ # A socket timeout cannot detect that as data keeps arriving within every
118
+ # timeout window.
119
+ _MAXINTERIMRESPONSES = 100
120
+
121
+ # Data larger than this will be read in chunks, to prevent extreme
122
+ # overallocation.
123
+ _MIN_READ_BUF_SIZE = 1 << 20
124
+
125
+
126
+ # Header name/value ABNF (http://tools.ietf.org/html/rfc7230#section-3.2)
127
+ #
128
+ # VCHAR = %x21-7E
129
+ # obs-text = %x80-FF
130
+ # header-field = field-name ":" OWS field-value OWS
131
+ # field-name = token
132
+ # field-value = *( field-content / obs-fold )
133
+ # field-content = field-vchar [ 1*( SP / HTAB ) field-vchar ]
134
+ # field-vchar = VCHAR / obs-text
135
+ #
136
+ # obs-fold = CRLF 1*( SP / HTAB )
137
+ # ; obsolete line folding
138
+ # ; see Section 3.2.4
139
+
140
+ # token = 1*tchar
141
+ #
142
+ # tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
143
+ # / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
144
+ # / DIGIT / ALPHA
145
+ # ; any VCHAR, except delimiters
146
+ #
147
+ # VCHAR defined in http://tools.ietf.org/html/rfc5234#appendix-B.1
148
+
149
+ # the patterns for both name and value are more lenient than RFC
150
+ # definitions to allow for backwards compatibility
151
+ _is_legal_header_name = re.compile(rb'[^:\s][^:\r\n]*').fullmatch
152
+ _is_illegal_header_value = re.compile(rb'\n(?![ \t])|\r(?![ \t\n])').search
153
+
154
+ # These characters are not allowed within HTTP URL paths.
155
+ # See https://tools.ietf.org/html/rfc3986#section-3.3 and the
156
+ # https://tools.ietf.org/html/rfc3986#appendix-A pchar definition.
157
+ # Prevents CVE-2019-9740. Includes control characters such as \r\n.
158
+ # We don't restrict chars above \x7f as putrequest() limits us to ASCII.
159
+ _contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f]')
160
+ # Arguably only these _should_ allowed:
161
+ # _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$")
162
+ # We are more lenient for assumed real world compatibility purposes.
163
+
164
+ # These characters are not allowed within HTTP method names
165
+ # to prevent http header injection.
166
+ _contains_disallowed_method_pchar_re = re.compile('[\x00-\x1f]')
167
+
168
+ # We always set the Content-Length header for these methods because some
169
+ # servers will otherwise respond with a 411
170
+ _METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}
171
+
172
+
173
+ def _encode(data, name='data'):
174
+ """Call data.encode("latin-1") but show a better error message."""
175
+ try:
176
+ return data.encode("latin-1")
177
+ except UnicodeEncodeError as err:
178
+ raise UnicodeEncodeError(
179
+ err.encoding,
180
+ err.object,
181
+ err.start,
182
+ err.end,
183
+ "%s (%.20r) is not valid Latin-1. Use %s.encode('utf-8') "
184
+ "if you want to send it encoded in UTF-8." %
185
+ (name.title(), data[err.start:err.end], name)) from None
186
+
187
+ def _strip_ipv6_iface(enc_name: bytes) -> bytes:
188
+ """Remove interface scope from IPv6 address."""
189
+ enc_name, percent, _ = enc_name.partition(b"%")
190
+ if percent:
191
+ assert enc_name.startswith(b'['), enc_name
192
+ enc_name += b']'
193
+ return enc_name
194
+
195
+ class HTTPMessage(email.message.Message):
196
+ # XXX The only usage of this method is in
197
+ # http.server.CGIHTTPRequestHandler. Maybe move the code there so
198
+ # that it doesn't need to be part of the public API. The API has
199
+ # never been defined so this could cause backwards compatibility
200
+ # issues.
201
+
202
+ def getallmatchingheaders(self, name):
203
+ """Find all header lines matching a given header name.
204
+
205
+ Look through the list of headers and find all lines matching a given
206
+ header name (and their continuation lines). A list of the lines is
207
+ returned, without interpretation. If the header does not occur, an
208
+ empty list is returned. If the header occurs multiple times, all
209
+ occurrences are returned. Case is not important in the header name.
210
+
211
+ """
212
+ name = name.lower() + ':'
213
+ n = len(name)
214
+ lst = []
215
+ hit = 0
216
+ for line in self.keys():
217
+ if line[:n].lower() == name:
218
+ hit = 1
219
+ elif not line[:1].isspace():
220
+ hit = 0
221
+ if hit:
222
+ lst.append(line)
223
+ return lst
224
+
225
+ def _read_headers(fp):
226
+ """Reads potential header lines into a list from a file pointer.
227
+
228
+ Length of line is limited by _MAXLINE, and number of
229
+ headers is limited by _MAXHEADERS.
230
+ """
231
+ headers = []
232
+ while True:
233
+ line = fp.readline(_MAXLINE + 1)
234
+ if len(line) > _MAXLINE:
235
+ raise LineTooLong("header line")
236
+ headers.append(line)
237
+ if len(headers) > _MAXHEADERS:
238
+ raise HTTPException("got more than %d headers" % _MAXHEADERS)
239
+ if line in (b'\r\n', b'\n', b''):
240
+ break
241
+ return headers
242
+
243
+ def _parse_header_lines(header_lines, _class=HTTPMessage):
244
+ """
245
+ Parses only RFC 5322 headers from header lines.
246
+
247
+ email Parser wants to see strings rather than bytes.
248
+ But a TextIOWrapper around self.rfile would buffer too many bytes
249
+ from the stream, bytes which we later need to read as bytes.
250
+ So we read the correct bytes here, as bytes, for email Parser
251
+ to parse.
252
+
253
+ """
254
+ hstring = b''.join(header_lines).decode('iso-8859-1')
255
+ return email.parser.Parser(_class=_class).parsestr(hstring)
256
+
257
+ def parse_headers(fp, _class=HTTPMessage):
258
+ """Parses only RFC 5322 headers from a file pointer."""
259
+
260
+ headers = _read_headers(fp)
261
+ return _parse_header_lines(headers, _class)
262
+
263
+
264
+ class HTTPResponse(io.BufferedIOBase):
265
+
266
+ # See RFC 2616 sec 19.6 and RFC 1945 sec 6 for details.
267
+
268
+ # The bytes from the socket object are iso-8859-1 strings.
269
+ # See RFC 2616 sec 2.2 which notes an exception for MIME-encoded
270
+ # text following RFC 2047. The basic status line parsing only
271
+ # accepts iso-8859-1.
272
+
273
+ def __init__(self, sock, debuglevel=0, method=None, url=None):
274
+ # If the response includes a content-length header, we need to
275
+ # make sure that the client doesn't read more than the
276
+ # specified number of bytes. If it does, it will block until
277
+ # the server times out and closes the connection. This will
278
+ # happen if a self.fp.read() is done (without a size) whether
279
+ # self.fp is buffered or not. So, no self.fp.read() by
280
+ # clients unless they know what they are doing.
281
+ self.fp = sock.makefile("rb")
282
+ self.debuglevel = debuglevel
283
+ self._method = method
284
+
285
+ # The HTTPResponse object is returned via urllib. The clients
286
+ # of http and urllib expect different attributes for the
287
+ # headers. headers is used here and supports urllib. msg is
288
+ # provided as a backwards compatibility layer for http
289
+ # clients.
290
+
291
+ self.headers = self.msg = None
292
+
293
+ # from the Status-Line of the response
294
+ self.version = _UNKNOWN # HTTP-Version
295
+ self.status = _UNKNOWN # Status-Code
296
+ self.reason = _UNKNOWN # Reason-Phrase
297
+
298
+ self.chunked = _UNKNOWN # is "chunked" being used?
299
+ self.chunk_left = _UNKNOWN # bytes left to read in current chunk
300
+ self.length = _UNKNOWN # number of bytes left in response
301
+ self.will_close = _UNKNOWN # conn will close at end of response
302
+
303
+ def _read_status(self):
304
+ line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
305
+ if len(line) > _MAXLINE:
306
+ raise LineTooLong("status line")
307
+ if self.debuglevel > 0:
308
+ print("reply:", repr(line))
309
+ if not line:
310
+ # Presumably, the server closed the connection before
311
+ # sending a valid response.
312
+ raise RemoteDisconnected("Remote end closed connection without"
313
+ " response")
314
+ try:
315
+ version, status, reason = line.split(None, 2)
316
+ except ValueError:
317
+ try:
318
+ version, status = line.split(None, 1)
319
+ reason = ""
320
+ except ValueError:
321
+ # empty version will cause next test to fail.
322
+ version = ""
323
+ if not version.startswith("HTTP/"):
324
+ self._close_conn()
325
+ raise BadStatusLine(line)
326
+
327
+ # The status code is a three-digit number
328
+ try:
329
+ status = int(status)
330
+ if status < 100 or status > 999:
331
+ raise BadStatusLine(line)
332
+ except ValueError:
333
+ raise BadStatusLine(line)
334
+ return version, status, reason
335
+
336
+ def begin(self):
337
+ if self.headers is not None:
338
+ # we've already started reading the response
339
+ return
340
+
341
+ # read until we get a non-100 response
342
+ for _ in range(_MAXINTERIMRESPONSES):
343
+ version, status, reason = self._read_status()
344
+ if status != CONTINUE:
345
+ break
346
+ # skip the header from the 100 response
347
+ skipped_headers = _read_headers(self.fp)
348
+ if self.debuglevel > 0:
349
+ print("headers:", skipped_headers)
350
+ del skipped_headers
351
+ else:
352
+ raise HTTPException(
353
+ f"got more than {_MAXINTERIMRESPONSES} interim responses")
354
+
355
+ self.code = self.status = status
356
+ self.reason = reason.strip()
357
+ if version in ("HTTP/1.0", "HTTP/0.9"):
358
+ # Some servers might still return "0.9", treat it as 1.0 anyway
359
+ self.version = 10
360
+ elif version.startswith("HTTP/1."):
361
+ self.version = 11 # use HTTP/1.1 code for HTTP/1.x where x>=1
362
+ else:
363
+ raise UnknownProtocol(version)
364
+
365
+ self.headers = self.msg = parse_headers(self.fp)
366
+
367
+ if self.debuglevel > 0:
368
+ for hdr, val in self.headers.items():
369
+ print("header:", hdr + ":", val)
370
+
371
+ # are we using the chunked-style of transfer encoding?
372
+ tr_enc = self.headers.get("transfer-encoding")
373
+ if tr_enc and tr_enc.lower() == "chunked":
374
+ self.chunked = True
375
+ self.chunk_left = None
376
+ else:
377
+ self.chunked = False
378
+
379
+ # will the connection close at the end of the response?
380
+ self.will_close = self._check_close()
381
+
382
+ # do we have a Content-Length?
383
+ # NOTE: RFC 2616, S4.4, #3 says we ignore this if tr_enc is "chunked"
384
+ self.length = None
385
+ length = self.headers.get("content-length")
386
+ if length and not self.chunked:
387
+ try:
388
+ self.length = int(length)
389
+ except ValueError:
390
+ self.length = None
391
+ else:
392
+ if self.length < 0: # ignore nonsensical negative lengths
393
+ self.length = None
394
+ else:
395
+ self.length = None
396
+
397
+ # does the body have a fixed length? (of zero)
398
+ if (status == NO_CONTENT or status == NOT_MODIFIED or
399
+ 100 <= status < 200 or # 1xx codes
400
+ self._method == "HEAD"):
401
+ self.length = 0
402
+
403
+ # if the connection remains open, and we aren't using chunked, and
404
+ # a content-length was not provided, then assume that the connection
405
+ # WILL close.
406
+ if (not self.will_close and
407
+ not self.chunked and
408
+ self.length is None):
409
+ self.will_close = True
410
+
411
+ def _check_close(self):
412
+ conn = self.headers.get("connection")
413
+ if self.version == 11:
414
+ # An HTTP/1.1 proxy is assumed to stay open unless
415
+ # explicitly closed.
416
+ if conn and "close" in conn.lower():
417
+ return True
418
+ return False
419
+
420
+ # Some HTTP/1.0 implementations have support for persistent
421
+ # connections, using rules different than HTTP/1.1.
422
+
423
+ # For older HTTP, Keep-Alive indicates persistent connection.
424
+ if self.headers.get("keep-alive"):
425
+ return False
426
+
427
+ # At least Akamai returns a "Connection: Keep-Alive" header,
428
+ # which was supposed to be sent by the client.
429
+ if conn and "keep-alive" in conn.lower():
430
+ return False
431
+
432
+ # Proxy-Connection is a netscape hack.
433
+ pconn = self.headers.get("proxy-connection")
434
+ if pconn and "keep-alive" in pconn.lower():
435
+ return False
436
+
437
+ # otherwise, assume it will close
438
+ return True
439
+
440
+ def _close_conn(self):
441
+ fp = self.fp
442
+ self.fp = None
443
+ fp.close()
444
+
445
+ def close(self):
446
+ try:
447
+ super().close() # set "closed" flag
448
+ finally:
449
+ if self.fp:
450
+ self._close_conn()
451
+
452
+ # These implementations are for the benefit of io.BufferedReader.
453
+
454
+ # XXX This class should probably be revised to act more like
455
+ # the "raw stream" that BufferedReader expects.
456
+
457
+ def flush(self):
458
+ super().flush()
459
+ if self.fp:
460
+ self.fp.flush()
461
+
462
+ def readable(self):
463
+ """Always returns True"""
464
+ return True
465
+
466
+ # End of "raw stream" methods
467
+
468
+ def isclosed(self):
469
+ """True if the connection is closed."""
470
+ # NOTE: it is possible that we will not ever call self.close(). This
471
+ # case occurs when will_close is TRUE, length is None, and we
472
+ # read up to the last byte, but NOT past it.
473
+ #
474
+ # IMPLIES: if will_close is FALSE, then self.close() will ALWAYS be
475
+ # called, meaning self.isclosed() is meaningful.
476
+ return self.fp is None
477
+
478
+ def read(self, amt=None):
479
+ """Read and return the response body, or up to the next amt bytes."""
480
+ if self.fp is None:
481
+ return b""
482
+
483
+ if self._method == "HEAD":
484
+ self._close_conn()
485
+ return b""
486
+
487
+ if self.chunked:
488
+ return self._read_chunked(amt)
489
+
490
+ if amt is not None and amt >= 0:
491
+ if self.length is not None and amt > self.length:
492
+ # clip the read to the "end of response"
493
+ amt = self.length
494
+ s = self.fp.read(amt)
495
+ if not s and amt:
496
+ # Ideally, we would raise IncompleteRead if the content-length
497
+ # wasn't satisfied, but it might break compatibility.
498
+ self._close_conn()
499
+ elif self.length is not None:
500
+ self.length -= len(s)
501
+ if not self.length:
502
+ self._close_conn()
503
+ return s
504
+ else:
505
+ # Amount is not given (unbounded read) so we must check self.length
506
+ if self.length is None:
507
+ s = self.fp.read()
508
+ else:
509
+ try:
510
+ s = self._safe_read(self.length)
511
+ except IncompleteRead:
512
+ self._close_conn()
513
+ raise
514
+ self.length = 0
515
+ self._close_conn() # we read everything
516
+ return s
517
+
518
+ def readinto(self, b):
519
+ """Read up to len(b) bytes into bytearray b and return the number
520
+ of bytes read.
521
+ """
522
+
523
+ if self.fp is None:
524
+ return 0
525
+
526
+ if self._method == "HEAD":
527
+ self._close_conn()
528
+ return 0
529
+
530
+ if self.chunked:
531
+ return self._readinto_chunked(b)
532
+
533
+ if self.length is not None:
534
+ if len(b) > self.length:
535
+ # clip the read to the "end of response"
536
+ b = memoryview(b)[0:self.length]
537
+
538
+ # we do not use _safe_read() here because this may be a .will_close
539
+ # connection, and the user is reading more bytes than will be provided
540
+ # (for example, reading in 1k chunks)
541
+ n = self.fp.readinto(b)
542
+ if not n and b:
543
+ # Ideally, we would raise IncompleteRead if the content-length
544
+ # wasn't satisfied, but it might break compatibility.
545
+ self._close_conn()
546
+ elif self.length is not None:
547
+ self.length -= n
548
+ if not self.length:
549
+ self._close_conn()
550
+ return n
551
+
552
+ def _read_next_chunk_size(self):
553
+ # Read the next chunk size from the file
554
+ line = self.fp.readline(_MAXLINE + 1)
555
+ if len(line) > _MAXLINE:
556
+ raise LineTooLong("chunk size")
557
+ i = line.find(b";")
558
+ if i >= 0:
559
+ line = line[:i] # strip chunk-extensions
560
+ try:
561
+ return int(line, 16)
562
+ except ValueError:
563
+ # close the connection as protocol synchronisation is
564
+ # probably lost
565
+ self._close_conn()
566
+ raise
567
+
568
+ def _read_and_discard_trailer(self):
569
+ # read and discard trailer up to the CRLF terminator
570
+ ### note: we shouldn't have any trailers!
571
+ trailers_read = 0
572
+ while True:
573
+ line = self.fp.readline(_MAXLINE + 1)
574
+ if len(line) > _MAXLINE:
575
+ raise LineTooLong("trailer line")
576
+ if not line:
577
+ # a vanishingly small number of sites EOF without
578
+ # sending the trailer
579
+ break
580
+ if line in (b'\r\n', b'\n', b''):
581
+ break
582
+ # Bound the trailer count just as response headers are bounded.
583
+ # A server streaming trailer lines forever would otherwise hang
584
+ # the client; a socket timeout cannot detect that as data keeps
585
+ # arriving within every timeout window.
586
+ trailers_read += 1
587
+ if trailers_read > _MAXHEADERS:
588
+ raise HTTPException(
589
+ f"got more than {_MAXHEADERS} trailers")
590
+
591
+ def _get_chunk_left(self):
592
+ # return self.chunk_left, reading a new chunk if necessary.
593
+ # chunk_left == 0: at the end of the current chunk, need to close it
594
+ # chunk_left == None: No current chunk, should read next.
595
+ # This function returns non-zero or None if the last chunk has
596
+ # been read.
597
+ chunk_left = self.chunk_left
598
+ if not chunk_left: # Can be 0 or None
599
+ if chunk_left is not None:
600
+ # We are at the end of chunk, discard chunk end
601
+ self._safe_read(2) # toss the CRLF at the end of the chunk
602
+ try:
603
+ chunk_left = self._read_next_chunk_size()
604
+ except ValueError:
605
+ raise IncompleteRead(b'')
606
+ if chunk_left == 0:
607
+ # last chunk: 1*("0") [ chunk-extension ] CRLF
608
+ self._read_and_discard_trailer()
609
+ # we read everything; close the "file"
610
+ self._close_conn()
611
+ chunk_left = None
612
+ self.chunk_left = chunk_left
613
+ return chunk_left
614
+
615
+ def _read_chunked(self, amt=None):
616
+ assert self.chunked != _UNKNOWN
617
+ if amt is not None and amt < 0:
618
+ amt = None
619
+ value = []
620
+ try:
621
+ while (chunk_left := self._get_chunk_left()) is not None:
622
+ if amt is not None and amt <= chunk_left:
623
+ value.append(self._safe_read(amt))
624
+ self.chunk_left = chunk_left - amt
625
+ break
626
+
627
+ value.append(self._safe_read(chunk_left))
628
+ if amt is not None:
629
+ amt -= chunk_left
630
+ self.chunk_left = 0
631
+ return b''.join(value)
632
+ except IncompleteRead as exc:
633
+ raise IncompleteRead(b''.join(value)) from exc
634
+
635
+ def _readinto_chunked(self, b):
636
+ assert self.chunked != _UNKNOWN
637
+ total_bytes = 0
638
+ mvb = memoryview(b)
639
+ try:
640
+ while True:
641
+ chunk_left = self._get_chunk_left()
642
+ if chunk_left is None:
643
+ return total_bytes
644
+
645
+ if len(mvb) <= chunk_left:
646
+ n = self._safe_readinto(mvb)
647
+ self.chunk_left = chunk_left - n
648
+ return total_bytes + n
649
+
650
+ temp_mvb = mvb[:chunk_left]
651
+ n = self._safe_readinto(temp_mvb)
652
+ mvb = mvb[n:]
653
+ total_bytes += n
654
+ self.chunk_left = 0
655
+
656
+ except IncompleteRead:
657
+ raise IncompleteRead(bytes(b[0:total_bytes]))
658
+
659
+ def _safe_read(self, amt):
660
+ """Read the number of bytes requested.
661
+
662
+ This function should be used when <amt> bytes "should" be present for
663
+ reading. If the bytes are truly not available (due to EOF), then the
664
+ IncompleteRead exception can be used to detect the problem.
665
+ """
666
+ cursize = min(amt, _MIN_READ_BUF_SIZE)
667
+ data = self.fp.read(cursize)
668
+ if len(data) >= amt:
669
+ return data
670
+ if len(data) < cursize:
671
+ raise IncompleteRead(data, amt - len(data))
672
+
673
+ data = io.BytesIO(data)
674
+ data.seek(0, 2)
675
+ while True:
676
+ # This is a geometric increase in read size (never more than
677
+ # doubling out the current length of data per loop iteration).
678
+ delta = min(cursize, amt - cursize)
679
+ data.write(self.fp.read(delta))
680
+ if data.tell() >= amt:
681
+ return data.getvalue()
682
+ cursize += delta
683
+ if data.tell() < cursize:
684
+ raise IncompleteRead(data.getvalue(), amt - data.tell())
685
+
686
+ def _safe_readinto(self, b):
687
+ """Same as _safe_read, but for reading into a buffer."""
688
+ amt = len(b)
689
+ n = self.fp.readinto(b)
690
+ if n < amt:
691
+ raise IncompleteRead(bytes(b[:n]), amt-n)
692
+ return n
693
+
694
+ def read1(self, n=-1):
695
+ """Read with at most one underlying system call. If at least one
696
+ byte is buffered, return that instead.
697
+ """
698
+ if self.fp is None or self._method == "HEAD":
699
+ return b""
700
+ if self.chunked:
701
+ return self._read1_chunked(n)
702
+ if self.length is not None and (n < 0 or n > self.length):
703
+ n = self.length
704
+ result = self.fp.read1(n)
705
+ if not result and n:
706
+ self._close_conn()
707
+ elif self.length is not None:
708
+ self.length -= len(result)
709
+ if not self.length:
710
+ self._close_conn()
711
+ return result
712
+
713
+ def peek(self, n=-1):
714
+ # Having this enables IOBase.readline() to read more than one
715
+ # byte at a time
716
+ if self.fp is None or self._method == "HEAD":
717
+ return b""
718
+ if self.chunked:
719
+ return self._peek_chunked(n)
720
+ return self.fp.peek(n)
721
+
722
+ def readline(self, limit=-1):
723
+ if self.fp is None or self._method == "HEAD":
724
+ return b""
725
+ if self.chunked:
726
+ # Fallback to IOBase readline which uses peek() and read()
727
+ return super().readline(limit)
728
+ if self.length is not None and (limit < 0 or limit > self.length):
729
+ limit = self.length
730
+ result = self.fp.readline(limit)
731
+ if not result and limit:
732
+ self._close_conn()
733
+ elif self.length is not None:
734
+ self.length -= len(result)
735
+ if not self.length:
736
+ self._close_conn()
737
+ return result
738
+
739
+ def _read1_chunked(self, n):
740
+ # Strictly speaking, _get_chunk_left() may cause more than one read,
741
+ # but that is ok, since that is to satisfy the chunked protocol.
742
+ chunk_left = self._get_chunk_left()
743
+ if chunk_left is None or n == 0:
744
+ return b''
745
+ if not (0 <= n <= chunk_left):
746
+ n = chunk_left # if n is negative or larger than chunk_left
747
+ read = self.fp.read1(n)
748
+ self.chunk_left -= len(read)
749
+ if not read:
750
+ raise IncompleteRead(b"")
751
+ return read
752
+
753
+ def _peek_chunked(self, n):
754
+ # Strictly speaking, _get_chunk_left() may cause more than one read,
755
+ # but that is ok, since that is to satisfy the chunked protocol.
756
+ try:
757
+ chunk_left = self._get_chunk_left()
758
+ except IncompleteRead:
759
+ return b'' # peek doesn't worry about protocol
760
+ if chunk_left is None:
761
+ return b'' # eof
762
+ # peek is allowed to return more than requested. Just request the
763
+ # entire chunk, and truncate what we get.
764
+ return self.fp.peek(chunk_left)[:chunk_left]
765
+
766
+ def fileno(self):
767
+ return self.fp.fileno()
768
+
769
+ def getheader(self, name, default=None):
770
+ '''Returns the value of the header matching *name*.
771
+
772
+ If there are multiple matching headers, the values are
773
+ combined into a single string separated by commas and spaces.
774
+
775
+ If no matching header is found, returns *default* or None if
776
+ the *default* is not specified.
777
+
778
+ If the headers are unknown, raises http.client.ResponseNotReady.
779
+
780
+ '''
781
+ if self.headers is None:
782
+ raise ResponseNotReady()
783
+ headers = self.headers.get_all(name) or default
784
+ if isinstance(headers, str) or not hasattr(headers, '__iter__'):
785
+ return headers
786
+ else:
787
+ return ', '.join(headers)
788
+
789
+ def getheaders(self):
790
+ """Return list of (header, value) tuples."""
791
+ if self.headers is None:
792
+ raise ResponseNotReady()
793
+ return list(self.headers.items())
794
+
795
+ # We override IOBase.__iter__ so that it doesn't check for closed-ness
796
+
797
+ def __iter__(self):
798
+ return self
799
+
800
+ # For compatibility with old-style urllib responses.
801
+
802
+ def info(self):
803
+ '''Returns an instance of the class mimetools.Message containing
804
+ meta-information associated with the URL.
805
+
806
+ When the method is HTTP, these headers are those returned by
807
+ the server at the head of the retrieved HTML page (including
808
+ Content-Length and Content-Type).
809
+
810
+ When the method is FTP, a Content-Length header will be
811
+ present if (as is now usual) the server passed back a file
812
+ length in response to the FTP retrieval request. A
813
+ Content-Type header will be present if the MIME type can be
814
+ guessed.
815
+
816
+ When the method is local-file, returned headers will include
817
+ a Date representing the file's last-modified time, a
818
+ Content-Length giving file size, and a Content-Type
819
+ containing a guess at the file's type. See also the
820
+ description of the mimetools module.
821
+
822
+ '''
823
+ return self.headers
824
+
825
+ def geturl(self):
826
+ '''Return the real URL of the page.
827
+
828
+ In some cases, the HTTP server redirects a client to another
829
+ URL. The urlopen() function handles this transparently, but in
830
+ some cases the caller needs to know which URL the client was
831
+ redirected to. The geturl() method can be used to get at this
832
+ redirected URL.
833
+
834
+ '''
835
+ return self.url
836
+
837
+ def getcode(self):
838
+ '''Return the HTTP status code that was sent with the response,
839
+ or None if the URL is not an HTTP URL.
840
+
841
+ '''
842
+ return self.status
843
+
844
+
845
+ def _create_https_context(http_version):
846
+ # Function also used by urllib.request to be able to set the check_hostname
847
+ # attribute on a context object.
848
+ context = ssl._create_default_https_context()
849
+ # send ALPN extension to indicate HTTP/1.1 protocol
850
+ if http_version == 11:
851
+ context.set_alpn_protocols(['http/1.1'])
852
+ # enable PHA for TLS 1.3 connections if available
853
+ if context.post_handshake_auth is not None:
854
+ context.post_handshake_auth = True
855
+ return context
856
+
857
+
858
+ class HTTPConnection:
859
+
860
+ _http_vsn = 11
861
+ _http_vsn_str = 'HTTP/1.1'
862
+
863
+ response_class = HTTPResponse
864
+ default_port = HTTP_PORT
865
+ auto_open = 1
866
+ debuglevel = 0
867
+
868
+ @staticmethod
869
+ def _is_textIO(stream):
870
+ """Test whether a file-like object is a text or a binary stream.
871
+ """
872
+ return isinstance(stream, io.TextIOBase)
873
+
874
+ @staticmethod
875
+ def _get_content_length(body, method):
876
+ """Get the content-length based on the body.
877
+
878
+ If the body is None, we set Content-Length: 0 for methods that expect
879
+ a body (RFC 7230, Section 3.3.2). We also set the Content-Length for
880
+ any method if the body is a str or bytes-like object and not a file.
881
+ """
882
+ if body is None:
883
+ # do an explicit check for not None here to distinguish
884
+ # between unset and set but empty
885
+ if method.upper() in _METHODS_EXPECTING_BODY:
886
+ return 0
887
+ else:
888
+ return None
889
+
890
+ if hasattr(body, 'read'):
891
+ # file-like object.
892
+ return None
893
+
894
+ try:
895
+ # does it implement the buffer protocol (bytes, bytearray, array)?
896
+ mv = memoryview(body)
897
+ return mv.nbytes
898
+ except TypeError:
899
+ pass
900
+
901
+ if isinstance(body, str):
902
+ return len(body)
903
+
904
+ return None
905
+
906
+ def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
907
+ source_address=None, blocksize=8192):
908
+ self.timeout = timeout
909
+ self.source_address = source_address
910
+ self.blocksize = blocksize
911
+ self.sock = None
912
+ self._buffer = []
913
+ self.__response = None
914
+ self.__state = _CS_IDLE
915
+ self._method = None
916
+ self._tunnel_host = None
917
+ self._tunnel_port = None
918
+ self._tunnel_headers = {}
919
+ self._raw_proxy_headers = None
920
+
921
+ (self.host, self.port) = self._get_hostport(host, port)
922
+
923
+ self._validate_host(self.host)
924
+
925
+ # This is stored as an instance variable to allow unit
926
+ # tests to replace it with a suitable mockup
927
+ self._create_connection = socket.create_connection
928
+
929
+ def set_tunnel(self, host, port=None, headers=None):
930
+ """Set up host and port for HTTP CONNECT tunnelling.
931
+
932
+ In a connection that uses HTTP CONNECT tunnelling, the host passed to
933
+ the constructor is used as a proxy server that relays all communication
934
+ to the endpoint passed to `set_tunnel`. This done by sending an HTTP
935
+ CONNECT request to the proxy server when the connection is established.
936
+
937
+ This method must be called before the HTTP connection has been
938
+ established.
939
+
940
+ The headers argument should be a mapping of extra HTTP headers to send
941
+ with the CONNECT request.
942
+
943
+ As HTTP/1.1 is used for HTTP CONNECT tunnelling request, as per the RFC
944
+ (https://tools.ietf.org/html/rfc7231#section-4.3.6), a HTTP Host:
945
+ header must be provided, matching the authority-form of the request
946
+ target provided as the destination for the CONNECT request. If a
947
+ HTTP Host: header is not provided via the headers argument, one
948
+ is generated and transmitted automatically.
949
+ """
950
+
951
+ if self.sock:
952
+ raise RuntimeError("Can't set up tunnel for established connection")
953
+
954
+ self._tunnel_host, self._tunnel_port = self._get_hostport(host, port)
955
+ if headers:
956
+ self._tunnel_headers = headers.copy()
957
+ else:
958
+ self._tunnel_headers.clear()
959
+
960
+ if not any(header.lower() == "host" for header in self._tunnel_headers):
961
+ encoded_host = self._tunnel_host.encode("idna").decode("ascii")
962
+ self._tunnel_headers["Host"] = "%s:%d" % (
963
+ encoded_host, self._tunnel_port)
964
+
965
+ def _get_hostport(self, host, port):
966
+ if port is None:
967
+ i = host.rfind(':')
968
+ j = host.rfind(']') # ipv6 addresses have [...]
969
+ if i > j:
970
+ try:
971
+ port = int(host[i+1:])
972
+ except ValueError:
973
+ if host[i+1:] == "": # http://foo.com:/ == http://foo.com/
974
+ port = self.default_port
975
+ else:
976
+ raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
977
+ host = host[:i]
978
+ else:
979
+ port = self.default_port
980
+ if host and host[0] == '[' and host[-1] == ']':
981
+ host = host[1:-1]
982
+
983
+ return (host, port)
984
+
985
+ def set_debuglevel(self, level):
986
+ self.debuglevel = level
987
+
988
+ def _wrap_ipv6(self, ip):
989
+ if b':' in ip and ip[0] != b'['[0]:
990
+ return b"[" + ip + b"]"
991
+ return ip
992
+
993
+ def _tunnel(self):
994
+ if _contains_disallowed_url_pchar_re.search(self._tunnel_host):
995
+ raise ValueError('Tunnel host can\'t contain control characters %r'
996
+ % (self._tunnel_host,))
997
+ connect = b"CONNECT %s:%d %s\r\n" % (
998
+ self._wrap_ipv6(self._tunnel_host.encode("idna")),
999
+ self._tunnel_port,
1000
+ self._http_vsn_str.encode("ascii"))
1001
+ headers = [connect]
1002
+ for header, value in self._tunnel_headers.items():
1003
+ header_bytes = header.encode("latin-1")
1004
+ value_bytes = value.encode("latin-1")
1005
+ if not _is_legal_header_name(header_bytes):
1006
+ raise ValueError('Invalid header name %r' % (header_bytes,))
1007
+ if _is_illegal_header_value(value_bytes):
1008
+ raise ValueError('Invalid header value %r' % (value_bytes,))
1009
+ headers.append(b"%s: %s\r\n" % (header_bytes, value_bytes))
1010
+ headers.append(b"\r\n")
1011
+ # Making a single send() call instead of one per line encourages
1012
+ # the host OS to use a more optimal packet size instead of
1013
+ # potentially emitting a series of small packets.
1014
+ self.send(b"".join(headers))
1015
+ del headers
1016
+
1017
+ response = self.response_class(self.sock, method=self._method)
1018
+ try:
1019
+ (version, code, message) = response._read_status()
1020
+
1021
+ self._raw_proxy_headers = _read_headers(response.fp)
1022
+
1023
+ if self.debuglevel > 0:
1024
+ for header in self._raw_proxy_headers:
1025
+ print('header:', header.decode())
1026
+
1027
+ if code != http.HTTPStatus.OK:
1028
+ self.close()
1029
+ raise OSError(f"Tunnel connection failed: {code} {message.strip()}")
1030
+
1031
+ finally:
1032
+ response.close()
1033
+
1034
+ def get_proxy_response_headers(self):
1035
+ """
1036
+ Returns a dictionary with the headers of the response
1037
+ received from the proxy server to the CONNECT request
1038
+ sent to set the tunnel.
1039
+
1040
+ If the CONNECT request was not sent, the method returns None.
1041
+ """
1042
+ return (
1043
+ _parse_header_lines(self._raw_proxy_headers)
1044
+ if self._raw_proxy_headers is not None
1045
+ else None
1046
+ )
1047
+
1048
+ def connect(self):
1049
+ """Connect to the host and port specified in __init__."""
1050
+ sys.audit("http.client.connect", self, self.host, self.port)
1051
+ self.sock = self._create_connection(
1052
+ (self.host,self.port), self.timeout, self.source_address)
1053
+ # Might fail in OSs that don't implement TCP_NODELAY
1054
+ try:
1055
+ self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
1056
+ except OSError as e:
1057
+ if e.errno != errno.ENOPROTOOPT:
1058
+ raise
1059
+
1060
+ if self._tunnel_host:
1061
+ self._tunnel()
1062
+
1063
+ def close(self):
1064
+ """Close the connection to the HTTP server."""
1065
+ self.__state = _CS_IDLE
1066
+ try:
1067
+ sock = self.sock
1068
+ if sock:
1069
+ self.sock = None
1070
+ sock.close() # close it manually... there may be other refs
1071
+ finally:
1072
+ response = self.__response
1073
+ if response:
1074
+ self.__response = None
1075
+ response.close()
1076
+
1077
+ def send(self, data):
1078
+ """Send `data' to the server.
1079
+ ``data`` can be a string object, a bytes object, an array object, a
1080
+ file-like object that supports a .read() method, or an iterable object.
1081
+ """
1082
+
1083
+ if self.sock is None:
1084
+ if self.auto_open:
1085
+ self.connect()
1086
+ else:
1087
+ raise NotConnected()
1088
+
1089
+ if self.debuglevel > 0:
1090
+ print("send:", repr(data))
1091
+ if hasattr(data, "read") :
1092
+ if self.debuglevel > 0:
1093
+ print("sending a readable")
1094
+ encode = self._is_textIO(data)
1095
+ if encode and self.debuglevel > 0:
1096
+ print("encoding file using iso-8859-1")
1097
+ while datablock := data.read(self.blocksize):
1098
+ if encode:
1099
+ datablock = datablock.encode("iso-8859-1")
1100
+ sys.audit("http.client.send", self, datablock)
1101
+ self.sock.sendall(datablock)
1102
+ return
1103
+ sys.audit("http.client.send", self, data)
1104
+ try:
1105
+ self.sock.sendall(data)
1106
+ except TypeError:
1107
+ if isinstance(data, collections.abc.Iterable):
1108
+ for d in data:
1109
+ self.sock.sendall(d)
1110
+ else:
1111
+ raise TypeError("data should be a bytes-like object "
1112
+ "or an iterable, got %r" % type(data))
1113
+
1114
+ def _output(self, s):
1115
+ """Add a line of output to the current request buffer.
1116
+
1117
+ Assumes that the line does *not* end with \\r\\n.
1118
+ """
1119
+ self._buffer.append(s)
1120
+
1121
+ def _read_readable(self, readable):
1122
+ if self.debuglevel > 0:
1123
+ print("reading a readable")
1124
+ encode = self._is_textIO(readable)
1125
+ if encode and self.debuglevel > 0:
1126
+ print("encoding file using iso-8859-1")
1127
+ while datablock := readable.read(self.blocksize):
1128
+ if encode:
1129
+ datablock = datablock.encode("iso-8859-1")
1130
+ yield datablock
1131
+
1132
+ def _send_output(self, message_body=None, encode_chunked=False):
1133
+ """Send the currently buffered request and clear the buffer.
1134
+
1135
+ Appends an extra \\r\\n to the buffer.
1136
+ A message_body may be specified, to be appended to the request.
1137
+ """
1138
+ self._buffer.extend((b"", b""))
1139
+ msg = b"\r\n".join(self._buffer)
1140
+ del self._buffer[:]
1141
+ self.send(msg)
1142
+
1143
+ if message_body is not None:
1144
+
1145
+ # create a consistent interface to message_body
1146
+ if hasattr(message_body, 'read'):
1147
+ # Let file-like take precedence over byte-like. This
1148
+ # is needed to allow the current position of mmap'ed
1149
+ # files to be taken into account.
1150
+ chunks = self._read_readable(message_body)
1151
+ else:
1152
+ try:
1153
+ # this is solely to check to see if message_body
1154
+ # implements the buffer API. it /would/ be easier
1155
+ # to capture if PyObject_CheckBuffer was exposed
1156
+ # to Python.
1157
+ memoryview(message_body)
1158
+ except TypeError:
1159
+ try:
1160
+ chunks = iter(message_body)
1161
+ except TypeError:
1162
+ raise TypeError("message_body should be a bytes-like "
1163
+ "object or an iterable, got %r"
1164
+ % type(message_body))
1165
+ else:
1166
+ # the object implements the buffer interface and
1167
+ # can be passed directly into socket methods
1168
+ chunks = (message_body,)
1169
+
1170
+ for chunk in chunks:
1171
+ if not chunk:
1172
+ if self.debuglevel > 0:
1173
+ print('Zero length chunk ignored')
1174
+ continue
1175
+
1176
+ if encode_chunked and self._http_vsn == 11:
1177
+ # chunked encoding
1178
+ chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk \
1179
+ + b'\r\n'
1180
+ self.send(chunk)
1181
+
1182
+ if encode_chunked and self._http_vsn == 11:
1183
+ # end chunked transfer
1184
+ self.send(b'0\r\n\r\n')
1185
+
1186
+ def putrequest(self, method, url, skip_host=False,
1187
+ skip_accept_encoding=False):
1188
+ """Send a request to the server.
1189
+
1190
+ `method' specifies an HTTP request method, e.g. 'GET'.
1191
+ `url' specifies the object being requested, e.g. '/index.html'.
1192
+ `skip_host' if True does not add automatically a 'Host:' header
1193
+ `skip_accept_encoding' if True does not add automatically an
1194
+ 'Accept-Encoding:' header
1195
+ """
1196
+
1197
+ # if a prior response has been completed, then forget about it.
1198
+ if self.__response and self.__response.isclosed():
1199
+ self.__response = None
1200
+
1201
+
1202
+ # in certain cases, we cannot issue another request on this connection.
1203
+ # this occurs when:
1204
+ # 1) we are in the process of sending a request. (_CS_REQ_STARTED)
1205
+ # 2) a response to a previous request has signalled that it is going
1206
+ # to close the connection upon completion.
1207
+ # 3) the headers for the previous response have not been read, thus
1208
+ # we cannot determine whether point (2) is true. (_CS_REQ_SENT)
1209
+ #
1210
+ # if there is no prior response, then we can request at will.
1211
+ #
1212
+ # if point (2) is true, then we will have passed the socket to the
1213
+ # response (effectively meaning, "there is no prior response"), and
1214
+ # will open a new one when a new request is made.
1215
+ #
1216
+ # Note: if a prior response exists, then we *can* start a new request.
1217
+ # We are not allowed to begin fetching the response to this new
1218
+ # request, however, until that prior response is complete.
1219
+ #
1220
+ if self.__state == _CS_IDLE:
1221
+ self.__state = _CS_REQ_STARTED
1222
+ else:
1223
+ raise CannotSendRequest(self.__state)
1224
+
1225
+ self._validate_method(method)
1226
+
1227
+ # Save the method for use later in the response phase
1228
+ self._method = method
1229
+
1230
+ url = url or '/'
1231
+ self._validate_path(url)
1232
+
1233
+ request = '%s %s %s' % (method, url, self._http_vsn_str)
1234
+
1235
+ self._output(self._encode_request(request))
1236
+
1237
+ if self._http_vsn == 11:
1238
+ # Issue some standard headers for better HTTP/1.1 compliance
1239
+
1240
+ if not skip_host:
1241
+ # this header is issued *only* for HTTP/1.1
1242
+ # connections. more specifically, this means it is
1243
+ # only issued when the client uses the new
1244
+ # HTTPConnection() class. backwards-compat clients
1245
+ # will be using HTTP/1.0 and those clients may be
1246
+ # issuing this header themselves. we should NOT issue
1247
+ # it twice; some web servers (such as Apache) barf
1248
+ # when they see two Host: headers
1249
+
1250
+ # If we need a non-standard port,include it in the
1251
+ # header. If the request is going through a proxy,
1252
+ # but the host of the actual URL, not the host of the
1253
+ # proxy.
1254
+
1255
+ netloc = ''
1256
+ if url.startswith('http'):
1257
+ nil, netloc, nil, nil, nil = urlsplit(url)
1258
+
1259
+ if netloc:
1260
+ try:
1261
+ netloc_enc = netloc.encode("ascii")
1262
+ except UnicodeEncodeError:
1263
+ netloc_enc = netloc.encode("idna")
1264
+ self.putheader('Host', _strip_ipv6_iface(netloc_enc))
1265
+ else:
1266
+ if self._tunnel_host:
1267
+ host = self._tunnel_host
1268
+ port = self._tunnel_port
1269
+ else:
1270
+ host = self.host
1271
+ port = self.port
1272
+
1273
+ try:
1274
+ host_enc = host.encode("ascii")
1275
+ except UnicodeEncodeError:
1276
+ host_enc = host.encode("idna")
1277
+
1278
+ # As per RFC 273, IPv6 address should be wrapped with []
1279
+ # when used as Host header
1280
+ host_enc = self._wrap_ipv6(host_enc)
1281
+ if ":" in host:
1282
+ host_enc = _strip_ipv6_iface(host_enc)
1283
+
1284
+ if port == self.default_port:
1285
+ self.putheader('Host', host_enc)
1286
+ else:
1287
+ host_enc = host_enc.decode("ascii")
1288
+ self.putheader('Host', "%s:%s" % (host_enc, port))
1289
+
1290
+ # note: we are assuming that clients will not attempt to set these
1291
+ # headers since *this* library must deal with the
1292
+ # consequences. this also means that when the supporting
1293
+ # libraries are updated to recognize other forms, then this
1294
+ # code should be changed (removed or updated).
1295
+
1296
+ # we only want a Content-Encoding of "identity" since we don't
1297
+ # support encodings such as x-gzip or x-deflate.
1298
+ if not skip_accept_encoding:
1299
+ self.putheader('Accept-Encoding', 'identity')
1300
+
1301
+ # we can accept "chunked" Transfer-Encodings, but no others
1302
+ # NOTE: no TE header implies *only* "chunked"
1303
+ #self.putheader('TE', 'chunked')
1304
+
1305
+ # if TE is supplied in the header, then it must appear in a
1306
+ # Connection header.
1307
+ #self.putheader('Connection', 'TE')
1308
+
1309
+ else:
1310
+ # For HTTP/1.0, the server will assume "not chunked"
1311
+ pass
1312
+
1313
+ def _encode_request(self, request):
1314
+ # ASCII also helps prevent CVE-2019-9740.
1315
+ return request.encode('ascii')
1316
+
1317
+ def _validate_method(self, method):
1318
+ """Validate a method name for putrequest."""
1319
+ # prevent http header injection
1320
+ match = _contains_disallowed_method_pchar_re.search(method)
1321
+ if match:
1322
+ raise ValueError(
1323
+ f"method can't contain control characters. {method!r} "
1324
+ f"(found at least {match.group()!r})")
1325
+
1326
+ def _validate_path(self, url):
1327
+ """Validate a url for putrequest."""
1328
+ # Prevent CVE-2019-9740.
1329
+ match = _contains_disallowed_url_pchar_re.search(url)
1330
+ if match:
1331
+ raise InvalidURL(f"URL can't contain control characters. {url!r} "
1332
+ f"(found at least {match.group()!r})")
1333
+
1334
+ def _validate_host(self, host):
1335
+ """Validate a host so it doesn't contain control characters."""
1336
+ # Prevent CVE-2019-18348.
1337
+ match = _contains_disallowed_url_pchar_re.search(host)
1338
+ if match:
1339
+ raise InvalidURL(f"URL can't contain control characters. {host!r} "
1340
+ f"(found at least {match.group()!r})")
1341
+
1342
+ def putheader(self, header, *values):
1343
+ """Send a request header line to the server.
1344
+
1345
+ For example: h.putheader('Accept', 'text/html')
1346
+ """
1347
+ if self.__state != _CS_REQ_STARTED:
1348
+ raise CannotSendHeader()
1349
+
1350
+ if hasattr(header, 'encode'):
1351
+ header = header.encode('ascii')
1352
+
1353
+ if not _is_legal_header_name(header):
1354
+ raise ValueError('Invalid header name %r' % (header,))
1355
+
1356
+ values = list(values)
1357
+ for i, one_value in enumerate(values):
1358
+ if hasattr(one_value, 'encode'):
1359
+ values[i] = one_value.encode('latin-1')
1360
+ elif isinstance(one_value, int):
1361
+ values[i] = str(one_value).encode('ascii')
1362
+
1363
+ if _is_illegal_header_value(values[i]):
1364
+ raise ValueError('Invalid header value %r' % (values[i],))
1365
+
1366
+ value = b'\r\n\t'.join(values)
1367
+ header = header + b': ' + value
1368
+ self._output(header)
1369
+
1370
+ def endheaders(self, message_body=None, *, encode_chunked=False):
1371
+ """Indicate that the last header line has been sent to the server.
1372
+
1373
+ This method sends the request to the server. The optional message_body
1374
+ argument can be used to pass a message body associated with the
1375
+ request.
1376
+ """
1377
+ if self.__state == _CS_REQ_STARTED:
1378
+ self.__state = _CS_REQ_SENT
1379
+ else:
1380
+ raise CannotSendHeader()
1381
+ self._send_output(message_body, encode_chunked=encode_chunked)
1382
+
1383
+ def request(self, method, url, body=None, headers={}, *,
1384
+ encode_chunked=False):
1385
+ """Send a complete request to the server."""
1386
+ self._send_request(method, url, body, headers, encode_chunked)
1387
+
1388
+ def _send_request(self, method, url, body, headers, encode_chunked):
1389
+ # Honor explicitly requested Host: and Accept-Encoding: headers.
1390
+ header_names = frozenset(k.lower() for k in headers)
1391
+ skips = {}
1392
+ if 'host' in header_names:
1393
+ skips['skip_host'] = 1
1394
+ if 'accept-encoding' in header_names:
1395
+ skips['skip_accept_encoding'] = 1
1396
+
1397
+ self.putrequest(method, url, **skips)
1398
+
1399
+ # chunked encoding will happen if HTTP/1.1 is used and either
1400
+ # the caller passes encode_chunked=True or the following
1401
+ # conditions hold:
1402
+ # 1. content-length has not been explicitly set
1403
+ # 2. the body is a file or iterable, but not a str or bytes-like
1404
+ # 3. Transfer-Encoding has NOT been explicitly set by the caller
1405
+
1406
+ if 'content-length' not in header_names:
1407
+ # only chunk body if not explicitly set for backwards
1408
+ # compatibility, assuming the client code is already handling the
1409
+ # chunking
1410
+ if 'transfer-encoding' not in header_names:
1411
+ # if content-length cannot be automatically determined, fall
1412
+ # back to chunked encoding
1413
+ encode_chunked = False
1414
+ content_length = self._get_content_length(body, method)
1415
+ if content_length is None:
1416
+ if body is not None:
1417
+ if self.debuglevel > 0:
1418
+ print('Unable to determine size of %r' % body)
1419
+ encode_chunked = True
1420
+ self.putheader('Transfer-Encoding', 'chunked')
1421
+ else:
1422
+ self.putheader('Content-Length', str(content_length))
1423
+ else:
1424
+ encode_chunked = False
1425
+
1426
+ for hdr, value in headers.items():
1427
+ self.putheader(hdr, value)
1428
+ if isinstance(body, str):
1429
+ # RFC 2616 Section 3.7.1 says that text default has a
1430
+ # default charset of iso-8859-1.
1431
+ body = _encode(body, 'body')
1432
+ self.endheaders(body, encode_chunked=encode_chunked)
1433
+
1434
+ def getresponse(self):
1435
+ """Get the response from the server.
1436
+
1437
+ If the HTTPConnection is in the correct state, returns an
1438
+ instance of HTTPResponse or of whatever object is returned by
1439
+ the response_class variable.
1440
+
1441
+ If a request has not been sent or if a previous response has
1442
+ not be handled, ResponseNotReady is raised. If the HTTP
1443
+ response indicates that the connection should be closed, then
1444
+ it will be closed before the response is returned. When the
1445
+ connection is closed, the underlying socket is closed.
1446
+ """
1447
+
1448
+ # if a prior response has been completed, then forget about it.
1449
+ if self.__response and self.__response.isclosed():
1450
+ self.__response = None
1451
+
1452
+ # if a prior response exists, then it must be completed (otherwise, we
1453
+ # cannot read this response's header to determine the connection-close
1454
+ # behavior)
1455
+ #
1456
+ # note: if a prior response existed, but was connection-close, then the
1457
+ # socket and response were made independent of this HTTPConnection
1458
+ # object since a new request requires that we open a whole new
1459
+ # connection
1460
+ #
1461
+ # this means the prior response had one of two states:
1462
+ # 1) will_close: this connection was reset and the prior socket and
1463
+ # response operate independently
1464
+ # 2) persistent: the response was retained and we await its
1465
+ # isclosed() status to become true.
1466
+ #
1467
+ if self.__state != _CS_REQ_SENT or self.__response:
1468
+ raise ResponseNotReady(self.__state)
1469
+
1470
+ if self.debuglevel > 0:
1471
+ response = self.response_class(self.sock, self.debuglevel,
1472
+ method=self._method)
1473
+ else:
1474
+ response = self.response_class(self.sock, method=self._method)
1475
+
1476
+ try:
1477
+ try:
1478
+ response.begin()
1479
+ except ConnectionError:
1480
+ self.close()
1481
+ raise
1482
+ assert response.will_close != _UNKNOWN
1483
+ self.__state = _CS_IDLE
1484
+
1485
+ if response.will_close:
1486
+ # this effectively passes the connection to the response
1487
+ self.close()
1488
+ else:
1489
+ # remember this, so we can tell when it is complete
1490
+ self.__response = response
1491
+
1492
+ return response
1493
+ except:
1494
+ response.close()
1495
+ raise
1496
+
1497
+ try:
1498
+ import ssl
1499
+ except ImportError:
1500
+ pass
1501
+ else:
1502
+ class HTTPSConnection(HTTPConnection):
1503
+ "This class allows communication via SSL."
1504
+
1505
+ default_port = HTTPS_PORT
1506
+
1507
+ def __init__(self, host, port=None,
1508
+ *, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
1509
+ source_address=None, context=None, blocksize=8192):
1510
+ super(HTTPSConnection, self).__init__(host, port, timeout,
1511
+ source_address,
1512
+ blocksize=blocksize)
1513
+ if context is None:
1514
+ context = _create_https_context(self._http_vsn)
1515
+ self._context = context
1516
+
1517
+ def connect(self):
1518
+ "Connect to a host on a given (SSL) port."
1519
+
1520
+ super().connect()
1521
+
1522
+ if self._tunnel_host:
1523
+ server_hostname = self._tunnel_host
1524
+ else:
1525
+ server_hostname = self.host
1526
+
1527
+ self.sock = self._context.wrap_socket(self.sock,
1528
+ server_hostname=server_hostname)
1529
+
1530
+ __all__.append("HTTPSConnection")
1531
+
1532
+ class HTTPException(Exception):
1533
+ # Subclasses that define an __init__ must call Exception.__init__
1534
+ # or define self.args. Otherwise, str() will fail.
1535
+ pass
1536
+
1537
+ class NotConnected(HTTPException):
1538
+ pass
1539
+
1540
+ class InvalidURL(HTTPException):
1541
+ pass
1542
+
1543
+ class UnknownProtocol(HTTPException):
1544
+ def __init__(self, version):
1545
+ self.args = version,
1546
+ self.version = version
1547
+
1548
+ class UnknownTransferEncoding(HTTPException):
1549
+ pass
1550
+
1551
+ class UnimplementedFileMode(HTTPException):
1552
+ pass
1553
+
1554
+ class IncompleteRead(HTTPException):
1555
+ def __init__(self, partial, expected=None):
1556
+ self.args = partial,
1557
+ self.partial = partial
1558
+ self.expected = expected
1559
+ def __repr__(self):
1560
+ if self.expected is not None:
1561
+ e = ', %i more expected' % self.expected
1562
+ else:
1563
+ e = ''
1564
+ return '%s(%i bytes read%s)' % (self.__class__.__name__,
1565
+ len(self.partial), e)
1566
+ __str__ = object.__str__
1567
+
1568
+ class ImproperConnectionState(HTTPException):
1569
+ pass
1570
+
1571
+ class CannotSendRequest(ImproperConnectionState):
1572
+ pass
1573
+
1574
+ class CannotSendHeader(ImproperConnectionState):
1575
+ pass
1576
+
1577
+ class ResponseNotReady(ImproperConnectionState):
1578
+ pass
1579
+
1580
+ class BadStatusLine(HTTPException):
1581
+ def __init__(self, line):
1582
+ if not line:
1583
+ line = repr(line)
1584
+ self.args = line,
1585
+ self.line = line
1586
+
1587
+ class LineTooLong(HTTPException):
1588
+ def __init__(self, line_type):
1589
+ HTTPException.__init__(self, "got more than %d bytes when reading %s"
1590
+ % (_MAXLINE, line_type))
1591
+
1592
+ class RemoteDisconnected(ConnectionResetError, BadStatusLine):
1593
+ def __init__(self, *pos, **kw):
1594
+ BadStatusLine.__init__(self, "")
1595
+ ConnectionResetError.__init__(self, *pos, **kw)
1596
+
1597
+ # for backwards compatibility
1598
+ error = HTTPException