@rowstile/cli-win32-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 (759) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +5 -0
  3. package/package.json +23 -0
  4. package/python/DLLs/_asyncio.pyd +0 -0
  5. package/python/DLLs/_bz2.pyd +0 -0
  6. package/python/DLLs/_ctypes.pyd +0 -0
  7. package/python/DLLs/_ctypes_test.pyd +0 -0
  8. package/python/DLLs/_decimal.pyd +0 -0
  9. package/python/DLLs/_elementtree.pyd +0 -0
  10. package/python/DLLs/_hashlib.pyd +0 -0
  11. package/python/DLLs/_lzma.pyd +0 -0
  12. package/python/DLLs/_multiprocessing.pyd +0 -0
  13. package/python/DLLs/_overlapped.pyd +0 -0
  14. package/python/DLLs/_queue.pyd +0 -0
  15. package/python/DLLs/_socket.pyd +0 -0
  16. package/python/DLLs/_sqlite3.pyd +0 -0
  17. package/python/DLLs/_ssl.pyd +0 -0
  18. package/python/DLLs/_testbuffer.pyd +0 -0
  19. package/python/DLLs/_testcapi.pyd +0 -0
  20. package/python/DLLs/_testclinic.pyd +0 -0
  21. package/python/DLLs/_testclinic_limited.pyd +0 -0
  22. package/python/DLLs/_testconsole.pyd +0 -0
  23. package/python/DLLs/_testimportmultiple.pyd +0 -0
  24. package/python/DLLs/_testinternalcapi.pyd +0 -0
  25. package/python/DLLs/_testlimitedcapi.pyd +0 -0
  26. package/python/DLLs/_testmultiphase.pyd +0 -0
  27. package/python/DLLs/_testsinglephase.pyd +0 -0
  28. package/python/DLLs/_uuid.pyd +0 -0
  29. package/python/DLLs/_wmi.pyd +0 -0
  30. package/python/DLLs/_zoneinfo.pyd +0 -0
  31. package/python/DLLs/libcrypto-3-x64.dll +0 -0
  32. package/python/DLLs/libffi-8.dll +0 -0
  33. package/python/DLLs/libssl-3-x64.dll +0 -0
  34. package/python/DLLs/pyexpat.pyd +0 -0
  35. package/python/DLLs/select.pyd +0 -0
  36. package/python/DLLs/sqlite3.dll +0 -0
  37. package/python/DLLs/unicodedata.pyd +0 -0
  38. package/python/DLLs/winsound.pyd +0 -0
  39. package/python/DLLs/zlib1.dll +0 -0
  40. package/python/LICENSE.txt +445 -0
  41. package/python/Lib/__future__.py +147 -0
  42. package/python/Lib/__hello__.py +16 -0
  43. package/python/Lib/__pycache__/__future__.cpython-313.pyc +0 -0
  44. package/python/Lib/__pycache__/_colorize.cpython-313.pyc +0 -0
  45. package/python/Lib/__pycache__/_compat_pickle.cpython-313.pyc +0 -0
  46. package/python/Lib/__pycache__/_compression.cpython-313.pyc +0 -0
  47. package/python/Lib/__pycache__/_markupbase.cpython-313.pyc +0 -0
  48. package/python/Lib/__pycache__/_opcode_metadata.cpython-313.pyc +0 -0
  49. package/python/Lib/__pycache__/_weakrefset.cpython-313.pyc +0 -0
  50. package/python/Lib/__pycache__/ast.cpython-313.pyc +0 -0
  51. package/python/Lib/__pycache__/base64.cpython-313.pyc +0 -0
  52. package/python/Lib/__pycache__/bisect.cpython-313.pyc +0 -0
  53. package/python/Lib/__pycache__/bz2.cpython-313.pyc +0 -0
  54. package/python/Lib/__pycache__/calendar.cpython-313.pyc +0 -0
  55. package/python/Lib/__pycache__/colorsys.cpython-313.pyc +0 -0
  56. package/python/Lib/__pycache__/compileall.cpython-313.pyc +0 -0
  57. package/python/Lib/__pycache__/configparser.cpython-313.pyc +0 -0
  58. package/python/Lib/__pycache__/contextlib.cpython-313.pyc +0 -0
  59. package/python/Lib/__pycache__/copy.cpython-313.pyc +0 -0
  60. package/python/Lib/__pycache__/copyreg.cpython-313.pyc +0 -0
  61. package/python/Lib/__pycache__/csv.cpython-313.pyc +0 -0
  62. package/python/Lib/__pycache__/dataclasses.cpython-313.pyc +0 -0
  63. package/python/Lib/__pycache__/datetime.cpython-313.pyc +0 -0
  64. package/python/Lib/__pycache__/decimal.cpython-313.pyc +0 -0
  65. package/python/Lib/__pycache__/dis.cpython-313.pyc +0 -0
  66. package/python/Lib/__pycache__/enum.cpython-313.pyc +0 -0
  67. package/python/Lib/__pycache__/filecmp.cpython-313.pyc +0 -0
  68. package/python/Lib/__pycache__/fnmatch.cpython-313.pyc +0 -0
  69. package/python/Lib/__pycache__/fractions.cpython-313.pyc +0 -0
  70. package/python/Lib/__pycache__/functools.cpython-313.pyc +0 -0
  71. package/python/Lib/__pycache__/getpass.cpython-313.pyc +0 -0
  72. package/python/Lib/__pycache__/gettext.cpython-313.pyc +0 -0
  73. package/python/Lib/__pycache__/glob.cpython-313.pyc +0 -0
  74. package/python/Lib/__pycache__/gzip.cpython-313.pyc +0 -0
  75. package/python/Lib/__pycache__/hashlib.cpython-313.pyc +0 -0
  76. package/python/Lib/__pycache__/heapq.cpython-313.pyc +0 -0
  77. package/python/Lib/__pycache__/hmac.cpython-313.pyc +0 -0
  78. package/python/Lib/__pycache__/inspect.cpython-313.pyc +0 -0
  79. package/python/Lib/__pycache__/ipaddress.cpython-313.pyc +0 -0
  80. package/python/Lib/__pycache__/keyword.cpython-313.pyc +0 -0
  81. package/python/Lib/__pycache__/linecache.cpython-313.pyc +0 -0
  82. package/python/Lib/__pycache__/locale.cpython-313.pyc +0 -0
  83. package/python/Lib/__pycache__/lzma.cpython-313.pyc +0 -0
  84. package/python/Lib/__pycache__/mimetypes.cpython-313.pyc +0 -0
  85. package/python/Lib/__pycache__/nturl2path.cpython-313.pyc +0 -0
  86. package/python/Lib/__pycache__/numbers.cpython-313.pyc +0 -0
  87. package/python/Lib/__pycache__/opcode.cpython-313.pyc +0 -0
  88. package/python/Lib/__pycache__/operator.cpython-313.pyc +0 -0
  89. package/python/Lib/__pycache__/optparse.cpython-313.pyc +0 -0
  90. package/python/Lib/__pycache__/pickle.cpython-313.pyc +0 -0
  91. package/python/Lib/__pycache__/pkgutil.cpython-313.pyc +0 -0
  92. package/python/Lib/__pycache__/platform.cpython-313.pyc +0 -0
  93. package/python/Lib/__pycache__/py_compile.cpython-313.pyc +0 -0
  94. package/python/Lib/__pycache__/queue.cpython-313.pyc +0 -0
  95. package/python/Lib/__pycache__/quopri.cpython-313.pyc +0 -0
  96. package/python/Lib/__pycache__/random.cpython-313.pyc +0 -0
  97. package/python/Lib/__pycache__/reprlib.cpython-313.pyc +0 -0
  98. package/python/Lib/__pycache__/selectors.cpython-313.pyc +0 -0
  99. package/python/Lib/__pycache__/shlex.cpython-313.pyc +0 -0
  100. package/python/Lib/__pycache__/shutil.cpython-313.pyc +0 -0
  101. package/python/Lib/__pycache__/signal.cpython-313.pyc +0 -0
  102. package/python/Lib/__pycache__/socket.cpython-313.pyc +0 -0
  103. package/python/Lib/__pycache__/socketserver.cpython-313.pyc +0 -0
  104. package/python/Lib/__pycache__/ssl.cpython-313.pyc +0 -0
  105. package/python/Lib/__pycache__/string.cpython-313.pyc +0 -0
  106. package/python/Lib/__pycache__/stringprep.cpython-313.pyc +0 -0
  107. package/python/Lib/__pycache__/struct.cpython-313.pyc +0 -0
  108. package/python/Lib/__pycache__/subprocess.cpython-313.pyc +0 -0
  109. package/python/Lib/__pycache__/tarfile.cpython-313.pyc +0 -0
  110. package/python/Lib/__pycache__/tempfile.cpython-313.pyc +0 -0
  111. package/python/Lib/__pycache__/textwrap.cpython-313.pyc +0 -0
  112. package/python/Lib/__pycache__/threading.cpython-313.pyc +0 -0
  113. package/python/Lib/__pycache__/token.cpython-313.pyc +0 -0
  114. package/python/Lib/__pycache__/tokenize.cpython-313.pyc +0 -0
  115. package/python/Lib/__pycache__/traceback.cpython-313.pyc +0 -0
  116. package/python/Lib/__pycache__/types.cpython-313.pyc +0 -0
  117. package/python/Lib/__pycache__/typing.cpython-313.pyc +0 -0
  118. package/python/Lib/__pycache__/uuid.cpython-313.pyc +0 -0
  119. package/python/Lib/__pycache__/warnings.cpython-313.pyc +0 -0
  120. package/python/Lib/__pycache__/weakref.cpython-313.pyc +0 -0
  121. package/python/Lib/_aix_support.py +108 -0
  122. package/python/Lib/_android_support.py +192 -0
  123. package/python/Lib/_apple_support.py +66 -0
  124. package/python/Lib/_collections_abc.py +1187 -0
  125. package/python/Lib/_colorize.py +119 -0
  126. package/python/Lib/_compat_pickle.py +251 -0
  127. package/python/Lib/_compression.py +162 -0
  128. package/python/Lib/_ios_support.py +71 -0
  129. package/python/Lib/_markupbase.py +396 -0
  130. package/python/Lib/_opcode_metadata.py +343 -0
  131. package/python/Lib/_osx_support.py +579 -0
  132. package/python/Lib/_py_abc.py +147 -0
  133. package/python/Lib/_pydatetime.py +2640 -0
  134. package/python/Lib/_pydecimal.py +6356 -0
  135. package/python/Lib/_pyio.py +2714 -0
  136. package/python/Lib/_pylong.py +363 -0
  137. package/python/Lib/_pyrepl/__init__.py +19 -0
  138. package/python/Lib/_pyrepl/__main__.py +10 -0
  139. package/python/Lib/_pyrepl/_minimal_curses.py +68 -0
  140. package/python/Lib/_pyrepl/_threading_handler.py +74 -0
  141. package/python/Lib/_pyrepl/base_eventqueue.py +110 -0
  142. package/python/Lib/_pyrepl/commands.py +492 -0
  143. package/python/Lib/_pyrepl/completing_reader.py +295 -0
  144. package/python/Lib/_pyrepl/console.py +229 -0
  145. package/python/Lib/_pyrepl/curses.py +33 -0
  146. package/python/Lib/_pyrepl/fancy_termios.py +82 -0
  147. package/python/Lib/_pyrepl/historical_reader.py +419 -0
  148. package/python/Lib/_pyrepl/input.py +114 -0
  149. package/python/Lib/_pyrepl/keymap.py +213 -0
  150. package/python/Lib/_pyrepl/main.py +59 -0
  151. package/python/Lib/_pyrepl/mypy.ini +29 -0
  152. package/python/Lib/_pyrepl/pager.py +175 -0
  153. package/python/Lib/_pyrepl/reader.py +764 -0
  154. package/python/Lib/_pyrepl/readline.py +599 -0
  155. package/python/Lib/_pyrepl/simple_interact.py +180 -0
  156. package/python/Lib/_pyrepl/trace.py +21 -0
  157. package/python/Lib/_pyrepl/types.py +10 -0
  158. package/python/Lib/_pyrepl/unix_console.py +852 -0
  159. package/python/Lib/_pyrepl/unix_eventqueue.py +76 -0
  160. package/python/Lib/_pyrepl/utils.py +83 -0
  161. package/python/Lib/_pyrepl/windows_console.py +687 -0
  162. package/python/Lib/_pyrepl/windows_eventqueue.py +42 -0
  163. package/python/Lib/_sitebuiltins.py +91 -0
  164. package/python/Lib/_strptime.py +800 -0
  165. package/python/Lib/_threading_local.py +120 -0
  166. package/python/Lib/_weakrefset.py +205 -0
  167. package/python/Lib/abc.py +188 -0
  168. package/python/Lib/antigravity.py +17 -0
  169. package/python/Lib/argparse.py +2690 -0
  170. package/python/Lib/ast.py +1865 -0
  171. package/python/Lib/asyncio/__init__.py +47 -0
  172. package/python/Lib/asyncio/__main__.py +211 -0
  173. package/python/Lib/asyncio/base_events.py +2086 -0
  174. package/python/Lib/asyncio/base_futures.py +67 -0
  175. package/python/Lib/asyncio/base_subprocess.py +312 -0
  176. package/python/Lib/asyncio/base_tasks.py +94 -0
  177. package/python/Lib/asyncio/constants.py +41 -0
  178. package/python/Lib/asyncio/coroutines.py +109 -0
  179. package/python/Lib/asyncio/events.py +885 -0
  180. package/python/Lib/asyncio/exceptions.py +62 -0
  181. package/python/Lib/asyncio/format_helpers.py +84 -0
  182. package/python/Lib/asyncio/futures.py +425 -0
  183. package/python/Lib/asyncio/locks.py +617 -0
  184. package/python/Lib/asyncio/log.py +7 -0
  185. package/python/Lib/asyncio/mixins.py +21 -0
  186. package/python/Lib/asyncio/proactor_events.py +891 -0
  187. package/python/Lib/asyncio/protocols.py +216 -0
  188. package/python/Lib/asyncio/queues.py +309 -0
  189. package/python/Lib/asyncio/runners.py +217 -0
  190. package/python/Lib/asyncio/selector_events.py +1328 -0
  191. package/python/Lib/asyncio/sslproto.py +929 -0
  192. package/python/Lib/asyncio/staggered.py +174 -0
  193. package/python/Lib/asyncio/streams.py +787 -0
  194. package/python/Lib/asyncio/subprocess.py +229 -0
  195. package/python/Lib/asyncio/taskgroups.py +278 -0
  196. package/python/Lib/asyncio/tasks.py +1121 -0
  197. package/python/Lib/asyncio/threads.py +26 -0
  198. package/python/Lib/asyncio/timeouts.py +185 -0
  199. package/python/Lib/asyncio/transports.py +337 -0
  200. package/python/Lib/asyncio/trsock.py +98 -0
  201. package/python/Lib/asyncio/unix_events.py +1550 -0
  202. package/python/Lib/asyncio/windows_events.py +906 -0
  203. package/python/Lib/asyncio/windows_utils.py +181 -0
  204. package/python/Lib/base64.py +628 -0
  205. package/python/Lib/bdb.py +973 -0
  206. package/python/Lib/bisect.py +118 -0
  207. package/python/Lib/bz2.py +352 -0
  208. package/python/Lib/cProfile.py +197 -0
  209. package/python/Lib/calendar.py +813 -0
  210. package/python/Lib/cmd.py +409 -0
  211. package/python/Lib/code.py +386 -0
  212. package/python/Lib/codecs.py +1132 -0
  213. package/python/Lib/codeop.py +155 -0
  214. package/python/Lib/collections/__init__.py +1603 -0
  215. package/python/Lib/collections/__pycache__/__init__.cpython-313.pyc +0 -0
  216. package/python/Lib/colorsys.py +166 -0
  217. package/python/Lib/compileall.py +470 -0
  218. package/python/Lib/concurrent/__init__.py +1 -0
  219. package/python/Lib/concurrent/futures/__init__.py +54 -0
  220. package/python/Lib/concurrent/futures/_base.py +660 -0
  221. package/python/Lib/concurrent/futures/process.py +892 -0
  222. package/python/Lib/concurrent/futures/thread.py +240 -0
  223. package/python/Lib/configparser.py +1396 -0
  224. package/python/Lib/contextlib.py +814 -0
  225. package/python/Lib/contextvars.py +4 -0
  226. package/python/Lib/copy.py +306 -0
  227. package/python/Lib/copyreg.py +217 -0
  228. package/python/Lib/csv.py +527 -0
  229. package/python/Lib/ctypes/__init__.py +602 -0
  230. package/python/Lib/ctypes/__pycache__/__init__.cpython-313.pyc +0 -0
  231. package/python/Lib/ctypes/__pycache__/_endian.cpython-313.pyc +0 -0
  232. package/python/Lib/ctypes/__pycache__/wintypes.cpython-313.pyc +0 -0
  233. package/python/Lib/ctypes/_aix.py +327 -0
  234. package/python/Lib/ctypes/_endian.py +78 -0
  235. package/python/Lib/ctypes/macholib/README.ctypes +7 -0
  236. package/python/Lib/ctypes/macholib/__init__.py +9 -0
  237. package/python/Lib/ctypes/macholib/dyld.py +165 -0
  238. package/python/Lib/ctypes/macholib/dylib.py +42 -0
  239. package/python/Lib/ctypes/macholib/fetch_macholib +2 -0
  240. package/python/Lib/ctypes/macholib/fetch_macholib.bat +1 -0
  241. package/python/Lib/ctypes/macholib/framework.py +42 -0
  242. package/python/Lib/ctypes/util.py +387 -0
  243. package/python/Lib/ctypes/wintypes.py +202 -0
  244. package/python/Lib/curses/__init__.py +101 -0
  245. package/python/Lib/curses/ascii.py +99 -0
  246. package/python/Lib/curses/has_key.py +192 -0
  247. package/python/Lib/curses/panel.py +6 -0
  248. package/python/Lib/curses/textpad.py +236 -0
  249. package/python/Lib/dataclasses.py +1679 -0
  250. package/python/Lib/datetime.py +9 -0
  251. package/python/Lib/dbm/__init__.py +194 -0
  252. package/python/Lib/dbm/dumb.py +319 -0
  253. package/python/Lib/dbm/gnu.py +3 -0
  254. package/python/Lib/dbm/ndbm.py +3 -0
  255. package/python/Lib/dbm/sqlite3.py +144 -0
  256. package/python/Lib/decimal.py +109 -0
  257. package/python/Lib/difflib.py +2058 -0
  258. package/python/Lib/dis.py +1075 -0
  259. package/python/Lib/doctest.py +2919 -0
  260. package/python/Lib/email/__init__.py +61 -0
  261. package/python/Lib/email/__pycache__/__init__.cpython-313.pyc +0 -0
  262. package/python/Lib/email/__pycache__/_encoded_words.cpython-313.pyc +0 -0
  263. package/python/Lib/email/__pycache__/_parseaddr.cpython-313.pyc +0 -0
  264. package/python/Lib/email/__pycache__/_policybase.cpython-313.pyc +0 -0
  265. package/python/Lib/email/__pycache__/base64mime.cpython-313.pyc +0 -0
  266. package/python/Lib/email/__pycache__/charset.cpython-313.pyc +0 -0
  267. package/python/Lib/email/__pycache__/encoders.cpython-313.pyc +0 -0
  268. package/python/Lib/email/__pycache__/errors.cpython-313.pyc +0 -0
  269. package/python/Lib/email/__pycache__/feedparser.cpython-313.pyc +0 -0
  270. package/python/Lib/email/__pycache__/header.cpython-313.pyc +0 -0
  271. package/python/Lib/email/__pycache__/iterators.cpython-313.pyc +0 -0
  272. package/python/Lib/email/__pycache__/message.cpython-313.pyc +0 -0
  273. package/python/Lib/email/__pycache__/parser.cpython-313.pyc +0 -0
  274. package/python/Lib/email/__pycache__/quoprimime.cpython-313.pyc +0 -0
  275. package/python/Lib/email/__pycache__/utils.cpython-313.pyc +0 -0
  276. package/python/Lib/email/_encoded_words.py +233 -0
  277. package/python/Lib/email/_header_value_parser.py +3153 -0
  278. package/python/Lib/email/_parseaddr.py +563 -0
  279. package/python/Lib/email/_policybase.py +382 -0
  280. package/python/Lib/email/architecture.rst +216 -0
  281. package/python/Lib/email/base64mime.py +115 -0
  282. package/python/Lib/email/charset.py +396 -0
  283. package/python/Lib/email/contentmanager.py +254 -0
  284. package/python/Lib/email/encoders.py +65 -0
  285. package/python/Lib/email/errors.py +117 -0
  286. package/python/Lib/email/feedparser.py +536 -0
  287. package/python/Lib/email/generator.py +530 -0
  288. package/python/Lib/email/header.py +582 -0
  289. package/python/Lib/email/headerregistry.py +618 -0
  290. package/python/Lib/email/iterators.py +68 -0
  291. package/python/Lib/email/message.py +1217 -0
  292. package/python/Lib/email/mime/__init__.py +0 -0
  293. package/python/Lib/email/mime/application.py +37 -0
  294. package/python/Lib/email/mime/audio.py +97 -0
  295. package/python/Lib/email/mime/base.py +29 -0
  296. package/python/Lib/email/mime/image.py +152 -0
  297. package/python/Lib/email/mime/message.py +33 -0
  298. package/python/Lib/email/mime/multipart.py +47 -0
  299. package/python/Lib/email/mime/nonmultipart.py +21 -0
  300. package/python/Lib/email/mime/text.py +40 -0
  301. package/python/Lib/email/parser.py +127 -0
  302. package/python/Lib/email/policy.py +232 -0
  303. package/python/Lib/email/quoprimime.py +300 -0
  304. package/python/Lib/email/utils.py +497 -0
  305. package/python/Lib/encodings/__init__.py +179 -0
  306. package/python/Lib/encodings/__pycache__/__init__.cpython-313.pyc +0 -0
  307. package/python/Lib/encodings/__pycache__/aliases.cpython-313.pyc +0 -0
  308. package/python/Lib/encodings/__pycache__/cp1252.cpython-313.pyc +0 -0
  309. package/python/Lib/encodings/__pycache__/cp437.cpython-313.pyc +0 -0
  310. package/python/Lib/encodings/__pycache__/hex_codec.cpython-313.pyc +0 -0
  311. package/python/Lib/encodings/__pycache__/idna.cpython-313.pyc +0 -0
  312. package/python/Lib/encodings/__pycache__/utf_8.cpython-313.pyc +0 -0
  313. package/python/Lib/encodings/aliases.py +560 -0
  314. package/python/Lib/encodings/ascii.py +50 -0
  315. package/python/Lib/encodings/base64_codec.py +55 -0
  316. package/python/Lib/encodings/big5.py +39 -0
  317. package/python/Lib/encodings/big5hkscs.py +39 -0
  318. package/python/Lib/encodings/bz2_codec.py +78 -0
  319. package/python/Lib/encodings/charmap.py +69 -0
  320. package/python/Lib/encodings/cp037.py +307 -0
  321. package/python/Lib/encodings/cp1006.py +307 -0
  322. package/python/Lib/encodings/cp1026.py +307 -0
  323. package/python/Lib/encodings/cp1125.py +698 -0
  324. package/python/Lib/encodings/cp1140.py +307 -0
  325. package/python/Lib/encodings/cp1250.py +307 -0
  326. package/python/Lib/encodings/cp1251.py +307 -0
  327. package/python/Lib/encodings/cp1252.py +307 -0
  328. package/python/Lib/encodings/cp1253.py +307 -0
  329. package/python/Lib/encodings/cp1254.py +307 -0
  330. package/python/Lib/encodings/cp1255.py +307 -0
  331. package/python/Lib/encodings/cp1256.py +307 -0
  332. package/python/Lib/encodings/cp1257.py +307 -0
  333. package/python/Lib/encodings/cp1258.py +307 -0
  334. package/python/Lib/encodings/cp273.py +307 -0
  335. package/python/Lib/encodings/cp424.py +307 -0
  336. package/python/Lib/encodings/cp437.py +698 -0
  337. package/python/Lib/encodings/cp500.py +307 -0
  338. package/python/Lib/encodings/cp720.py +309 -0
  339. package/python/Lib/encodings/cp737.py +698 -0
  340. package/python/Lib/encodings/cp775.py +697 -0
  341. package/python/Lib/encodings/cp850.py +698 -0
  342. package/python/Lib/encodings/cp852.py +698 -0
  343. package/python/Lib/encodings/cp855.py +698 -0
  344. package/python/Lib/encodings/cp856.py +307 -0
  345. package/python/Lib/encodings/cp857.py +694 -0
  346. package/python/Lib/encodings/cp858.py +698 -0
  347. package/python/Lib/encodings/cp860.py +698 -0
  348. package/python/Lib/encodings/cp861.py +698 -0
  349. package/python/Lib/encodings/cp862.py +698 -0
  350. package/python/Lib/encodings/cp863.py +698 -0
  351. package/python/Lib/encodings/cp864.py +690 -0
  352. package/python/Lib/encodings/cp865.py +698 -0
  353. package/python/Lib/encodings/cp866.py +698 -0
  354. package/python/Lib/encodings/cp869.py +689 -0
  355. package/python/Lib/encodings/cp874.py +307 -0
  356. package/python/Lib/encodings/cp875.py +307 -0
  357. package/python/Lib/encodings/cp932.py +39 -0
  358. package/python/Lib/encodings/cp949.py +39 -0
  359. package/python/Lib/encodings/cp950.py +39 -0
  360. package/python/Lib/encodings/euc_jis_2004.py +39 -0
  361. package/python/Lib/encodings/euc_jisx0213.py +39 -0
  362. package/python/Lib/encodings/euc_jp.py +39 -0
  363. package/python/Lib/encodings/euc_kr.py +39 -0
  364. package/python/Lib/encodings/gb18030.py +39 -0
  365. package/python/Lib/encodings/gb2312.py +39 -0
  366. package/python/Lib/encodings/gbk.py +39 -0
  367. package/python/Lib/encodings/hex_codec.py +55 -0
  368. package/python/Lib/encodings/hp_roman8.py +314 -0
  369. package/python/Lib/encodings/hz.py +39 -0
  370. package/python/Lib/encodings/idna.py +387 -0
  371. package/python/Lib/encodings/iso2022_jp.py +39 -0
  372. package/python/Lib/encodings/iso2022_jp_1.py +39 -0
  373. package/python/Lib/encodings/iso2022_jp_2.py +39 -0
  374. package/python/Lib/encodings/iso2022_jp_2004.py +39 -0
  375. package/python/Lib/encodings/iso2022_jp_3.py +39 -0
  376. package/python/Lib/encodings/iso2022_jp_ext.py +39 -0
  377. package/python/Lib/encodings/iso2022_kr.py +39 -0
  378. package/python/Lib/encodings/iso8859_1.py +307 -0
  379. package/python/Lib/encodings/iso8859_10.py +307 -0
  380. package/python/Lib/encodings/iso8859_11.py +307 -0
  381. package/python/Lib/encodings/iso8859_13.py +307 -0
  382. package/python/Lib/encodings/iso8859_14.py +307 -0
  383. package/python/Lib/encodings/iso8859_15.py +307 -0
  384. package/python/Lib/encodings/iso8859_16.py +307 -0
  385. package/python/Lib/encodings/iso8859_2.py +307 -0
  386. package/python/Lib/encodings/iso8859_3.py +307 -0
  387. package/python/Lib/encodings/iso8859_4.py +307 -0
  388. package/python/Lib/encodings/iso8859_5.py +307 -0
  389. package/python/Lib/encodings/iso8859_6.py +307 -0
  390. package/python/Lib/encodings/iso8859_7.py +307 -0
  391. package/python/Lib/encodings/iso8859_8.py +307 -0
  392. package/python/Lib/encodings/iso8859_9.py +307 -0
  393. package/python/Lib/encodings/johab.py +39 -0
  394. package/python/Lib/encodings/koi8_r.py +307 -0
  395. package/python/Lib/encodings/koi8_t.py +308 -0
  396. package/python/Lib/encodings/koi8_u.py +307 -0
  397. package/python/Lib/encodings/kz1048.py +307 -0
  398. package/python/Lib/encodings/latin_1.py +50 -0
  399. package/python/Lib/encodings/mac_arabic.py +698 -0
  400. package/python/Lib/encodings/mac_croatian.py +307 -0
  401. package/python/Lib/encodings/mac_cyrillic.py +307 -0
  402. package/python/Lib/encodings/mac_farsi.py +307 -0
  403. package/python/Lib/encodings/mac_greek.py +307 -0
  404. package/python/Lib/encodings/mac_iceland.py +307 -0
  405. package/python/Lib/encodings/mac_latin2.py +312 -0
  406. package/python/Lib/encodings/mac_roman.py +307 -0
  407. package/python/Lib/encodings/mac_romanian.py +307 -0
  408. package/python/Lib/encodings/mac_turkish.py +307 -0
  409. package/python/Lib/encodings/mbcs.py +47 -0
  410. package/python/Lib/encodings/oem.py +41 -0
  411. package/python/Lib/encodings/palmos.py +308 -0
  412. package/python/Lib/encodings/ptcp154.py +312 -0
  413. package/python/Lib/encodings/punycode.py +253 -0
  414. package/python/Lib/encodings/quopri_codec.py +56 -0
  415. package/python/Lib/encodings/raw_unicode_escape.py +46 -0
  416. package/python/Lib/encodings/rot_13.py +113 -0
  417. package/python/Lib/encodings/shift_jis.py +39 -0
  418. package/python/Lib/encodings/shift_jis_2004.py +39 -0
  419. package/python/Lib/encodings/shift_jisx0213.py +39 -0
  420. package/python/Lib/encodings/tis_620.py +307 -0
  421. package/python/Lib/encodings/undefined.py +49 -0
  422. package/python/Lib/encodings/unicode_escape.py +46 -0
  423. package/python/Lib/encodings/utf_16.py +155 -0
  424. package/python/Lib/encodings/utf_16_be.py +42 -0
  425. package/python/Lib/encodings/utf_16_le.py +42 -0
  426. package/python/Lib/encodings/utf_32.py +150 -0
  427. package/python/Lib/encodings/utf_32_be.py +37 -0
  428. package/python/Lib/encodings/utf_32_le.py +37 -0
  429. package/python/Lib/encodings/utf_7.py +38 -0
  430. package/python/Lib/encodings/utf_8.py +42 -0
  431. package/python/Lib/encodings/utf_8_sig.py +130 -0
  432. package/python/Lib/encodings/uu_codec.py +103 -0
  433. package/python/Lib/encodings/zlib_codec.py +77 -0
  434. package/python/Lib/enum.py +2183 -0
  435. package/python/Lib/filecmp.py +320 -0
  436. package/python/Lib/fileinput.py +442 -0
  437. package/python/Lib/fnmatch.py +192 -0
  438. package/python/Lib/fractions.py +1043 -0
  439. package/python/Lib/ftplib.py +975 -0
  440. package/python/Lib/functools.py +1036 -0
  441. package/python/Lib/genericpath.py +200 -0
  442. package/python/Lib/getopt.py +215 -0
  443. package/python/Lib/getpass.py +192 -0
  444. package/python/Lib/gettext.py +657 -0
  445. package/python/Lib/glob.py +572 -0
  446. package/python/Lib/graphlib.py +250 -0
  447. package/python/Lib/gzip.py +693 -0
  448. package/python/Lib/hashlib.py +255 -0
  449. package/python/Lib/heapq.py +603 -0
  450. package/python/Lib/hmac.py +220 -0
  451. package/python/Lib/html/__init__.py +132 -0
  452. package/python/Lib/html/__pycache__/__init__.cpython-313.pyc +0 -0
  453. package/python/Lib/html/__pycache__/entities.cpython-313.pyc +0 -0
  454. package/python/Lib/html/__pycache__/parser.cpython-313.pyc +0 -0
  455. package/python/Lib/html/entities.py +2513 -0
  456. package/python/Lib/html/parser.py +583 -0
  457. package/python/Lib/http/__init__.py +202 -0
  458. package/python/Lib/http/__pycache__/__init__.cpython-313.pyc +0 -0
  459. package/python/Lib/http/__pycache__/client.cpython-313.pyc +0 -0
  460. package/python/Lib/http/__pycache__/cookiejar.cpython-313.pyc +0 -0
  461. package/python/Lib/http/__pycache__/cookies.cpython-313.pyc +0 -0
  462. package/python/Lib/http/client.py +1598 -0
  463. package/python/Lib/http/cookiejar.py +2122 -0
  464. package/python/Lib/http/cookies.py +635 -0
  465. package/python/Lib/http/server.py +1355 -0
  466. package/python/Lib/imaplib.py +1769 -0
  467. package/python/Lib/importlib/__init__.py +136 -0
  468. package/python/Lib/importlib/__pycache__/__init__.cpython-313.pyc +0 -0
  469. package/python/Lib/importlib/__pycache__/_abc.cpython-313.pyc +0 -0
  470. package/python/Lib/importlib/__pycache__/abc.cpython-313.pyc +0 -0
  471. package/python/Lib/importlib/__pycache__/readers.cpython-313.pyc +0 -0
  472. package/python/Lib/importlib/_abc.py +39 -0
  473. package/python/Lib/importlib/_bootstrap.py +1559 -0
  474. package/python/Lib/importlib/_bootstrap_external.py +1826 -0
  475. package/python/Lib/importlib/abc.py +243 -0
  476. package/python/Lib/importlib/machinery.py +21 -0
  477. package/python/Lib/importlib/metadata/__init__.py +1093 -0
  478. package/python/Lib/importlib/metadata/__pycache__/__init__.cpython-313.pyc +0 -0
  479. package/python/Lib/importlib/metadata/__pycache__/_adapters.cpython-313.pyc +0 -0
  480. package/python/Lib/importlib/metadata/__pycache__/_collections.cpython-313.pyc +0 -0
  481. package/python/Lib/importlib/metadata/__pycache__/_functools.cpython-313.pyc +0 -0
  482. package/python/Lib/importlib/metadata/__pycache__/_itertools.cpython-313.pyc +0 -0
  483. package/python/Lib/importlib/metadata/__pycache__/_meta.cpython-313.pyc +0 -0
  484. package/python/Lib/importlib/metadata/__pycache__/_text.cpython-313.pyc +0 -0
  485. package/python/Lib/importlib/metadata/_adapters.py +89 -0
  486. package/python/Lib/importlib/metadata/_collections.py +30 -0
  487. package/python/Lib/importlib/metadata/_functools.py +104 -0
  488. package/python/Lib/importlib/metadata/_itertools.py +73 -0
  489. package/python/Lib/importlib/metadata/_meta.py +67 -0
  490. package/python/Lib/importlib/metadata/_text.py +99 -0
  491. package/python/Lib/importlib/metadata/diagnose.py +21 -0
  492. package/python/Lib/importlib/readers.py +12 -0
  493. package/python/Lib/importlib/resources/__init__.py +43 -0
  494. package/python/Lib/importlib/resources/__pycache__/__init__.cpython-313.pyc +0 -0
  495. package/python/Lib/importlib/resources/__pycache__/_adapters.cpython-313.pyc +0 -0
  496. package/python/Lib/importlib/resources/__pycache__/_common.cpython-313.pyc +0 -0
  497. package/python/Lib/importlib/resources/__pycache__/_functional.cpython-313.pyc +0 -0
  498. package/python/Lib/importlib/resources/__pycache__/_itertools.cpython-313.pyc +0 -0
  499. package/python/Lib/importlib/resources/__pycache__/abc.cpython-313.pyc +0 -0
  500. package/python/Lib/importlib/resources/__pycache__/readers.cpython-313.pyc +0 -0
  501. package/python/Lib/importlib/resources/_adapters.py +168 -0
  502. package/python/Lib/importlib/resources/_common.py +211 -0
  503. package/python/Lib/importlib/resources/_functional.py +81 -0
  504. package/python/Lib/importlib/resources/_itertools.py +38 -0
  505. package/python/Lib/importlib/resources/abc.py +173 -0
  506. package/python/Lib/importlib/resources/readers.py +203 -0
  507. package/python/Lib/importlib/resources/simple.py +106 -0
  508. package/python/Lib/importlib/simple.py +14 -0
  509. package/python/Lib/importlib/util.py +274 -0
  510. package/python/Lib/inspect.py +3479 -0
  511. package/python/Lib/io.py +99 -0
  512. package/python/Lib/ipaddress.py +2440 -0
  513. package/python/Lib/json/__init__.py +365 -0
  514. package/python/Lib/json/__pycache__/__init__.cpython-313.pyc +0 -0
  515. package/python/Lib/json/__pycache__/decoder.cpython-313.pyc +0 -0
  516. package/python/Lib/json/__pycache__/encoder.cpython-313.pyc +0 -0
  517. package/python/Lib/json/__pycache__/scanner.cpython-313.pyc +0 -0
  518. package/python/Lib/json/decoder.py +364 -0
  519. package/python/Lib/json/encoder.py +446 -0
  520. package/python/Lib/json/scanner.py +73 -0
  521. package/python/Lib/json/tool.py +90 -0
  522. package/python/Lib/keyword.py +64 -0
  523. package/python/Lib/linecache.py +236 -0
  524. package/python/Lib/locale.py +1987 -0
  525. package/python/Lib/logging/__init__.py +2330 -0
  526. package/python/Lib/logging/__pycache__/__init__.cpython-313.pyc +0 -0
  527. package/python/Lib/logging/__pycache__/config.cpython-313.pyc +0 -0
  528. package/python/Lib/logging/__pycache__/handlers.cpython-313.pyc +0 -0
  529. package/python/Lib/logging/config.py +1080 -0
  530. package/python/Lib/logging/handlers.py +1629 -0
  531. package/python/Lib/lzma.py +364 -0
  532. package/python/Lib/mailbox.py +2219 -0
  533. package/python/Lib/mimetypes.py +679 -0
  534. package/python/Lib/modulefinder.py +671 -0
  535. package/python/Lib/multiprocessing/__init__.py +37 -0
  536. package/python/Lib/multiprocessing/connection.py +1216 -0
  537. package/python/Lib/multiprocessing/context.py +383 -0
  538. package/python/Lib/multiprocessing/dummy/__init__.py +126 -0
  539. package/python/Lib/multiprocessing/dummy/connection.py +75 -0
  540. package/python/Lib/multiprocessing/forkserver.py +373 -0
  541. package/python/Lib/multiprocessing/heap.py +337 -0
  542. package/python/Lib/multiprocessing/managers.py +1397 -0
  543. package/python/Lib/multiprocessing/pool.py +957 -0
  544. package/python/Lib/multiprocessing/popen_fork.py +97 -0
  545. package/python/Lib/multiprocessing/popen_forkserver.py +74 -0
  546. package/python/Lib/multiprocessing/popen_spawn_posix.py +76 -0
  547. package/python/Lib/multiprocessing/popen_spawn_win32.py +147 -0
  548. package/python/Lib/multiprocessing/process.py +436 -0
  549. package/python/Lib/multiprocessing/queues.py +399 -0
  550. package/python/Lib/multiprocessing/reduction.py +281 -0
  551. package/python/Lib/multiprocessing/resource_sharer.py +154 -0
  552. package/python/Lib/multiprocessing/resource_tracker.py +499 -0
  553. package/python/Lib/multiprocessing/shared_memory.py +544 -0
  554. package/python/Lib/multiprocessing/sharedctypes.py +240 -0
  555. package/python/Lib/multiprocessing/spawn.py +307 -0
  556. package/python/Lib/multiprocessing/synchronize.py +404 -0
  557. package/python/Lib/multiprocessing/util.py +562 -0
  558. package/python/Lib/netrc.py +199 -0
  559. package/python/Lib/ntpath.py +872 -0
  560. package/python/Lib/nturl2path.py +69 -0
  561. package/python/Lib/numbers.py +427 -0
  562. package/python/Lib/opcode.py +115 -0
  563. package/python/Lib/operator.py +467 -0
  564. package/python/Lib/optparse.py +1681 -0
  565. package/python/Lib/os.py +1184 -0
  566. package/python/Lib/pathlib/__init__.py +12 -0
  567. package/python/Lib/pathlib/__pycache__/__init__.cpython-313.pyc +0 -0
  568. package/python/Lib/pathlib/__pycache__/_abc.cpython-313.pyc +0 -0
  569. package/python/Lib/pathlib/__pycache__/_local.cpython-313.pyc +0 -0
  570. package/python/Lib/pathlib/_abc.py +930 -0
  571. package/python/Lib/pathlib/_local.py +861 -0
  572. package/python/Lib/pdb.py +2550 -0
  573. package/python/Lib/pickle.py +1860 -0
  574. package/python/Lib/pickletools.py +2904 -0
  575. package/python/Lib/pkgutil.py +529 -0
  576. package/python/Lib/platform.py +1454 -0
  577. package/python/Lib/plistlib.py +948 -0
  578. package/python/Lib/poplib.py +477 -0
  579. package/python/Lib/posixpath.py +578 -0
  580. package/python/Lib/pprint.py +658 -0
  581. package/python/Lib/profile.py +616 -0
  582. package/python/Lib/pstats.py +778 -0
  583. package/python/Lib/pty.py +211 -0
  584. package/python/Lib/py_compile.py +212 -0
  585. package/python/Lib/pyclbr.py +314 -0
  586. package/python/Lib/pydoc.py +2861 -0
  587. package/python/Lib/queue.py +383 -0
  588. package/python/Lib/quopri.py +237 -0
  589. package/python/Lib/random.py +1078 -0
  590. package/python/Lib/re/__init__.py +428 -0
  591. package/python/Lib/re/__pycache__/__init__.cpython-313.pyc +0 -0
  592. package/python/Lib/re/__pycache__/_casefix.cpython-313.pyc +0 -0
  593. package/python/Lib/re/__pycache__/_compiler.cpython-313.pyc +0 -0
  594. package/python/Lib/re/__pycache__/_constants.cpython-313.pyc +0 -0
  595. package/python/Lib/re/__pycache__/_parser.cpython-313.pyc +0 -0
  596. package/python/Lib/re/_casefix.py +106 -0
  597. package/python/Lib/re/_compiler.py +768 -0
  598. package/python/Lib/re/_constants.py +222 -0
  599. package/python/Lib/re/_parser.py +1081 -0
  600. package/python/Lib/reprlib.py +230 -0
  601. package/python/Lib/rlcompleter.py +222 -0
  602. package/python/Lib/runpy.py +326 -0
  603. package/python/Lib/sched.py +167 -0
  604. package/python/Lib/secrets.py +71 -0
  605. package/python/Lib/selectors.py +603 -0
  606. package/python/Lib/shelve.py +250 -0
  607. package/python/Lib/shlex.py +345 -0
  608. package/python/Lib/shutil.py +1569 -0
  609. package/python/Lib/signal.py +94 -0
  610. package/python/Lib/site.py +773 -0
  611. package/python/Lib/smtplib.py +1123 -0
  612. package/python/Lib/socket.py +988 -0
  613. package/python/Lib/socketserver.py +863 -0
  614. package/python/Lib/sqlite3/__init__.py +70 -0
  615. package/python/Lib/sqlite3/__main__.py +139 -0
  616. package/python/Lib/sqlite3/dbapi2.py +108 -0
  617. package/python/Lib/sqlite3/dump.py +118 -0
  618. package/python/Lib/sre_compile.py +7 -0
  619. package/python/Lib/sre_constants.py +7 -0
  620. package/python/Lib/sre_parse.py +7 -0
  621. package/python/Lib/ssl.py +1529 -0
  622. package/python/Lib/stat.py +212 -0
  623. package/python/Lib/statistics.py +1817 -0
  624. package/python/Lib/string.py +314 -0
  625. package/python/Lib/stringprep.py +272 -0
  626. package/python/Lib/struct.py +15 -0
  627. package/python/Lib/subprocess.py +2258 -0
  628. package/python/Lib/symtable.py +414 -0
  629. package/python/Lib/sysconfig/__init__.py +734 -0
  630. package/python/Lib/sysconfig/__main__.py +248 -0
  631. package/python/Lib/sysconfig/__pycache__/__init__.cpython-313.pyc +0 -0
  632. package/python/Lib/tabnanny.py +340 -0
  633. package/python/Lib/tarfile.py +3136 -0
  634. package/python/Lib/tempfile.py +958 -0
  635. package/python/Lib/textwrap.py +497 -0
  636. package/python/Lib/this.py +28 -0
  637. package/python/Lib/threading.py +1602 -0
  638. package/python/Lib/timeit.py +381 -0
  639. package/python/Lib/token.py +141 -0
  640. package/python/Lib/tokenize.py +592 -0
  641. package/python/Lib/tomllib/__init__.py +10 -0
  642. package/python/Lib/tomllib/__pycache__/__init__.cpython-313.pyc +0 -0
  643. package/python/Lib/tomllib/__pycache__/_parser.cpython-313.pyc +0 -0
  644. package/python/Lib/tomllib/__pycache__/_re.cpython-313.pyc +0 -0
  645. package/python/Lib/tomllib/__pycache__/_types.cpython-313.pyc +0 -0
  646. package/python/Lib/tomllib/_parser.py +703 -0
  647. package/python/Lib/tomllib/_re.py +107 -0
  648. package/python/Lib/tomllib/_types.py +10 -0
  649. package/python/Lib/tomllib/mypy.ini +15 -0
  650. package/python/Lib/trace.py +754 -0
  651. package/python/Lib/traceback.py +1639 -0
  652. package/python/Lib/tracemalloc.py +560 -0
  653. package/python/Lib/tty.py +73 -0
  654. package/python/Lib/types.py +346 -0
  655. package/python/Lib/typing.py +3846 -0
  656. package/python/Lib/unittest/__init__.py +80 -0
  657. package/python/Lib/unittest/__main__.py +18 -0
  658. package/python/Lib/unittest/_log.py +86 -0
  659. package/python/Lib/unittest/async_case.py +146 -0
  660. package/python/Lib/unittest/case.py +1478 -0
  661. package/python/Lib/unittest/loader.py +460 -0
  662. package/python/Lib/unittest/main.py +280 -0
  663. package/python/Lib/unittest/mock.py +3189 -0
  664. package/python/Lib/unittest/result.py +256 -0
  665. package/python/Lib/unittest/runner.py +292 -0
  666. package/python/Lib/unittest/signals.py +71 -0
  667. package/python/Lib/unittest/suite.py +379 -0
  668. package/python/Lib/unittest/util.py +170 -0
  669. package/python/Lib/urllib/__init__.py +0 -0
  670. package/python/Lib/urllib/__pycache__/__init__.cpython-313.pyc +0 -0
  671. package/python/Lib/urllib/__pycache__/error.cpython-313.pyc +0 -0
  672. package/python/Lib/urllib/__pycache__/parse.cpython-313.pyc +0 -0
  673. package/python/Lib/urllib/__pycache__/request.cpython-313.pyc +0 -0
  674. package/python/Lib/urllib/__pycache__/response.cpython-313.pyc +0 -0
  675. package/python/Lib/urllib/error.py +74 -0
  676. package/python/Lib/urllib/parse.py +1264 -0
  677. package/python/Lib/urllib/request.py +2796 -0
  678. package/python/Lib/urllib/response.py +84 -0
  679. package/python/Lib/urllib/robotparser.py +363 -0
  680. package/python/Lib/uuid.py +784 -0
  681. package/python/Lib/warnings.py +735 -0
  682. package/python/Lib/wave.py +665 -0
  683. package/python/Lib/weakref.py +674 -0
  684. package/python/Lib/webbrowser.py +724 -0
  685. package/python/Lib/wsgiref/__init__.py +25 -0
  686. package/python/Lib/wsgiref/handlers.py +575 -0
  687. package/python/Lib/wsgiref/headers.py +192 -0
  688. package/python/Lib/wsgiref/simple_server.py +161 -0
  689. package/python/Lib/wsgiref/types.py +54 -0
  690. package/python/Lib/wsgiref/util.py +159 -0
  691. package/python/Lib/wsgiref/validate.py +438 -0
  692. package/python/Lib/xml/__init__.py +20 -0
  693. package/python/Lib/xml/__pycache__/__init__.cpython-313.pyc +0 -0
  694. package/python/Lib/xml/dom/NodeFilter.py +27 -0
  695. package/python/Lib/xml/dom/__init__.py +140 -0
  696. package/python/Lib/xml/dom/domreg.py +99 -0
  697. package/python/Lib/xml/dom/expatbuilder.py +962 -0
  698. package/python/Lib/xml/dom/minicompat.py +109 -0
  699. package/python/Lib/xml/dom/minidom.py +2024 -0
  700. package/python/Lib/xml/dom/pulldom.py +336 -0
  701. package/python/Lib/xml/dom/xmlbuilder.py +389 -0
  702. package/python/Lib/xml/etree/ElementInclude.py +186 -0
  703. package/python/Lib/xml/etree/ElementPath.py +430 -0
  704. package/python/Lib/xml/etree/ElementTree.py +2116 -0
  705. package/python/Lib/xml/etree/__init__.py +33 -0
  706. package/python/Lib/xml/etree/cElementTree.py +3 -0
  707. package/python/Lib/xml/parsers/__init__.py +8 -0
  708. package/python/Lib/xml/parsers/__pycache__/__init__.cpython-313.pyc +0 -0
  709. package/python/Lib/xml/parsers/__pycache__/expat.cpython-313.pyc +0 -0
  710. package/python/Lib/xml/parsers/expat.py +8 -0
  711. package/python/Lib/xml/sax/__init__.py +94 -0
  712. package/python/Lib/xml/sax/_exceptions.py +127 -0
  713. package/python/Lib/xml/sax/expatreader.py +454 -0
  714. package/python/Lib/xml/sax/handler.py +387 -0
  715. package/python/Lib/xml/sax/saxutils.py +369 -0
  716. package/python/Lib/xml/sax/xmlreader.py +378 -0
  717. package/python/Lib/xmlrpc/__init__.py +1 -0
  718. package/python/Lib/xmlrpc/__pycache__/__init__.cpython-313.pyc +0 -0
  719. package/python/Lib/xmlrpc/__pycache__/client.cpython-313.pyc +0 -0
  720. package/python/Lib/xmlrpc/client.py +1503 -0
  721. package/python/Lib/xmlrpc/server.py +1002 -0
  722. package/python/Lib/zipapp.py +229 -0
  723. package/python/Lib/zipfile/__init__.py +2391 -0
  724. package/python/Lib/zipfile/__main__.py +4 -0
  725. package/python/Lib/zipfile/__pycache__/__init__.cpython-313.pyc +0 -0
  726. package/python/Lib/zipfile/_path/__init__.py +452 -0
  727. package/python/Lib/zipfile/_path/__pycache__/__init__.cpython-313.pyc +0 -0
  728. package/python/Lib/zipfile/_path/__pycache__/glob.cpython-313.pyc +0 -0
  729. package/python/Lib/zipfile/_path/glob.py +113 -0
  730. package/python/Lib/zipimport.py +803 -0
  731. package/python/Lib/zoneinfo/__init__.py +34 -0
  732. package/python/Lib/zoneinfo/_common.py +172 -0
  733. package/python/Lib/zoneinfo/_tzpath.py +189 -0
  734. package/python/Lib/zoneinfo/_zoneinfo.py +779 -0
  735. package/python/licenses/LICENSE.bdb.txt +126 -0
  736. package/python/licenses/LICENSE.bzip2.txt +37 -0
  737. package/python/licenses/LICENSE.cpython.txt +771 -0
  738. package/python/licenses/LICENSE.expat.txt +21 -0
  739. package/python/licenses/LICENSE.libX11.txt +942 -0
  740. package/python/licenses/LICENSE.libXau.txt +21 -0
  741. package/python/licenses/LICENSE.libedit.txt +29 -0
  742. package/python/licenses/LICENSE.libffi.txt +21 -0
  743. package/python/licenses/LICENSE.liblzma.txt +13 -0
  744. package/python/licenses/LICENSE.libuuid.txt +27 -0
  745. package/python/licenses/LICENSE.libxcb.txt +30 -0
  746. package/python/licenses/LICENSE.mpdecimal.txt +24 -0
  747. package/python/licenses/LICENSE.ncurses.txt +29 -0
  748. package/python/licenses/LICENSE.openssl-1.1.txt +124 -0
  749. package/python/licenses/LICENSE.openssl-3.txt +177 -0
  750. package/python/licenses/LICENSE.sqlite.txt +23 -0
  751. package/python/licenses/LICENSE.tcl.txt +40 -0
  752. package/python/licenses/LICENSE.tix.txt +54 -0
  753. package/python/licenses/LICENSE.zlib.txt +21 -0
  754. package/python/python.exe +0 -0
  755. package/python/python3.dll +0 -0
  756. package/python/python313.dll +0 -0
  757. package/python/pythonw.exe +0 -0
  758. package/python/vcruntime140.dll +0 -0
  759. package/python/vcruntime140_1.dll +0 -0
