@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,1216 @@
1
+ #
2
+ # A higher level module for using sockets (or Windows named pipes)
3
+ #
4
+ # multiprocessing/connection.py
5
+ #
6
+ # Copyright (c) 2006-2008, R Oudkerk
7
+ # Licensed to PSF under a Contributor Agreement.
8
+ #
9
+
10
+ __all__ = [ 'Client', 'Listener', 'Pipe', 'wait' ]
11
+
12
+ import errno
13
+ import io
14
+ import os
15
+ import sys
16
+ import socket
17
+ import struct
18
+ import time
19
+ import tempfile
20
+ import itertools
21
+
22
+
23
+ from . import util
24
+
25
+ from . import AuthenticationError, BufferTooShort
26
+ from .context import reduction
27
+ _ForkingPickler = reduction.ForkingPickler
28
+
29
+ try:
30
+ import _multiprocessing
31
+ import _winapi
32
+ from _winapi import WAIT_OBJECT_0, WAIT_ABANDONED_0, WAIT_TIMEOUT, INFINITE
33
+ except ImportError:
34
+ if sys.platform == 'win32':
35
+ raise
36
+ _winapi = None
37
+
38
+ #
39
+ #
40
+ #
41
+
42
+ BUFSIZE = 8192
43
+ # A very generous timeout when it comes to local connections...
44
+ CONNECTION_TIMEOUT = 20.
45
+
46
+ _mmap_counter = itertools.count()
47
+ _MAX_PIPE_ATTEMPTS = 100
48
+
49
+ default_family = 'AF_INET'
50
+ families = ['AF_INET']
51
+
52
+ if hasattr(socket, 'AF_UNIX'):
53
+ default_family = 'AF_UNIX'
54
+ families += ['AF_UNIX']
55
+
56
+ if sys.platform == 'win32':
57
+ default_family = 'AF_PIPE'
58
+ families += ['AF_PIPE']
59
+
60
+
61
+ def _init_timeout(timeout=CONNECTION_TIMEOUT):
62
+ return time.monotonic() + timeout
63
+
64
+ def _check_timeout(t):
65
+ return time.monotonic() > t
66
+
67
+ #
68
+ #
69
+ #
70
+
71
+ def arbitrary_address(family):
72
+ '''
73
+ Return an arbitrary free address for the given family
74
+ '''
75
+ if family == 'AF_INET':
76
+ return ('localhost', 0)
77
+ elif family == 'AF_UNIX':
78
+ # NOTE: util.get_temp_dir() is a 0o700 per-process directory. A
79
+ # mktemp-style ToC vs ToU concern is not important; bind() surfaces
80
+ # the extremely unlikely collision as EADDRINUSE.
81
+ return os.path.join(util.get_temp_dir(),
82
+ f'sock-{os.urandom(6).hex()}')
83
+ elif family == 'AF_PIPE':
84
+ return (r'\\.\pipe\pyc-%d-%d-%s' %
85
+ (os.getpid(), next(_mmap_counter), os.urandom(8).hex()))
86
+ else:
87
+ raise ValueError('unrecognized family')
88
+
89
+ def _validate_family(family):
90
+ '''
91
+ Checks if the family is valid for the current environment.
92
+ '''
93
+ if sys.platform != 'win32' and family == 'AF_PIPE':
94
+ raise ValueError('Family %s is not recognized.' % family)
95
+
96
+ if sys.platform == 'win32' and family == 'AF_UNIX':
97
+ # double check
98
+ if not hasattr(socket, family):
99
+ raise ValueError('Family %s is not recognized.' % family)
100
+
101
+ def address_type(address):
102
+ '''
103
+ Return the types of the address
104
+
105
+ This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
106
+ '''
107
+ if type(address) == tuple:
108
+ return 'AF_INET'
109
+ elif type(address) is str and address.startswith('\\\\'):
110
+ return 'AF_PIPE'
111
+ elif type(address) is str or util.is_abstract_socket_namespace(address):
112
+ return 'AF_UNIX'
113
+ else:
114
+ raise ValueError('address type of %r unrecognized' % address)
115
+
116
+ #
117
+ # Connection classes
118
+ #
119
+
120
+ class _ConnectionBase:
121
+ _handle = None
122
+
123
+ def __init__(self, handle, readable=True, writable=True):
124
+ handle = handle.__index__()
125
+ if handle < 0:
126
+ raise ValueError("invalid handle")
127
+ if not readable and not writable:
128
+ raise ValueError(
129
+ "at least one of `readable` and `writable` must be True")
130
+ self._handle = handle
131
+ self._readable = readable
132
+ self._writable = writable
133
+
134
+ # XXX should we use util.Finalize instead of a __del__?
135
+
136
+ def __del__(self):
137
+ if self._handle is not None:
138
+ self._close()
139
+
140
+ def _check_closed(self):
141
+ if self._handle is None:
142
+ raise OSError("handle is closed")
143
+
144
+ def _check_readable(self):
145
+ if not self._readable:
146
+ raise OSError("connection is write-only")
147
+
148
+ def _check_writable(self):
149
+ if not self._writable:
150
+ raise OSError("connection is read-only")
151
+
152
+ def _bad_message_length(self):
153
+ if self._writable:
154
+ self._readable = False
155
+ else:
156
+ self.close()
157
+ raise OSError("bad message length")
158
+
159
+ @property
160
+ def closed(self):
161
+ """True if the connection is closed"""
162
+ return self._handle is None
163
+
164
+ @property
165
+ def readable(self):
166
+ """True if the connection is readable"""
167
+ return self._readable
168
+
169
+ @property
170
+ def writable(self):
171
+ """True if the connection is writable"""
172
+ return self._writable
173
+
174
+ def fileno(self):
175
+ """File descriptor or handle of the connection"""
176
+ self._check_closed()
177
+ return self._handle
178
+
179
+ def close(self):
180
+ """Close the connection"""
181
+ if self._handle is not None:
182
+ try:
183
+ self._close()
184
+ finally:
185
+ self._handle = None
186
+
187
+ def send_bytes(self, buf, offset=0, size=None):
188
+ """Send the bytes data from a bytes-like object"""
189
+ self._check_closed()
190
+ self._check_writable()
191
+ m = memoryview(buf)
192
+ if m.itemsize > 1:
193
+ m = m.cast('B')
194
+ n = m.nbytes
195
+ if offset < 0:
196
+ raise ValueError("offset is negative")
197
+ if n < offset:
198
+ raise ValueError("buffer length < offset")
199
+ if size is None:
200
+ size = n - offset
201
+ elif size < 0:
202
+ raise ValueError("size is negative")
203
+ elif offset + size > n:
204
+ raise ValueError("buffer length < offset + size")
205
+ self._send_bytes(m[offset:offset + size])
206
+
207
+ def send(self, obj):
208
+ """Send a (picklable) object"""
209
+ self._check_closed()
210
+ self._check_writable()
211
+ self._send_bytes(_ForkingPickler.dumps(obj))
212
+
213
+ def recv_bytes(self, maxlength=None):
214
+ """
215
+ Receive bytes data as a bytes object.
216
+ """
217
+ self._check_closed()
218
+ self._check_readable()
219
+ if maxlength is not None and maxlength < 0:
220
+ raise ValueError("negative maxlength")
221
+ buf = self._recv_bytes(maxlength)
222
+ if buf is None:
223
+ self._bad_message_length()
224
+ return buf.getvalue()
225
+
226
+ def recv_bytes_into(self, buf, offset=0):
227
+ """
228
+ Receive bytes data into a writeable bytes-like object.
229
+ Return the number of bytes read.
230
+ """
231
+ self._check_closed()
232
+ self._check_readable()
233
+ with memoryview(buf) as m:
234
+ # Get bytesize of arbitrary buffer
235
+ itemsize = m.itemsize
236
+ bytesize = itemsize * len(m)
237
+ if offset < 0:
238
+ raise ValueError("negative offset")
239
+ elif offset > bytesize:
240
+ raise ValueError("offset too large")
241
+ result = self._recv_bytes()
242
+ size = result.tell()
243
+ if bytesize < offset + size:
244
+ raise BufferTooShort(result.getvalue())
245
+ # Message can fit in dest
246
+ result.seek(0)
247
+ result.readinto(m[offset // itemsize :
248
+ (offset + size) // itemsize])
249
+ return size
250
+
251
+ def recv(self):
252
+ """Receive a (picklable) object"""
253
+ self._check_closed()
254
+ self._check_readable()
255
+ buf = self._recv_bytes()
256
+ return _ForkingPickler.loads(buf.getbuffer())
257
+
258
+ def poll(self, timeout=0.0):
259
+ """Whether there is any input available to be read"""
260
+ self._check_closed()
261
+ self._check_readable()
262
+ return self._poll(timeout)
263
+
264
+ def __enter__(self):
265
+ return self
266
+
267
+ def __exit__(self, exc_type, exc_value, exc_tb):
268
+ self.close()
269
+
270
+
271
+ if _winapi:
272
+
273
+ class PipeConnection(_ConnectionBase):
274
+ """
275
+ Connection class based on a Windows named pipe.
276
+ Overlapped I/O is used, so the handles must have been created
277
+ with FILE_FLAG_OVERLAPPED.
278
+ """
279
+ _got_empty_message = False
280
+ _send_ov = None
281
+
282
+ def _close(self, _CloseHandle=_winapi.CloseHandle):
283
+ ov = self._send_ov
284
+ if ov is not None:
285
+ # Interrupt WaitForMultipleObjects() in _send_bytes()
286
+ ov.cancel()
287
+ _CloseHandle(self._handle)
288
+
289
+ def _send_bytes(self, buf):
290
+ if self._send_ov is not None:
291
+ # A connection should only be used by a single thread
292
+ raise ValueError("concurrent send_bytes() calls "
293
+ "are not supported")
294
+ ov, err = _winapi.WriteFile(self._handle, buf, overlapped=True)
295
+ self._send_ov = ov
296
+ try:
297
+ if err == _winapi.ERROR_IO_PENDING:
298
+ waitres = _winapi.WaitForMultipleObjects(
299
+ [ov.event], False, INFINITE)
300
+ assert waitres == WAIT_OBJECT_0
301
+ except:
302
+ ov.cancel()
303
+ raise
304
+ finally:
305
+ self._send_ov = None
306
+ nwritten, err = ov.GetOverlappedResult(True)
307
+ if err == _winapi.ERROR_OPERATION_ABORTED:
308
+ # close() was called by another thread while
309
+ # WaitForMultipleObjects() was waiting for the overlapped
310
+ # operation.
311
+ raise OSError(errno.EPIPE, "handle is closed")
312
+ assert err == 0
313
+ assert nwritten == len(buf)
314
+
315
+ def _recv_bytes(self, maxsize=None):
316
+ if self._got_empty_message:
317
+ self._got_empty_message = False
318
+ return io.BytesIO()
319
+ else:
320
+ bsize = 128 if maxsize is None else min(maxsize, 128)
321
+ try:
322
+ ov, err = _winapi.ReadFile(self._handle, bsize,
323
+ overlapped=True)
324
+ try:
325
+ if err == _winapi.ERROR_IO_PENDING:
326
+ waitres = _winapi.WaitForMultipleObjects(
327
+ [ov.event], False, INFINITE)
328
+ assert waitres == WAIT_OBJECT_0
329
+ except:
330
+ ov.cancel()
331
+ raise
332
+ finally:
333
+ nread, err = ov.GetOverlappedResult(True)
334
+ if err == 0:
335
+ f = io.BytesIO()
336
+ f.write(ov.getbuffer())
337
+ return f
338
+ elif err == _winapi.ERROR_MORE_DATA:
339
+ return self._get_more_data(ov, maxsize)
340
+ except OSError as e:
341
+ if e.winerror == _winapi.ERROR_BROKEN_PIPE:
342
+ raise EOFError
343
+ else:
344
+ raise
345
+ raise RuntimeError("shouldn't get here; expected KeyboardInterrupt")
346
+
347
+ def _poll(self, timeout):
348
+ if (self._got_empty_message or
349
+ _winapi.PeekNamedPipe(self._handle)[0] != 0):
350
+ return True
351
+ return bool(wait([self], timeout))
352
+
353
+ def _get_more_data(self, ov, maxsize):
354
+ buf = ov.getbuffer()
355
+ f = io.BytesIO()
356
+ f.write(buf)
357
+ left = _winapi.PeekNamedPipe(self._handle)[1]
358
+ assert left > 0
359
+ if maxsize is not None and len(buf) + left > maxsize:
360
+ self._bad_message_length()
361
+ ov, err = _winapi.ReadFile(self._handle, left, overlapped=True)
362
+ rbytes, err = ov.GetOverlappedResult(True)
363
+ assert err == 0
364
+ assert rbytes == left
365
+ f.write(ov.getbuffer())
366
+ return f
367
+
368
+
369
+ class Connection(_ConnectionBase):
370
+ """
371
+ Connection class based on an arbitrary file descriptor (Unix only), or
372
+ a socket handle (Windows).
373
+ """
374
+
375
+ if _winapi:
376
+ def _close(self, _close=_multiprocessing.closesocket):
377
+ _close(self._handle)
378
+ _write = _multiprocessing.send
379
+ _read = _multiprocessing.recv
380
+ else:
381
+ def _close(self, _close=os.close):
382
+ _close(self._handle)
383
+ _write = os.write
384
+ _read = os.read
385
+
386
+ def _send(self, buf, write=_write):
387
+ remaining = len(buf)
388
+ while True:
389
+ n = write(self._handle, buf)
390
+ remaining -= n
391
+ if remaining == 0:
392
+ break
393
+ buf = buf[n:]
394
+
395
+ def _recv(self, size, read=_read):
396
+ buf = io.BytesIO()
397
+ handle = self._handle
398
+ remaining = size
399
+ while remaining > 0:
400
+ chunk = read(handle, remaining)
401
+ n = len(chunk)
402
+ if n == 0:
403
+ if remaining == size:
404
+ raise EOFError
405
+ else:
406
+ raise OSError("got end of file during message")
407
+ buf.write(chunk)
408
+ remaining -= n
409
+ return buf
410
+
411
+ def _send_bytes(self, buf):
412
+ n = len(buf)
413
+ if n > 0x7fffffff:
414
+ pre_header = struct.pack("!i", -1)
415
+ header = struct.pack("!Q", n)
416
+ self._send(pre_header)
417
+ self._send(header)
418
+ self._send(buf)
419
+ else:
420
+ # For wire compatibility with 3.7 and lower
421
+ header = struct.pack("!i", n)
422
+ if n > 16384:
423
+ # The payload is large so Nagle's algorithm won't be triggered
424
+ # and we'd better avoid the cost of concatenation.
425
+ self._send(header)
426
+ self._send(buf)
427
+ else:
428
+ # Issue #20540: concatenate before sending, to avoid delays due
429
+ # to Nagle's algorithm on a TCP socket.
430
+ # Also note we want to avoid sending a 0-length buffer separately,
431
+ # to avoid "broken pipe" errors if the other end closed the pipe.
432
+ self._send(header + buf)
433
+
434
+ def _recv_bytes(self, maxsize=None):
435
+ buf = self._recv(4)
436
+ size, = struct.unpack("!i", buf.getvalue())
437
+ if size == -1:
438
+ buf = self._recv(8)
439
+ size, = struct.unpack("!Q", buf.getvalue())
440
+ if maxsize is not None and size > maxsize:
441
+ return None
442
+ return self._recv(size)
443
+
444
+ def _poll(self, timeout):
445
+ r = wait([self], timeout)
446
+ return bool(r)
447
+
448
+
449
+ #
450
+ # Public functions
451
+ #
452
+
453
+ class Listener(object):
454
+ '''
455
+ Returns a listener object.
456
+
457
+ This is a wrapper for a bound socket which is 'listening' for
458
+ connections, or for a Windows named pipe.
459
+ '''
460
+ def __init__(self, address=None, family=None, backlog=1, authkey=None):
461
+ family = family or (address and address_type(address)) \
462
+ or default_family
463
+ _validate_family(family)
464
+ if authkey is not None and not isinstance(authkey, bytes):
465
+ raise TypeError('authkey should be a byte string')
466
+
467
+ if family == 'AF_PIPE':
468
+ if address:
469
+ self._listener = PipeListener(address, backlog)
470
+ else:
471
+ for attempts in itertools.count():
472
+ address = arbitrary_address(family)
473
+ try:
474
+ self._listener = PipeListener(address, backlog)
475
+ break
476
+ except OSError as e:
477
+ if attempts >= _MAX_PIPE_ATTEMPTS:
478
+ raise
479
+ if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
480
+ _winapi.ERROR_ACCESS_DENIED):
481
+ raise
482
+ else:
483
+ address = address or arbitrary_address(family)
484
+ self._listener = SocketListener(address, family, backlog)
485
+
486
+ self._authkey = authkey
487
+
488
+ def accept(self):
489
+ '''
490
+ Accept a connection on the bound socket or named pipe of `self`.
491
+
492
+ Returns a `Connection` object.
493
+ '''
494
+ if self._listener is None:
495
+ raise OSError('listener is closed')
496
+
497
+ c = self._listener.accept()
498
+ if self._authkey is not None:
499
+ deliver_challenge(c, self._authkey)
500
+ answer_challenge(c, self._authkey)
501
+ return c
502
+
503
+ def close(self):
504
+ '''
505
+ Close the bound socket or named pipe of `self`.
506
+ '''
507
+ listener = self._listener
508
+ if listener is not None:
509
+ self._listener = None
510
+ listener.close()
511
+
512
+ @property
513
+ def address(self):
514
+ return self._listener._address
515
+
516
+ @property
517
+ def last_accepted(self):
518
+ return self._listener._last_accepted
519
+
520
+ def __enter__(self):
521
+ return self
522
+
523
+ def __exit__(self, exc_type, exc_value, exc_tb):
524
+ self.close()
525
+
526
+
527
+ def Client(address, family=None, authkey=None):
528
+ '''
529
+ Returns a connection to the address of a `Listener`
530
+ '''
531
+ family = family or address_type(address)
532
+ _validate_family(family)
533
+ if family == 'AF_PIPE':
534
+ c = PipeClient(address)
535
+ else:
536
+ c = SocketClient(address)
537
+
538
+ if authkey is not None and not isinstance(authkey, bytes):
539
+ raise TypeError('authkey should be a byte string')
540
+
541
+ if authkey is not None:
542
+ answer_challenge(c, authkey)
543
+ deliver_challenge(c, authkey)
544
+
545
+ return c
546
+
547
+
548
+ if sys.platform != 'win32':
549
+
550
+ def Pipe(duplex=True):
551
+ '''
552
+ Returns pair of connection objects at either end of a pipe
553
+ '''
554
+ if duplex:
555
+ s1, s2 = socket.socketpair()
556
+ s1.setblocking(True)
557
+ s2.setblocking(True)
558
+ c1 = Connection(s1.detach())
559
+ c2 = Connection(s2.detach())
560
+ else:
561
+ fd1, fd2 = os.pipe()
562
+ c1 = Connection(fd1, writable=False)
563
+ c2 = Connection(fd2, readable=False)
564
+
565
+ return c1, c2
566
+
567
+ else:
568
+
569
+ def Pipe(duplex=True):
570
+ '''
571
+ Returns pair of connection objects at either end of a pipe
572
+ '''
573
+ if duplex:
574
+ openmode = _winapi.PIPE_ACCESS_DUPLEX
575
+ access = _winapi.GENERIC_READ | _winapi.GENERIC_WRITE
576
+ obsize, ibsize = BUFSIZE, BUFSIZE
577
+ else:
578
+ openmode = _winapi.PIPE_ACCESS_INBOUND
579
+ access = _winapi.GENERIC_WRITE
580
+ obsize, ibsize = 0, BUFSIZE
581
+
582
+ for attempts in itertools.count():
583
+ address = arbitrary_address('AF_PIPE')
584
+ try:
585
+ h1 = _winapi.CreateNamedPipe(
586
+ address, openmode | _winapi.FILE_FLAG_OVERLAPPED |
587
+ _winapi.FILE_FLAG_FIRST_PIPE_INSTANCE,
588
+ _winapi.PIPE_TYPE_MESSAGE | _winapi.PIPE_READMODE_MESSAGE |
589
+ _winapi.PIPE_WAIT,
590
+ 1, obsize, ibsize, _winapi.NMPWAIT_WAIT_FOREVER,
591
+ # default security descriptor: the handle cannot be inherited
592
+ _winapi.NULL
593
+ )
594
+ break
595
+ except OSError as e:
596
+ if attempts >= _MAX_PIPE_ATTEMPTS:
597
+ raise
598
+ if e.winerror not in (_winapi.ERROR_PIPE_BUSY,
599
+ _winapi.ERROR_ACCESS_DENIED):
600
+ raise
601
+ h2 = _winapi.CreateFile(
602
+ address, access, 0, _winapi.NULL, _winapi.OPEN_EXISTING,
603
+ _winapi.FILE_FLAG_OVERLAPPED, _winapi.NULL
604
+ )
605
+ _winapi.SetNamedPipeHandleState(
606
+ h2, _winapi.PIPE_READMODE_MESSAGE, None, None
607
+ )
608
+
609
+ overlapped = _winapi.ConnectNamedPipe(h1, overlapped=True)
610
+ _, err = overlapped.GetOverlappedResult(True)
611
+ assert err == 0
612
+
613
+ c1 = PipeConnection(h1, writable=duplex)
614
+ c2 = PipeConnection(h2, readable=duplex)
615
+
616
+ return c1, c2
617
+
618
+ #
619
+ # Definitions for connections based on sockets
620
+ #
621
+
622
+ class SocketListener(object):
623
+ '''
624
+ Representation of a socket which is bound to an address and listening
625
+ '''
626
+ def __init__(self, address, family, backlog=1):
627
+ self._socket = socket.socket(getattr(socket, family))
628
+ try:
629
+ # SO_REUSEADDR has different semantics on Windows (issue #2550).
630
+ if os.name == 'posix':
631
+ self._socket.setsockopt(socket.SOL_SOCKET,
632
+ socket.SO_REUSEADDR, 1)
633
+ self._socket.setblocking(True)
634
+ self._socket.bind(address)
635
+ self._socket.listen(backlog)
636
+ self._address = self._socket.getsockname()
637
+ except OSError:
638
+ self._socket.close()
639
+ raise
640
+ self._family = family
641
+ self._last_accepted = None
642
+
643
+ if family == 'AF_UNIX' and not util.is_abstract_socket_namespace(address):
644
+ # Linux abstract socket namespaces do not need to be explicitly unlinked
645
+ self._unlink = util.Finalize(
646
+ self, os.unlink, args=(address,), exitpriority=0
647
+ )
648
+ else:
649
+ self._unlink = None
650
+
651
+ def accept(self):
652
+ s, self._last_accepted = self._socket.accept()
653
+ s.setblocking(True)
654
+ return Connection(s.detach())
655
+
656
+ def close(self):
657
+ try:
658
+ self._socket.close()
659
+ finally:
660
+ unlink = self._unlink
661
+ if unlink is not None:
662
+ self._unlink = None
663
+ unlink()
664
+
665
+
666
+ def SocketClient(address):
667
+ '''
668
+ Return a connection object connected to the socket given by `address`
669
+ '''
670
+ family = address_type(address)
671
+ with socket.socket( getattr(socket, family) ) as s:
672
+ s.setblocking(True)
673
+ s.connect(address)
674
+ return Connection(s.detach())
675
+
676
+ #
677
+ # Definitions for connections based on named pipes
678
+ #
679
+
680
+ if sys.platform == 'win32':
681
+
682
+ class PipeListener(object):
683
+ '''
684
+ Representation of a named pipe
685
+ '''
686
+ def __init__(self, address, backlog=None):
687
+ self._address = address
688
+ self._handle_queue = [self._new_handle(first=True)]
689
+
690
+ self._last_accepted = None
691
+ util.sub_debug('listener created with address=%r', self._address)
692
+ self.close = util.Finalize(
693
+ self, PipeListener._finalize_pipe_listener,
694
+ args=(self._handle_queue, self._address), exitpriority=0
695
+ )
696
+
697
+ def _new_handle(self, first=False):
698
+ flags = _winapi.PIPE_ACCESS_DUPLEX | _winapi.FILE_FLAG_OVERLAPPED
699
+ if first:
700
+ flags |= _winapi.FILE_FLAG_FIRST_PIPE_INSTANCE
701
+ return _winapi.CreateNamedPipe(
702
+ self._address, flags,
703
+ _winapi.PIPE_TYPE_MESSAGE | _winapi.PIPE_READMODE_MESSAGE |
704
+ _winapi.PIPE_WAIT,
705
+ _winapi.PIPE_UNLIMITED_INSTANCES, BUFSIZE, BUFSIZE,
706
+ _winapi.NMPWAIT_WAIT_FOREVER, _winapi.NULL
707
+ )
708
+
709
+ def accept(self):
710
+ self._handle_queue.append(self._new_handle())
711
+ handle = self._handle_queue.pop(0)
712
+ try:
713
+ ov = _winapi.ConnectNamedPipe(handle, overlapped=True)
714
+ except OSError as e:
715
+ if e.winerror != _winapi.ERROR_NO_DATA:
716
+ raise
717
+ # ERROR_NO_DATA can occur if a client has already connected,
718
+ # written data and then disconnected -- see Issue 14725.
719
+ else:
720
+ try:
721
+ res = _winapi.WaitForMultipleObjects(
722
+ [ov.event], False, INFINITE)
723
+ except:
724
+ ov.cancel()
725
+ _winapi.CloseHandle(handle)
726
+ raise
727
+ finally:
728
+ _, err = ov.GetOverlappedResult(True)
729
+ assert err == 0
730
+ return PipeConnection(handle)
731
+
732
+ @staticmethod
733
+ def _finalize_pipe_listener(queue, address):
734
+ util.sub_debug('closing listener with address=%r', address)
735
+ for handle in queue:
736
+ _winapi.CloseHandle(handle)
737
+
738
+ def PipeClient(address):
739
+ '''
740
+ Return a connection object connected to the pipe given by `address`
741
+ '''
742
+ t = _init_timeout()
743
+ while 1:
744
+ try:
745
+ _winapi.WaitNamedPipe(address, 1000)
746
+ h = _winapi.CreateFile(
747
+ address, _winapi.GENERIC_READ | _winapi.GENERIC_WRITE,
748
+ 0, _winapi.NULL, _winapi.OPEN_EXISTING,
749
+ _winapi.FILE_FLAG_OVERLAPPED, _winapi.NULL
750
+ )
751
+ except OSError as e:
752
+ if e.winerror not in (_winapi.ERROR_SEM_TIMEOUT,
753
+ _winapi.ERROR_PIPE_BUSY) or _check_timeout(t):
754
+ raise
755
+ else:
756
+ break
757
+ else:
758
+ raise
759
+
760
+ _winapi.SetNamedPipeHandleState(
761
+ h, _winapi.PIPE_READMODE_MESSAGE, None, None
762
+ )
763
+ return PipeConnection(h)
764
+
765
+ #
766
+ # Authentication stuff
767
+ #
768
+
769
+ MESSAGE_LENGTH = 40 # MUST be > 20
770
+
771
+ _CHALLENGE = b'#CHALLENGE#'
772
+ _WELCOME = b'#WELCOME#'
773
+ _FAILURE = b'#FAILURE#'
774
+
775
+ # multiprocessing.connection Authentication Handshake Protocol Description
776
+ # (as documented for reference after reading the existing code)
777
+ # =============================================================================
778
+ #
779
+ # On Windows: native pipes with "overlapped IO" are used to send the bytes,
780
+ # instead of the length prefix SIZE scheme described below. (ie: the OS deals
781
+ # with message sizes for us)
782
+ #
783
+ # Protocol error behaviors:
784
+ #
785
+ # On POSIX, any failure to receive the length prefix into SIZE, for SIZE greater
786
+ # than the requested maxsize to receive, or receiving fewer than SIZE bytes
787
+ # results in the connection being closed and auth to fail.
788
+ #
789
+ # On Windows, receiving too few bytes is never a low level _recv_bytes read
790
+ # error, receiving too many will trigger an error only if receive maxsize
791
+ # value was larger than 128 OR the if the data arrived in smaller pieces.
792
+ #
793
+ # Serving side Client side
794
+ # ------------------------------ ---------------------------------------
795
+ # 0. Open a connection on the pipe.
796
+ # 1. Accept connection.
797
+ # 2. Random 20+ bytes -> MESSAGE
798
+ # Modern servers always send
799
+ # more than 20 bytes and include
800
+ # a {digest} prefix on it with
801
+ # their preferred HMAC digest.
802
+ # Legacy ones send ==20 bytes.
803
+ # 3. send 4 byte length (net order)
804
+ # prefix followed by:
805
+ # b'#CHALLENGE#' + MESSAGE
806
+ # 4. Receive 4 bytes, parse as network byte
807
+ # order integer. If it is -1, receive an
808
+ # additional 8 bytes, parse that as network
809
+ # byte order. The result is the length of
810
+ # the data that follows -> SIZE.
811
+ # 5. Receive min(SIZE, 256) bytes -> M1
812
+ # 6. Assert that M1 starts with:
813
+ # b'#CHALLENGE#'
814
+ # 7. Strip that prefix from M1 into -> M2
815
+ # 7.1. Parse M2: if it is exactly 20 bytes in
816
+ # length this indicates a legacy server
817
+ # supporting only HMAC-MD5. Otherwise the
818
+ # 7.2. preferred digest is looked up from an
819
+ # expected "{digest}" prefix on M2. No prefix
820
+ # or unsupported digest? <- AuthenticationError
821
+ # 7.3. Put divined algorithm name in -> D_NAME
822
+ # 8. Compute HMAC-D_NAME of AUTHKEY, M2 -> C_DIGEST
823
+ # 9. Send 4 byte length prefix (net order)
824
+ # followed by C_DIGEST bytes.
825
+ # 10. Receive 4 or 4+8 byte length
826
+ # prefix (#4 dance) -> SIZE.
827
+ # 11. Receive min(SIZE, 256) -> C_D.
828
+ # 11.1. Parse C_D: legacy servers
829
+ # accept it as is, "md5" -> D_NAME
830
+ # 11.2. modern servers check the length
831
+ # of C_D, IF it is 16 bytes?
832
+ # 11.2.1. "md5" -> D_NAME
833
+ # and skip to step 12.
834
+ # 11.3. longer? expect and parse a "{digest}"
835
+ # prefix into -> D_NAME.
836
+ # Strip the prefix and store remaining
837
+ # bytes in -> C_D.
838
+ # 11.4. Don't like D_NAME? <- AuthenticationError
839
+ # 12. Compute HMAC-D_NAME of AUTHKEY,
840
+ # MESSAGE into -> M_DIGEST.
841
+ # 13. Compare M_DIGEST == C_D:
842
+ # 14a: Match? Send length prefix &
843
+ # b'#WELCOME#'
844
+ # <- RETURN
845
+ # 14b: Mismatch? Send len prefix &
846
+ # b'#FAILURE#'
847
+ # <- CLOSE & AuthenticationError
848
+ # 15. Receive 4 or 4+8 byte length prefix (net
849
+ # order) again as in #4 into -> SIZE.
850
+ # 16. Receive min(SIZE, 256) bytes -> M3.
851
+ # 17. Compare M3 == b'#WELCOME#':
852
+ # 17a. Match? <- RETURN
853
+ # 17b. Mismatch? <- CLOSE & AuthenticationError
854
+ #
855
+ # If this RETURNed, the connection remains open: it has been authenticated.
856
+ #
857
+ # Length prefixes are used consistently. Even on the legacy protocol, this
858
+ # was good fortune and allowed us to evolve the protocol by using the length
859
+ # of the opening challenge or length of the returned digest as a signal as
860
+ # to which protocol the other end supports.
861
+
862
+ _ALLOWED_DIGESTS = frozenset(
863
+ {b'md5', b'sha256', b'sha384', b'sha3_256', b'sha3_384'})
864
+ _MAX_DIGEST_LEN = max(len(_) for _ in _ALLOWED_DIGESTS)
865
+
866
+ # Old hmac-md5 only server versions from Python <=3.11 sent a message of this
867
+ # length. It happens to not match the length of any supported digest so we can
868
+ # use a message of this length to indicate that we should work in backwards
869
+ # compatible md5-only mode without a {digest_name} prefix on our response.
870
+ _MD5ONLY_MESSAGE_LENGTH = 20
871
+ _MD5_DIGEST_LEN = 16
872
+ _LEGACY_LENGTHS = (_MD5ONLY_MESSAGE_LENGTH, _MD5_DIGEST_LEN)
873
+
874
+
875
+ def _get_digest_name_and_payload(message): # type: (bytes) -> tuple[str, bytes]
876
+ """Returns a digest name and the payload for a response hash.
877
+
878
+ If a legacy protocol is detected based on the message length
879
+ or contents the digest name returned will be empty to indicate
880
+ legacy mode where MD5 and no digest prefix should be sent.
881
+ """
882
+ # modern message format: b"{digest}payload" longer than 20 bytes
883
+ # legacy message format: 16 or 20 byte b"payload"
884
+ if len(message) in _LEGACY_LENGTHS:
885
+ # Either this was a legacy server challenge, or we're processing
886
+ # a reply from a legacy client that sent an unprefixed 16-byte
887
+ # HMAC-MD5 response. All messages using the modern protocol will
888
+ # be longer than either of these lengths.
889
+ return '', message
890
+ if (message.startswith(b'{') and
891
+ (curly := message.find(b'}', 1, _MAX_DIGEST_LEN+2)) > 0):
892
+ digest = message[1:curly]
893
+ if digest in _ALLOWED_DIGESTS:
894
+ payload = message[curly+1:]
895
+ return digest.decode('ascii'), payload
896
+ raise AuthenticationError(
897
+ 'unsupported message length, missing digest prefix, '
898
+ f'or unsupported digest: {message=}')
899
+
900
+
901
+ def _create_response(authkey, message):
902
+ """Create a MAC based on authkey and message
903
+
904
+ The MAC algorithm defaults to HMAC-MD5, unless MD5 is not available or
905
+ the message has a '{digest_name}' prefix. For legacy HMAC-MD5, the response
906
+ is the raw MAC, otherwise the response is prefixed with '{digest_name}',
907
+ e.g. b'{sha256}abcdefg...'
908
+
909
+ Note: The MAC protects the entire message including the digest_name prefix.
910
+ """
911
+ import hmac
912
+ digest_name = _get_digest_name_and_payload(message)[0]
913
+ # The MAC protects the entire message: digest header and payload.
914
+ if not digest_name:
915
+ # Legacy server without a {digest} prefix on message.
916
+ # Generate a legacy non-prefixed HMAC-MD5 reply.
917
+ try:
918
+ return hmac.new(authkey, message, 'md5').digest()
919
+ except ValueError:
920
+ # HMAC-MD5 is not available (FIPS mode?), fall back to
921
+ # HMAC-SHA2-256 modern protocol. The legacy server probably
922
+ # doesn't support it and will reject us anyways. :shrug:
923
+ digest_name = 'sha256'
924
+ # Modern protocol, indicate the digest used in the reply.
925
+ response = hmac.new(authkey, message, digest_name).digest()
926
+ return b'{%s}%s' % (digest_name.encode('ascii'), response)
927
+
928
+
929
+ def _verify_challenge(authkey, message, response):
930
+ """Verify MAC challenge
931
+
932
+ If our message did not include a digest_name prefix, the client is allowed
933
+ to select a stronger digest_name from _ALLOWED_DIGESTS.
934
+
935
+ In case our message is prefixed, a client cannot downgrade to a weaker
936
+ algorithm, because the MAC is calculated over the entire message
937
+ including the '{digest_name}' prefix.
938
+ """
939
+ import hmac
940
+ response_digest, response_mac = _get_digest_name_and_payload(response)
941
+ response_digest = response_digest or 'md5'
942
+ try:
943
+ expected = hmac.new(authkey, message, response_digest).digest()
944
+ except ValueError:
945
+ raise AuthenticationError(f'{response_digest=} unsupported')
946
+ if len(expected) != len(response_mac):
947
+ raise AuthenticationError(
948
+ f'expected {response_digest!r} of length {len(expected)} '
949
+ f'got {len(response_mac)}')
950
+ if not hmac.compare_digest(expected, response_mac):
951
+ raise AuthenticationError('digest received was wrong')
952
+
953
+
954
+ def deliver_challenge(connection, authkey: bytes, digest_name='sha256'):
955
+ if not isinstance(authkey, bytes):
956
+ raise ValueError(
957
+ "Authkey must be bytes, not {0!s}".format(type(authkey)))
958
+ assert MESSAGE_LENGTH > _MD5ONLY_MESSAGE_LENGTH, "protocol constraint"
959
+ message = os.urandom(MESSAGE_LENGTH)
960
+ message = b'{%s}%s' % (digest_name.encode('ascii'), message)
961
+ # Even when sending a challenge to a legacy client that does not support
962
+ # digest prefixes, they'll take the entire thing as a challenge and
963
+ # respond to it with a raw HMAC-MD5.
964
+ connection.send_bytes(_CHALLENGE + message)
965
+ response = connection.recv_bytes(256) # reject large message
966
+ try:
967
+ _verify_challenge(authkey, message, response)
968
+ except AuthenticationError:
969
+ connection.send_bytes(_FAILURE)
970
+ raise
971
+ else:
972
+ connection.send_bytes(_WELCOME)
973
+
974
+
975
+ def answer_challenge(connection, authkey: bytes):
976
+ if not isinstance(authkey, bytes):
977
+ raise ValueError(
978
+ "Authkey must be bytes, not {0!s}".format(type(authkey)))
979
+ message = connection.recv_bytes(256) # reject large message
980
+ if not message.startswith(_CHALLENGE):
981
+ raise AuthenticationError(
982
+ f'Protocol error, expected challenge: {message=}')
983
+ message = message[len(_CHALLENGE):]
984
+ if len(message) < _MD5ONLY_MESSAGE_LENGTH:
985
+ raise AuthenticationError(f'challenge too short: {len(message)} bytes')
986
+ digest = _create_response(authkey, message)
987
+ connection.send_bytes(digest)
988
+ response = connection.recv_bytes(256) # reject large message
989
+ if response != _WELCOME:
990
+ raise AuthenticationError('digest sent was rejected')
991
+
992
+ #
993
+ # Support for using xmlrpclib for serialization
994
+ #
995
+
996
+ class ConnectionWrapper(object):
997
+ def __init__(self, conn, dumps, loads):
998
+ self._conn = conn
999
+ self._dumps = dumps
1000
+ self._loads = loads
1001
+ for attr in ('fileno', 'close', 'poll', 'recv_bytes', 'send_bytes'):
1002
+ obj = getattr(conn, attr)
1003
+ setattr(self, attr, obj)
1004
+ def send(self, obj):
1005
+ s = self._dumps(obj)
1006
+ self._conn.send_bytes(s)
1007
+ def recv(self):
1008
+ s = self._conn.recv_bytes()
1009
+ return self._loads(s)
1010
+
1011
+ def _xml_dumps(obj):
1012
+ return xmlrpclib.dumps((obj,), None, None, None, 1).encode('utf-8')
1013
+
1014
+ def _xml_loads(s):
1015
+ (obj,), method = xmlrpclib.loads(s.decode('utf-8'))
1016
+ return obj
1017
+
1018
+ class XmlListener(Listener):
1019
+ def accept(self):
1020
+ global xmlrpclib
1021
+ import xmlrpc.client as xmlrpclib
1022
+ obj = Listener.accept(self)
1023
+ return ConnectionWrapper(obj, _xml_dumps, _xml_loads)
1024
+
1025
+ def XmlClient(*args, **kwds):
1026
+ global xmlrpclib
1027
+ import xmlrpc.client as xmlrpclib
1028
+ return ConnectionWrapper(Client(*args, **kwds), _xml_dumps, _xml_loads)
1029
+
1030
+ #
1031
+ # Wait
1032
+ #
1033
+
1034
+ if sys.platform == 'win32':
1035
+
1036
+ def _exhaustive_wait(handles, timeout):
1037
+ # Return ALL handles which are currently signalled. (Only
1038
+ # returning the first signalled might create starvation issues.)
1039
+ L = list(handles)
1040
+ ready = []
1041
+ # Windows limits WaitForMultipleObjects at 64 handles, and we use a
1042
+ # few for synchronisation, so we switch to batched waits at 60.
1043
+ if len(L) > 60:
1044
+ try:
1045
+ res = _winapi.BatchedWaitForMultipleObjects(L, False, timeout)
1046
+ except TimeoutError:
1047
+ return []
1048
+ ready.extend(L[i] for i in res)
1049
+ if res:
1050
+ L = [h for i, h in enumerate(L) if i > res[0] & i not in res]
1051
+ timeout = 0
1052
+ while L:
1053
+ short_L = L[:60] if len(L) > 60 else L
1054
+ res = _winapi.WaitForMultipleObjects(short_L, False, timeout)
1055
+ if res == WAIT_TIMEOUT:
1056
+ break
1057
+ elif WAIT_OBJECT_0 <= res < WAIT_OBJECT_0 + len(L):
1058
+ res -= WAIT_OBJECT_0
1059
+ elif WAIT_ABANDONED_0 <= res < WAIT_ABANDONED_0 + len(L):
1060
+ res -= WAIT_ABANDONED_0
1061
+ else:
1062
+ raise RuntimeError('Should not get here')
1063
+ ready.append(L[res])
1064
+ L = L[res+1:]
1065
+ timeout = 0
1066
+ return ready
1067
+
1068
+ _ready_errors = {_winapi.ERROR_BROKEN_PIPE, _winapi.ERROR_NETNAME_DELETED}
1069
+
1070
+ def wait(object_list, timeout=None):
1071
+ '''
1072
+ Wait till an object in object_list is ready/readable.
1073
+
1074
+ Returns list of those objects in object_list which are ready/readable.
1075
+ '''
1076
+ if timeout is None:
1077
+ timeout = INFINITE
1078
+ elif timeout < 0:
1079
+ timeout = 0
1080
+ else:
1081
+ timeout = int(timeout * 1000 + 0.5)
1082
+
1083
+ object_list = list(object_list)
1084
+ waithandle_to_obj = {}
1085
+ ov_list = []
1086
+ ready_objects = set()
1087
+ ready_handles = set()
1088
+
1089
+ try:
1090
+ for o in object_list:
1091
+ try:
1092
+ fileno = getattr(o, 'fileno')
1093
+ except AttributeError:
1094
+ waithandle_to_obj[o.__index__()] = o
1095
+ else:
1096
+ # start an overlapped read of length zero
1097
+ try:
1098
+ ov, err = _winapi.ReadFile(fileno(), 0, True)
1099
+ except OSError as e:
1100
+ ov, err = None, e.winerror
1101
+ if err not in _ready_errors:
1102
+ raise
1103
+ if err == _winapi.ERROR_IO_PENDING:
1104
+ ov_list.append(ov)
1105
+ waithandle_to_obj[ov.event] = o
1106
+ else:
1107
+ # If o.fileno() is an overlapped pipe handle and
1108
+ # err == 0 then there is a zero length message
1109
+ # in the pipe, but it HAS NOT been consumed...
1110
+ if ov and sys.getwindowsversion()[:2] >= (6, 2):
1111
+ # ... except on Windows 8 and later, where
1112
+ # the message HAS been consumed.
1113
+ try:
1114
+ _, err = ov.GetOverlappedResult(False)
1115
+ except OSError as e:
1116
+ err = e.winerror
1117
+ if not err and hasattr(o, '_got_empty_message'):
1118
+ o._got_empty_message = True
1119
+ ready_objects.add(o)
1120
+ timeout = 0
1121
+
1122
+ ready_handles = _exhaustive_wait(waithandle_to_obj.keys(), timeout)
1123
+ finally:
1124
+ # request that overlapped reads stop
1125
+ for ov in ov_list:
1126
+ ov.cancel()
1127
+
1128
+ # wait for all overlapped reads to stop
1129
+ for ov in ov_list:
1130
+ try:
1131
+ _, err = ov.GetOverlappedResult(True)
1132
+ except OSError as e:
1133
+ err = e.winerror
1134
+ if err not in _ready_errors:
1135
+ raise
1136
+ if err != _winapi.ERROR_OPERATION_ABORTED:
1137
+ o = waithandle_to_obj[ov.event]
1138
+ ready_objects.add(o)
1139
+ if err == 0:
1140
+ # If o.fileno() is an overlapped pipe handle then
1141
+ # a zero length message HAS been consumed.
1142
+ if hasattr(o, '_got_empty_message'):
1143
+ o._got_empty_message = True
1144
+
1145
+ ready_objects.update(waithandle_to_obj[h] for h in ready_handles)
1146
+ return [o for o in object_list if o in ready_objects]
1147
+
1148
+ else:
1149
+
1150
+ import selectors
1151
+
1152
+ # poll/select have the advantage of not requiring any extra file
1153
+ # descriptor, contrarily to epoll/kqueue (also, they require a single
1154
+ # syscall).
1155
+ if hasattr(selectors, 'PollSelector'):
1156
+ _WaitSelector = selectors.PollSelector
1157
+ else:
1158
+ _WaitSelector = selectors.SelectSelector
1159
+
1160
+ def wait(object_list, timeout=None):
1161
+ '''
1162
+ Wait till an object in object_list is ready/readable.
1163
+
1164
+ Returns list of those objects in object_list which are ready/readable.
1165
+ '''
1166
+ with _WaitSelector() as selector:
1167
+ for obj in object_list:
1168
+ selector.register(obj, selectors.EVENT_READ)
1169
+
1170
+ if timeout is not None:
1171
+ deadline = time.monotonic() + timeout
1172
+
1173
+ while True:
1174
+ ready = selector.select(timeout)
1175
+ if ready:
1176
+ return [key.fileobj for (key, events) in ready]
1177
+ else:
1178
+ if timeout is not None:
1179
+ timeout = deadline - time.monotonic()
1180
+ if timeout < 0:
1181
+ return ready
1182
+
1183
+ #
1184
+ # Make connection and socket objects shareable if possible
1185
+ #
1186
+
1187
+ if sys.platform == 'win32':
1188
+ def reduce_connection(conn):
1189
+ handle = conn.fileno()
1190
+ with socket.fromfd(handle, socket.AF_INET, socket.SOCK_STREAM) as s:
1191
+ from . import resource_sharer
1192
+ ds = resource_sharer.DupSocket(s)
1193
+ return rebuild_connection, (ds, conn.readable, conn.writable)
1194
+ def rebuild_connection(ds, readable, writable):
1195
+ sock = ds.detach()
1196
+ return Connection(sock.detach(), readable, writable)
1197
+ reduction.register(Connection, reduce_connection)
1198
+
1199
+ def reduce_pipe_connection(conn):
1200
+ access = ((_winapi.FILE_GENERIC_READ if conn.readable else 0) |
1201
+ (_winapi.FILE_GENERIC_WRITE if conn.writable else 0))
1202
+ dh = reduction.DupHandle(conn.fileno(), access)
1203
+ return rebuild_pipe_connection, (dh, conn.readable, conn.writable)
1204
+ def rebuild_pipe_connection(dh, readable, writable):
1205
+ handle = dh.detach()
1206
+ return PipeConnection(handle, readable, writable)
1207
+ reduction.register(PipeConnection, reduce_pipe_connection)
1208
+
1209
+ else:
1210
+ def reduce_connection(conn):
1211
+ df = reduction.DupFd(conn.fileno())
1212
+ return rebuild_connection, (df, conn.readable, conn.writable)
1213
+ def rebuild_connection(df, readable, writable):
1214
+ fd = df.detach()
1215
+ return Connection(fd, readable, writable)
1216
+ reduction.register(Connection, reduce_connection)