@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,1397 @@
1
+ #
2
+ # Module providing manager classes for dealing
3
+ # with shared objects
4
+ #
5
+ # multiprocessing/managers.py
6
+ #
7
+ # Copyright (c) 2006-2008, R Oudkerk
8
+ # Licensed to PSF under a Contributor Agreement.
9
+ #
10
+
11
+ __all__ = [ 'BaseManager', 'SyncManager', 'BaseProxy', 'Token' ]
12
+
13
+ #
14
+ # Imports
15
+ #
16
+
17
+ import sys
18
+ import threading
19
+ import signal
20
+ import array
21
+ import queue
22
+ import time
23
+ import types
24
+ import os
25
+ from os import getpid
26
+
27
+ from traceback import format_exc
28
+
29
+ from . import connection
30
+ from .context import reduction, get_spawning_popen, ProcessError
31
+ from . import pool
32
+ from . import process
33
+ from . import util
34
+ from . import get_context
35
+ try:
36
+ from . import shared_memory
37
+ except ImportError:
38
+ HAS_SHMEM = False
39
+ else:
40
+ HAS_SHMEM = True
41
+ __all__.append('SharedMemoryManager')
42
+
43
+ #
44
+ # Register some things for pickling
45
+ #
46
+
47
+ def reduce_array(a):
48
+ return array.array, (a.typecode, a.tobytes())
49
+ reduction.register(array.array, reduce_array)
50
+
51
+ view_types = [type(getattr({}, name)()) for name in ('items','keys','values')]
52
+ def rebuild_as_list(obj):
53
+ return list, (list(obj),)
54
+ for view_type in view_types:
55
+ reduction.register(view_type, rebuild_as_list)
56
+ del view_type, view_types
57
+
58
+ #
59
+ # Type for identifying shared objects
60
+ #
61
+
62
+ class Token(object):
63
+ '''
64
+ Type to uniquely identify a shared object
65
+ '''
66
+ __slots__ = ('typeid', 'address', 'id')
67
+
68
+ def __init__(self, typeid, address, id):
69
+ (self.typeid, self.address, self.id) = (typeid, address, id)
70
+
71
+ def __getstate__(self):
72
+ return (self.typeid, self.address, self.id)
73
+
74
+ def __setstate__(self, state):
75
+ (self.typeid, self.address, self.id) = state
76
+
77
+ def __repr__(self):
78
+ return '%s(typeid=%r, address=%r, id=%r)' % \
79
+ (self.__class__.__name__, self.typeid, self.address, self.id)
80
+
81
+ #
82
+ # Function for communication with a manager's server process
83
+ #
84
+
85
+ def dispatch(c, id, methodname, args=(), kwds={}):
86
+ '''
87
+ Send a message to manager using connection `c` and return response
88
+ '''
89
+ c.send((id, methodname, args, kwds))
90
+ kind, result = c.recv()
91
+ if kind == '#RETURN':
92
+ return result
93
+ try:
94
+ raise convert_to_error(kind, result)
95
+ finally:
96
+ del result # break reference cycle
97
+
98
+ def convert_to_error(kind, result):
99
+ if kind == '#ERROR':
100
+ return result
101
+ elif kind in ('#TRACEBACK', '#UNSERIALIZABLE'):
102
+ if not isinstance(result, str):
103
+ raise TypeError(
104
+ "Result {0!r} (kind '{1}') type is {2}, not str".format(
105
+ result, kind, type(result)))
106
+ if kind == '#UNSERIALIZABLE':
107
+ return RemoteError('Unserializable message: %s\n' % result)
108
+ else:
109
+ return RemoteError(result)
110
+ else:
111
+ return ValueError('Unrecognized message type {!r}'.format(kind))
112
+
113
+ class RemoteError(Exception):
114
+ def __str__(self):
115
+ return ('\n' + '-'*75 + '\n' + str(self.args[0]) + '-'*75)
116
+
117
+ #
118
+ # Functions for finding the method names of an object
119
+ #
120
+
121
+ def all_methods(obj):
122
+ '''
123
+ Return a list of names of methods of `obj`
124
+ '''
125
+ temp = []
126
+ for name in dir(obj):
127
+ func = getattr(obj, name)
128
+ if callable(func):
129
+ temp.append(name)
130
+ return temp
131
+
132
+ def public_methods(obj):
133
+ '''
134
+ Return a list of names of methods of `obj` which do not start with '_'
135
+ '''
136
+ return [name for name in all_methods(obj) if name[0] != '_']
137
+
138
+ #
139
+ # Server which is run in a process controlled by a manager
140
+ #
141
+
142
+ class Server(object):
143
+ '''
144
+ Server class which runs in a process controlled by a manager object
145
+ '''
146
+ public = ['shutdown', 'create', 'accept_connection', 'get_methods',
147
+ 'debug_info', 'number_of_objects', 'dummy', 'incref', 'decref']
148
+
149
+ def __init__(self, registry, address, authkey, serializer):
150
+ if not isinstance(authkey, bytes):
151
+ raise TypeError(
152
+ "Authkey {0!r} is type {1!s}, not bytes".format(
153
+ authkey, type(authkey)))
154
+ self.registry = registry
155
+ self.authkey = process.AuthenticationString(authkey)
156
+ Listener, Client = listener_client[serializer]
157
+
158
+ # do authentication later
159
+ self.listener = Listener(address=address, backlog=128)
160
+ self.address = self.listener.address
161
+
162
+ self.id_to_obj = {'0': (None, ())}
163
+ self.id_to_refcount = {}
164
+ self.id_to_local_proxy_obj = {}
165
+ self.mutex = threading.Lock()
166
+
167
+ def serve_forever(self):
168
+ '''
169
+ Run the server forever
170
+ '''
171
+ self.stop_event = threading.Event()
172
+ process.current_process()._manager_server = self
173
+ try:
174
+ accepter = threading.Thread(target=self.accepter)
175
+ accepter.daemon = True
176
+ accepter.start()
177
+ try:
178
+ while not self.stop_event.is_set():
179
+ self.stop_event.wait(1)
180
+ except (KeyboardInterrupt, SystemExit):
181
+ pass
182
+ finally:
183
+ if sys.stdout != sys.__stdout__: # what about stderr?
184
+ util.debug('resetting stdout, stderr')
185
+ sys.stdout = sys.__stdout__
186
+ sys.stderr = sys.__stderr__
187
+ sys.exit(0)
188
+
189
+ def accepter(self):
190
+ while True:
191
+ try:
192
+ c = self.listener.accept()
193
+ except OSError:
194
+ continue
195
+ t = threading.Thread(target=self.handle_request, args=(c,))
196
+ t.daemon = True
197
+ t.start()
198
+
199
+ def _handle_request(self, c):
200
+ request = None
201
+ try:
202
+ connection.deliver_challenge(c, self.authkey)
203
+ connection.answer_challenge(c, self.authkey)
204
+ request = c.recv()
205
+ ignore, funcname, args, kwds = request
206
+ assert funcname in self.public, '%r unrecognized' % funcname
207
+ func = getattr(self, funcname)
208
+ except Exception:
209
+ msg = ('#TRACEBACK', format_exc())
210
+ else:
211
+ try:
212
+ result = func(c, *args, **kwds)
213
+ except Exception:
214
+ msg = ('#TRACEBACK', format_exc())
215
+ else:
216
+ msg = ('#RETURN', result)
217
+
218
+ try:
219
+ c.send(msg)
220
+ except Exception as e:
221
+ try:
222
+ c.send(('#TRACEBACK', format_exc()))
223
+ except Exception:
224
+ pass
225
+ util.info('Failure to send message: %r', msg)
226
+ util.info(' ... request was %r', request)
227
+ util.info(' ... exception was %r', e)
228
+
229
+ def handle_request(self, conn):
230
+ '''
231
+ Handle a new connection
232
+ '''
233
+ try:
234
+ self._handle_request(conn)
235
+ except SystemExit:
236
+ # Server.serve_client() calls sys.exit(0) on EOF
237
+ pass
238
+ finally:
239
+ conn.close()
240
+
241
+ def serve_client(self, conn):
242
+ '''
243
+ Handle requests from the proxies in a particular process/thread
244
+ '''
245
+ util.debug('starting server thread to service %r',
246
+ threading.current_thread().name)
247
+
248
+ recv = conn.recv
249
+ send = conn.send
250
+ id_to_obj = self.id_to_obj
251
+
252
+ while not self.stop_event.is_set():
253
+
254
+ try:
255
+ methodname = obj = None
256
+ request = recv()
257
+ ident, methodname, args, kwds = request
258
+ try:
259
+ obj, exposed, gettypeid = id_to_obj[ident]
260
+ except KeyError as ke:
261
+ try:
262
+ obj, exposed, gettypeid = \
263
+ self.id_to_local_proxy_obj[ident]
264
+ except KeyError:
265
+ raise ke
266
+
267
+ if methodname not in exposed:
268
+ raise AttributeError(
269
+ 'method %r of %r object is not in exposed=%r' %
270
+ (methodname, type(obj), exposed)
271
+ )
272
+
273
+ function = getattr(obj, methodname)
274
+
275
+ try:
276
+ res = function(*args, **kwds)
277
+ except Exception as e:
278
+ msg = ('#ERROR', e)
279
+ else:
280
+ typeid = gettypeid and gettypeid.get(methodname, None)
281
+ if typeid:
282
+ rident, rexposed = self.create(conn, typeid, res)
283
+ token = Token(typeid, self.address, rident)
284
+ msg = ('#PROXY', (rexposed, token))
285
+ else:
286
+ msg = ('#RETURN', res)
287
+
288
+ except AttributeError:
289
+ if methodname is None:
290
+ msg = ('#TRACEBACK', format_exc())
291
+ else:
292
+ try:
293
+ fallback_func = self.fallback_mapping[methodname]
294
+ result = fallback_func(
295
+ self, conn, ident, obj, *args, **kwds
296
+ )
297
+ msg = ('#RETURN', result)
298
+ except Exception:
299
+ msg = ('#TRACEBACK', format_exc())
300
+
301
+ except EOFError:
302
+ util.debug('got EOF -- exiting thread serving %r',
303
+ threading.current_thread().name)
304
+ sys.exit(0)
305
+
306
+ except Exception:
307
+ msg = ('#TRACEBACK', format_exc())
308
+
309
+ try:
310
+ try:
311
+ send(msg)
312
+ except Exception:
313
+ send(('#UNSERIALIZABLE', format_exc()))
314
+ except Exception as e:
315
+ util.info('exception in thread serving %r',
316
+ threading.current_thread().name)
317
+ util.info(' ... message was %r', msg)
318
+ util.info(' ... exception was %r', e)
319
+ conn.close()
320
+ sys.exit(1)
321
+
322
+ def fallback_getvalue(self, conn, ident, obj):
323
+ return obj
324
+
325
+ def fallback_str(self, conn, ident, obj):
326
+ return str(obj)
327
+
328
+ def fallback_repr(self, conn, ident, obj):
329
+ return repr(obj)
330
+
331
+ fallback_mapping = {
332
+ '__str__':fallback_str,
333
+ '__repr__':fallback_repr,
334
+ '#GETVALUE':fallback_getvalue
335
+ }
336
+
337
+ def dummy(self, c):
338
+ pass
339
+
340
+ def debug_info(self, c):
341
+ '''
342
+ Return some info --- useful to spot problems with refcounting
343
+ '''
344
+ # Perhaps include debug info about 'c'?
345
+ with self.mutex:
346
+ result = []
347
+ keys = list(self.id_to_refcount.keys())
348
+ keys.sort()
349
+ for ident in keys:
350
+ if ident != '0':
351
+ result.append(' %s: refcount=%s\n %s' %
352
+ (ident, self.id_to_refcount[ident],
353
+ str(self.id_to_obj[ident][0])[:75]))
354
+ return '\n'.join(result)
355
+
356
+ def number_of_objects(self, c):
357
+ '''
358
+ Number of shared objects
359
+ '''
360
+ # Doesn't use (len(self.id_to_obj) - 1) as we shouldn't count ident='0'
361
+ return len(self.id_to_refcount)
362
+
363
+ def shutdown(self, c):
364
+ '''
365
+ Shutdown this process
366
+ '''
367
+ try:
368
+ util.debug('manager received shutdown message')
369
+ c.send(('#RETURN', None))
370
+ except:
371
+ import traceback
372
+ traceback.print_exc()
373
+ finally:
374
+ self.stop_event.set()
375
+
376
+ def create(self, c, typeid, /, *args, **kwds):
377
+ '''
378
+ Create a new shared object and return its id
379
+ '''
380
+ with self.mutex:
381
+ callable, exposed, method_to_typeid, proxytype = \
382
+ self.registry[typeid]
383
+
384
+ if callable is None:
385
+ if kwds or (len(args) != 1):
386
+ raise ValueError(
387
+ "Without callable, must have one non-keyword argument")
388
+ obj = args[0]
389
+ else:
390
+ obj = callable(*args, **kwds)
391
+
392
+ if exposed is None:
393
+ exposed = public_methods(obj)
394
+ if method_to_typeid is not None:
395
+ if not isinstance(method_to_typeid, dict):
396
+ raise TypeError(
397
+ "Method_to_typeid {0!r}: type {1!s}, not dict".format(
398
+ method_to_typeid, type(method_to_typeid)))
399
+ exposed = list(exposed) + list(method_to_typeid)
400
+
401
+ ident = '%x' % id(obj) # convert to string because xmlrpclib
402
+ # only has 32 bit signed integers
403
+ util.debug('%r callable returned object with id %r', typeid, ident)
404
+
405
+ self.id_to_obj[ident] = (obj, set(exposed), method_to_typeid)
406
+ if ident not in self.id_to_refcount:
407
+ self.id_to_refcount[ident] = 0
408
+
409
+ self.incref(c, ident)
410
+ return ident, tuple(exposed)
411
+
412
+ def get_methods(self, c, token):
413
+ '''
414
+ Return the methods of the shared object indicated by token
415
+ '''
416
+ return tuple(self.id_to_obj[token.id][1])
417
+
418
+ def accept_connection(self, c, name):
419
+ '''
420
+ Spawn a new thread to serve this connection
421
+ '''
422
+ threading.current_thread().name = name
423
+ c.send(('#RETURN', None))
424
+ self.serve_client(c)
425
+
426
+ def incref(self, c, ident):
427
+ with self.mutex:
428
+ try:
429
+ self.id_to_refcount[ident] += 1
430
+ except KeyError as ke:
431
+ # If no external references exist but an internal (to the
432
+ # manager) still does and a new external reference is created
433
+ # from it, restore the manager's tracking of it from the
434
+ # previously stashed internal ref.
435
+ if ident in self.id_to_local_proxy_obj:
436
+ self.id_to_refcount[ident] = 1
437
+ self.id_to_obj[ident] = \
438
+ self.id_to_local_proxy_obj[ident]
439
+ util.debug('Server re-enabled tracking & INCREF %r', ident)
440
+ else:
441
+ raise ke
442
+
443
+ def decref(self, c, ident):
444
+ if ident not in self.id_to_refcount and \
445
+ ident in self.id_to_local_proxy_obj:
446
+ util.debug('Server DECREF skipping %r', ident)
447
+ return
448
+
449
+ with self.mutex:
450
+ if self.id_to_refcount[ident] <= 0:
451
+ raise AssertionError(
452
+ "Id {0!s} ({1!r}) has refcount {2:n}, not 1+".format(
453
+ ident, self.id_to_obj[ident],
454
+ self.id_to_refcount[ident]))
455
+ self.id_to_refcount[ident] -= 1
456
+ if self.id_to_refcount[ident] == 0:
457
+ del self.id_to_refcount[ident]
458
+
459
+ if ident not in self.id_to_refcount:
460
+ # Two-step process in case the object turns out to contain other
461
+ # proxy objects (e.g. a managed list of managed lists).
462
+ # Otherwise, deleting self.id_to_obj[ident] would trigger the
463
+ # deleting of the stored value (another managed object) which would
464
+ # in turn attempt to acquire the mutex that is already held here.
465
+ self.id_to_obj[ident] = (None, (), None) # thread-safe
466
+ util.debug('disposing of obj with id %r', ident)
467
+ with self.mutex:
468
+ del self.id_to_obj[ident]
469
+
470
+
471
+ #
472
+ # Class to represent state of a manager
473
+ #
474
+
475
+ class State(object):
476
+ __slots__ = ['value']
477
+ INITIAL = 0
478
+ STARTED = 1
479
+ SHUTDOWN = 2
480
+
481
+ #
482
+ # Mapping from serializer name to Listener and Client types
483
+ #
484
+
485
+ listener_client = {
486
+ 'pickle' : (connection.Listener, connection.Client),
487
+ 'xmlrpclib' : (connection.XmlListener, connection.XmlClient)
488
+ }
489
+
490
+ #
491
+ # Definition of BaseManager
492
+ #
493
+
494
+ class BaseManager(object):
495
+ '''
496
+ Base class for managers
497
+ '''
498
+ _registry = {}
499
+ _Server = Server
500
+
501
+ def __init__(self, address=None, authkey=None, serializer='pickle',
502
+ ctx=None, *, shutdown_timeout=1.0):
503
+ if authkey is None:
504
+ authkey = process.current_process().authkey
505
+ self._address = address # XXX not final address if eg ('', 0)
506
+ self._authkey = process.AuthenticationString(authkey)
507
+ self._state = State()
508
+ self._state.value = State.INITIAL
509
+ self._serializer = serializer
510
+ self._Listener, self._Client = listener_client[serializer]
511
+ self._ctx = ctx or get_context()
512
+ self._shutdown_timeout = shutdown_timeout
513
+
514
+ def get_server(self):
515
+ '''
516
+ Return server object with serve_forever() method and address attribute
517
+ '''
518
+ if self._state.value != State.INITIAL:
519
+ if self._state.value == State.STARTED:
520
+ raise ProcessError("Already started server")
521
+ elif self._state.value == State.SHUTDOWN:
522
+ raise ProcessError("Manager has shut down")
523
+ else:
524
+ raise ProcessError(
525
+ "Unknown state {!r}".format(self._state.value))
526
+ return Server(self._registry, self._address,
527
+ self._authkey, self._serializer)
528
+
529
+ def connect(self):
530
+ '''
531
+ Connect manager object to the server process
532
+ '''
533
+ Listener, Client = listener_client[self._serializer]
534
+ conn = Client(self._address, authkey=self._authkey)
535
+ dispatch(conn, None, 'dummy')
536
+ self._state.value = State.STARTED
537
+
538
+ def start(self, initializer=None, initargs=()):
539
+ '''
540
+ Spawn a server process for this manager object
541
+ '''
542
+ if self._state.value != State.INITIAL:
543
+ if self._state.value == State.STARTED:
544
+ raise ProcessError("Already started server")
545
+ elif self._state.value == State.SHUTDOWN:
546
+ raise ProcessError("Manager has shut down")
547
+ else:
548
+ raise ProcessError(
549
+ "Unknown state {!r}".format(self._state.value))
550
+
551
+ if initializer is not None and not callable(initializer):
552
+ raise TypeError('initializer must be a callable')
553
+
554
+ # pipe over which we will retrieve address of server
555
+ reader, writer = connection.Pipe(duplex=False)
556
+
557
+ # spawn process which runs a server
558
+ self._process = self._ctx.Process(
559
+ target=type(self)._run_server,
560
+ args=(self._registry, self._address, self._authkey,
561
+ self._serializer, writer, initializer, initargs),
562
+ )
563
+ ident = ':'.join(str(i) for i in self._process._identity)
564
+ self._process.name = type(self).__name__ + '-' + ident
565
+ self._process.start()
566
+
567
+ # get address of server
568
+ writer.close()
569
+ self._address = reader.recv()
570
+ reader.close()
571
+
572
+ # register a finalizer
573
+ self._state.value = State.STARTED
574
+ self.shutdown = util.Finalize(
575
+ self, type(self)._finalize_manager,
576
+ args=(self._process, self._address, self._authkey, self._state,
577
+ self._Client, self._shutdown_timeout),
578
+ exitpriority=0
579
+ )
580
+
581
+ @classmethod
582
+ def _run_server(cls, registry, address, authkey, serializer, writer,
583
+ initializer=None, initargs=()):
584
+ '''
585
+ Create a server, report its address and run it
586
+ '''
587
+ # bpo-36368: protect server process from KeyboardInterrupt signals
588
+ signal.signal(signal.SIGINT, signal.SIG_IGN)
589
+
590
+ if initializer is not None:
591
+ initializer(*initargs)
592
+
593
+ # create server
594
+ server = cls._Server(registry, address, authkey, serializer)
595
+
596
+ # inform parent process of the server's address
597
+ writer.send(server.address)
598
+ writer.close()
599
+
600
+ # run the manager
601
+ util.info('manager serving at %r', server.address)
602
+ server.serve_forever()
603
+
604
+ def _create(self, typeid, /, *args, **kwds):
605
+ '''
606
+ Create a new shared object; return the token and exposed tuple
607
+ '''
608
+ assert self._state.value == State.STARTED, 'server not yet started'
609
+ conn = self._Client(self._address, authkey=self._authkey)
610
+ try:
611
+ id, exposed = dispatch(conn, None, 'create', (typeid,)+args, kwds)
612
+ finally:
613
+ conn.close()
614
+ return Token(typeid, self._address, id), exposed
615
+
616
+ def join(self, timeout=None):
617
+ '''
618
+ Join the manager process (if it has been spawned)
619
+ '''
620
+ if self._process is not None:
621
+ self._process.join(timeout)
622
+ if not self._process.is_alive():
623
+ self._process = None
624
+
625
+ def _debug_info(self):
626
+ '''
627
+ Return some info about the servers shared objects and connections
628
+ '''
629
+ conn = self._Client(self._address, authkey=self._authkey)
630
+ try:
631
+ return dispatch(conn, None, 'debug_info')
632
+ finally:
633
+ conn.close()
634
+
635
+ def _number_of_objects(self):
636
+ '''
637
+ Return the number of shared objects
638
+ '''
639
+ conn = self._Client(self._address, authkey=self._authkey)
640
+ try:
641
+ return dispatch(conn, None, 'number_of_objects')
642
+ finally:
643
+ conn.close()
644
+
645
+ def __enter__(self):
646
+ if self._state.value == State.INITIAL:
647
+ self.start()
648
+ if self._state.value != State.STARTED:
649
+ if self._state.value == State.INITIAL:
650
+ raise ProcessError("Unable to start server")
651
+ elif self._state.value == State.SHUTDOWN:
652
+ raise ProcessError("Manager has shut down")
653
+ else:
654
+ raise ProcessError(
655
+ "Unknown state {!r}".format(self._state.value))
656
+ return self
657
+
658
+ def __exit__(self, exc_type, exc_val, exc_tb):
659
+ self.shutdown()
660
+
661
+ @staticmethod
662
+ def _finalize_manager(process, address, authkey, state, _Client,
663
+ shutdown_timeout):
664
+ '''
665
+ Shutdown the manager process; will be registered as a finalizer
666
+ '''
667
+ if process.is_alive():
668
+ util.info('sending shutdown message to manager')
669
+ try:
670
+ conn = _Client(address, authkey=authkey)
671
+ try:
672
+ dispatch(conn, None, 'shutdown')
673
+ finally:
674
+ conn.close()
675
+ except Exception:
676
+ pass
677
+
678
+ process.join(timeout=shutdown_timeout)
679
+ if process.is_alive():
680
+ util.info('manager still alive')
681
+ if hasattr(process, 'terminate'):
682
+ util.info('trying to `terminate()` manager process')
683
+ process.terminate()
684
+ process.join(timeout=shutdown_timeout)
685
+ if process.is_alive():
686
+ util.info('manager still alive after terminate')
687
+ process.kill()
688
+ process.join()
689
+
690
+ state.value = State.SHUTDOWN
691
+ try:
692
+ del BaseProxy._address_to_local[address]
693
+ except KeyError:
694
+ pass
695
+
696
+ @property
697
+ def address(self):
698
+ return self._address
699
+
700
+ @classmethod
701
+ def register(cls, typeid, callable=None, proxytype=None, exposed=None,
702
+ method_to_typeid=None, create_method=True):
703
+ '''
704
+ Register a typeid with the manager type
705
+ '''
706
+ if '_registry' not in cls.__dict__:
707
+ cls._registry = cls._registry.copy()
708
+
709
+ if proxytype is None:
710
+ proxytype = AutoProxy
711
+
712
+ exposed = exposed or getattr(proxytype, '_exposed_', None)
713
+
714
+ method_to_typeid = method_to_typeid or \
715
+ getattr(proxytype, '_method_to_typeid_', None)
716
+
717
+ if method_to_typeid:
718
+ for key, value in list(method_to_typeid.items()): # isinstance?
719
+ assert type(key) is str, '%r is not a string' % key
720
+ assert type(value) is str, '%r is not a string' % value
721
+
722
+ cls._registry[typeid] = (
723
+ callable, exposed, method_to_typeid, proxytype
724
+ )
725
+
726
+ if create_method:
727
+ def temp(self, /, *args, **kwds):
728
+ util.debug('requesting creation of a shared %r object', typeid)
729
+ token, exp = self._create(typeid, *args, **kwds)
730
+ proxy = proxytype(
731
+ token, self._serializer, manager=self,
732
+ authkey=self._authkey, exposed=exp
733
+ )
734
+ conn = self._Client(token.address, authkey=self._authkey)
735
+ dispatch(conn, None, 'decref', (token.id,))
736
+ return proxy
737
+ temp.__name__ = typeid
738
+ setattr(cls, typeid, temp)
739
+
740
+ #
741
+ # Subclass of set which get cleared after a fork
742
+ #
743
+
744
+ class ProcessLocalSet(set):
745
+ def __init__(self):
746
+ util.register_after_fork(self, lambda obj: obj.clear())
747
+ def __reduce__(self):
748
+ return type(self), ()
749
+
750
+ #
751
+ # Definition of BaseProxy
752
+ #
753
+
754
+ class BaseProxy(object):
755
+ '''
756
+ A base for proxies of shared objects
757
+ '''
758
+ _address_to_local = {}
759
+ _mutex = util.ForkAwareThreadLock()
760
+
761
+ # Each instance gets a `_serial` number. Unlike `id(...)`, this number
762
+ # is never reused.
763
+ _next_serial = 1
764
+
765
+ def __init__(self, token, serializer, manager=None,
766
+ authkey=None, exposed=None, incref=True, manager_owned=False):
767
+ with BaseProxy._mutex:
768
+ tls_serials = BaseProxy._address_to_local.get(token.address, None)
769
+ if tls_serials is None:
770
+ tls_serials = util.ForkAwareLocal(), ProcessLocalSet()
771
+ BaseProxy._address_to_local[token.address] = tls_serials
772
+
773
+ self._serial = BaseProxy._next_serial
774
+ BaseProxy._next_serial += 1
775
+
776
+ # self._tls is used to record the connection used by this
777
+ # thread to communicate with the manager at token.address
778
+ self._tls = tls_serials[0]
779
+
780
+ # self._all_serials is a set used to record the identities of all
781
+ # shared objects for which the current process owns references and
782
+ # which are in the manager at token.address
783
+ self._all_serials = tls_serials[1]
784
+
785
+ self._token = token
786
+ self._id = self._token.id
787
+ self._manager = manager
788
+ self._serializer = serializer
789
+ self._Client = listener_client[serializer][1]
790
+
791
+ # Should be set to True only when a proxy object is being created
792
+ # on the manager server; primary use case: nested proxy objects.
793
+ # RebuildProxy detects when a proxy is being created on the manager
794
+ # and sets this value appropriately.
795
+ self._owned_by_manager = manager_owned
796
+
797
+ if authkey is not None:
798
+ self._authkey = process.AuthenticationString(authkey)
799
+ elif self._manager is not None:
800
+ self._authkey = self._manager._authkey
801
+ else:
802
+ self._authkey = process.current_process().authkey
803
+
804
+ if incref:
805
+ self._incref()
806
+
807
+ util.register_after_fork(self, BaseProxy._after_fork)
808
+
809
+ def _connect(self):
810
+ util.debug('making connection to manager')
811
+ name = process.current_process().name
812
+ if threading.current_thread().name != 'MainThread':
813
+ name += '|' + threading.current_thread().name
814
+ conn = self._Client(self._token.address, authkey=self._authkey)
815
+ dispatch(conn, None, 'accept_connection', (name,))
816
+ self._tls.connection = conn
817
+
818
+ def _callmethod(self, methodname, args=(), kwds={}):
819
+ '''
820
+ Try to call a method of the referent and return a copy of the result
821
+ '''
822
+ try:
823
+ conn = self._tls.connection
824
+ except AttributeError:
825
+ util.debug('thread %r does not own a connection',
826
+ threading.current_thread().name)
827
+ self._connect()
828
+ conn = self._tls.connection
829
+
830
+ conn.send((self._id, methodname, args, kwds))
831
+ kind, result = conn.recv()
832
+
833
+ if kind == '#RETURN':
834
+ return result
835
+ elif kind == '#PROXY':
836
+ exposed, token = result
837
+ proxytype = self._manager._registry[token.typeid][-1]
838
+ token.address = self._token.address
839
+ proxy = proxytype(
840
+ token, self._serializer, manager=self._manager,
841
+ authkey=self._authkey, exposed=exposed
842
+ )
843
+ conn = self._Client(token.address, authkey=self._authkey)
844
+ dispatch(conn, None, 'decref', (token.id,))
845
+ return proxy
846
+ try:
847
+ raise convert_to_error(kind, result)
848
+ finally:
849
+ del result # break reference cycle
850
+
851
+ def _getvalue(self):
852
+ '''
853
+ Get a copy of the value of the referent
854
+ '''
855
+ return self._callmethod('#GETVALUE')
856
+
857
+ def _incref(self):
858
+ if self._owned_by_manager:
859
+ util.debug('owned_by_manager skipped INCREF of %r', self._token.id)
860
+ return
861
+
862
+ conn = self._Client(self._token.address, authkey=self._authkey)
863
+ dispatch(conn, None, 'incref', (self._id,))
864
+ util.debug('INCREF %r', self._token.id)
865
+
866
+ self._all_serials.add(self._serial)
867
+
868
+ state = self._manager and self._manager._state
869
+
870
+ self._close = util.Finalize(
871
+ self, BaseProxy._decref,
872
+ args=(self._token, self._serial, self._authkey, state,
873
+ self._tls, self._all_serials, self._Client),
874
+ exitpriority=10
875
+ )
876
+
877
+ @staticmethod
878
+ def _decref(token, serial, authkey, state, tls, idset, _Client):
879
+ idset.discard(serial)
880
+
881
+ # check whether manager is still alive
882
+ if state is None or state.value == State.STARTED:
883
+ # tell manager this process no longer cares about referent
884
+ try:
885
+ util.debug('DECREF %r', token.id)
886
+ conn = _Client(token.address, authkey=authkey)
887
+ dispatch(conn, None, 'decref', (token.id,))
888
+ except Exception as e:
889
+ util.debug('... decref failed %s', e)
890
+
891
+ else:
892
+ util.debug('DECREF %r -- manager already shutdown', token.id)
893
+
894
+ # check whether we can close this thread's connection because
895
+ # the process owns no more references to objects for this manager
896
+ if not idset and hasattr(tls, 'connection'):
897
+ util.debug('thread %r has no more proxies so closing conn',
898
+ threading.current_thread().name)
899
+ tls.connection.close()
900
+ del tls.connection
901
+
902
+ def _after_fork(self):
903
+ self._manager = None
904
+ try:
905
+ self._incref()
906
+ except Exception as e:
907
+ # the proxy may just be for a manager which has shutdown
908
+ util.info('incref failed: %s' % e)
909
+
910
+ def __reduce__(self):
911
+ kwds = {}
912
+ if get_spawning_popen() is not None:
913
+ kwds['authkey'] = self._authkey
914
+
915
+ if getattr(self, '_isauto', False):
916
+ kwds['exposed'] = self._exposed_
917
+ return (RebuildProxy,
918
+ (AutoProxy, self._token, self._serializer, kwds))
919
+ else:
920
+ return (RebuildProxy,
921
+ (type(self), self._token, self._serializer, kwds))
922
+
923
+ def __deepcopy__(self, memo):
924
+ return self._getvalue()
925
+
926
+ def __repr__(self):
927
+ return '<%s object, typeid %r at %#x>' % \
928
+ (type(self).__name__, self._token.typeid, id(self))
929
+
930
+ def __str__(self):
931
+ '''
932
+ Return representation of the referent (or a fall-back if that fails)
933
+ '''
934
+ try:
935
+ return self._callmethod('__repr__')
936
+ except Exception:
937
+ return repr(self)[:-1] + "; '__str__()' failed>"
938
+
939
+ #
940
+ # Function used for unpickling
941
+ #
942
+
943
+ def RebuildProxy(func, token, serializer, kwds):
944
+ '''
945
+ Function used for unpickling proxy objects.
946
+ '''
947
+ server = getattr(process.current_process(), '_manager_server', None)
948
+ if server and server.address == token.address:
949
+ util.debug('Rebuild a proxy owned by manager, token=%r', token)
950
+ kwds['manager_owned'] = True
951
+ if token.id not in server.id_to_local_proxy_obj:
952
+ server.id_to_local_proxy_obj[token.id] = \
953
+ server.id_to_obj[token.id]
954
+ incref = (
955
+ kwds.pop('incref', True) and
956
+ not getattr(process.current_process(), '_inheriting', False)
957
+ )
958
+ return func(token, serializer, incref=incref, **kwds)
959
+
960
+ #
961
+ # Functions to create proxies and proxy types
962
+ #
963
+
964
+ def MakeProxyType(name, exposed, _cache={}):
965
+ '''
966
+ Return a proxy type whose methods are given by `exposed`
967
+ '''
968
+ exposed = tuple(exposed)
969
+ try:
970
+ return _cache[(name, exposed)]
971
+ except KeyError:
972
+ pass
973
+
974
+ dic = {}
975
+
976
+ for meth in exposed:
977
+ exec('''def %s(self, /, *args, **kwds):
978
+ return self._callmethod(%r, args, kwds)''' % (meth, meth), dic)
979
+
980
+ ProxyType = type(name, (BaseProxy,), dic)
981
+ ProxyType._exposed_ = exposed
982
+ _cache[(name, exposed)] = ProxyType
983
+ return ProxyType
984
+
985
+
986
+ def AutoProxy(token, serializer, manager=None, authkey=None,
987
+ exposed=None, incref=True, manager_owned=False):
988
+ '''
989
+ Return an auto-proxy for `token`
990
+ '''
991
+ _Client = listener_client[serializer][1]
992
+
993
+ if exposed is None:
994
+ conn = _Client(token.address, authkey=authkey)
995
+ try:
996
+ exposed = dispatch(conn, None, 'get_methods', (token,))
997
+ finally:
998
+ conn.close()
999
+
1000
+ if authkey is None and manager is not None:
1001
+ authkey = manager._authkey
1002
+ if authkey is None:
1003
+ authkey = process.current_process().authkey
1004
+
1005
+ ProxyType = MakeProxyType('AutoProxy[%s]' % token.typeid, exposed)
1006
+ proxy = ProxyType(token, serializer, manager=manager, authkey=authkey,
1007
+ incref=incref, manager_owned=manager_owned)
1008
+ proxy._isauto = True
1009
+ return proxy
1010
+
1011
+ #
1012
+ # Types/callables which we will register with SyncManager
1013
+ #
1014
+
1015
+ class Namespace(object):
1016
+ def __init__(self, /, **kwds):
1017
+ self.__dict__.update(kwds)
1018
+ def __repr__(self):
1019
+ items = list(self.__dict__.items())
1020
+ temp = []
1021
+ for name, value in items:
1022
+ if not name.startswith('_'):
1023
+ temp.append('%s=%r' % (name, value))
1024
+ temp.sort()
1025
+ return '%s(%s)' % (self.__class__.__name__, ', '.join(temp))
1026
+
1027
+ class Value(object):
1028
+ def __init__(self, typecode, value, lock=True):
1029
+ self._typecode = typecode
1030
+ self._value = value
1031
+ def get(self):
1032
+ return self._value
1033
+ def set(self, value):
1034
+ self._value = value
1035
+ def __repr__(self):
1036
+ return '%s(%r, %r)'%(type(self).__name__, self._typecode, self._value)
1037
+ value = property(get, set)
1038
+
1039
+ def Array(typecode, sequence, lock=True):
1040
+ return array.array(typecode, sequence)
1041
+
1042
+ #
1043
+ # Proxy types used by SyncManager
1044
+ #
1045
+
1046
+ class IteratorProxy(BaseProxy):
1047
+ _exposed_ = ('__next__', 'send', 'throw', 'close')
1048
+ def __iter__(self):
1049
+ return self
1050
+ def __next__(self, *args):
1051
+ return self._callmethod('__next__', args)
1052
+ def send(self, *args):
1053
+ return self._callmethod('send', args)
1054
+ def throw(self, *args):
1055
+ return self._callmethod('throw', args)
1056
+ def close(self, *args):
1057
+ return self._callmethod('close', args)
1058
+
1059
+
1060
+ class AcquirerProxy(BaseProxy):
1061
+ _exposed_ = ('acquire', 'release')
1062
+ def acquire(self, blocking=True, timeout=None):
1063
+ args = (blocking,) if timeout is None else (blocking, timeout)
1064
+ return self._callmethod('acquire', args)
1065
+ def release(self):
1066
+ return self._callmethod('release')
1067
+ def __enter__(self):
1068
+ return self._callmethod('acquire')
1069
+ def __exit__(self, exc_type, exc_val, exc_tb):
1070
+ return self._callmethod('release')
1071
+
1072
+
1073
+ class ConditionProxy(AcquirerProxy):
1074
+ _exposed_ = ('acquire', 'release', 'wait', 'notify', 'notify_all')
1075
+ def wait(self, timeout=None):
1076
+ return self._callmethod('wait', (timeout,))
1077
+ def notify(self, n=1):
1078
+ return self._callmethod('notify', (n,))
1079
+ def notify_all(self):
1080
+ return self._callmethod('notify_all')
1081
+ def wait_for(self, predicate, timeout=None):
1082
+ result = predicate()
1083
+ if result:
1084
+ return result
1085
+ if timeout is not None:
1086
+ endtime = time.monotonic() + timeout
1087
+ else:
1088
+ endtime = None
1089
+ waittime = None
1090
+ while not result:
1091
+ if endtime is not None:
1092
+ waittime = endtime - time.monotonic()
1093
+ if waittime <= 0:
1094
+ break
1095
+ self.wait(waittime)
1096
+ result = predicate()
1097
+ return result
1098
+
1099
+
1100
+ class EventProxy(BaseProxy):
1101
+ _exposed_ = ('is_set', 'set', 'clear', 'wait')
1102
+ def is_set(self):
1103
+ return self._callmethod('is_set')
1104
+ def set(self):
1105
+ return self._callmethod('set')
1106
+ def clear(self):
1107
+ return self._callmethod('clear')
1108
+ def wait(self, timeout=None):
1109
+ return self._callmethod('wait', (timeout,))
1110
+
1111
+
1112
+ class BarrierProxy(BaseProxy):
1113
+ _exposed_ = ('__getattribute__', 'wait', 'abort', 'reset')
1114
+ def wait(self, timeout=None):
1115
+ return self._callmethod('wait', (timeout,))
1116
+ def abort(self):
1117
+ return self._callmethod('abort')
1118
+ def reset(self):
1119
+ return self._callmethod('reset')
1120
+ @property
1121
+ def parties(self):
1122
+ return self._callmethod('__getattribute__', ('parties',))
1123
+ @property
1124
+ def n_waiting(self):
1125
+ return self._callmethod('__getattribute__', ('n_waiting',))
1126
+ @property
1127
+ def broken(self):
1128
+ return self._callmethod('__getattribute__', ('broken',))
1129
+
1130
+
1131
+ class NamespaceProxy(BaseProxy):
1132
+ _exposed_ = ('__getattribute__', '__setattr__', '__delattr__')
1133
+ def __getattr__(self, key):
1134
+ if key[0] == '_':
1135
+ return object.__getattribute__(self, key)
1136
+ callmethod = object.__getattribute__(self, '_callmethod')
1137
+ return callmethod('__getattribute__', (key,))
1138
+ def __setattr__(self, key, value):
1139
+ if key[0] == '_':
1140
+ return object.__setattr__(self, key, value)
1141
+ callmethod = object.__getattribute__(self, '_callmethod')
1142
+ return callmethod('__setattr__', (key, value))
1143
+ def __delattr__(self, key):
1144
+ if key[0] == '_':
1145
+ return object.__delattr__(self, key)
1146
+ callmethod = object.__getattribute__(self, '_callmethod')
1147
+ return callmethod('__delattr__', (key,))
1148
+
1149
+
1150
+ class ValueProxy(BaseProxy):
1151
+ _exposed_ = ('get', 'set')
1152
+ def get(self):
1153
+ return self._callmethod('get')
1154
+ def set(self, value):
1155
+ return self._callmethod('set', (value,))
1156
+ value = property(get, set)
1157
+
1158
+ __class_getitem__ = classmethod(types.GenericAlias)
1159
+
1160
+
1161
+ BaseListProxy = MakeProxyType('BaseListProxy', (
1162
+ '__add__', '__contains__', '__delitem__', '__getitem__', '__len__',
1163
+ '__mul__', '__reversed__', '__rmul__', '__setitem__',
1164
+ 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
1165
+ 'reverse', 'sort', '__imul__'
1166
+ ))
1167
+ class ListProxy(BaseListProxy):
1168
+ def __iadd__(self, value):
1169
+ self._callmethod('extend', (value,))
1170
+ return self
1171
+ def __imul__(self, value):
1172
+ self._callmethod('__imul__', (value,))
1173
+ return self
1174
+
1175
+ __class_getitem__ = classmethod(types.GenericAlias)
1176
+
1177
+
1178
+ _BaseDictProxy = MakeProxyType('DictProxy', (
1179
+ '__contains__', '__delitem__', '__getitem__', '__iter__', '__len__',
1180
+ '__setitem__', 'clear', 'copy', 'get', 'items',
1181
+ 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'
1182
+ ))
1183
+ _BaseDictProxy._method_to_typeid_ = {
1184
+ '__iter__': 'Iterator',
1185
+ }
1186
+ class DictProxy(_BaseDictProxy):
1187
+ __class_getitem__ = classmethod(types.GenericAlias)
1188
+
1189
+
1190
+ ArrayProxy = MakeProxyType('ArrayProxy', (
1191
+ '__len__', '__getitem__', '__setitem__'
1192
+ ))
1193
+
1194
+
1195
+ BasePoolProxy = MakeProxyType('PoolProxy', (
1196
+ 'apply', 'apply_async', 'close', 'imap', 'imap_unordered', 'join',
1197
+ 'map', 'map_async', 'starmap', 'starmap_async', 'terminate',
1198
+ ))
1199
+ BasePoolProxy._method_to_typeid_ = {
1200
+ 'apply_async': 'AsyncResult',
1201
+ 'map_async': 'AsyncResult',
1202
+ 'starmap_async': 'AsyncResult',
1203
+ 'imap': 'Iterator',
1204
+ 'imap_unordered': 'Iterator'
1205
+ }
1206
+ class PoolProxy(BasePoolProxy):
1207
+ def __enter__(self):
1208
+ return self
1209
+ def __exit__(self, exc_type, exc_val, exc_tb):
1210
+ self.terminate()
1211
+
1212
+ #
1213
+ # Definition of SyncManager
1214
+ #
1215
+
1216
+ class SyncManager(BaseManager):
1217
+ '''
1218
+ Subclass of `BaseManager` which supports a number of shared object types.
1219
+
1220
+ The types registered are those intended for the synchronization
1221
+ of threads, plus `dict`, `list` and `Namespace`.
1222
+
1223
+ The `multiprocessing.Manager()` function creates started instances of
1224
+ this class.
1225
+ '''
1226
+
1227
+ SyncManager.register('Queue', queue.Queue)
1228
+ SyncManager.register('JoinableQueue', queue.Queue)
1229
+ SyncManager.register('Event', threading.Event, EventProxy)
1230
+ SyncManager.register('Lock', threading.Lock, AcquirerProxy)
1231
+ SyncManager.register('RLock', threading.RLock, AcquirerProxy)
1232
+ SyncManager.register('Semaphore', threading.Semaphore, AcquirerProxy)
1233
+ SyncManager.register('BoundedSemaphore', threading.BoundedSemaphore,
1234
+ AcquirerProxy)
1235
+ SyncManager.register('Condition', threading.Condition, ConditionProxy)
1236
+ SyncManager.register('Barrier', threading.Barrier, BarrierProxy)
1237
+ SyncManager.register('Pool', pool.Pool, PoolProxy)
1238
+ SyncManager.register('list', list, ListProxy)
1239
+ SyncManager.register('dict', dict, DictProxy)
1240
+ SyncManager.register('Value', Value, ValueProxy)
1241
+ SyncManager.register('Array', Array, ArrayProxy)
1242
+ SyncManager.register('Namespace', Namespace, NamespaceProxy)
1243
+
1244
+ # types returned by methods of PoolProxy
1245
+ SyncManager.register('Iterator', proxytype=IteratorProxy, create_method=False)
1246
+ SyncManager.register('AsyncResult', create_method=False)
1247
+
1248
+ #
1249
+ # Definition of SharedMemoryManager and SharedMemoryServer
1250
+ #
1251
+
1252
+ if HAS_SHMEM:
1253
+ class _SharedMemoryTracker:
1254
+ "Manages one or more shared memory segments."
1255
+
1256
+ def __init__(self, name, segment_names=None):
1257
+ self.shared_memory_context_name = name
1258
+ self.segment_names = [] if segment_names is None else segment_names
1259
+
1260
+ def register_segment(self, segment_name):
1261
+ "Adds the supplied shared memory block name to tracker."
1262
+ util.debug(f"Register segment {segment_name!r} in pid {getpid()}")
1263
+ self.segment_names.append(segment_name)
1264
+
1265
+ def destroy_segment(self, segment_name):
1266
+ """Calls unlink() on the shared memory block with the supplied name
1267
+ and removes it from the list of blocks being tracked."""
1268
+ util.debug(f"Destroy segment {segment_name!r} in pid {getpid()}")
1269
+ self.segment_names.remove(segment_name)
1270
+ segment = shared_memory.SharedMemory(segment_name)
1271
+ segment.close()
1272
+ segment.unlink()
1273
+
1274
+ def unlink(self):
1275
+ "Calls destroy_segment() on all tracked shared memory blocks."
1276
+ for segment_name in self.segment_names[:]:
1277
+ self.destroy_segment(segment_name)
1278
+
1279
+ def __del__(self):
1280
+ util.debug(f"Call {self.__class__.__name__}.__del__ in {getpid()}")
1281
+ self.unlink()
1282
+
1283
+ def __getstate__(self):
1284
+ return (self.shared_memory_context_name, self.segment_names)
1285
+
1286
+ def __setstate__(self, state):
1287
+ self.__init__(*state)
1288
+
1289
+
1290
+ class SharedMemoryServer(Server):
1291
+
1292
+ public = Server.public + \
1293
+ ['track_segment', 'release_segment', 'list_segments']
1294
+
1295
+ def __init__(self, *args, **kwargs):
1296
+ Server.__init__(self, *args, **kwargs)
1297
+ address = self.address
1298
+ # The address of Linux abstract namespaces can be bytes
1299
+ if isinstance(address, bytes):
1300
+ address = os.fsdecode(address)
1301
+ self.shared_memory_context = \
1302
+ _SharedMemoryTracker(f"shm_{address}_{getpid()}")
1303
+ util.debug(f"SharedMemoryServer started by pid {getpid()}")
1304
+
1305
+ def create(self, c, typeid, /, *args, **kwargs):
1306
+ """Create a new distributed-shared object (not backed by a shared
1307
+ memory block) and return its id to be used in a Proxy Object."""
1308
+ # Unless set up as a shared proxy, don't make shared_memory_context
1309
+ # a standard part of kwargs. This makes things easier for supplying
1310
+ # simple functions.
1311
+ if hasattr(self.registry[typeid][-1], "_shared_memory_proxy"):
1312
+ kwargs['shared_memory_context'] = self.shared_memory_context
1313
+ return Server.create(self, c, typeid, *args, **kwargs)
1314
+
1315
+ def shutdown(self, c):
1316
+ "Call unlink() on all tracked shared memory, terminate the Server."
1317
+ self.shared_memory_context.unlink()
1318
+ return Server.shutdown(self, c)
1319
+
1320
+ def track_segment(self, c, segment_name):
1321
+ "Adds the supplied shared memory block name to Server's tracker."
1322
+ self.shared_memory_context.register_segment(segment_name)
1323
+
1324
+ def release_segment(self, c, segment_name):
1325
+ """Calls unlink() on the shared memory block with the supplied name
1326
+ and removes it from the tracker instance inside the Server."""
1327
+ self.shared_memory_context.destroy_segment(segment_name)
1328
+
1329
+ def list_segments(self, c):
1330
+ """Returns a list of names of shared memory blocks that the Server
1331
+ is currently tracking."""
1332
+ return self.shared_memory_context.segment_names
1333
+
1334
+
1335
+ class SharedMemoryManager(BaseManager):
1336
+ """Like SyncManager but uses SharedMemoryServer instead of Server.
1337
+
1338
+ It provides methods for creating and returning SharedMemory instances
1339
+ and for creating a list-like object (ShareableList) backed by shared
1340
+ memory. It also provides methods that create and return Proxy Objects
1341
+ that support synchronization across processes (i.e. multi-process-safe
1342
+ locks and semaphores).
1343
+ """
1344
+
1345
+ _Server = SharedMemoryServer
1346
+
1347
+ def __init__(self, *args, **kwargs):
1348
+ if os.name == "posix":
1349
+ # bpo-36867: Ensure the resource_tracker is running before
1350
+ # launching the manager process, so that concurrent
1351
+ # shared_memory manipulation both in the manager and in the
1352
+ # current process does not create two resource_tracker
1353
+ # processes.
1354
+ from . import resource_tracker
1355
+ resource_tracker.ensure_running()
1356
+ BaseManager.__init__(self, *args, **kwargs)
1357
+ util.debug(f"{self.__class__.__name__} created by pid {getpid()}")
1358
+
1359
+ def __del__(self):
1360
+ util.debug(f"{self.__class__.__name__}.__del__ by pid {getpid()}")
1361
+
1362
+ def get_server(self):
1363
+ 'Better than monkeypatching for now; merge into Server ultimately'
1364
+ if self._state.value != State.INITIAL:
1365
+ if self._state.value == State.STARTED:
1366
+ raise ProcessError("Already started SharedMemoryServer")
1367
+ elif self._state.value == State.SHUTDOWN:
1368
+ raise ProcessError("SharedMemoryManager has shut down")
1369
+ else:
1370
+ raise ProcessError(
1371
+ "Unknown state {!r}".format(self._state.value))
1372
+ return self._Server(self._registry, self._address,
1373
+ self._authkey, self._serializer)
1374
+
1375
+ def SharedMemory(self, size):
1376
+ """Returns a new SharedMemory instance with the specified size in
1377
+ bytes, to be tracked by the manager."""
1378
+ with self._Client(self._address, authkey=self._authkey) as conn:
1379
+ sms = shared_memory.SharedMemory(None, create=True, size=size)
1380
+ try:
1381
+ dispatch(conn, None, 'track_segment', (sms.name,))
1382
+ except BaseException as e:
1383
+ sms.unlink()
1384
+ raise e
1385
+ return sms
1386
+
1387
+ def ShareableList(self, sequence):
1388
+ """Returns a new ShareableList instance populated with the values
1389
+ from the input sequence, to be tracked by the manager."""
1390
+ with self._Client(self._address, authkey=self._authkey) as conn:
1391
+ sl = shared_memory.ShareableList(sequence)
1392
+ try:
1393
+ dispatch(conn, None, 'track_segment', (sl.shm.name,))
1394
+ except BaseException as e:
1395
+ sl.shm.unlink()
1396
+ raise e
1397
+ return sl