@@ -0,0 +1,2183 @@
1
+ import sys
2
+ import builtins as bltns
3
+ from functools import partial
4
+ from types import MappingProxyType, DynamicClassAttribute
5
+
6
+
7
+ __all__ = [
8
+ 'EnumType', 'EnumMeta', 'EnumDict',
9
+ 'Enum', 'IntEnum', 'StrEnum', 'Flag', 'IntFlag', 'ReprEnum',
10
+ 'auto', 'unique', 'property', 'verify', 'member', 'nonmember',
11
+ 'FlagBoundary', 'STRICT', 'CONFORM', 'EJECT', 'KEEP',
12
+ 'global_flag_repr', 'global_enum_repr', 'global_str', 'global_enum',
13
+ 'EnumCheck', 'CONTINUOUS', 'NAMED_FLAGS', 'UNIQUE',
14
+ 'pickle_by_global_name', 'pickle_by_enum_name',
15
+ ]
16
+
17
+
18
+ # Dummy value for Enum and Flag as there are explicit checks for them
19
+ # before they have been created.
20
+ # This is also why there are checks in EnumType like `if Enum is not None`
21
+ Enum = Flag = EJECT = _stdlib_enums = ReprEnum = None
22
+
23
+ class nonmember(object):
24
+ """
25
+ Protects item from becoming an Enum member during class creation.
26
+ """
27
+ def __init__(self, value):
28
+ self.value = value
29
+
30
+ class member(object):
31
+ """
32
+ Forces item to become an Enum member during class creation.
33
+ """
34
+ def __init__(self, value):
35
+ self.value = value
36
+
37
+ def _is_descriptor(obj):
38
+ """
39
+ Returns True if obj is a descriptor, False otherwise.
40
+ """
41
+ return not isinstance(obj, partial) and (
42
+ hasattr(obj, '__get__') or
43
+ hasattr(obj, '__set__') or
44
+ hasattr(obj, '__delete__')
45
+ )
46
+
47
+ def _is_dunder(name):
48
+ """
49
+ Returns True if a __dunder__ name, False otherwise.
50
+ """
51
+ return (
52
+ len(name) > 4 and
53
+ name[:2] == name[-2:] == '__' and
54
+ name[2] != '_' and
55
+ name[-3] != '_'
56
+ )
57
+
58
+ def _is_sunder(name):
59
+ """
60
+ Returns True if a _sunder_ name, False otherwise.
61
+ """
62
+ return (
63
+ len(name) > 2 and
64
+ name[0] == name[-1] == '_' and
65
+ name[1] != '_' and
66
+ name[-2] != '_'
67
+ )
68
+
69
+ def _is_internal_class(cls_name, obj):
70
+ # do not use `re` as `re` imports `enum`
71
+ if not isinstance(obj, type):
72
+ return False
73
+ qualname = getattr(obj, '__qualname__', '')
74
+ s_pattern = cls_name + '.' + getattr(obj, '__name__', '')
75
+ e_pattern = '.' + s_pattern
76
+ return qualname == s_pattern or qualname.endswith(e_pattern)
77
+
78
+ def _is_private(cls_name, name):
79
+ # do not use `re` as `re` imports `enum`
80
+ pattern = '_%s__' % (cls_name, )
81
+ pat_len = len(pattern)
82
+ if (
83
+ len(name) > pat_len
84
+ and name.startswith(pattern)
85
+ and (name[-1] != '_' or name[-2] != '_')
86
+ ):
87
+ return True
88
+ else:
89
+ return False
90
+
91
+ def _is_single_bit(num):
92
+ """
93
+ True if only one bit set in num (should be an int)
94
+ """
95
+ if num == 0:
96
+ return False
97
+ num &= num - 1
98
+ return num == 0
99
+
100
+ def _make_class_unpicklable(obj):
101
+ """
102
+ Make the given obj un-picklable.
103
+
104
+ obj should be either a dictionary, or an Enum
105
+ """
106
+ def _break_on_call_reduce(self, proto):
107
+ raise TypeError('%r cannot be pickled' % self)
108
+ if isinstance(obj, dict):
109
+ obj['__reduce_ex__'] = _break_on_call_reduce
110
+ obj['__module__'] = '<unknown>'
111
+ else:
112
+ setattr(obj, '__reduce_ex__', _break_on_call_reduce)
113
+ setattr(obj, '__module__', '<unknown>')
114
+
115
+ def _iter_bits_lsb(num):
116
+ # num must be a positive integer
117
+ original = num
118
+ if isinstance(num, Enum):
119
+ num = num.value
120
+ if num < 0:
121
+ raise ValueError('%r is not a positive integer' % original)
122
+ while num:
123
+ b = num & (~num + 1)
124
+ yield b
125
+ num ^= b
126
+
127
+ def show_flag_values(value):
128
+ return list(_iter_bits_lsb(value))
129
+
130
+ def bin(num, max_bits=None):
131
+ """
132
+ Like built-in bin(), except negative values are represented in
133
+ twos-complement, and the leading bit always indicates sign
134
+ (0=positive, 1=negative).
135
+
136
+ >>> bin(10)
137
+ '0b0 1010'
138
+ >>> bin(~10) # ~10 is -11
139
+ '0b1 0101'
140
+ """
141
+
142
+ num = num.__index__()
143
+ ceiling = 2 ** (num).bit_length()
144
+ if num >= 0:
145
+ s = bltns.bin(num + ceiling).replace('1', '0', 1)
146
+ else:
147
+ s = bltns.bin(~num ^ (ceiling - 1) + ceiling)
148
+ sign = s[:3]
149
+ digits = s[3:]
150
+ if max_bits is not None:
151
+ if len(digits) < max_bits:
152
+ digits = (sign[-1] * max_bits + digits)[-max_bits:]
153
+ return "%s %s" % (sign, digits)
154
+
155
+ def _dedent(text):
156
+ """
157
+ Like textwrap.dedent. Rewritten because we cannot import textwrap.
158
+ """
159
+ lines = text.split('\n')
160
+ for i, ch in enumerate(lines[0]):
161
+ if ch != ' ':
162
+ break
163
+ for j, l in enumerate(lines):
164
+ lines[j] = l[i:]
165
+ return '\n'.join(lines)
166
+
167
+ class _not_given:
168
+ def __repr__(self):
169
+ return('<not given>')
170
+ _not_given = _not_given()
171
+
172
+ class _auto_null:
173
+ def __repr__(self):
174
+ return '_auto_null'
175
+ _auto_null = _auto_null()
176
+
177
+ class auto:
178
+ """
179
+ Instances are replaced with an appropriate value in Enum class suites.
180
+ """
181
+ def __init__(self, value=_auto_null):
182
+ self.value = value
183
+
184
+ def __repr__(self):
185
+ return "auto(%r)" % self.value
186
+
187
+ class property(DynamicClassAttribute):
188
+ """
189
+ This is a descriptor, used to define attributes that act differently
190
+ when accessed through an enum member and through an enum class.
191
+ Instance access is the same as property(), but access to an attribute
192
+ through the enum class will instead look in the class' _member_map_ for
193
+ a corresponding enum member.
194
+ """
195
+
196
+ member = None
197
+ _attr_type = None
198
+ _cls_type = None
199
+
200
+ def __get__(self, instance, ownerclass=None):
201
+ if instance is None:
202
+ if self.member is not None:
203
+ return self.member
204
+ else:
205
+ raise AttributeError(
206
+ '%r has no attribute %r' % (ownerclass, self.name)
207
+ )
208
+ if self.fget is not None:
209
+ # use previous enum.property
210
+ return self.fget(instance)
211
+ elif self._attr_type == 'attr':
212
+ # look up previous attibute
213
+ return getattr(self._cls_type, self.name)
214
+ elif self._attr_type == 'desc':
215
+ # use previous descriptor
216
+ return getattr(instance._value_, self.name)
217
+ # look for a member by this name.
218
+ try:
219
+ return ownerclass._member_map_[self.name]
220
+ except KeyError:
221
+ raise AttributeError(
222
+ '%r has no attribute %r' % (ownerclass, self.name)
223
+ ) from None
224
+
225
+ def __set__(self, instance, value):
226
+ if self.fset is not None:
227
+ return self.fset(instance, value)
228
+ raise AttributeError(
229
+ "<enum %r> cannot set attribute %r" % (self.clsname, self.name)
230
+ )
231
+
232
+ def __delete__(self, instance):
233
+ if self.fdel is not None:
234
+ return self.fdel(instance)
235
+ raise AttributeError(
236
+ "<enum %r> cannot delete attribute %r" % (self.clsname, self.name)
237
+ )
238
+
239
+ def __set_name__(self, ownerclass, name):
240
+ self.name = name
241
+ self.clsname = ownerclass.__name__
242
+
243
+
244
+ class _proto_member:
245
+ """
246
+ intermediate step for enum members between class execution and final creation
247
+ """
248
+
249
+ def __init__(self, value):
250
+ self.value = value
251
+
252
+ def __set_name__(self, enum_class, member_name):
253
+ """
254
+ convert each quasi-member into an instance of the new enum class
255
+ """
256
+ # first step: remove ourself from enum_class
257
+ delattr(enum_class, member_name)
258
+ # second step: create member based on enum_class
259
+ value = self.value
260
+ if not isinstance(value, tuple):
261
+ args = (value, )
262
+ else:
263
+ args = value
264
+ if enum_class._member_type_ is tuple: # special case for tuple enums
265
+ args = (args, ) # wrap it one more time
266
+ if not enum_class._use_args_:
267
+ enum_member = enum_class._new_member_(enum_class)
268
+ else:
269
+ enum_member = enum_class._new_member_(enum_class, *args)
270
+ if not hasattr(enum_member, '_value_'):
271
+ if enum_class._member_type_ is object:
272
+ enum_member._value_ = value
273
+ else:
274
+ try:
275
+ enum_member._value_ = enum_class._member_type_(*args)
276
+ except Exception as exc:
277
+ new_exc = TypeError(
278
+ '_value_ not set in __new__, unable to create it'
279
+ )
280
+ new_exc.__cause__ = exc
281
+ raise new_exc
282
+ value = enum_member._value_
283
+ enum_member._name_ = member_name
284
+ enum_member.__objclass__ = enum_class
285
+ enum_member.__init__(*args)
286
+ enum_member._sort_order_ = len(enum_class._member_names_)
287
+
288
+ if Flag is not None and issubclass(enum_class, Flag):
289
+ if isinstance(value, int):
290
+ enum_class._flag_mask_ |= value
291
+ if _is_single_bit(value):
292
+ enum_class._singles_mask_ |= value
293
+ enum_class._all_bits_ = 2 ** ((enum_class._flag_mask_).bit_length()) - 1
294
+
295
+ # If another member with the same value was already defined, the
296
+ # new member becomes an alias to the existing one.
297
+ try:
298
+ try:
299
+ # try to do a fast lookup to avoid the quadratic loop
300
+ enum_member = enum_class._value2member_map_[value]
301
+ except TypeError:
302
+ for name, canonical_member in enum_class._member_map_.items():
303
+ if canonical_member._value_ == value:
304
+ enum_member = canonical_member
305
+ break
306
+ else:
307
+ raise KeyError
308
+ except KeyError:
309
+ # this could still be an alias if the value is multi-bit and the
310
+ # class is a flag class
311
+ if (
312
+ Flag is None
313
+ or not issubclass(enum_class, Flag)
314
+ ):
315
+ # no other instances found, record this member in _member_names_
316
+ enum_class._member_names_.append(member_name)
317
+ elif (
318
+ Flag is not None
319
+ and issubclass(enum_class, Flag)
320
+ and isinstance(value, int)
321
+ and _is_single_bit(value)
322
+ ):
323
+ # no other instances found, record this member in _member_names_
324
+ enum_class._member_names_.append(member_name)
325
+
326
+ enum_class._add_member_(member_name, enum_member)
327
+ try:
328
+ # This may fail if value is not hashable. We can't add the value
329
+ # to the map, and by-value lookups for this value will be
330
+ # linear.
331
+ enum_class._value2member_map_.setdefault(value, enum_member)
332
+ if value not in enum_class._hashable_values_:
333
+ enum_class._hashable_values_.append(value)
334
+ except TypeError:
335
+ # keep track of the value in a list so containment checks are quick
336
+ enum_class._unhashable_values_.append(value)
337
+ enum_class._unhashable_values_map_.setdefault(member_name, []).append(value)
338
+
339
+
340
+ class EnumDict(dict):
341
+ """
342
+ Track enum member order and ensure member names are not reused.
343
+
344
+ EnumType will use the names found in self._member_names as the
345
+ enumeration member names.
346
+ """
347
+ def __init__(self, cls_name=None):
348
+ super().__init__()
349
+ self._member_names = {} # use a dict -- faster look-up than a list, and keeps insertion order since 3.7
350
+ self._last_values = []
351
+ self._ignore = []
352
+ self._auto_called = False
353
+ self._cls_name = cls_name
354
+
355
+ def __setitem__(self, key, value):
356
+ """
357
+ Changes anything not dundered or not a descriptor.
358
+
359
+ If an enum member name is used twice, an error is raised; duplicate
360
+ values are not checked for.
361
+
362
+ Single underscore (sunder) names are reserved.
363
+ """
364
+ if self._cls_name is not None and _is_private(self._cls_name, key):
365
+ # do nothing, name will be a normal attribute
366
+ pass
367
+ elif _is_sunder(key):
368
+ if key not in (
369
+ '_order_',
370
+ '_generate_next_value_', '_numeric_repr_', '_missing_', '_ignore_',
371
+ '_iter_member_', '_iter_member_by_value_', '_iter_member_by_def_',
372
+ '_add_alias_', '_add_value_alias_',
373
+ # While not in use internally, those are common for pretty
374
+ # printing and thus excluded from Enum's reservation of
375
+ # _sunder_ names
376
+ ) and not key.startswith('_repr_'):
377
+ raise ValueError(
378
+ '_sunder_ names, such as %r, are reserved for future Enum use'
379
+ % (key, )
380
+ )
381
+ if key == '_generate_next_value_':
382
+ # check if members already defined as auto()
383
+ if self._auto_called:
384
+ raise TypeError("_generate_next_value_ must be defined before members")
385
+ _gnv = value.__func__ if isinstance(value, staticmethod) else value
386
+ setattr(self, '_generate_next_value', _gnv)
387
+ elif key == '_ignore_':
388
+ if isinstance(value, str):
389
+ value = value.replace(',',' ').split()
390
+ else:
391
+ value = list(value)
392
+ self._ignore = value
393
+ already = set(value) & set(self._member_names)
394
+ if already:
395
+ raise ValueError(
396
+ '_ignore_ cannot specify already set names: %r'
397
+ % (already, )
398
+ )
399
+ elif _is_dunder(key):
400
+ if key == '__order__':
401
+ key = '_order_'
402
+ elif key in self._member_names:
403
+ # descriptor overwriting an enum?
404
+ raise TypeError('%r already defined as %r' % (key, self[key]))
405
+ elif key in self._ignore:
406
+ pass
407
+ elif isinstance(value, nonmember):
408
+ # unwrap value here; it won't be processed by the below `else`
409
+ value = value.value
410
+ elif isinstance(value, partial):
411
+ import warnings
412
+ warnings.warn('functools.partial will be a method descriptor '
413
+ 'in future Python versions; wrap it in '
414
+ 'enum.member() if you want to preserve the '
415
+ 'old behavior', FutureWarning, stacklevel=2)
416
+ elif _is_descriptor(value):
417
+ pass
418
+ elif self._cls_name is not None and _is_internal_class(self._cls_name, value):
419
+ # do nothing, name will be a normal attribute
420
+ pass
421
+ else:
422
+ if key in self:
423
+ # enum overwriting a descriptor?
424
+ raise TypeError('%r already defined as %r' % (key, self[key]))
425
+ elif isinstance(value, member):
426
+ # unwrap value here -- it will become a member
427
+ value = value.value
428
+ non_auto_store = True
429
+ single = False
430
+ if isinstance(value, auto):
431
+ single = True
432
+ value = (value, )
433
+ if isinstance(value, tuple) and any(isinstance(v, auto) for v in value):
434
+ # insist on an actual tuple, no subclasses, in keeping with only supporting
435
+ # top-level auto() usage (not contained in any other data structure)
436
+ auto_valued = []
437
+ t = type(value)
438
+ for v in value:
439
+ if isinstance(v, auto):
440
+ non_auto_store = False
441
+ if v.value == _auto_null:
442
+ v.value = self._generate_next_value(
443
+ key, 1, len(self._member_names), self._last_values[:],
444
+ )
445
+ self._auto_called = True
446
+ v = v.value
447
+ self._last_values.append(v)
448
+ auto_valued.append(v)
449
+ if single:
450
+ value = auto_valued[0]
451
+ else:
452
+ try:
453
+ # accepts iterable as multiple arguments?
454
+ value = t(auto_valued)
455
+ except TypeError:
456
+ # then pass them in singly
457
+ value = t(*auto_valued)
458
+ self._member_names[key] = None
459
+ if non_auto_store:
460
+ self._last_values.append(value)
461
+ super().__setitem__(key, value)
462
+
463
+ @property
464
+ def member_names(self):
465
+ return list(self._member_names)
466
+
467
+ def update(self, members, **more_members):
468
+ try:
469
+ for name in members.keys():
470
+ self[name] = members[name]
471
+ except AttributeError:
472
+ for name, value in members:
473
+ self[name] = value
474
+ for name, value in more_members.items():
475
+ self[name] = value
476
+
477
+ _EnumDict = EnumDict # keep private name for backwards compatibility
478
+
479
+
480
+ class EnumType(type):
481
+ """
482
+ Metaclass for Enum
483
+ """
484
+
485
+ @classmethod
486
+ def __prepare__(metacls, cls, bases, **kwds):
487
+ # check that previous enum members do not exist
488
+ metacls._check_for_existing_members_(cls, bases)
489
+ # create the namespace dict
490
+ enum_dict = EnumDict(cls)
491
+ # inherit previous flags and _generate_next_value_ function
492
+ member_type, first_enum = metacls._get_mixins_(cls, bases)
493
+ if first_enum is not None:
494
+ enum_dict['_generate_next_value_'] = getattr(
495
+ first_enum, '_generate_next_value_', None,
496
+ )
497
+ return enum_dict
498
+
499
+ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **kwds):
500
+ # an Enum class is final once enumeration items have been defined; it
501
+ # cannot be mixed with other types (int, float, etc.) if it has an
502
+ # inherited __new__ unless a new __new__ is defined (or the resulting
503
+ # class will fail).
504
+ #
505
+ if _simple:
506
+ return super().__new__(metacls, cls, bases, classdict, **kwds)
507
+ #
508
+ # remove any keys listed in _ignore_
509
+ classdict.setdefault('_ignore_', []).append('_ignore_')
510
+ ignore = classdict['_ignore_']
511
+ for key in ignore:
512
+ classdict.pop(key, None)
513
+ #
514
+ # grab member names
515
+ member_names = classdict._member_names
516
+ #
517
+ # check for illegal enum names (any others?)
518
+ invalid_names = set(member_names) & {'mro', ''}
519
+ if invalid_names:
520
+ raise ValueError('invalid enum member name(s) %s' % (
521
+ ','.join(repr(n) for n in invalid_names)
522
+ ))
523
+ #
524
+ # adjust the sunders
525
+ _order_ = classdict.pop('_order_', None)
526
+ _gnv = classdict.get('_generate_next_value_')
527
+ if _gnv is not None and type(_gnv) is not staticmethod:
528
+ _gnv = staticmethod(_gnv)
529
+ # convert to normal dict
530
+ classdict = dict(classdict.items())
531
+ if _gnv is not None:
532
+ classdict['_generate_next_value_'] = _gnv
533
+ #
534
+ # data type of member and the controlling Enum class
535
+ member_type, first_enum = metacls._get_mixins_(cls, bases)
536
+ __new__, save_new, use_args = metacls._find_new_(
537
+ classdict, member_type, first_enum,
538
+ )
539
+ classdict['_new_member_'] = __new__
540
+ classdict['_use_args_'] = use_args
541
+ #
542
+ # convert future enum members into temporary _proto_members
543
+ for name in member_names:
544
+ value = classdict[name]
545
+ classdict[name] = _proto_member(value)
546
+ #
547
+ # house-keeping structures
548
+ classdict['_member_names_'] = []
549
+ classdict['_member_map_'] = {}
550
+ classdict['_value2member_map_'] = {}
551
+ classdict['_hashable_values_'] = [] # for comparing with non-hashable types
552
+ classdict['_unhashable_values_'] = [] # e.g. frozenset() with set()
553
+ classdict['_unhashable_values_map_'] = {}
554
+ classdict['_member_type_'] = member_type
555
+ # now set the __repr__ for the value
556
+ classdict['_value_repr_'] = metacls._find_data_repr_(cls, bases)
557
+ #
558
+ # Flag structures (will be removed if final class is not a Flag
559
+ classdict['_boundary_'] = (
560
+ boundary
561
+ or getattr(first_enum, '_boundary_', None)
562
+ )
563
+ classdict['_flag_mask_'] = 0
564
+ classdict['_singles_mask_'] = 0
565
+ classdict['_all_bits_'] = 0
566
+ classdict['_inverted_'] = None
567
+ try:
568
+ classdict['_%s__in_progress' % cls] = True
569
+ enum_class = super().__new__(metacls, cls, bases, classdict, **kwds)
570
+ classdict['_%s__in_progress' % cls] = False
571
+ delattr(enum_class, '_%s__in_progress' % cls)
572
+ except Exception as e:
573
+ # since 3.12 the note "Error calling __set_name__ on '_proto_member' instance ..."
574
+ # is tacked on to the error instead of raising a RuntimeError, so discard it
575
+ if hasattr(e, '__notes__'):
576
+ del e.__notes__
577
+ raise
578
+ # update classdict with any changes made by __init_subclass__
579
+ classdict.update(enum_class.__dict__)
580
+ #
581
+ # double check that repr and friends are not the mixin's or various
582
+ # things break (such as pickle)
583
+ # however, if the method is defined in the Enum itself, don't replace
584
+ # it
585
+ #
586
+ # Also, special handling for ReprEnum
587
+ if ReprEnum is not None and ReprEnum in bases:
588
+ if member_type is object:
589
+ raise TypeError(
590
+ 'ReprEnum subclasses must be mixed with a data type (i.e.'
591
+ ' int, str, float, etc.)'
592
+ )
593
+ if '__format__' not in classdict:
594
+ enum_class.__format__ = member_type.__format__
595
+ classdict['__format__'] = enum_class.__format__
596
+ if '__str__' not in classdict:
597
+ method = member_type.__str__
598
+ if method is object.__str__:
599
+ # if member_type does not define __str__, object.__str__ will use
600
+ # its __repr__ instead, so we'll also use its __repr__
601
+ method = member_type.__repr__
602
+ enum_class.__str__ = method
603
+ classdict['__str__'] = enum_class.__str__
604
+ for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
605
+ if name not in classdict:
606
+ # check for mixin overrides before replacing
607
+ enum_method = getattr(first_enum, name)
608
+ found_method = getattr(enum_class, name)
609
+ object_method = getattr(object, name)
610
+ data_type_method = getattr(member_type, name)
611
+ if found_method in (data_type_method, object_method):
612
+ setattr(enum_class, name, enum_method)
613
+ #
614
+ # for Flag, add __or__, __and__, __xor__, and __invert__
615
+ if Flag is not None and issubclass(enum_class, Flag):
616
+ for name in (
617
+ '__or__', '__and__', '__xor__',
618
+ '__ror__', '__rand__', '__rxor__',
619
+ '__invert__'
620
+ ):
621
+ if name not in classdict:
622
+ enum_method = getattr(Flag, name)
623
+ setattr(enum_class, name, enum_method)
624
+ classdict[name] = enum_method
625
+ #
626
+ # replace any other __new__ with our own (as long as Enum is not None,
627
+ # anyway) -- again, this is to support pickle
628
+ if Enum is not None:
629
+ # if the user defined their own __new__, save it before it gets
630
+ # clobbered in case they subclass later
631
+ if save_new:
632
+ enum_class.__new_member__ = __new__
633
+ enum_class.__new__ = Enum.__new__
634
+ #
635
+ # py3 support for definition order (helps keep py2/py3 code in sync)
636
+ #
637
+ # _order_ checking is spread out into three/four steps
638
+ # - if enum_class is a Flag:
639
+ # - remove any non-single-bit flags from _order_
640
+ # - remove any aliases from _order_
641
+ # - check that _order_ and _member_names_ match
642
+ #
643
+ # step 1: ensure we have a list
644
+ if _order_ is not None:
645
+ if isinstance(_order_, str):
646
+ _order_ = _order_.replace(',', ' ').split()
647
+ #
648
+ # remove Flag structures if final class is not a Flag
649
+ if (
650
+ Flag is None and cls != 'Flag'
651
+ or Flag is not None and not issubclass(enum_class, Flag)
652
+ ):
653
+ delattr(enum_class, '_boundary_')
654
+ delattr(enum_class, '_flag_mask_')
655
+ delattr(enum_class, '_singles_mask_')
656
+ delattr(enum_class, '_all_bits_')
657
+ delattr(enum_class, '_inverted_')
658
+ elif Flag is not None and issubclass(enum_class, Flag):
659
+ # set correct __iter__
660
+ member_list = [m._value_ for m in enum_class]
661
+ if member_list != sorted(member_list):
662
+ enum_class._iter_member_ = enum_class._iter_member_by_def_
663
+ if _order_:
664
+ # _order_ step 2: remove any items from _order_ that are not single-bit
665
+ _order_ = [
666
+ o
667
+ for o in _order_
668
+ if o not in enum_class._member_map_ or _is_single_bit(enum_class[o]._value_)
669
+ ]
670
+ #
671
+ if _order_:
672
+ # _order_ step 3: remove aliases from _order_
673
+ _order_ = [
674
+ o
675
+ for o in _order_
676
+ if (
677
+ o not in enum_class._member_map_
678
+ or
679
+ (o in enum_class._member_map_ and o in enum_class._member_names_)
680
+ )]
681
+ # _order_ step 4: verify that _order_ and _member_names_ match
682
+ if _order_ != enum_class._member_names_:
683
+ raise TypeError(
684
+ 'member order does not match _order_:\n %r\n %r'
685
+ % (enum_class._member_names_, _order_)
686
+ )
687
+ #
688
+ return enum_class
689
+
690
+ def __bool__(cls):
691
+ """
692
+ classes/types should always be True.
693
+ """
694
+ return True
695
+
696
+ def __call__(cls, value, names=_not_given, *values, module=None, qualname=None, type=None, start=1, boundary=None):
697
+ """
698
+ Either returns an existing member, or creates a new enum class.
699
+
700
+ This method is used both when an enum class is given a value to
701
+ match to an enumeration member (i.e. Color(3)) and for the
702
+ functional API (i.e. Color = Enum('Color', names='RED GREEN BLUE')).
703
+
704
+ The value lookup branch is chosen if the enum is final.
705
+
706
+ When used for the functional API:
707
+
708
+ `value` will be the name of the new class.
709
+
710
+ `names` should be either a string of white-space/comma delimited
711
+ names (values will start at `start`), or an iterator/mapping of
712
+ name, value pairs.
713
+
714
+ `module` should be set to the module this class is being created in;
715
+ if it is not set, an attempt to find that module will be made, but
716
+ if it fails the class will not be picklable.
717
+
718
+ `qualname` should be set to the actual location this class can be
719
+ found at in its module; by default it is set to the global scope.
720
+ If this is not correct, unpickling will fail in some circumstances.
721
+
722
+ `type`, if set, will be mixed in as the first base class.
723
+ """
724
+ if cls._member_map_:
725
+ # simple value lookup if members exist
726
+ if names is not _not_given:
727
+ value = (value, names) + values
728
+ return cls.__new__(cls, value)
729
+ # otherwise, functional API: we're creating a new Enum type
730
+ if names is _not_given and type is None:
731
+ # no body? no data-type? possibly wrong usage
732
+ raise TypeError(
733
+ f"{cls} has no members; specify `names=()` if you meant to create a new, empty, enum"
734
+ )
735
+ return cls._create_(
736
+ class_name=value,
737
+ names=None if names is _not_given else names,
738
+ module=module,
739
+ qualname=qualname,
740
+ type=type,
741
+ start=start,
742
+ boundary=boundary,
743
+ )
744
+
745
+ def __contains__(cls, value):
746
+ """Return True if `value` is in `cls`.
747
+
748
+ `value` is in `cls` if:
749
+ 1) `value` is a member of `cls`, or
750
+ 2) `value` is the value of one of the `cls`'s members.
751
+ 3) `value` is a pseudo-member (flags)
752
+ """
753
+ if isinstance(value, cls):
754
+ return True
755
+ if issubclass(cls, Flag):
756
+ try:
757
+ result = cls._missing_(value)
758
+ return isinstance(result, cls)
759
+ except ValueError:
760
+ pass
761
+ return (
762
+ value in cls._unhashable_values_ # both structures are lists
763
+ or value in cls._hashable_values_
764
+ )
765
+
766
+ def __delattr__(cls, attr):
767
+ # nicer error message when someone tries to delete an attribute
768
+ # (see issue19025).
769
+ if attr in cls._member_map_:
770
+ raise AttributeError("%r cannot delete member %r." % (cls.__name__, attr))
771
+ super().__delattr__(attr)
772
+
773
+ def __dir__(cls):
774
+ interesting = set([
775
+ '__class__', '__contains__', '__doc__', '__getitem__',
776
+ '__iter__', '__len__', '__members__', '__module__',
777
+ '__name__', '__qualname__',
778
+ ]
779
+ + cls._member_names_
780
+ )
781
+ if cls._new_member_ is not object.__new__:
782
+ interesting.add('__new__')
783
+ if cls.__init_subclass__ is not object.__init_subclass__:
784
+ interesting.add('__init_subclass__')
785
+ if cls._member_type_ is object:
786
+ return sorted(interesting)
787
+ else:
788
+ # return whatever mixed-in data type has
789
+ return sorted(set(dir(cls._member_type_)) | interesting)
790
+
791
+ def __getitem__(cls, name):
792
+ """
793
+ Return the member matching `name`.
794
+ """
795
+ return cls._member_map_[name]
796
+
797
+ def __iter__(cls):
798
+ """
799
+ Return members in definition order.
800
+ """
801
+ return (cls._member_map_[name] for name in cls._member_names_)
802
+
803
+ def __len__(cls):
804
+ """
805
+ Return the number of members (no aliases)
806
+ """
807
+ return len(cls._member_names_)
808
+
809
+ @bltns.property
810
+ def __members__(cls):
811
+ """
812
+ Returns a mapping of member name->value.
813
+
814
+ This mapping lists all enum members, including aliases. Note that
815
+ this is a read-only view of the internal mapping.
816
+ """
817
+ return MappingProxyType(cls._member_map_)
818
+
819
+ def __repr__(cls):
820
+ if Flag is not None and issubclass(cls, Flag):
821
+ return "<flag %r>" % cls.__name__
822
+ else:
823
+ return "<enum %r>" % cls.__name__
824
+
825
+ def __reversed__(cls):
826
+ """
827
+ Return members in reverse definition order.
828
+ """
829
+ return (cls._member_map_[name] for name in reversed(cls._member_names_))
830
+
831
+ def __setattr__(cls, name, value):
832
+ """
833
+ Block attempts to reassign Enum members.
834
+
835
+ A simple assignment to the class namespace only changes one of the
836
+ several possible ways to get an Enum member from the Enum class,
837
+ resulting in an inconsistent Enumeration.
838
+ """
839
+ member_map = cls.__dict__.get('_member_map_', {})
840
+ if name in member_map:
841
+ raise AttributeError('cannot reassign member %r' % (name, ))
842
+ super().__setattr__(name, value)
843
+
844
+ def _create_(cls, class_name, names, *, module=None, qualname=None, type=None, start=1, boundary=None):
845
+ """
846
+ Convenience method to create a new Enum class.
847
+
848
+ `names` can be:
849
+
850
+ * A string containing member names, separated either with spaces or
851
+ commas. Values are incremented by 1 from `start`.
852
+ * An iterable of member names. Values are incremented by 1 from `start`.
853
+ * An iterable of (member name, value) pairs.
854
+ * A mapping of member name -> value pairs.
855
+ """
856
+ metacls = cls.__class__
857
+ bases = (cls, ) if type is None else (type, cls)
858
+ _, first_enum = cls._get_mixins_(class_name, bases)
859
+ classdict = metacls.__prepare__(class_name, bases)
860
+
861
+ # special processing needed for names?
862
+ if isinstance(names, str):
863
+ names = names.replace(',', ' ').split()
864
+ if isinstance(names, (tuple, list)) and names and isinstance(names[0], str):
865
+ original_names, names = names, []
866
+ last_values = []
867
+ for count, name in enumerate(original_names):
868
+ value = first_enum._generate_next_value_(name, start, count, last_values[:])
869
+ last_values.append(value)
870
+ names.append((name, value))
871
+ if names is None:
872
+ names = ()
873
+
874
+ # Here, names is either an iterable of (name, value) or a mapping.
875
+ for item in names:
876
+ if isinstance(item, str):
877
+ member_name, member_value = item, names[item]
878
+ else:
879
+ member_name, member_value = item
880
+ classdict[member_name] = member_value
881
+
882
+ if module is None:
883
+ try:
884
+ module = sys._getframemodulename(2)
885
+ except AttributeError:
886
+ # Fall back on _getframe if _getframemodulename is missing
887
+ try:
888
+ module = sys._getframe(2).f_globals['__name__']
889
+ except (AttributeError, ValueError, KeyError):
890
+ pass
891
+ if module is None:
892
+ _make_class_unpicklable(classdict)
893
+ else:
894
+ classdict['__module__'] = module
895
+ if qualname is not None:
896
+ classdict['__qualname__'] = qualname
897
+
898
+ return metacls.__new__(metacls, class_name, bases, classdict, boundary=boundary)
899
+
900
+ def _convert_(cls, name, module, filter, source=None, *, boundary=None, as_global=False):
901
+ """
902
+ Create a new Enum subclass that replaces a collection of global constants
903
+ """
904
+ # convert all constants from source (or module) that pass filter() to
905
+ # a new Enum called name, and export the enum and its members back to
906
+ # module;
907
+ # also, replace the __reduce_ex__ method so unpickling works in
908
+ # previous Python versions
909
+ module_globals = sys.modules[module].__dict__
910
+ if source:
911
+ source = source.__dict__
912
+ else:
913
+ source = module_globals
914
+ # _value2member_map_ is populated in the same order every time
915
+ # for a consistent reverse mapping of number to name when there
916
+ # are multiple names for the same number.
917
+ members = [
918
+ (name, value)
919
+ for name, value in source.items()
920
+ if filter(name)]
921
+ try:
922
+ # sort by value
923
+ members.sort(key=lambda t: (t[1], t[0]))
924
+ except TypeError:
925
+ # unless some values aren't comparable, in which case sort by name
926
+ members.sort(key=lambda t: t[0])
927
+ body = {t[0]: t[1] for t in members}
928
+ body['__module__'] = module
929
+ tmp_cls = type(name, (object, ), body)
930
+ cls = _simple_enum(etype=cls, boundary=boundary or KEEP)(tmp_cls)
931
+ if as_global:
932
+ global_enum(cls)
933
+ else:
934
+ sys.modules[cls.__module__].__dict__.update(cls.__members__)
935
+ module_globals[name] = cls
936
+ return cls
937
+
938
+ @classmethod
939
+ def _check_for_existing_members_(mcls, class_name, bases):
940
+ for chain in bases:
941
+ for base in chain.__mro__:
942
+ if isinstance(base, EnumType) and base._member_names_:
943
+ raise TypeError(
944
+ "<enum %r> cannot extend %r"
945
+ % (class_name, base)
946
+ )
947
+
948
+ @classmethod
949
+ def _get_mixins_(mcls, class_name, bases):
950
+ """
951
+ Returns the type for creating enum members, and the first inherited
952
+ enum class.
953
+
954
+ bases: the tuple of bases that was given to __new__
955
+ """
956
+ if not bases:
957
+ return object, Enum
958
+ # ensure final parent class is an Enum derivative, find any concrete
959
+ # data type, and check that Enum has no members
960
+ first_enum = bases[-1]
961
+ if not isinstance(first_enum, EnumType):
962
+ raise TypeError("new enumerations should be created as "
963
+ "`EnumName([mixin_type, ...] [data_type,] enum_type)`")
964
+ member_type = mcls._find_data_type_(class_name, bases) or object
965
+ return member_type, first_enum
966
+
967
+ @classmethod
968
+ def _find_data_repr_(mcls, class_name, bases):
969
+ for chain in bases:
970
+ for base in chain.__mro__:
971
+ if base is object:
972
+ continue
973
+ elif isinstance(base, EnumType):
974
+ # if we hit an Enum, use it's _value_repr_
975
+ return base._value_repr_
976
+ elif '__repr__' in base.__dict__:
977
+ # this is our data repr
978
+ # double-check if a dataclass with a default __repr__
979
+ if (
980
+ '__dataclass_fields__' in base.__dict__
981
+ and '__dataclass_params__' in base.__dict__
982
+ and base.__dict__['__dataclass_params__'].repr
983
+ ):
984
+ return _dataclass_repr
985
+ else:
986
+ return base.__dict__['__repr__']
987
+ return None
988
+
989
+ @classmethod
990
+ def _find_data_type_(mcls, class_name, bases):
991
+ # a datatype has a __new__ method, or a __dataclass_fields__ attribute
992
+ data_types = set()
993
+ base_chain = set()
994
+ for chain in bases:
995
+ candidate = None
996
+ for base in chain.__mro__:
997
+ base_chain.add(base)
998
+ if base is object:
999
+ continue
1000
+ elif isinstance(base, EnumType):
1001
+ if base._member_type_ is not object:
1002
+ data_types.add(base._member_type_)
1003
+ break
1004
+ elif '__new__' in base.__dict__ or '__dataclass_fields__' in base.__dict__:
1005
+ data_types.add(candidate or base)
1006
+ break
1007
+ else:
1008
+ candidate = candidate or base
1009
+ if len(data_types) > 1:
1010
+ raise TypeError('too many data types for %r: %r' % (class_name, data_types))
1011
+ elif data_types:
1012
+ return data_types.pop()
1013
+ else:
1014
+ return None
1015
+
1016
+ @classmethod
1017
+ def _find_new_(mcls, classdict, member_type, first_enum):
1018
+ """
1019
+ Returns the __new__ to be used for creating the enum members.
1020
+
1021
+ classdict: the class dictionary given to __new__
1022
+ member_type: the data type whose __new__ will be used by default
1023
+ first_enum: enumeration to check for an overriding __new__
1024
+ """
1025
+ # now find the correct __new__, checking to see of one was defined
1026
+ # by the user; also check earlier enum classes in case a __new__ was
1027
+ # saved as __new_member__
1028
+ __new__ = classdict.get('__new__', None)
1029
+
1030
+ # should __new__ be saved as __new_member__ later?
1031
+ save_new = first_enum is not None and __new__ is not None
1032
+
1033
+ if __new__ is None:
1034
+ # check all possibles for __new_member__ before falling back to
1035
+ # __new__
1036
+ for method in ('__new_member__', '__new__'):
1037
+ for possible in (member_type, first_enum):
1038
+ target = getattr(possible, method, None)
1039
+ if target not in {
1040
+ None,
1041
+ None.__new__,
1042
+ object.__new__,
1043
+ Enum.__new__,
1044
+ }:
1045
+ __new__ = target
1046
+ break
1047
+ if __new__ is not None:
1048
+ break
1049
+ else:
1050
+ __new__ = object.__new__
1051
+
1052
+ # if a non-object.__new__ is used then whatever value/tuple was
1053
+ # assigned to the enum member name will be passed to __new__ and to the
1054
+ # new enum member's __init__
1055
+ if first_enum is None or __new__ in (Enum.__new__, object.__new__):
1056
+ use_args = False
1057
+ else:
1058
+ use_args = True
1059
+ return __new__, save_new, use_args
1060
+
1061
+ def _add_member_(cls, name, member):
1062
+ # _value_ structures are not updated
1063
+ if name in cls._member_map_:
1064
+ if cls._member_map_[name] is not member:
1065
+ raise NameError('%r is already bound: %r' % (name, cls._member_map_[name]))
1066
+ return
1067
+ #
1068
+ # if necessary, get redirect in place and then add it to _member_map_
1069
+ found_descriptor = None
1070
+ descriptor_type = None
1071
+ class_type = None
1072
+ for base in cls.__mro__[1:]:
1073
+ attr = base.__dict__.get(name)
1074
+ if attr is not None:
1075
+ if isinstance(attr, (property, DynamicClassAttribute)):
1076
+ found_descriptor = attr
1077
+ class_type = base
1078
+ descriptor_type = 'enum'
1079
+ break
1080
+ elif _is_descriptor(attr):
1081
+ found_descriptor = attr
1082
+ descriptor_type = descriptor_type or 'desc'
1083
+ class_type = class_type or base
1084
+ continue
1085
+ else:
1086
+ descriptor_type = 'attr'
1087
+ class_type = base
1088
+ if found_descriptor:
1089
+ redirect = property()
1090
+ redirect.member = member
1091
+ redirect.__set_name__(cls, name)
1092
+ if descriptor_type in ('enum', 'desc'):
1093
+ # earlier descriptor found; copy fget, fset, fdel to this one.
1094
+ redirect.fget = getattr(found_descriptor, 'fget', None)
1095
+ redirect._get = getattr(found_descriptor, '__get__', None)
1096
+ redirect.fset = getattr(found_descriptor, 'fset', None)
1097
+ redirect._set = getattr(found_descriptor, '__set__', None)
1098
+ redirect.fdel = getattr(found_descriptor, 'fdel', None)
1099
+ redirect._del = getattr(found_descriptor, '__delete__', None)
1100
+ redirect._attr_type = descriptor_type
1101
+ redirect._cls_type = class_type
1102
+ setattr(cls, name, redirect)
1103
+ else:
1104
+ setattr(cls, name, member)
1105
+ # now add to _member_map_ (even aliases)
1106
+ cls._member_map_[name] = member
1107
+
1108
+ EnumMeta = EnumType # keep EnumMeta name for backwards compatibility
1109
+
1110
+
1111
+ class Enum(metaclass=EnumType):
1112
+ """
1113
+ Create a collection of name/value pairs.
1114
+
1115
+ Example enumeration:
1116
+
1117
+ >>> class Color(Enum):
1118
+ ... RED = 1
1119
+ ... BLUE = 2
1120
+ ... GREEN = 3
1121
+
1122
+ Access them by:
1123
+
1124
+ - attribute access:
1125
+
1126
+ >>> Color.RED
1127
+ <Color.RED: 1>
1128
+
1129
+ - value lookup:
1130
+
1131
+ >>> Color(1)
1132
+ <Color.RED: 1>
1133
+
1134
+ - name lookup:
1135
+
1136
+ >>> Color['RED']
1137
+ <Color.RED: 1>
1138
+
1139
+ Enumerations can be iterated over, and know how many members they have:
1140
+
1141
+ >>> len(Color)
1142
+ 3
1143
+
1144
+ >>> list(Color)
1145
+ [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]
1146
+
1147
+ Methods can be added to enumerations, and members can have their own
1148
+ attributes -- see the documentation for details.
1149
+ """
1150
+
1151
+ @classmethod
1152
+ def __signature__(cls):
1153
+ if cls._member_names_:
1154
+ return '(*values)'
1155
+ else:
1156
+ return '(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)'
1157
+
1158
+ def __new__(cls, value):
1159
+ # all enum instances are actually created during class construction
1160
+ # without calling this method; this method is called by the metaclass'
1161
+ # __call__ (i.e. Color(3) ), and by pickle
1162
+ if type(value) is cls:
1163
+ # For lookups like Color(Color.RED)
1164
+ return value
1165
+ # by-value search for a matching enum member
1166
+ # see if it's in the reverse mapping (for hashable values)
1167
+ try:
1168
+ return cls._value2member_map_[value]
1169
+ except KeyError:
1170
+ # Not found, no need to do long O(n) search
1171
+ pass
1172
+ except TypeError:
1173
+ # not there, now do long search -- O(n) behavior
1174
+ for name, unhashable_values in cls._unhashable_values_map_.items():
1175
+ if value in unhashable_values:
1176
+ return cls[name]
1177
+ for name, member in cls._member_map_.items():
1178
+ if value == member._value_:
1179
+ return cls[name]
1180
+ # still not found -- verify that members exist, in-case somebody got here mistakenly
1181
+ # (such as via super when trying to override __new__)
1182
+ if not cls._member_map_:
1183
+ if getattr(cls, '_%s__in_progress' % cls.__name__, False):
1184
+ raise TypeError('do not use `super().__new__; call the appropriate __new__ directly') from None
1185
+ raise TypeError("%r has no members defined" % cls)
1186
+ #
1187
+ # still not found -- try _missing_ hook
1188
+ try:
1189
+ exc = None
1190
+ result = cls._missing_(value)
1191
+ except Exception as e:
1192
+ exc = e
1193
+ result = None
1194
+ try:
1195
+ if isinstance(result, cls):
1196
+ return result
1197
+ elif (
1198
+ Flag is not None and issubclass(cls, Flag)
1199
+ and cls._boundary_ is EJECT and isinstance(result, int)
1200
+ ):
1201
+ return result
1202
+ else:
1203
+ ve_exc = ValueError("%r is not a valid %s" % (value, cls.__qualname__))
1204
+ if result is None and exc is None:
1205
+ raise ve_exc
1206
+ elif exc is None:
1207
+ exc = TypeError(
1208
+ 'error in %s._missing_: returned %r instead of None or a valid member'
1209
+ % (cls.__name__, result)
1210
+ )
1211
+ if not isinstance(exc, ValueError):
1212
+ exc.__context__ = ve_exc
1213
+ raise exc
1214
+ finally:
1215
+ # ensure all variables that could hold an exception are destroyed
1216
+ exc = None
1217
+ ve_exc = None
1218
+
1219
+ def __init__(self, *args, **kwds):
1220
+ pass
1221
+
1222
+ def _add_alias_(self, name):
1223
+ self.__class__._add_member_(name, self)
1224
+
1225
+ def _add_value_alias_(self, value):
1226
+ cls = self.__class__
1227
+ try:
1228
+ if value in cls._value2member_map_:
1229
+ if cls._value2member_map_[value] is not self:
1230
+ raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1231
+ return
1232
+ except TypeError:
1233
+ # unhashable value, do long search
1234
+ for m in cls._member_map_.values():
1235
+ if m._value_ == value:
1236
+ if m is not self:
1237
+ raise ValueError('%r is already bound: %r' % (value, cls._value2member_map_[value]))
1238
+ return
1239
+ try:
1240
+ # This may fail if value is not hashable. We can't add the value
1241
+ # to the map, and by-value lookups for this value will be
1242
+ # linear.
1243
+ cls._value2member_map_.setdefault(value, self)
1244
+ cls._hashable_values_.append(value)
1245
+ except TypeError:
1246
+ # keep track of the value in a list so containment checks are quick
1247
+ cls._unhashable_values_.append(value)
1248
+ cls._unhashable_values_map_.setdefault(self.name, []).append(value)
1249
+
1250
+ @staticmethod
1251
+ def _generate_next_value_(name, start, count, last_values):
1252
+ """
1253
+ Generate the next value when not given.
1254
+
1255
+ name: the name of the member
1256
+ start: the initial start value or None
1257
+ count: the number of existing members
1258
+ last_values: the list of values assigned
1259
+ """
1260
+ if not last_values:
1261
+ return start
1262
+ try:
1263
+ last_value = sorted(last_values).pop()
1264
+ except TypeError:
1265
+ raise TypeError('unable to sort non-numeric values') from None
1266
+ try:
1267
+ return last_value + 1
1268
+ except TypeError:
1269
+ raise TypeError('unable to increment %r' % (last_value, )) from None
1270
+
1271
+ @classmethod
1272
+ def _missing_(cls, value):
1273
+ return None
1274
+
1275
+ def __repr__(self):
1276
+ v_repr = self.__class__._value_repr_ or repr
1277
+ return "<%s.%s: %s>" % (self.__class__.__name__, self._name_, v_repr(self._value_))
1278
+
1279
+ def __str__(self):
1280
+ return "%s.%s" % (self.__class__.__name__, self._name_, )
1281
+
1282
+ def __dir__(self):
1283
+ """
1284
+ Returns public methods and other interesting attributes.
1285
+ """
1286
+ interesting = set()
1287
+ if self.__class__._member_type_ is not object:
1288
+ interesting = set(object.__dir__(self))
1289
+ for name in getattr(self, '__dict__', []):
1290
+ if name[0] != '_' and name not in self._member_map_:
1291
+ interesting.add(name)
1292
+ for cls in self.__class__.mro():
1293
+ for name, obj in cls.__dict__.items():
1294
+ if name[0] == '_':
1295
+ continue
1296
+ if isinstance(obj, property):
1297
+ # that's an enum.property
1298
+ if obj.fget is not None or name not in self._member_map_:
1299
+ interesting.add(name)
1300
+ else:
1301
+ # in case it was added by `dir(self)`
1302
+ interesting.discard(name)
1303
+ elif name not in self._member_map_:
1304
+ interesting.add(name)
1305
+ names = sorted(
1306
+ set(['__class__', '__doc__', '__eq__', '__hash__', '__module__'])
1307
+ | interesting
1308
+ )
1309
+ return names
1310
+
1311
+ def __format__(self, format_spec):
1312
+ return str.__format__(str(self), format_spec)
1313
+
1314
+ def __hash__(self):
1315
+ return hash(self._name_)
1316
+
1317
+ def __reduce_ex__(self, proto):
1318
+ return self.__class__, (self._value_, )
1319
+
1320
+ def __deepcopy__(self,memo):
1321
+ return self
1322
+
1323
+ def __copy__(self):
1324
+ return self
1325
+
1326
+ # enum.property is used to provide access to the `name` and
1327
+ # `value` attributes of enum members while keeping some measure of
1328
+ # protection from modification, while still allowing for an enumeration
1329
+ # to have members named `name` and `value`. This works because each
1330
+ # instance of enum.property saves its companion member, which it returns
1331
+ # on class lookup; on instance lookup it either executes a provided function
1332
+ # or raises an AttributeError.
1333
+
1334
+ @property
1335
+ def name(self):
1336
+ """The name of the Enum member."""
1337
+ return self._name_
1338
+
1339
+ @property
1340
+ def value(self):
1341
+ """The value of the Enum member."""
1342
+ return self._value_
1343
+
1344
+
1345
+ class ReprEnum(Enum):
1346
+ """
1347
+ Only changes the repr(), leaving str() and format() to the mixed-in type.
1348
+ """
1349
+
1350
+
1351
+ class IntEnum(int, ReprEnum):
1352
+ """
1353
+ Enum where members are also (and must be) ints
1354
+ """
1355
+
1356
+
1357
+ class StrEnum(str, ReprEnum):
1358
+ """
1359
+ Enum where members are also (and must be) strings
1360
+ """
1361
+
1362
+ def __new__(cls, *values):
1363
+ "values must already be of type `str`"
1364
+ if len(values) > 3:
1365
+ raise TypeError('too many arguments for str(): %r' % (values, ))
1366
+ if len(values) == 1:
1367
+ # it must be a string
1368
+ if not isinstance(values[0], str):
1369
+ raise TypeError('%r is not a string' % (values[0], ))
1370
+ if len(values) >= 2:
1371
+ # check that encoding argument is a string
1372
+ if not isinstance(values[1], str):
1373
+ raise TypeError('encoding must be a string, not %r' % (values[1], ))
1374
+ if len(values) == 3:
1375
+ # check that errors argument is a string
1376
+ if not isinstance(values[2], str):
1377
+ raise TypeError('errors must be a string, not %r' % (values[2]))
1378
+ value = str(*values)
1379
+ member = str.__new__(cls, value)
1380
+ member._value_ = value
1381
+ return member
1382
+
1383
+ @staticmethod
1384
+ def _generate_next_value_(name, start, count, last_values):
1385
+ """
1386
+ Return the lower-cased version of the member name.
1387
+ """
1388
+ return name.lower()
1389
+
1390
+
1391
+ def pickle_by_global_name(self, proto):
1392
+ # should not be used with Flag-type enums
1393
+ return self.name
1394
+ _reduce_ex_by_global_name = pickle_by_global_name
1395
+
1396
+ def pickle_by_enum_name(self, proto):
1397
+ # should not be used with Flag-type enums
1398
+ return getattr, (self.__class__, self._name_)
1399
+
1400
+ class FlagBoundary(StrEnum):
1401
+ """
1402
+ control how out of range values are handled
1403
+ "strict" -> error is raised [default for Flag]
1404
+ "conform" -> extra bits are discarded
1405
+ "eject" -> lose flag status
1406
+ "keep" -> keep flag status and all bits [default for IntFlag]
1407
+ """
1408
+ STRICT = auto()
1409
+ CONFORM = auto()
1410
+ EJECT = auto()
1411
+ KEEP = auto()
1412
+ STRICT, CONFORM, EJECT, KEEP = FlagBoundary
1413
+
1414
+
1415
+ class Flag(Enum, boundary=STRICT):
1416
+ """
1417
+ Support for flags
1418
+ """
1419
+
1420
+ _numeric_repr_ = repr
1421
+
1422
+ @staticmethod
1423
+ def _generate_next_value_(name, start, count, last_values):
1424
+ """
1425
+ Generate the next value when not given.
1426
+
1427
+ name: the name of the member
1428
+ start: the initial start value or None
1429
+ count: the number of existing members
1430
+ last_values: the last value assigned or None
1431
+ """
1432
+ if not count:
1433
+ return start if start is not None else 1
1434
+ last_value = max(last_values)
1435
+ try:
1436
+ high_bit = _high_bit(last_value)
1437
+ except Exception:
1438
+ raise TypeError('invalid flag value %r' % last_value) from None
1439
+ return 2 ** (high_bit+1)
1440
+
1441
+ @classmethod
1442
+ def _iter_member_by_value_(cls, value):
1443
+ """
1444
+ Extract all members from the value in definition (i.e. increasing value) order.
1445
+ """
1446
+ for val in _iter_bits_lsb(value & cls._flag_mask_):
1447
+ yield cls._value2member_map_.get(val)
1448
+
1449
+ _iter_member_ = _iter_member_by_value_
1450
+
1451
+ @classmethod
1452
+ def _iter_member_by_def_(cls, value):
1453
+ """
1454
+ Extract all members from the value in definition order.
1455
+ """
1456
+ yield from sorted(
1457
+ cls._iter_member_by_value_(value),
1458
+ key=lambda m: m._sort_order_,
1459
+ )
1460
+
1461
+ @classmethod
1462
+ def _missing_(cls, value):
1463
+ """
1464
+ Create a composite member containing all canonical members present in `value`.
1465
+
1466
+ If non-member values are present, result depends on `_boundary_` setting.
1467
+ """
1468
+ if not isinstance(value, int):
1469
+ raise ValueError(
1470
+ "%r is not a valid %s" % (value, cls.__qualname__)
1471
+ )
1472
+ # check boundaries
1473
+ # - value must be in range (e.g. -16 <-> +15, i.e. ~15 <-> 15)
1474
+ # - value must not include any skipped flags (e.g. if bit 2 is not
1475
+ # defined, then 0d10 is invalid)
1476
+ flag_mask = cls._flag_mask_
1477
+ singles_mask = cls._singles_mask_
1478
+ all_bits = cls._all_bits_
1479
+ neg_value = None
1480
+ if (
1481
+ not ~all_bits <= value <= all_bits
1482
+ or value & (all_bits ^ flag_mask)
1483
+ ):
1484
+ if cls._boundary_ is STRICT:
1485
+ max_bits = max(value.bit_length(), flag_mask.bit_length())
1486
+ raise ValueError(
1487
+ "%r invalid value %r\n given %s\n allowed %s" % (
1488
+ cls, value, bin(value, max_bits), bin(flag_mask, max_bits),
1489
+ ))
1490
+ elif cls._boundary_ is CONFORM:
1491
+ value = value & flag_mask
1492
+ elif cls._boundary_ is EJECT:
1493
+ return value
1494
+ elif cls._boundary_ is KEEP:
1495
+ if value < 0:
1496
+ value = (
1497
+ max(all_bits+1, 2**(value.bit_length()))
1498
+ + value
1499
+ )
1500
+ else:
1501
+ raise ValueError(
1502
+ '%r unknown flag boundary %r' % (cls, cls._boundary_, )
1503
+ )
1504
+ if value < 0:
1505
+ neg_value = value
1506
+ value = all_bits + 1 + value
1507
+ # get members and unknown
1508
+ unknown = value & ~flag_mask
1509
+ aliases = value & ~singles_mask
1510
+ member_value = value & singles_mask
1511
+ if unknown and cls._boundary_ is not KEEP:
1512
+ raise ValueError(
1513
+ '%s(%r) --> unknown values %r [%s]'
1514
+ % (cls.__name__, value, unknown, bin(unknown))
1515
+ )
1516
+ # normal Flag?
1517
+ if cls._member_type_ is object:
1518
+ # construct a singleton enum pseudo-member
1519
+ pseudo_member = object.__new__(cls)
1520
+ else:
1521
+ pseudo_member = cls._member_type_.__new__(cls, value)
1522
+ if not hasattr(pseudo_member, '_value_'):
1523
+ pseudo_member._value_ = value
1524
+ if member_value or aliases:
1525
+ members = []
1526
+ combined_value = 0
1527
+ for m in cls._iter_member_(member_value):
1528
+ members.append(m)
1529
+ combined_value |= m._value_
1530
+ if aliases:
1531
+ value = member_value | aliases
1532
+ for n, pm in cls._member_map_.items():
1533
+ if pm not in members and pm._value_ and pm._value_ & value == pm._value_:
1534
+ members.append(pm)
1535
+ combined_value |= pm._value_
1536
+ unknown = value ^ combined_value
1537
+ pseudo_member._name_ = '|'.join([m._name_ for m in members])
1538
+ if not combined_value:
1539
+ pseudo_member._name_ = None
1540
+ elif unknown and cls._boundary_ is STRICT:
1541
+ raise ValueError('%r: no members with value %r' % (cls, unknown))
1542
+ elif unknown:
1543
+ pseudo_member._name_ += '|%s' % cls._numeric_repr_(unknown)
1544
+ else:
1545
+ pseudo_member._name_ = None
1546
+ # use setdefault in case another thread already created a composite
1547
+ # with this value
1548
+ # note: zero is a special case -- always add it
1549
+ pseudo_member = cls._value2member_map_.setdefault(value, pseudo_member)
1550
+ if neg_value is not None:
1551
+ cls._value2member_map_[neg_value] = pseudo_member
1552
+ return pseudo_member
1553
+
1554
+ def __contains__(self, other):
1555
+ """
1556
+ Returns True if self has at least the same flags set as other.
1557
+ """
1558
+ if not isinstance(other, self.__class__):
1559
+ raise TypeError(
1560
+ "unsupported operand type(s) for 'in': %r and %r" % (
1561
+ type(other).__qualname__, self.__class__.__qualname__))
1562
+ return other._value_ & self._value_ == other._value_
1563
+
1564
+ def __iter__(self):
1565
+ """
1566
+ Returns flags in definition order.
1567
+ """
1568
+ yield from self._iter_member_(self._value_)
1569
+
1570
+ def __len__(self):
1571
+ return self._value_.bit_count()
1572
+
1573
+ def __repr__(self):
1574
+ cls_name = self.__class__.__name__
1575
+ v_repr = self.__class__._value_repr_ or repr
1576
+ if self._name_ is None:
1577
+ return "<%s: %s>" % (cls_name, v_repr(self._value_))
1578
+ else:
1579
+ return "<%s.%s: %s>" % (cls_name, self._name_, v_repr(self._value_))
1580
+
1581
+ def __str__(self):
1582
+ cls_name = self.__class__.__name__
1583
+ if self._name_ is None:
1584
+ return '%s(%r)' % (cls_name, self._value_)
1585
+ else:
1586
+ return "%s.%s" % (cls_name, self._name_)
1587
+
1588
+ def __bool__(self):
1589
+ return bool(self._value_)
1590
+
1591
+ def _get_value(self, flag):
1592
+ if isinstance(flag, self.__class__):
1593
+ return flag._value_
1594
+ elif self._member_type_ is not object and isinstance(flag, self._member_type_):
1595
+ return flag
1596
+ return NotImplemented
1597
+
1598
+ def __or__(self, other):
1599
+ other_value = self._get_value(other)
1600
+ if other_value is NotImplemented:
1601
+ return NotImplemented
1602
+
1603
+ for flag in self, other:
1604
+ if self._get_value(flag) is None:
1605
+ raise TypeError(f"'{flag}' cannot be combined with other flags with |")
1606
+ value = self._value_
1607
+ return self.__class__(value | other_value)
1608
+
1609
+ def __and__(self, other):
1610
+ other_value = self._get_value(other)
1611
+ if other_value is NotImplemented:
1612
+ return NotImplemented
1613
+
1614
+ for flag in self, other:
1615
+ if self._get_value(flag) is None:
1616
+ raise TypeError(f"'{flag}' cannot be combined with other flags with &")
1617
+ value = self._value_
1618
+ return self.__class__(value & other_value)
1619
+
1620
+ def __xor__(self, other):
1621
+ other_value = self._get_value(other)
1622
+ if other_value is NotImplemented:
1623
+ return NotImplemented
1624
+
1625
+ for flag in self, other:
1626
+ if self._get_value(flag) is None:
1627
+ raise TypeError(f"'{flag}' cannot be combined with other flags with ^")
1628
+ value = self._value_
1629
+ return self.__class__(value ^ other_value)
1630
+
1631
+ def __invert__(self):
1632
+ if self._get_value(self) is None:
1633
+ raise TypeError(f"'{self}' cannot be inverted")
1634
+
1635
+ if self._inverted_ is None:
1636
+ if self._boundary_ in (EJECT, KEEP):
1637
+ self._inverted_ = self.__class__(~self._value_)
1638
+ else:
1639
+ self._inverted_ = self.__class__(self._singles_mask_ & ~self._value_)
1640
+ return self._inverted_
1641
+
1642
+ __rand__ = __and__
1643
+ __ror__ = __or__
1644
+ __rxor__ = __xor__
1645
+
1646
+
1647
+ class IntFlag(int, ReprEnum, Flag, boundary=KEEP):
1648
+ """
1649
+ Support for integer-based Flags
1650
+ """
1651
+
1652
+
1653
+ def _high_bit(value):
1654
+ """
1655
+ returns index of highest bit, or -1 if value is zero or negative
1656
+ """
1657
+ return value.bit_length() - 1
1658
+
1659
+ def unique(enumeration):
1660
+ """
1661
+ Class decorator for enumerations ensuring unique member values.
1662
+ """
1663
+ duplicates = []
1664
+ for name, member in enumeration.__members__.items():
1665
+ if name != member.name:
1666
+ duplicates.append((name, member.name))
1667
+ if duplicates:
1668
+ alias_details = ', '.join(
1669
+ ["%s -> %s" % (alias, name) for (alias, name) in duplicates])
1670
+ raise ValueError('duplicate values found in %r: %s' %
1671
+ (enumeration, alias_details))
1672
+ return enumeration
1673
+
1674
+ def _dataclass_repr(self):
1675
+ dcf = self.__dataclass_fields__
1676
+ return ', '.join(
1677
+ '%s=%r' % (k, getattr(self, k))
1678
+ for k in dcf.keys()
1679
+ if dcf[k].repr
1680
+ )
1681
+
1682
+ def global_enum_repr(self):
1683
+ """
1684
+ use module.enum_name instead of class.enum_name
1685
+
1686
+ the module is the last module in case of a multi-module name
1687
+ """
1688
+ module = self.__class__.__module__.split('.')[-1]
1689
+ return '%s.%s' % (module, self._name_)
1690
+
1691
+ def global_flag_repr(self):
1692
+ """
1693
+ use module.flag_name instead of class.flag_name
1694
+
1695
+ the module is the last module in case of a multi-module name
1696
+ """
1697
+ module = self.__class__.__module__.split('.')[-1]
1698
+ cls_name = self.__class__.__name__
1699
+ if self._name_ is None:
1700
+ return "%s.%s(%r)" % (module, cls_name, self._value_)
1701
+ if _is_single_bit(self._value_):
1702
+ return '%s.%s' % (module, self._name_)
1703
+ if self._boundary_ is not FlagBoundary.KEEP:
1704
+ return '|'.join(['%s.%s' % (module, name) for name in self.name.split('|')])
1705
+ else:
1706
+ name = []
1707
+ for n in self._name_.split('|'):
1708
+ if n[0].isdigit():
1709
+ name.append(n)
1710
+ else:
1711
+ name.append('%s.%s' % (module, n))
1712
+ return '|'.join(name)
1713
+
1714
+ def global_str(self):
1715
+ """
1716
+ use enum_name instead of class.enum_name
1717
+ """
1718
+ if self._name_ is None:
1719
+ cls_name = self.__class__.__name__
1720
+ return "%s(%r)" % (cls_name, self._value_)
1721
+ else:
1722
+ return self._name_
1723
+
1724
+ def global_enum(cls, update_str=False):
1725
+ """
1726
+ decorator that makes the repr() of an enum member reference its module
1727
+ instead of its class; also exports all members to the enum's module's
1728
+ global namespace
1729
+ """
1730
+ if issubclass(cls, Flag):
1731
+ cls.__repr__ = global_flag_repr
1732
+ else:
1733
+ cls.__repr__ = global_enum_repr
1734
+ if not issubclass(cls, ReprEnum) or update_str:
1735
+ cls.__str__ = global_str
1736
+ sys.modules[cls.__module__].__dict__.update(cls.__members__)
1737
+ return cls
1738
+
1739
+ def _simple_enum(etype=Enum, *, boundary=None, use_args=None):
1740
+ """
1741
+ Class decorator that converts a normal class into an :class:`Enum`. No
1742
+ safety checks are done, and some advanced behavior (such as
1743
+ :func:`__init_subclass__`) is not available. Enum creation can be faster
1744
+ using :func:`_simple_enum`.
1745
+
1746
+ >>> from enum import Enum, _simple_enum
1747
+ >>> @_simple_enum(Enum)
1748
+ ... class Color:
1749
+ ... RED = auto()
1750
+ ... GREEN = auto()
1751
+ ... BLUE = auto()
1752
+ >>> Color
1753
+ <enum 'Color'>
1754
+ """
1755
+ def convert_class(cls):
1756
+ nonlocal use_args
1757
+ cls_name = cls.__name__
1758
+ if use_args is None:
1759
+ use_args = etype._use_args_
1760
+ __new__ = cls.__dict__.get('__new__')
1761
+ if __new__ is not None:
1762
+ new_member = __new__.__func__
1763
+ else:
1764
+ new_member = etype._member_type_.__new__
1765
+ attrs = {}
1766
+ body = {}
1767
+ if __new__ is not None:
1768
+ body['__new_member__'] = new_member
1769
+ body['_new_member_'] = new_member
1770
+ body['_use_args_'] = use_args
1771
+ body['_generate_next_value_'] = gnv = etype._generate_next_value_
1772
+ body['_member_names_'] = member_names = []
1773
+ body['_member_map_'] = member_map = {}
1774
+ body['_value2member_map_'] = value2member_map = {}
1775
+ body['_hashable_values_'] = hashable_values = []
1776
+ body['_unhashable_values_'] = unhashable_values = []
1777
+ body['_unhashable_values_map_'] = {}
1778
+ body['_member_type_'] = member_type = etype._member_type_
1779
+ body['_value_repr_'] = etype._value_repr_
1780
+ if issubclass(etype, Flag):
1781
+ body['_boundary_'] = boundary or etype._boundary_
1782
+ body['_flag_mask_'] = None
1783
+ body['_all_bits_'] = None
1784
+ body['_singles_mask_'] = None
1785
+ body['_inverted_'] = None
1786
+ body['__or__'] = Flag.__or__
1787
+ body['__xor__'] = Flag.__xor__
1788
+ body['__and__'] = Flag.__and__
1789
+ body['__ror__'] = Flag.__ror__
1790
+ body['__rxor__'] = Flag.__rxor__
1791
+ body['__rand__'] = Flag.__rand__
1792
+ body['__invert__'] = Flag.__invert__
1793
+ for name, obj in cls.__dict__.items():
1794
+ if name in ('__dict__', '__weakref__'):
1795
+ continue
1796
+ if _is_dunder(name) or _is_private(cls_name, name) or _is_sunder(name) or _is_descriptor(obj):
1797
+ body[name] = obj
1798
+ else:
1799
+ attrs[name] = obj
1800
+ if cls.__dict__.get('__doc__') is None:
1801
+ body['__doc__'] = 'An enumeration.'
1802
+ #
1803
+ # double check that repr and friends are not the mixin's or various
1804
+ # things break (such as pickle)
1805
+ # however, if the method is defined in the Enum itself, don't replace
1806
+ # it
1807
+ enum_class = type(cls_name, (etype, ), body, boundary=boundary, _simple=True)
1808
+ for name in ('__repr__', '__str__', '__format__', '__reduce_ex__'):
1809
+ if name not in body:
1810
+ # check for mixin overrides before replacing
1811
+ enum_method = getattr(etype, name)
1812
+ found_method = getattr(enum_class, name)
1813
+ object_method = getattr(object, name)
1814
+ data_type_method = getattr(member_type, name)
1815
+ if found_method in (data_type_method, object_method):
1816
+ setattr(enum_class, name, enum_method)
1817
+ gnv_last_values = []
1818
+ if issubclass(enum_class, Flag):
1819
+ # Flag / IntFlag
1820
+ single_bits = multi_bits = 0
1821
+ for name, value in attrs.items():
1822
+ if isinstance(value, auto) and auto.value is _auto_null:
1823
+ value = gnv(name, 1, len(member_names), gnv_last_values)
1824
+ # create basic member (possibly isolate value for alias check)
1825
+ if use_args:
1826
+ if not isinstance(value, tuple):
1827
+ value = (value, )
1828
+ member = new_member(enum_class, *value)
1829
+ value = value[0]
1830
+ else:
1831
+ member = new_member(enum_class)
1832
+ if __new__ is None:
1833
+ member._value_ = value
1834
+ # now check if alias
1835
+ try:
1836
+ contained = value2member_map.get(member._value_)
1837
+ except TypeError:
1838
+ contained = None
1839
+ if member._value_ in unhashable_values or member.value in hashable_values:
1840
+ for m in enum_class:
1841
+ if m._value_ == member._value_:
1842
+ contained = m
1843
+ break
1844
+ if contained is not None:
1845
+ # an alias to an existing member
1846
+ contained._add_alias_(name)
1847
+ else:
1848
+ # finish creating member
1849
+ member._name_ = name
1850
+ member.__objclass__ = enum_class
1851
+ member.__init__(value)
1852
+ member._sort_order_ = len(member_names)
1853
+ if name not in ('name', 'value'):
1854
+ setattr(enum_class, name, member)
1855
+ member_map[name] = member
1856
+ else:
1857
+ enum_class._add_member_(name, member)
1858
+ value2member_map[value] = member
1859
+ hashable_values.append(value)
1860
+ if _is_single_bit(value):
1861
+ # not a multi-bit alias, record in _member_names_ and _flag_mask_
1862
+ member_names.append(name)
1863
+ single_bits |= value
1864
+ else:
1865
+ multi_bits |= value
1866
+ gnv_last_values.append(value)
1867
+ enum_class._flag_mask_ = single_bits | multi_bits
1868
+ enum_class._singles_mask_ = single_bits
1869
+ enum_class._all_bits_ = 2 ** ((single_bits|multi_bits).bit_length()) - 1
1870
+ # set correct __iter__
1871
+ member_list = [m._value_ for m in enum_class]
1872
+ if member_list != sorted(member_list):
1873
+ enum_class._iter_member_ = enum_class._iter_member_by_def_
1874
+ else:
1875
+ # Enum / IntEnum / StrEnum
1876
+ for name, value in attrs.items():
1877
+ if isinstance(value, auto):
1878
+ if value.value is _auto_null:
1879
+ value.value = gnv(name, 1, len(member_names), gnv_last_values)
1880
+ value = value.value
1881
+ # create basic member (possibly isolate value for alias check)
1882
+ if use_args:
1883
+ if not isinstance(value, tuple):
1884
+ value = (value, )
1885
+ member = new_member(enum_class, *value)
1886
+ value = value[0]
1887
+ else:
1888
+ member = new_member(enum_class)
1889
+ if __new__ is None:
1890
+ member._value_ = value
1891
+ # now check if alias
1892
+ try:
1893
+ contained = value2member_map.get(member._value_)
1894
+ except TypeError:
1895
+ contained = None
1896
+ if member._value_ in unhashable_values or member._value_ in hashable_values:
1897
+ for m in enum_class:
1898
+ if m._value_ == member._value_:
1899
+ contained = m
1900
+ break
1901
+ if contained is not None:
1902
+ # an alias to an existing member
1903
+ contained._add_alias_(name)
1904
+ else:
1905
+ # finish creating member
1906
+ member._name_ = name
1907
+ member.__objclass__ = enum_class
1908
+ member.__init__(value)
1909
+ member._sort_order_ = len(member_names)
1910
+ if name not in ('name', 'value'):
1911
+ setattr(enum_class, name, member)
1912
+ member_map[name] = member
1913
+ else:
1914
+ enum_class._add_member_(name, member)
1915
+ member_names.append(name)
1916
+ gnv_last_values.append(value)
1917
+ try:
1918
+ # This may fail if value is not hashable. We can't add the value
1919
+ # to the map, and by-value lookups for this value will be
1920
+ # linear.
1921
+ enum_class._value2member_map_.setdefault(value, member)
1922
+ if value not in hashable_values:
1923
+ hashable_values.append(value)
1924
+ except TypeError:
1925
+ # keep track of the value in a list so containment checks are quick
1926
+ enum_class._unhashable_values_.append(value)
1927
+ enum_class._unhashable_values_map_.setdefault(name, []).append(value)
1928
+ if '__new__' in body:
1929
+ enum_class.__new_member__ = enum_class.__new__
1930
+ enum_class.__new__ = Enum.__new__
1931
+ return enum_class
1932
+ return convert_class
1933
+
1934
+ @_simple_enum(StrEnum)
1935
+ class EnumCheck:
1936
+ """
1937
+ various conditions to check an enumeration for
1938
+ """
1939
+ CONTINUOUS = "no skipped integer values"
1940
+ NAMED_FLAGS = "multi-flag aliases may not contain unnamed flags"
1941
+ UNIQUE = "one name per value"
1942
+ CONTINUOUS, NAMED_FLAGS, UNIQUE = EnumCheck
1943
+
1944
+
1945
+ class verify:
1946
+ """
1947
+ Check an enumeration for various constraints. (see EnumCheck)
1948
+ """
1949
+ def __init__(self, *checks):
1950
+ self.checks = checks
1951
+ def __call__(self, enumeration):
1952
+ checks = self.checks
1953
+ cls_name = enumeration.__name__
1954
+ if Flag is not None and issubclass(enumeration, Flag):
1955
+ enum_type = 'flag'
1956
+ elif issubclass(enumeration, Enum):
1957
+ enum_type = 'enum'
1958
+ else:
1959
+ raise TypeError("the 'verify' decorator only works with Enum and Flag")
1960
+ for check in checks:
1961
+ if check is UNIQUE:
1962
+ # check for duplicate names
1963
+ duplicates = []
1964
+ for name, member in enumeration.__members__.items():
1965
+ if name != member.name:
1966
+ duplicates.append((name, member.name))
1967
+ if duplicates:
1968
+ alias_details = ', '.join(
1969
+ ["%s -> %s" % (alias, name) for (alias, name) in duplicates])
1970
+ raise ValueError('aliases found in %r: %s' %
1971
+ (enumeration, alias_details))
1972
+ elif check is CONTINUOUS:
1973
+ values = set(e.value for e in enumeration)
1974
+ if len(values) < 2:
1975
+ continue
1976
+ low, high = min(values), max(values)
1977
+ missing = []
1978
+ if enum_type == 'flag':
1979
+ # check for powers of two
1980
+ for i in range(_high_bit(low)+1, _high_bit(high)):
1981
+ if 2**i not in values:
1982
+ missing.append(2**i)
1983
+ elif enum_type == 'enum':
1984
+ # check for missing consecutive integers
1985
+ for i in range(low+1, high):
1986
+ if i not in values:
1987
+ missing.append(i)
1988
+ else:
1989
+ raise Exception('verify: unknown type %r' % enum_type)
1990
+ if missing:
1991
+ raise ValueError(('invalid %s %r: missing values %s' % (
1992
+ enum_type, cls_name, ', '.join((str(m) for m in missing)))
1993
+ )[:256])
1994
+ # limit max length to protect against DOS attacks
1995
+ elif check is NAMED_FLAGS:
1996
+ # examine each alias and check for unnamed flags
1997
+ member_names = enumeration._member_names_
1998
+ member_values = [m.value for m in enumeration]
1999
+ missing_names = []
2000
+ missing_value = 0
2001
+ for name, alias in enumeration._member_map_.items():
2002
+ if name in member_names:
2003
+ # not an alias
2004
+ continue
2005
+ if alias.value < 0:
2006
+ # negative numbers are not checked
2007
+ continue
2008
+ values = list(_iter_bits_lsb(alias.value))
2009
+ missed = [v for v in values if v not in member_values]
2010
+ if missed:
2011
+ missing_names.append(name)
2012
+ for val in missed:
2013
+ missing_value |= val
2014
+ if missing_names:
2015
+ if len(missing_names) == 1:
2016
+ alias = 'alias %s is missing' % missing_names[0]
2017
+ else:
2018
+ alias = 'aliases %s and %s are missing' % (
2019
+ ', '.join(missing_names[:-1]), missing_names[-1]
2020
+ )
2021
+ if _is_single_bit(missing_value):
2022
+ value = 'value 0x%x' % missing_value
2023
+ else:
2024
+ value = 'combined values of 0x%x' % missing_value
2025
+ raise ValueError(
2026
+ 'invalid Flag %r: %s %s [use enum.show_flag_values(value) for details]'
2027
+ % (cls_name, alias, value)
2028
+ )
2029
+ return enumeration
2030
+
2031
+ def _test_simple_enum(checked_enum, simple_enum):
2032
+ """
2033
+ A function that can be used to test an enum created with :func:`_simple_enum`
2034
+ against the version created by subclassing :class:`Enum`::
2035
+
2036
+ >>> from enum import Enum, _simple_enum, _test_simple_enum
2037
+ >>> @_simple_enum(Enum)
2038
+ ... class Color:
2039
+ ... RED = auto()
2040
+ ... GREEN = auto()
2041
+ ... BLUE = auto()
2042
+ >>> class CheckedColor(Enum):
2043
+ ... RED = auto()
2044
+ ... GREEN = auto()
2045
+ ... BLUE = auto()
2046
+ >>> _test_simple_enum(CheckedColor, Color)
2047
+
2048
+ If differences are found, a :exc:`TypeError` is raised.
2049
+ """
2050
+ failed = []
2051
+ if checked_enum.__dict__ != simple_enum.__dict__:
2052
+ checked_dict = checked_enum.__dict__
2053
+ checked_keys = list(checked_dict.keys())
2054
+ simple_dict = simple_enum.__dict__
2055
+ simple_keys = list(simple_dict.keys())
2056
+ member_names = set(
2057
+ list(checked_enum._member_map_.keys())
2058
+ + list(simple_enum._member_map_.keys())
2059
+ )
2060
+ for key in set(checked_keys + simple_keys):
2061
+ if key in ('__module__', '_member_map_', '_value2member_map_', '__doc__',
2062
+ '__static_attributes__', '__firstlineno__'):
2063
+ # keys known to be different, or very long
2064
+ continue
2065
+ elif key in member_names:
2066
+ # members are checked below
2067
+ continue
2068
+ elif key not in simple_keys:
2069
+ failed.append("missing key: %r" % (key, ))
2070
+ elif key not in checked_keys:
2071
+ failed.append("extra key: %r" % (key, ))
2072
+ else:
2073
+ checked_value = checked_dict[key]
2074
+ simple_value = simple_dict[key]
2075
+ if callable(checked_value) or isinstance(checked_value, bltns.property):
2076
+ continue
2077
+ if key == '__doc__':
2078
+ # remove all spaces/tabs
2079
+ compressed_checked_value = checked_value.replace(' ','').replace('\t','')
2080
+ compressed_simple_value = simple_value.replace(' ','').replace('\t','')
2081
+ if compressed_checked_value != compressed_simple_value:
2082
+ failed.append("%r:\n %s\n %s" % (
2083
+ key,
2084
+ "checked -> %r" % (checked_value, ),
2085
+ "simple -> %r" % (simple_value, ),
2086
+ ))
2087
+ elif checked_value != simple_value:
2088
+ failed.append("%r:\n %s\n %s" % (
2089
+ key,
2090
+ "checked -> %r" % (checked_value, ),
2091
+ "simple -> %r" % (simple_value, ),
2092
+ ))
2093
+ failed.sort()
2094
+ for name in member_names:
2095
+ failed_member = []
2096
+ if name not in simple_keys:
2097
+ failed.append('missing member from simple enum: %r' % name)
2098
+ elif name not in checked_keys:
2099
+ failed.append('extra member in simple enum: %r' % name)
2100
+ else:
2101
+ checked_member_dict = checked_enum[name].__dict__
2102
+ checked_member_keys = list(checked_member_dict.keys())
2103
+ simple_member_dict = simple_enum[name].__dict__
2104
+ simple_member_keys = list(simple_member_dict.keys())
2105
+ for key in set(checked_member_keys + simple_member_keys):
2106
+ if key in ('__module__', '__objclass__', '_inverted_'):
2107
+ # keys known to be different or absent
2108
+ continue
2109
+ elif key not in simple_member_keys:
2110
+ failed_member.append("missing key %r not in the simple enum member %r" % (key, name))
2111
+ elif key not in checked_member_keys:
2112
+ failed_member.append("extra key %r in simple enum member %r" % (key, name))
2113
+ else:
2114
+ checked_value = checked_member_dict[key]
2115
+ simple_value = simple_member_dict[key]
2116
+ if checked_value != simple_value:
2117
+ failed_member.append("%r:\n %s\n %s" % (
2118
+ key,
2119
+ "checked member -> %r" % (checked_value, ),
2120
+ "simple member -> %r" % (simple_value, ),
2121
+ ))
2122
+ if failed_member:
2123
+ failed.append('%r member mismatch:\n %s' % (
2124
+ name, '\n '.join(failed_member),
2125
+ ))
2126
+ for method in (
2127
+ '__str__', '__repr__', '__reduce_ex__', '__format__',
2128
+ '__getnewargs_ex__', '__getnewargs__', '__reduce_ex__', '__reduce__'
2129
+ ):
2130
+ if method in simple_keys and method in checked_keys:
2131
+ # cannot compare functions, and it exists in both, so we're good
2132
+ continue
2133
+ elif method not in simple_keys and method not in checked_keys:
2134
+ # method is inherited -- check it out
2135
+ checked_method = getattr(checked_enum, method, None)
2136
+ simple_method = getattr(simple_enum, method, None)
2137
+ if hasattr(checked_method, '__func__'):
2138
+ checked_method = checked_method.__func__
2139
+ simple_method = simple_method.__func__
2140
+ if checked_method != simple_method:
2141
+ failed.append("%r: %-30s %s" % (
2142
+ method,
2143
+ "checked -> %r" % (checked_method, ),
2144
+ "simple -> %r" % (simple_method, ),
2145
+ ))
2146
+ else:
2147
+ # if the method existed in only one of the enums, it will have been caught
2148
+ # in the first checks above
2149
+ pass
2150
+ if failed:
2151
+ raise TypeError('enum mismatch:\n %s' % '\n '.join(failed))
2152
+
2153
+ def _old_convert_(etype, name, module, filter, source=None, *, boundary=None):
2154
+ """
2155
+ Create a new Enum subclass that replaces a collection of global constants
2156
+ """
2157
+ # convert all constants from source (or module) that pass filter() to
2158
+ # a new Enum called name, and export the enum and its members back to
2159
+ # module;
2160
+ # also, replace the __reduce_ex__ method so unpickling works in
2161
+ # previous Python versions
2162
+ module_globals = sys.modules[module].__dict__
2163
+ if source:
2164
+ source = source.__dict__
2165
+ else:
2166
+ source = module_globals
2167
+ # _value2member_map_ is populated in the same order every time
2168
+ # for a consistent reverse mapping of number to name when there
2169
+ # are multiple names for the same number.
2170
+ members = [
2171
+ (name, value)
2172
+ for name, value in source.items()
2173
+ if filter(name)]
2174
+ try:
2175
+ # sort by value
2176
+ members.sort(key=lambda t: (t[1], t[0]))
2177
+ except TypeError:
2178
+ # unless some values aren't comparable, in which case sort by name
2179
+ members.sort(key=lambda t: t[0])
2180
+ cls = etype(name, members, module=module, boundary=boundary or KEEP)
2181
+ return cls
2182
+
2183
+ _stdlib_enums = IntEnum, StrEnum, IntFlag