@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,2714 @@
1
+ """
2
+ Python implementation of the io module.
3
+ """
4
+
5
+ import os
6
+ import abc
7
+ import codecs
8
+ import errno
9
+ import stat
10
+ import sys
11
+ # Import _thread instead of threading to reduce startup cost
12
+ from _thread import allocate_lock as Lock
13
+ if sys.platform in {'win32', 'cygwin'}:
14
+ from msvcrt import setmode as _setmode
15
+ else:
16
+ _setmode = None
17
+
18
+ import io
19
+ from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
20
+
21
+ valid_seek_flags = {0, 1, 2} # Hardwired values
22
+ if hasattr(os, 'SEEK_HOLE') :
23
+ valid_seek_flags.add(os.SEEK_HOLE)
24
+ valid_seek_flags.add(os.SEEK_DATA)
25
+
26
+ # open() uses st_blksize whenever we can
27
+ DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
28
+
29
+ # NOTE: Base classes defined here are registered with the "official" ABCs
30
+ # defined in io.py. We don't use real inheritance though, because we don't want
31
+ # to inherit the C implementations.
32
+
33
+ # Rebind for compatibility
34
+ BlockingIOError = BlockingIOError
35
+
36
+ # Does open() check its 'errors' argument?
37
+ _CHECK_ERRORS = (hasattr(sys, "gettotalrefcount") or sys.flags.dev_mode)
38
+
39
+
40
+ def text_encoding(encoding, stacklevel=2):
41
+ """
42
+ A helper function to choose the text encoding.
43
+
44
+ When encoding is not None, this function returns it.
45
+ Otherwise, this function returns the default text encoding
46
+ (i.e. "locale" or "utf-8" depends on UTF-8 mode).
47
+
48
+ This function emits an EncodingWarning if *encoding* is None and
49
+ sys.flags.warn_default_encoding is true.
50
+
51
+ This can be used in APIs with an encoding=None parameter
52
+ that pass it to TextIOWrapper or open.
53
+ However, please consider using encoding="utf-8" for new APIs.
54
+ """
55
+ if encoding is None:
56
+ if sys.flags.utf8_mode:
57
+ encoding = "utf-8"
58
+ else:
59
+ encoding = "locale"
60
+ if sys.flags.warn_default_encoding:
61
+ import warnings
62
+ warnings.warn("'encoding' argument not specified.",
63
+ EncodingWarning, stacklevel + 1)
64
+ return encoding
65
+
66
+
67
+ # Wrapper for builtins.open
68
+ #
69
+ # Trick so that open() won't become a bound method when stored
70
+ # as a class variable (as dbm.dumb does).
71
+ #
72
+ # See init_set_builtins_open() in Python/pylifecycle.c.
73
+ @staticmethod
74
+ def open(file, mode="r", buffering=-1, encoding=None, errors=None,
75
+ newline=None, closefd=True, opener=None):
76
+
77
+ r"""Open file and return a stream. Raise OSError upon failure.
78
+
79
+ file is either a text or byte string giving the name (and the path
80
+ if the file isn't in the current working directory) of the file to
81
+ be opened or an integer file descriptor of the file to be
82
+ wrapped. (If a file descriptor is given, it is closed when the
83
+ returned I/O object is closed, unless closefd is set to False.)
84
+
85
+ mode is an optional string that specifies the mode in which the file
86
+ is opened. It defaults to 'r' which means open for reading in text
87
+ mode. Other common values are 'w' for writing (truncating the file if
88
+ it already exists), 'x' for exclusive creation of a new file, and
89
+ 'a' for appending (which on some Unix systems, means that all writes
90
+ append to the end of the file regardless of the current seek position).
91
+ In text mode, if encoding is not specified the encoding used is platform
92
+ dependent. (For reading and writing raw bytes use binary mode and leave
93
+ encoding unspecified.) The available modes are:
94
+
95
+ ========= ==========================================================
96
+ Character Meaning
97
+ --------- ----------------------------------------------------------
98
+ 'r' open for reading (default)
99
+ 'w' open for writing, truncating the file first
100
+ 'x' create a new file and open it for writing
101
+ 'a' open for writing, appending to the end of the file if it
102
+ exists
103
+ 'b' binary mode
104
+ 't' text mode (default)
105
+ '+' open a disk file for updating (reading and writing)
106
+ ========= ==========================================================
107
+
108
+ The default mode is 'rt' (open for reading text). For binary random
109
+ access, the mode 'w+b' opens and truncates the file to 0 bytes, while
110
+ 'r+b' opens the file without truncation. The 'x' mode implies 'w' and
111
+ raises an `FileExistsError` if the file already exists.
112
+
113
+ Python distinguishes between files opened in binary and text modes,
114
+ even when the underlying operating system doesn't. Files opened in
115
+ binary mode (appending 'b' to the mode argument) return contents as
116
+ bytes objects without any decoding. In text mode (the default, or when
117
+ 't' is appended to the mode argument), the contents of the file are
118
+ returned as strings, the bytes having been first decoded using a
119
+ platform-dependent encoding or using the specified encoding if given.
120
+
121
+ buffering is an optional integer used to set the buffering policy.
122
+ Pass 0 to switch buffering off (only allowed in binary mode), 1 to
123
+ select line buffering (only usable in text mode), and an integer > 1 to
124
+ indicate the size of a fixed-size chunk buffer. When no buffering
125
+ argument is given, the default buffering policy works as follows:
126
+
127
+ * Binary files are buffered in fixed-size chunks; the size of the buffer
128
+ is chosen using a heuristic trying to determine the underlying
129
+ device's "block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
130
+ On many systems, the buffer will typically be 4096 or 8192 bytes long.
131
+
132
+ * "Interactive" text files (files for which isatty() returns True)
133
+ use line buffering. Other text files use the policy described above
134
+ for binary files.
135
+
136
+ encoding is the str name of the encoding used to decode or encode the
137
+ file. This should only be used in text mode. The default encoding is
138
+ platform dependent, but any encoding supported by Python can be
139
+ passed. See the codecs module for the list of supported encodings.
140
+
141
+ errors is an optional string that specifies how encoding errors are to
142
+ be handled---this argument should not be used in binary mode. Pass
143
+ 'strict' to raise a ValueError exception if there is an encoding error
144
+ (the default of None has the same effect), or pass 'ignore' to ignore
145
+ errors. (Note that ignoring encoding errors can lead to data loss.)
146
+ See the documentation for codecs.register for a list of the permitted
147
+ encoding error strings.
148
+
149
+ newline is a string controlling how universal newlines works (it only
150
+ applies to text mode). It can be None, '', '\n', '\r', and '\r\n'. It
151
+ works as follows:
152
+
153
+ * On input, if newline is None, universal newlines mode is
154
+ enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
155
+ these are translated into '\n' before being returned to the
156
+ caller. If it is '', universal newline mode is enabled, but line
157
+ endings are returned to the caller untranslated. If it has any of
158
+ the other legal values, input lines are only terminated by the given
159
+ string, and the line ending is returned to the caller untranslated.
160
+
161
+ * On output, if newline is None, any '\n' characters written are
162
+ translated to the system default line separator, os.linesep. If
163
+ newline is '', no translation takes place. If newline is any of the
164
+ other legal values, any '\n' characters written are translated to
165
+ the given string.
166
+
167
+ closedfd is a bool. If closefd is False, the underlying file descriptor
168
+ will be kept open when the file is closed. This does not work when
169
+ a file name is given and must be True in that case.
170
+
171
+ The newly created file is non-inheritable.
172
+
173
+ A custom opener can be used by passing a callable as *opener*. The
174
+ underlying file descriptor for the file object is then obtained by
175
+ calling *opener* with (*file*, *flags*). *opener* must return an open
176
+ file descriptor (passing os.open as *opener* results in functionality
177
+ similar to passing None).
178
+
179
+ open() returns a file object whose type depends on the mode, and
180
+ through which the standard file operations such as reading and writing
181
+ are performed. When open() is used to open a file in a text mode ('w',
182
+ 'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
183
+ a file in a binary mode, the returned class varies: in read binary
184
+ mode, it returns a BufferedReader; in write binary and append binary
185
+ modes, it returns a BufferedWriter, and in read/write mode, it returns
186
+ a BufferedRandom.
187
+
188
+ It is also possible to use a string or bytearray as a file for both
189
+ reading and writing. For strings StringIO can be used like a file
190
+ opened in a text mode, and for bytes a BytesIO can be used like a file
191
+ opened in a binary mode.
192
+ """
193
+ if not isinstance(file, int):
194
+ file = os.fspath(file)
195
+ if not isinstance(file, (str, bytes, int)):
196
+ raise TypeError("invalid file: %r" % file)
197
+ if not isinstance(mode, str):
198
+ raise TypeError("invalid mode: %r" % mode)
199
+ if not isinstance(buffering, int):
200
+ raise TypeError("invalid buffering: %r" % buffering)
201
+ if encoding is not None and not isinstance(encoding, str):
202
+ raise TypeError("invalid encoding: %r" % encoding)
203
+ if errors is not None and not isinstance(errors, str):
204
+ raise TypeError("invalid errors: %r" % errors)
205
+ modes = set(mode)
206
+ if modes - set("axrwb+t") or len(mode) > len(modes):
207
+ raise ValueError("invalid mode: %r" % mode)
208
+ creating = "x" in modes
209
+ reading = "r" in modes
210
+ writing = "w" in modes
211
+ appending = "a" in modes
212
+ updating = "+" in modes
213
+ text = "t" in modes
214
+ binary = "b" in modes
215
+ if text and binary:
216
+ raise ValueError("can't have text and binary mode at once")
217
+ if creating + reading + writing + appending > 1:
218
+ raise ValueError("can't have read/write/append mode at once")
219
+ if not (creating or reading or writing or appending):
220
+ raise ValueError("must have exactly one of read/write/append mode")
221
+ if binary and encoding is not None:
222
+ raise ValueError("binary mode doesn't take an encoding argument")
223
+ if binary and errors is not None:
224
+ raise ValueError("binary mode doesn't take an errors argument")
225
+ if binary and newline is not None:
226
+ raise ValueError("binary mode doesn't take a newline argument")
227
+ if binary and buffering == 1:
228
+ import warnings
229
+ warnings.warn("line buffering (buffering=1) isn't supported in binary "
230
+ "mode, the default buffer size will be used",
231
+ RuntimeWarning, 2)
232
+ raw = FileIO(file,
233
+ (creating and "x" or "") +
234
+ (reading and "r" or "") +
235
+ (writing and "w" or "") +
236
+ (appending and "a" or "") +
237
+ (updating and "+" or ""),
238
+ closefd, opener=opener)
239
+ result = raw
240
+ try:
241
+ line_buffering = False
242
+ if buffering == 1 or buffering < 0 and raw.isatty():
243
+ buffering = -1
244
+ line_buffering = True
245
+ if buffering < 0:
246
+ buffering = DEFAULT_BUFFER_SIZE
247
+ try:
248
+ bs = os.fstat(raw.fileno()).st_blksize
249
+ except (OSError, AttributeError):
250
+ pass
251
+ else:
252
+ if bs > 1:
253
+ buffering = bs
254
+ if buffering < 0:
255
+ raise ValueError("invalid buffering size")
256
+ if buffering == 0:
257
+ if binary:
258
+ return result
259
+ raise ValueError("can't have unbuffered text I/O")
260
+ if updating:
261
+ buffer = BufferedRandom(raw, buffering)
262
+ elif creating or writing or appending:
263
+ buffer = BufferedWriter(raw, buffering)
264
+ elif reading:
265
+ buffer = BufferedReader(raw, buffering)
266
+ else:
267
+ raise ValueError("unknown mode: %r" % mode)
268
+ result = buffer
269
+ if binary:
270
+ return result
271
+ encoding = text_encoding(encoding)
272
+ text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
273
+ result = text
274
+ text.mode = mode
275
+ return result
276
+ except:
277
+ result.close()
278
+ raise
279
+
280
+ # Define a default pure-Python implementation for open_code()
281
+ # that does not allow hooks. Warn on first use. Defined for tests.
282
+ def _open_code_with_warning(path):
283
+ """Opens the provided file with mode ``'rb'``. This function
284
+ should be used when the intent is to treat the contents as
285
+ executable code.
286
+
287
+ ``path`` should be an absolute path.
288
+
289
+ When supported by the runtime, this function can be hooked
290
+ in order to allow embedders more control over code files.
291
+ This functionality is not supported on the current runtime.
292
+ """
293
+ import warnings
294
+ warnings.warn("_pyio.open_code() may not be using hooks",
295
+ RuntimeWarning, 2)
296
+ return open(path, "rb")
297
+
298
+ try:
299
+ open_code = io.open_code
300
+ except AttributeError:
301
+ open_code = _open_code_with_warning
302
+
303
+
304
+ # In normal operation, both `UnsupportedOperation`s should be bound to the
305
+ # same object.
306
+ try:
307
+ UnsupportedOperation = io.UnsupportedOperation
308
+ except AttributeError:
309
+ class UnsupportedOperation(OSError, ValueError):
310
+ pass
311
+
312
+
313
+ class IOBase(metaclass=abc.ABCMeta):
314
+
315
+ """The abstract base class for all I/O classes.
316
+
317
+ This class provides dummy implementations for many methods that
318
+ derived classes can override selectively; the default implementations
319
+ represent a file that cannot be read, written or seeked.
320
+
321
+ Even though IOBase does not declare read or write because
322
+ their signatures will vary, implementations and clients should
323
+ consider those methods part of the interface. Also, implementations
324
+ may raise UnsupportedOperation when operations they do not support are
325
+ called.
326
+
327
+ The basic type used for binary data read from or written to a file is
328
+ bytes. Other bytes-like objects are accepted as method arguments too.
329
+ Text I/O classes work with str data.
330
+
331
+ Note that calling any method (even inquiries) on a closed stream is
332
+ undefined. Implementations may raise OSError in this case.
333
+
334
+ IOBase (and its subclasses) support the iterator protocol, meaning
335
+ that an IOBase object can be iterated over yielding the lines in a
336
+ stream.
337
+
338
+ IOBase also supports the :keyword:`with` statement. In this example,
339
+ fp is closed after the suite of the with statement is complete:
340
+
341
+ with open('spam.txt', 'r') as fp:
342
+ fp.write('Spam and eggs!')
343
+ """
344
+
345
+ ### Internal ###
346
+
347
+ def _unsupported(self, name):
348
+ """Internal: raise an OSError exception for unsupported operations."""
349
+ raise UnsupportedOperation("%s.%s() not supported" %
350
+ (self.__class__.__name__, name))
351
+
352
+ ### Positioning ###
353
+
354
+ def seek(self, pos, whence=0):
355
+ """Change stream position.
356
+
357
+ Change the stream position to byte offset pos. Argument pos is
358
+ interpreted relative to the position indicated by whence. Values
359
+ for whence are ints:
360
+
361
+ * 0 -- start of stream (the default); offset should be zero or
362
+ positive
363
+ * 1 -- current stream position; offset may be negative
364
+ * 2 -- end of stream; offset is usually negative
365
+ Some operating systems / file systems could provide additional
366
+ values.
367
+
368
+ Return an int indicating the new absolute position.
369
+ """
370
+ self._unsupported("seek")
371
+
372
+ def tell(self):
373
+ """Return an int indicating the current stream position."""
374
+ return self.seek(0, 1)
375
+
376
+ def truncate(self, pos=None):
377
+ """Truncate file to size bytes.
378
+
379
+ Size defaults to the current IO position as reported by tell().
380
+ Return the new size.
381
+ """
382
+ self._unsupported("truncate")
383
+
384
+ ### Flush and close ###
385
+
386
+ def flush(self):
387
+ """Flush write buffers, if applicable.
388
+
389
+ This is not implemented for read-only and non-blocking streams.
390
+ """
391
+ self._checkClosed()
392
+ # XXX Should this return the number of bytes written???
393
+
394
+ __closed = False
395
+
396
+ def close(self):
397
+ """Flush and close the IO object.
398
+
399
+ This method has no effect if the file is already closed.
400
+ """
401
+ if not self.__closed:
402
+ try:
403
+ self.flush()
404
+ finally:
405
+ self.__closed = True
406
+
407
+ def __del__(self):
408
+ """Destructor. Calls close()."""
409
+ try:
410
+ closed = self.closed
411
+ except AttributeError:
412
+ # If getting closed fails, then the object is probably
413
+ # in an unusable state, so ignore.
414
+ return
415
+
416
+ if closed:
417
+ return
418
+
419
+ if dealloc_warn := getattr(self, "_dealloc_warn", None):
420
+ dealloc_warn(self)
421
+
422
+ # If close() fails, the caller logs the exception with
423
+ # sys.unraisablehook. close() must be called at the end at __del__().
424
+ self.close()
425
+
426
+ ### Inquiries ###
427
+
428
+ def seekable(self):
429
+ """Return a bool indicating whether object supports random access.
430
+
431
+ If False, seek(), tell() and truncate() will raise OSError.
432
+ This method may need to do a test seek().
433
+ """
434
+ return False
435
+
436
+ def _checkSeekable(self, msg=None):
437
+ """Internal: raise UnsupportedOperation if file is not seekable
438
+ """
439
+ if not self.seekable():
440
+ raise UnsupportedOperation("File or stream is not seekable."
441
+ if msg is None else msg)
442
+
443
+ def readable(self):
444
+ """Return a bool indicating whether object was opened for reading.
445
+
446
+ If False, read() will raise OSError.
447
+ """
448
+ return False
449
+
450
+ def _checkReadable(self, msg=None):
451
+ """Internal: raise UnsupportedOperation if file is not readable
452
+ """
453
+ if not self.readable():
454
+ raise UnsupportedOperation("File or stream is not readable."
455
+ if msg is None else msg)
456
+
457
+ def writable(self):
458
+ """Return a bool indicating whether object was opened for writing.
459
+
460
+ If False, write() and truncate() will raise OSError.
461
+ """
462
+ return False
463
+
464
+ def _checkWritable(self, msg=None):
465
+ """Internal: raise UnsupportedOperation if file is not writable
466
+ """
467
+ if not self.writable():
468
+ raise UnsupportedOperation("File or stream is not writable."
469
+ if msg is None else msg)
470
+
471
+ @property
472
+ def closed(self):
473
+ """closed: bool. True iff the file has been closed.
474
+
475
+ For backwards compatibility, this is a property, not a predicate.
476
+ """
477
+ return self.__closed
478
+
479
+ def _checkClosed(self, msg=None):
480
+ """Internal: raise a ValueError if file is closed
481
+ """
482
+ if self.closed:
483
+ raise ValueError("I/O operation on closed file."
484
+ if msg is None else msg)
485
+
486
+ ### Context manager ###
487
+
488
+ def __enter__(self): # That's a forward reference
489
+ """Context management protocol. Returns self (an instance of IOBase)."""
490
+ self._checkClosed()
491
+ return self
492
+
493
+ def __exit__(self, *args):
494
+ """Context management protocol. Calls close()"""
495
+ self.close()
496
+
497
+ ### Lower-level APIs ###
498
+
499
+ # XXX Should these be present even if unimplemented?
500
+
501
+ def fileno(self):
502
+ """Returns underlying file descriptor (an int) if one exists.
503
+
504
+ An OSError is raised if the IO object does not use a file
505
+ descriptor.
506
+ """
507
+ self._unsupported("fileno")
508
+
509
+ def isatty(self):
510
+ """Return a bool indicating whether this is an 'interactive' stream.
511
+
512
+ Return False if it can't be determined.
513
+ """
514
+ self._checkClosed()
515
+ return False
516
+
517
+ ### Readline[s] and writelines ###
518
+
519
+ def readline(self, size=-1):
520
+ r"""Read and return a line of bytes from the stream.
521
+
522
+ If size is specified, at most size bytes will be read.
523
+ Size should be an int.
524
+
525
+ The line terminator is always b'\n' for binary files; for text
526
+ files, the newlines argument to open can be used to select the line
527
+ terminator(s) recognized.
528
+ """
529
+ # For backwards compatibility, a (slowish) readline().
530
+ if hasattr(self, "peek"):
531
+ def nreadahead():
532
+ readahead = self.peek(1)
533
+ if not readahead:
534
+ return 1
535
+ n = (readahead.find(b"\n") + 1) or len(readahead)
536
+ if size >= 0:
537
+ n = min(n, size)
538
+ return n
539
+ else:
540
+ def nreadahead():
541
+ return 1
542
+ if size is None:
543
+ size = -1
544
+ else:
545
+ try:
546
+ size_index = size.__index__
547
+ except AttributeError:
548
+ raise TypeError(f"{size!r} is not an integer")
549
+ else:
550
+ size = size_index()
551
+ res = bytearray()
552
+ while size < 0 or len(res) < size:
553
+ b = self.read(nreadahead())
554
+ if not b:
555
+ break
556
+ res += b
557
+ if res.endswith(b"\n"):
558
+ break
559
+ return bytes(res)
560
+
561
+ def __iter__(self):
562
+ self._checkClosed()
563
+ return self
564
+
565
+ def __next__(self):
566
+ line = self.readline()
567
+ if not line:
568
+ raise StopIteration
569
+ return line
570
+
571
+ def readlines(self, hint=None):
572
+ """Return a list of lines from the stream.
573
+
574
+ hint can be specified to control the number of lines read: no more
575
+ lines will be read if the total size (in bytes/characters) of all
576
+ lines so far exceeds hint.
577
+ """
578
+ if hint is None or hint <= 0:
579
+ return list(self)
580
+ n = 0
581
+ lines = []
582
+ for line in self:
583
+ lines.append(line)
584
+ n += len(line)
585
+ if n >= hint:
586
+ break
587
+ return lines
588
+
589
+ def writelines(self, lines):
590
+ """Write a list of lines to the stream.
591
+
592
+ Line separators are not added, so it is usual for each of the lines
593
+ provided to have a line separator at the end.
594
+ """
595
+ self._checkClosed()
596
+ for line in lines:
597
+ self.write(line)
598
+
599
+ io.IOBase.register(IOBase)
600
+
601
+
602
+ class RawIOBase(IOBase):
603
+
604
+ """Base class for raw binary I/O."""
605
+
606
+ # The read() method is implemented by calling readinto(); derived
607
+ # classes that want to support read() only need to implement
608
+ # readinto() as a primitive operation. In general, readinto() can be
609
+ # more efficient than read().
610
+
611
+ # (It would be tempting to also provide an implementation of
612
+ # readinto() in terms of read(), in case the latter is a more suitable
613
+ # primitive operation, but that would lead to nasty recursion in case
614
+ # a subclass doesn't implement either.)
615
+
616
+ def read(self, size=-1):
617
+ """Read and return up to size bytes, where size is an int.
618
+
619
+ Returns an empty bytes object on EOF, or None if the object is
620
+ set not to block and has no data to read.
621
+ """
622
+ if size is None:
623
+ size = -1
624
+ if size < 0:
625
+ return self.readall()
626
+ b = bytearray(size.__index__())
627
+ n = self.readinto(b)
628
+ if n is None:
629
+ return None
630
+ if n < 0 or n > len(b):
631
+ raise ValueError(f"readinto returned {n} outside buffer size {len(b)}")
632
+ del b[n:]
633
+ return bytes(b)
634
+
635
+ def readall(self):
636
+ """Read until EOF, using multiple read() call."""
637
+ res = bytearray()
638
+ while data := self.read(DEFAULT_BUFFER_SIZE):
639
+ res += data
640
+ if res:
641
+ return bytes(res)
642
+ else:
643
+ # b'' or None
644
+ return data
645
+
646
+ def readinto(self, b):
647
+ """Read bytes into a pre-allocated bytes-like object b.
648
+
649
+ Returns an int representing the number of bytes read (0 for EOF), or
650
+ None if the object is set not to block and has no data to read.
651
+ """
652
+ self._unsupported("readinto")
653
+
654
+ def write(self, b):
655
+ """Write the given buffer to the IO stream.
656
+
657
+ Returns the number of bytes written, which may be less than the
658
+ length of b in bytes.
659
+ """
660
+ self._unsupported("write")
661
+
662
+ io.RawIOBase.register(RawIOBase)
663
+
664
+
665
+ class BufferedIOBase(IOBase):
666
+
667
+ """Base class for buffered IO objects.
668
+
669
+ The main difference with RawIOBase is that the read() method
670
+ supports omitting the size argument, and does not have a default
671
+ implementation that defers to readinto().
672
+
673
+ In addition, read(), readinto() and write() may raise
674
+ BlockingIOError if the underlying raw stream is in non-blocking
675
+ mode and not ready; unlike their raw counterparts, they will never
676
+ return None.
677
+
678
+ A typical implementation should not inherit from a RawIOBase
679
+ implementation, but wrap one.
680
+ """
681
+
682
+ def read(self, size=-1):
683
+ """Read and return up to size bytes, where size is an int.
684
+
685
+ If the argument is omitted, None, or negative, reads and
686
+ returns all data until EOF.
687
+
688
+ If the argument is positive, and the underlying raw stream is
689
+ not 'interactive', multiple raw reads may be issued to satisfy
690
+ the byte count (unless EOF is reached first). But for
691
+ interactive raw streams (XXX and for pipes?), at most one raw
692
+ read will be issued, and a short result does not imply that
693
+ EOF is imminent.
694
+
695
+ Returns an empty bytes array on EOF.
696
+
697
+ Raises BlockingIOError if the underlying raw stream has no
698
+ data at the moment.
699
+ """
700
+ self._unsupported("read")
701
+
702
+ def read1(self, size=-1):
703
+ """Read up to size bytes with at most one read() system call,
704
+ where size is an int.
705
+ """
706
+ self._unsupported("read1")
707
+
708
+ def readinto(self, b):
709
+ """Read bytes into a pre-allocated bytes-like object b.
710
+
711
+ Like read(), this may issue multiple reads to the underlying raw
712
+ stream, unless the latter is 'interactive'.
713
+
714
+ Returns an int representing the number of bytes read (0 for EOF).
715
+
716
+ Raises BlockingIOError if the underlying raw stream has no
717
+ data at the moment.
718
+ """
719
+
720
+ return self._readinto(b, read1=False)
721
+
722
+ def readinto1(self, b):
723
+ """Read bytes into buffer *b*, using at most one system call
724
+
725
+ Returns an int representing the number of bytes read (0 for EOF).
726
+
727
+ Raises BlockingIOError if the underlying raw stream has no
728
+ data at the moment.
729
+ """
730
+
731
+ return self._readinto(b, read1=True)
732
+
733
+ def _readinto(self, b, read1):
734
+ if not isinstance(b, memoryview):
735
+ b = memoryview(b)
736
+ b = b.cast('B')
737
+
738
+ if read1:
739
+ data = self.read1(len(b))
740
+ else:
741
+ data = self.read(len(b))
742
+ n = len(data)
743
+
744
+ b[:n] = data
745
+
746
+ return n
747
+
748
+ def write(self, b):
749
+ """Write the given bytes buffer to the IO stream.
750
+
751
+ Return the number of bytes written, which is always the length of b
752
+ in bytes.
753
+
754
+ Raises BlockingIOError if the buffer is full and the
755
+ underlying raw stream cannot accept more data at the moment.
756
+ """
757
+ self._unsupported("write")
758
+
759
+ def detach(self):
760
+ """
761
+ Separate the underlying raw stream from the buffer and return it.
762
+
763
+ After the raw stream has been detached, the buffer is in an unusable
764
+ state.
765
+ """
766
+ self._unsupported("detach")
767
+
768
+ io.BufferedIOBase.register(BufferedIOBase)
769
+
770
+
771
+ class _BufferedIOMixin(BufferedIOBase):
772
+
773
+ """A mixin implementation of BufferedIOBase with an underlying raw stream.
774
+
775
+ This passes most requests on to the underlying raw stream. It
776
+ does *not* provide implementations of read(), readinto() or
777
+ write().
778
+ """
779
+
780
+ def __init__(self, raw):
781
+ self._raw = raw
782
+
783
+ ### Positioning ###
784
+
785
+ def seek(self, pos, whence=0):
786
+ new_position = self.raw.seek(pos, whence)
787
+ if new_position < 0:
788
+ raise OSError("seek() returned an invalid position")
789
+ return new_position
790
+
791
+ def tell(self):
792
+ pos = self.raw.tell()
793
+ if pos < 0:
794
+ raise OSError("tell() returned an invalid position")
795
+ return pos
796
+
797
+ def truncate(self, pos=None):
798
+ self._checkClosed()
799
+ self._checkWritable()
800
+
801
+ # Flush the stream. We're mixing buffered I/O with lower-level I/O,
802
+ # and a flush may be necessary to synch both views of the current
803
+ # file state.
804
+ self.flush()
805
+
806
+ if pos is None:
807
+ pos = self.tell()
808
+ # XXX: Should seek() be used, instead of passing the position
809
+ # XXX directly to truncate?
810
+ return self.raw.truncate(pos)
811
+
812
+ ### Flush and close ###
813
+
814
+ def flush(self):
815
+ if self.closed:
816
+ raise ValueError("flush on closed file")
817
+ self.raw.flush()
818
+
819
+ def close(self):
820
+ if self.raw is not None and not self.closed:
821
+ try:
822
+ # may raise BlockingIOError or BrokenPipeError etc
823
+ self.flush()
824
+ finally:
825
+ self.raw.close()
826
+
827
+ def detach(self):
828
+ if self.raw is None:
829
+ raise ValueError("raw stream already detached")
830
+ self.flush()
831
+ raw = self._raw
832
+ self._raw = None
833
+ return raw
834
+
835
+ ### Inquiries ###
836
+
837
+ def seekable(self):
838
+ return self.raw.seekable()
839
+
840
+ @property
841
+ def raw(self):
842
+ return self._raw
843
+
844
+ @property
845
+ def closed(self):
846
+ return self.raw.closed
847
+
848
+ @property
849
+ def name(self):
850
+ return self.raw.name
851
+
852
+ @property
853
+ def mode(self):
854
+ return self.raw.mode
855
+
856
+ def __getstate__(self):
857
+ raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
858
+
859
+ def __repr__(self):
860
+ modname = self.__class__.__module__
861
+ clsname = self.__class__.__qualname__
862
+ try:
863
+ name = self.name
864
+ except AttributeError:
865
+ return "<{}.{}>".format(modname, clsname)
866
+ else:
867
+ return "<{}.{} name={!r}>".format(modname, clsname, name)
868
+
869
+ def _dealloc_warn(self, source):
870
+ if dealloc_warn := getattr(self.raw, "_dealloc_warn", None):
871
+ dealloc_warn(source)
872
+
873
+ ### Lower-level APIs ###
874
+
875
+ def fileno(self):
876
+ return self.raw.fileno()
877
+
878
+ def isatty(self):
879
+ return self.raw.isatty()
880
+
881
+
882
+ class BytesIO(BufferedIOBase):
883
+
884
+ """Buffered I/O implementation using an in-memory bytes buffer."""
885
+
886
+ # Initialize _buffer as soon as possible since it's used by __del__()
887
+ # which calls close()
888
+ _buffer = None
889
+
890
+ def __init__(self, initial_bytes=None):
891
+ buf = bytearray()
892
+ if initial_bytes is not None:
893
+ buf += initial_bytes
894
+ self._buffer = buf
895
+ self._pos = 0
896
+
897
+ def __getstate__(self):
898
+ if self.closed:
899
+ raise ValueError("__getstate__ on closed file")
900
+ return self.__dict__.copy()
901
+
902
+ def getvalue(self):
903
+ """Return the bytes value (contents) of the buffer
904
+ """
905
+ if self.closed:
906
+ raise ValueError("getvalue on closed file")
907
+ return bytes(self._buffer)
908
+
909
+ def getbuffer(self):
910
+ """Return a readable and writable view of the buffer.
911
+ """
912
+ if self.closed:
913
+ raise ValueError("getbuffer on closed file")
914
+ return memoryview(self._buffer)
915
+
916
+ def close(self):
917
+ if self._buffer is not None:
918
+ self._buffer.clear()
919
+ super().close()
920
+
921
+ def read(self, size=-1):
922
+ if self.closed:
923
+ raise ValueError("read from closed file")
924
+ if size is None:
925
+ size = -1
926
+ else:
927
+ try:
928
+ size_index = size.__index__
929
+ except AttributeError:
930
+ raise TypeError(f"{size!r} is not an integer")
931
+ else:
932
+ size = size_index()
933
+ if size < 0:
934
+ size = len(self._buffer)
935
+ if len(self._buffer) <= self._pos:
936
+ return b""
937
+ newpos = min(len(self._buffer), self._pos + size)
938
+ b = self._buffer[self._pos : newpos]
939
+ self._pos = newpos
940
+ return bytes(b)
941
+
942
+ def read1(self, size=-1):
943
+ """This is the same as read.
944
+ """
945
+ return self.read(size)
946
+
947
+ def write(self, b):
948
+ if isinstance(b, str):
949
+ raise TypeError("can't write str to binary stream")
950
+ with memoryview(b) as view:
951
+ if self.closed:
952
+ raise ValueError("write to closed file")
953
+
954
+ n = view.nbytes # Size of any bytes-like object
955
+ if n == 0:
956
+ return 0
957
+
958
+ pos = self._pos
959
+ if pos > len(self._buffer):
960
+ # Inserts null bytes between the current end of the file
961
+ # and the new write position.
962
+ padding = b'\x00' * (pos - len(self._buffer))
963
+ self._buffer += padding
964
+ self._buffer[pos:pos + n] = view
965
+ self._pos += n
966
+ return n
967
+
968
+ def seek(self, pos, whence=0):
969
+ if self.closed:
970
+ raise ValueError("seek on closed file")
971
+ try:
972
+ pos_index = pos.__index__
973
+ except AttributeError:
974
+ raise TypeError(f"{pos!r} is not an integer")
975
+ else:
976
+ pos = pos_index()
977
+ if whence == 0:
978
+ if pos < 0:
979
+ raise ValueError("negative seek position %r" % (pos,))
980
+ self._pos = pos
981
+ elif whence == 1:
982
+ self._pos = max(0, self._pos + pos)
983
+ elif whence == 2:
984
+ self._pos = max(0, len(self._buffer) + pos)
985
+ else:
986
+ raise ValueError("unsupported whence value")
987
+ return self._pos
988
+
989
+ def tell(self):
990
+ if self.closed:
991
+ raise ValueError("tell on closed file")
992
+ return self._pos
993
+
994
+ def truncate(self, pos=None):
995
+ if self.closed:
996
+ raise ValueError("truncate on closed file")
997
+ if pos is None:
998
+ pos = self._pos
999
+ else:
1000
+ try:
1001
+ pos_index = pos.__index__
1002
+ except AttributeError:
1003
+ raise TypeError(f"{pos!r} is not an integer")
1004
+ else:
1005
+ pos = pos_index()
1006
+ if pos < 0:
1007
+ raise ValueError("negative truncate position %r" % (pos,))
1008
+ del self._buffer[pos:]
1009
+ return pos
1010
+
1011
+ def readable(self):
1012
+ if self.closed:
1013
+ raise ValueError("I/O operation on closed file.")
1014
+ return True
1015
+
1016
+ def writable(self):
1017
+ if self.closed:
1018
+ raise ValueError("I/O operation on closed file.")
1019
+ return True
1020
+
1021
+ def seekable(self):
1022
+ if self.closed:
1023
+ raise ValueError("I/O operation on closed file.")
1024
+ return True
1025
+
1026
+
1027
+ class BufferedReader(_BufferedIOMixin):
1028
+
1029
+ """BufferedReader(raw[, buffer_size])
1030
+
1031
+ A buffer for a readable, sequential BaseRawIO object.
1032
+
1033
+ The constructor creates a BufferedReader for the given readable raw
1034
+ stream and buffer_size. If buffer_size is omitted, DEFAULT_BUFFER_SIZE
1035
+ is used.
1036
+ """
1037
+
1038
+ def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
1039
+ """Create a new buffered reader using the given readable raw IO object.
1040
+ """
1041
+ if not raw.readable():
1042
+ raise OSError('"raw" argument must be readable.')
1043
+
1044
+ _BufferedIOMixin.__init__(self, raw)
1045
+ if buffer_size <= 0:
1046
+ raise ValueError("invalid buffer size")
1047
+ self.buffer_size = buffer_size
1048
+ self._reset_read_buf()
1049
+ self._read_lock = Lock()
1050
+
1051
+ def readable(self):
1052
+ return self.raw.readable()
1053
+
1054
+ def _reset_read_buf(self):
1055
+ self._read_buf = b""
1056
+ self._read_pos = 0
1057
+
1058
+ def read(self, size=None):
1059
+ """Read size bytes.
1060
+
1061
+ Returns exactly size bytes of data unless the underlying raw IO
1062
+ stream reaches EOF or if the call would block in non-blocking
1063
+ mode. If size is negative, read until EOF or until read() would
1064
+ block.
1065
+ """
1066
+ if size is not None and size < -1:
1067
+ raise ValueError("invalid number of bytes to read")
1068
+ with self._read_lock:
1069
+ return self._read_unlocked(size)
1070
+
1071
+ def _read_unlocked(self, n=None):
1072
+ nodata_val = b""
1073
+ empty_values = (b"", None)
1074
+ buf = self._read_buf
1075
+ pos = self._read_pos
1076
+
1077
+ # Special case for when the number of bytes to read is unspecified.
1078
+ if n is None or n == -1:
1079
+ self._reset_read_buf()
1080
+ if hasattr(self.raw, 'readall'):
1081
+ chunk = self.raw.readall()
1082
+ if chunk is None:
1083
+ return buf[pos:] or None
1084
+ else:
1085
+ return buf[pos:] + chunk
1086
+ chunks = [buf[pos:]] # Strip the consumed bytes.
1087
+ current_size = 0
1088
+ while True:
1089
+ # Read until EOF or until read() would block.
1090
+ chunk = self.raw.read()
1091
+ if chunk in empty_values:
1092
+ nodata_val = chunk
1093
+ break
1094
+ current_size += len(chunk)
1095
+ chunks.append(chunk)
1096
+ return b"".join(chunks) or nodata_val
1097
+
1098
+ # The number of bytes to read is specified, return at most n bytes.
1099
+ avail = len(buf) - pos # Length of the available buffered data.
1100
+ if n <= avail:
1101
+ # Fast path: the data to read is fully buffered.
1102
+ self._read_pos += n
1103
+ return buf[pos:pos+n]
1104
+ # Slow path: read from the stream until enough bytes are read,
1105
+ # or until an EOF occurs or until read() would block.
1106
+ chunks = [buf[pos:]]
1107
+ wanted = max(self.buffer_size, n)
1108
+ while avail < n:
1109
+ chunk = self.raw.read(wanted)
1110
+ if chunk in empty_values:
1111
+ nodata_val = chunk
1112
+ break
1113
+ avail += len(chunk)
1114
+ chunks.append(chunk)
1115
+ # n is more than avail only when an EOF occurred or when
1116
+ # read() would have blocked.
1117
+ n = min(n, avail)
1118
+ out = b"".join(chunks)
1119
+ self._read_buf = out[n:] # Save the extra data in the buffer.
1120
+ self._read_pos = 0
1121
+ return out[:n] if out else nodata_val
1122
+
1123
+ def peek(self, size=0):
1124
+ """Returns buffered bytes without advancing the position.
1125
+
1126
+ The argument indicates a desired minimal number of bytes; we
1127
+ do at most one raw read to satisfy it. We never return more
1128
+ than self.buffer_size.
1129
+ """
1130
+ self._checkClosed("peek of closed file")
1131
+ with self._read_lock:
1132
+ return self._peek_unlocked(size)
1133
+
1134
+ def _peek_unlocked(self, n=0):
1135
+ want = min(n, self.buffer_size)
1136
+ have = len(self._read_buf) - self._read_pos
1137
+ if have < want or have <= 0:
1138
+ to_read = self.buffer_size - have
1139
+ current = self.raw.read(to_read)
1140
+ if current:
1141
+ self._read_buf = self._read_buf[self._read_pos:] + current
1142
+ self._read_pos = 0
1143
+ return self._read_buf[self._read_pos:]
1144
+
1145
+ def read1(self, size=-1):
1146
+ """Reads up to size bytes, with at most one read() system call."""
1147
+ # Returns up to size bytes. If at least one byte is buffered, we
1148
+ # only return buffered bytes. Otherwise, we do one raw read.
1149
+ self._checkClosed("read of closed file")
1150
+ if size < 0:
1151
+ size = self.buffer_size
1152
+ if size == 0:
1153
+ return b""
1154
+ with self._read_lock:
1155
+ self._peek_unlocked(1)
1156
+ return self._read_unlocked(
1157
+ min(size, len(self._read_buf) - self._read_pos))
1158
+
1159
+ # Implementing readinto() and readinto1() is not strictly necessary (we
1160
+ # could rely on the base class that provides an implementation in terms of
1161
+ # read() and read1()). We do it anyway to keep the _pyio implementation
1162
+ # similar to the io implementation (which implements the methods for
1163
+ # performance reasons).
1164
+ def _readinto(self, buf, read1):
1165
+ """Read data into *buf* with at most one system call."""
1166
+
1167
+ self._checkClosed("readinto of closed file")
1168
+
1169
+ # Need to create a memoryview object of type 'b', otherwise
1170
+ # we may not be able to assign bytes to it, and slicing it
1171
+ # would create a new object.
1172
+ if not isinstance(buf, memoryview):
1173
+ buf = memoryview(buf)
1174
+ if buf.nbytes == 0:
1175
+ return 0
1176
+ buf = buf.cast('B')
1177
+
1178
+ written = 0
1179
+ with self._read_lock:
1180
+ while written < len(buf):
1181
+
1182
+ # First try to read from internal buffer
1183
+ avail = min(len(self._read_buf) - self._read_pos, len(buf))
1184
+ if avail:
1185
+ buf[written:written+avail] = \
1186
+ self._read_buf[self._read_pos:self._read_pos+avail]
1187
+ self._read_pos += avail
1188
+ written += avail
1189
+ if written == len(buf):
1190
+ break
1191
+
1192
+ # If remaining space in callers buffer is larger than
1193
+ # internal buffer, read directly into callers buffer
1194
+ if len(buf) - written > self.buffer_size:
1195
+ n = self.raw.readinto(buf[written:])
1196
+ if not n:
1197
+ break # eof
1198
+ written += n
1199
+
1200
+ # Otherwise refill internal buffer - unless we're
1201
+ # in read1 mode and already got some data
1202
+ elif not (read1 and written):
1203
+ if not self._peek_unlocked(1):
1204
+ break # eof
1205
+
1206
+ # In readinto1 mode, return as soon as we have some data
1207
+ if read1 and written:
1208
+ break
1209
+
1210
+ return written
1211
+
1212
+ def tell(self):
1213
+ # GH-95782: Keep return value non-negative
1214
+ return max(_BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos, 0)
1215
+
1216
+ def seek(self, pos, whence=0):
1217
+ if whence not in valid_seek_flags:
1218
+ raise ValueError("invalid whence value")
1219
+ self._checkClosed("seek of closed file")
1220
+ with self._read_lock:
1221
+ if whence == 1:
1222
+ pos -= len(self._read_buf) - self._read_pos
1223
+ pos = _BufferedIOMixin.seek(self, pos, whence)
1224
+ self._reset_read_buf()
1225
+ return pos
1226
+
1227
+ class BufferedWriter(_BufferedIOMixin):
1228
+
1229
+ """A buffer for a writeable sequential RawIO object.
1230
+
1231
+ The constructor creates a BufferedWriter for the given writeable raw
1232
+ stream. If the buffer_size is not given, it defaults to
1233
+ DEFAULT_BUFFER_SIZE.
1234
+ """
1235
+
1236
+ def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
1237
+ if not raw.writable():
1238
+ raise OSError('"raw" argument must be writable.')
1239
+
1240
+ _BufferedIOMixin.__init__(self, raw)
1241
+ if buffer_size <= 0:
1242
+ raise ValueError("invalid buffer size")
1243
+ self.buffer_size = buffer_size
1244
+ self._write_buf = bytearray()
1245
+ self._write_lock = Lock()
1246
+
1247
+ def writable(self):
1248
+ return self.raw.writable()
1249
+
1250
+ def write(self, b):
1251
+ if isinstance(b, str):
1252
+ raise TypeError("can't write str to binary stream")
1253
+ with self._write_lock:
1254
+ if self.closed:
1255
+ raise ValueError("write to closed file")
1256
+ # XXX we can implement some more tricks to try and avoid
1257
+ # partial writes
1258
+ if len(self._write_buf) > self.buffer_size:
1259
+ # We're full, so let's pre-flush the buffer. (This may
1260
+ # raise BlockingIOError with characters_written == 0.)
1261
+ self._flush_unlocked()
1262
+ before = len(self._write_buf)
1263
+ self._write_buf.extend(b)
1264
+ written = len(self._write_buf) - before
1265
+ if len(self._write_buf) > self.buffer_size:
1266
+ try:
1267
+ self._flush_unlocked()
1268
+ except BlockingIOError as e:
1269
+ if len(self._write_buf) > self.buffer_size:
1270
+ # We've hit the buffer_size. We have to accept a partial
1271
+ # write and cut back our buffer.
1272
+ overage = len(self._write_buf) - self.buffer_size
1273
+ written -= overage
1274
+ self._write_buf = self._write_buf[:self.buffer_size]
1275
+ raise BlockingIOError(e.errno, e.strerror, written)
1276
+ return written
1277
+
1278
+ def truncate(self, pos=None):
1279
+ with self._write_lock:
1280
+ self._flush_unlocked()
1281
+ if pos is None:
1282
+ pos = self.raw.tell()
1283
+ return self.raw.truncate(pos)
1284
+
1285
+ def flush(self):
1286
+ with self._write_lock:
1287
+ self._flush_unlocked()
1288
+
1289
+ def _flush_unlocked(self):
1290
+ if self.closed:
1291
+ raise ValueError("flush on closed file")
1292
+ while self._write_buf:
1293
+ try:
1294
+ n = self.raw.write(self._write_buf)
1295
+ except BlockingIOError:
1296
+ raise RuntimeError("self.raw should implement RawIOBase: it "
1297
+ "should not raise BlockingIOError")
1298
+ if n is None:
1299
+ raise BlockingIOError(
1300
+ errno.EAGAIN,
1301
+ "write could not complete without blocking", 0)
1302
+ if n > len(self._write_buf) or n < 0:
1303
+ raise OSError("write() returned incorrect number of bytes")
1304
+ del self._write_buf[:n]
1305
+
1306
+ def tell(self):
1307
+ return _BufferedIOMixin.tell(self) + len(self._write_buf)
1308
+
1309
+ def seek(self, pos, whence=0):
1310
+ if whence not in valid_seek_flags:
1311
+ raise ValueError("invalid whence value")
1312
+ with self._write_lock:
1313
+ self._flush_unlocked()
1314
+ return _BufferedIOMixin.seek(self, pos, whence)
1315
+
1316
+ def close(self):
1317
+ with self._write_lock:
1318
+ if self.raw is None or self.closed:
1319
+ return
1320
+ # We have to release the lock and call self.flush() (which will
1321
+ # probably just re-take the lock) in case flush has been overridden in
1322
+ # a subclass or the user set self.flush to something. This is the same
1323
+ # behavior as the C implementation.
1324
+ try:
1325
+ # may raise BlockingIOError or BrokenPipeError etc
1326
+ self.flush()
1327
+ finally:
1328
+ with self._write_lock:
1329
+ self.raw.close()
1330
+
1331
+
1332
+ class BufferedRWPair(BufferedIOBase):
1333
+
1334
+ """A buffered reader and writer object together.
1335
+
1336
+ A buffered reader object and buffered writer object put together to
1337
+ form a sequential IO object that can read and write. This is typically
1338
+ used with a socket or two-way pipe.
1339
+
1340
+ reader and writer are RawIOBase objects that are readable and
1341
+ writeable respectively. If the buffer_size is omitted it defaults to
1342
+ DEFAULT_BUFFER_SIZE.
1343
+ """
1344
+
1345
+ # XXX The usefulness of this (compared to having two separate IO
1346
+ # objects) is questionable.
1347
+
1348
+ def __init__(self, reader, writer, buffer_size=DEFAULT_BUFFER_SIZE):
1349
+ """Constructor.
1350
+
1351
+ The arguments are two RawIO instances.
1352
+ """
1353
+ if not reader.readable():
1354
+ raise OSError('"reader" argument must be readable.')
1355
+
1356
+ if not writer.writable():
1357
+ raise OSError('"writer" argument must be writable.')
1358
+
1359
+ self.reader = BufferedReader(reader, buffer_size)
1360
+ self.writer = BufferedWriter(writer, buffer_size)
1361
+
1362
+ def read(self, size=-1):
1363
+ if size is None:
1364
+ size = -1
1365
+ return self.reader.read(size)
1366
+
1367
+ def readinto(self, b):
1368
+ return self.reader.readinto(b)
1369
+
1370
+ def write(self, b):
1371
+ return self.writer.write(b)
1372
+
1373
+ def peek(self, size=0):
1374
+ return self.reader.peek(size)
1375
+
1376
+ def read1(self, size=-1):
1377
+ return self.reader.read1(size)
1378
+
1379
+ def readinto1(self, b):
1380
+ return self.reader.readinto1(b)
1381
+
1382
+ def readable(self):
1383
+ return self.reader.readable()
1384
+
1385
+ def writable(self):
1386
+ return self.writer.writable()
1387
+
1388
+ def flush(self):
1389
+ return self.writer.flush()
1390
+
1391
+ def close(self):
1392
+ try:
1393
+ self.writer.close()
1394
+ finally:
1395
+ self.reader.close()
1396
+
1397
+ def isatty(self):
1398
+ return self.reader.isatty() or self.writer.isatty()
1399
+
1400
+ @property
1401
+ def closed(self):
1402
+ return self.writer.closed
1403
+
1404
+
1405
+ class BufferedRandom(BufferedWriter, BufferedReader):
1406
+
1407
+ """A buffered interface to random access streams.
1408
+
1409
+ The constructor creates a reader and writer for a seekable stream,
1410
+ raw, given in the first argument. If the buffer_size is omitted it
1411
+ defaults to DEFAULT_BUFFER_SIZE.
1412
+ """
1413
+
1414
+ def __init__(self, raw, buffer_size=DEFAULT_BUFFER_SIZE):
1415
+ raw._checkSeekable()
1416
+ BufferedReader.__init__(self, raw, buffer_size)
1417
+ BufferedWriter.__init__(self, raw, buffer_size)
1418
+
1419
+ def seek(self, pos, whence=0):
1420
+ if whence not in valid_seek_flags:
1421
+ raise ValueError("invalid whence value")
1422
+ self.flush()
1423
+ if self._read_buf:
1424
+ # Undo read ahead.
1425
+ with self._read_lock:
1426
+ self.raw.seek(self._read_pos - len(self._read_buf), 1)
1427
+ # First do the raw seek, then empty the read buffer, so that
1428
+ # if the raw seek fails, we don't lose buffered data forever.
1429
+ pos = self.raw.seek(pos, whence)
1430
+ with self._read_lock:
1431
+ self._reset_read_buf()
1432
+ if pos < 0:
1433
+ raise OSError("seek() returned invalid position")
1434
+ return pos
1435
+
1436
+ def tell(self):
1437
+ if self._write_buf:
1438
+ return BufferedWriter.tell(self)
1439
+ else:
1440
+ return BufferedReader.tell(self)
1441
+
1442
+ def truncate(self, pos=None):
1443
+ if pos is None:
1444
+ pos = self.tell()
1445
+ # Use seek to flush the read buffer.
1446
+ return BufferedWriter.truncate(self, pos)
1447
+
1448
+ def read(self, size=None):
1449
+ if size is None:
1450
+ size = -1
1451
+ self.flush()
1452
+ return BufferedReader.read(self, size)
1453
+
1454
+ def readinto(self, b):
1455
+ self.flush()
1456
+ return BufferedReader.readinto(self, b)
1457
+
1458
+ def peek(self, size=0):
1459
+ self.flush()
1460
+ return BufferedReader.peek(self, size)
1461
+
1462
+ def read1(self, size=-1):
1463
+ self.flush()
1464
+ return BufferedReader.read1(self, size)
1465
+
1466
+ def readinto1(self, b):
1467
+ self.flush()
1468
+ return BufferedReader.readinto1(self, b)
1469
+
1470
+ def write(self, b):
1471
+ if self._read_buf:
1472
+ # Undo readahead
1473
+ with self._read_lock:
1474
+ self.raw.seek(self._read_pos - len(self._read_buf), 1)
1475
+ self._reset_read_buf()
1476
+ return BufferedWriter.write(self, b)
1477
+
1478
+
1479
+ class FileIO(RawIOBase):
1480
+ _fd = -1
1481
+ _created = False
1482
+ _readable = False
1483
+ _writable = False
1484
+ _appending = False
1485
+ _seekable = None
1486
+ _closefd = True
1487
+
1488
+ def __init__(self, file, mode='r', closefd=True, opener=None):
1489
+ """Open a file.
1490
+
1491
+ The mode can be 'r' (default), 'w', 'x' or 'a' for reading,
1492
+ writing, exclusive creation or appending. The file will be created
1493
+ if it doesn't exist when opened for writing or appending; it will be
1494
+ truncated when opened for writing. A FileExistsError will be raised
1495
+ if it already exists when opened for creating. Opening a file for
1496
+ creating implies writing so this mode behaves in a similar way to
1497
+ 'w'. Add a '+' to the mode to allow simultaneous reading and
1498
+ writing.
1499
+
1500
+ A custom opener can be used by passing a callable as *opener*.
1501
+ The underlying file descriptor for the file object is then obtained
1502
+ by calling opener with (*name*, *flags*). *opener* must return
1503
+ an open file descriptor (passing os.open as *opener* results in
1504
+ functionality similar to passing None).
1505
+ """
1506
+ if self._fd >= 0:
1507
+ # Have to close the existing file first.
1508
+ try:
1509
+ if self._closefd:
1510
+ os.close(self._fd)
1511
+ finally:
1512
+ self._fd = -1
1513
+
1514
+ if isinstance(file, float):
1515
+ raise TypeError('integer argument expected, got float')
1516
+ if isinstance(file, int):
1517
+ if isinstance(file, bool):
1518
+ import warnings
1519
+ warnings.warn("bool is used as a file descriptor",
1520
+ RuntimeWarning, stacklevel=2)
1521
+ file = int(file)
1522
+ fd = file
1523
+ if fd < 0:
1524
+ raise ValueError('negative file descriptor')
1525
+ else:
1526
+ fd = -1
1527
+
1528
+ if not isinstance(mode, str):
1529
+ raise TypeError('invalid mode: %s' % (mode,))
1530
+ if not set(mode) <= set('xrwab+'):
1531
+ raise ValueError('invalid mode: %s' % (mode,))
1532
+ if sum(c in 'rwax' for c in mode) != 1 or mode.count('+') > 1:
1533
+ raise ValueError('Must have exactly one of create/read/write/append '
1534
+ 'mode and at most one plus')
1535
+
1536
+ if 'x' in mode:
1537
+ self._created = True
1538
+ self._writable = True
1539
+ flags = os.O_EXCL | os.O_CREAT
1540
+ elif 'r' in mode:
1541
+ self._readable = True
1542
+ flags = 0
1543
+ elif 'w' in mode:
1544
+ self._writable = True
1545
+ flags = os.O_CREAT | os.O_TRUNC
1546
+ elif 'a' in mode:
1547
+ self._writable = True
1548
+ self._appending = True
1549
+ flags = os.O_APPEND | os.O_CREAT
1550
+
1551
+ if '+' in mode:
1552
+ self._readable = True
1553
+ self._writable = True
1554
+
1555
+ if self._readable and self._writable:
1556
+ flags |= os.O_RDWR
1557
+ elif self._readable:
1558
+ flags |= os.O_RDONLY
1559
+ else:
1560
+ flags |= os.O_WRONLY
1561
+
1562
+ flags |= getattr(os, 'O_BINARY', 0)
1563
+
1564
+ noinherit_flag = (getattr(os, 'O_NOINHERIT', 0) or
1565
+ getattr(os, 'O_CLOEXEC', 0))
1566
+ flags |= noinherit_flag
1567
+
1568
+ owned_fd = None
1569
+ try:
1570
+ if fd < 0:
1571
+ if not closefd:
1572
+ raise ValueError('Cannot use closefd=False with file name')
1573
+ if opener is None:
1574
+ fd = os.open(file, flags, 0o666)
1575
+ else:
1576
+ fd = opener(file, flags)
1577
+ if not isinstance(fd, int):
1578
+ raise TypeError('expected integer from opener')
1579
+ if fd < 0:
1580
+ # bpo-27066: Raise a ValueError for bad value.
1581
+ raise ValueError(f'opener returned {fd}')
1582
+ owned_fd = fd
1583
+ if not noinherit_flag:
1584
+ os.set_inheritable(fd, False)
1585
+
1586
+ self._closefd = closefd
1587
+ fdfstat = os.fstat(fd)
1588
+ try:
1589
+ if stat.S_ISDIR(fdfstat.st_mode):
1590
+ raise IsADirectoryError(errno.EISDIR,
1591
+ os.strerror(errno.EISDIR), file)
1592
+ except AttributeError:
1593
+ # Ignore the AttributeError if stat.S_ISDIR or errno.EISDIR
1594
+ # don't exist.
1595
+ pass
1596
+ self._blksize = getattr(fdfstat, 'st_blksize', 0)
1597
+ if self._blksize <= 1:
1598
+ self._blksize = DEFAULT_BUFFER_SIZE
1599
+
1600
+ if _setmode:
1601
+ # don't translate newlines (\r\n <=> \n)
1602
+ _setmode(fd, os.O_BINARY)
1603
+
1604
+ self.name = file
1605
+ if self._appending:
1606
+ # For consistent behaviour, we explicitly seek to the
1607
+ # end of file (otherwise, it might be done only on the
1608
+ # first write()).
1609
+ try:
1610
+ os.lseek(fd, 0, SEEK_END)
1611
+ except OSError as e:
1612
+ if e.errno != errno.ESPIPE:
1613
+ raise
1614
+ except:
1615
+ if owned_fd is not None:
1616
+ os.close(owned_fd)
1617
+ raise
1618
+ self._fd = fd
1619
+
1620
+ def _dealloc_warn(self, source):
1621
+ if self._fd >= 0 and self._closefd and not self.closed:
1622
+ import warnings
1623
+ warnings.warn(f'unclosed file {source!r}', ResourceWarning,
1624
+ stacklevel=2, source=self)
1625
+
1626
+ def __getstate__(self):
1627
+ raise TypeError(f"cannot pickle {self.__class__.__name__!r} object")
1628
+
1629
+ def __repr__(self):
1630
+ class_name = '%s.%s' % (self.__class__.__module__,
1631
+ self.__class__.__qualname__)
1632
+ if self.closed:
1633
+ return '<%s [closed]>' % class_name
1634
+ try:
1635
+ name = self.name
1636
+ except AttributeError:
1637
+ return ('<%s fd=%d mode=%r closefd=%r>' %
1638
+ (class_name, self._fd, self.mode, self._closefd))
1639
+ else:
1640
+ return ('<%s name=%r mode=%r closefd=%r>' %
1641
+ (class_name, name, self.mode, self._closefd))
1642
+
1643
+ def _checkReadable(self):
1644
+ if not self._readable:
1645
+ raise UnsupportedOperation('File not open for reading')
1646
+
1647
+ def _checkWritable(self, msg=None):
1648
+ if not self._writable:
1649
+ raise UnsupportedOperation('File not open for writing')
1650
+
1651
+ def read(self, size=None):
1652
+ """Read at most size bytes, returned as bytes.
1653
+
1654
+ Only makes one system call, so less data may be returned than requested
1655
+ In non-blocking mode, returns None if no data is available.
1656
+ Return an empty bytes object at EOF.
1657
+ """
1658
+ self._checkClosed()
1659
+ self._checkReadable()
1660
+ if size is None or size < 0:
1661
+ return self.readall()
1662
+ try:
1663
+ return os.read(self._fd, size)
1664
+ except BlockingIOError:
1665
+ return None
1666
+
1667
+ def readall(self):
1668
+ """Read all data from the file, returned as bytes.
1669
+
1670
+ In non-blocking mode, returns as much as is immediately available,
1671
+ or None if no data is available. Return an empty bytes object at EOF.
1672
+ """
1673
+ self._checkClosed()
1674
+ self._checkReadable()
1675
+ bufsize = DEFAULT_BUFFER_SIZE
1676
+ try:
1677
+ pos = os.lseek(self._fd, 0, SEEK_CUR)
1678
+ end = os.fstat(self._fd).st_size
1679
+ if end >= pos:
1680
+ bufsize = end - pos + 1
1681
+ except OSError:
1682
+ pass
1683
+
1684
+ result = bytearray()
1685
+ while True:
1686
+ if len(result) >= bufsize:
1687
+ bufsize = len(result)
1688
+ bufsize += max(bufsize, DEFAULT_BUFFER_SIZE)
1689
+ n = bufsize - len(result)
1690
+ try:
1691
+ chunk = os.read(self._fd, n)
1692
+ except BlockingIOError:
1693
+ if result:
1694
+ break
1695
+ return None
1696
+ if not chunk: # reached the end of the file
1697
+ break
1698
+ result += chunk
1699
+
1700
+ return bytes(result)
1701
+
1702
+ def readinto(self, b):
1703
+ """Same as RawIOBase.readinto()."""
1704
+ m = memoryview(b).cast('B')
1705
+ data = self.read(len(m))
1706
+ n = len(data)
1707
+ m[:n] = data
1708
+ return n
1709
+
1710
+ def write(self, b):
1711
+ """Write bytes b to file, return number written.
1712
+
1713
+ Only makes one system call, so not all of the data may be written.
1714
+ The number of bytes actually written is returned. In non-blocking
1715
+ mode, returns None if the write would block.
1716
+ """
1717
+ self._checkClosed()
1718
+ self._checkWritable()
1719
+ try:
1720
+ return os.write(self._fd, b)
1721
+ except BlockingIOError:
1722
+ return None
1723
+
1724
+ def seek(self, pos, whence=SEEK_SET):
1725
+ """Move to new file position.
1726
+
1727
+ Argument offset is a byte count. Optional argument whence defaults
1728
+ to SEEK_SET or 0 (offset from start of file, offset should be >= 0);
1729
+ other values are SEEK_CUR or 1 (move relative to current position,
1730
+ positive or negative), and SEEK_END or 2 (move relative to end of
1731
+ file, usually negative, although many platforms allow seeking beyond
1732
+ the end of a file).
1733
+
1734
+ Note that not all file objects are seekable.
1735
+ """
1736
+ if isinstance(pos, float):
1737
+ raise TypeError('an integer is required')
1738
+ self._checkClosed()
1739
+ return os.lseek(self._fd, pos, whence)
1740
+
1741
+ def tell(self):
1742
+ """tell() -> int. Current file position.
1743
+
1744
+ Can raise OSError for non seekable files."""
1745
+ self._checkClosed()
1746
+ return os.lseek(self._fd, 0, SEEK_CUR)
1747
+
1748
+ def truncate(self, size=None):
1749
+ """Truncate the file to at most size bytes.
1750
+
1751
+ Size defaults to the current file position, as returned by tell().
1752
+ The current file position is changed to the value of size.
1753
+ """
1754
+ self._checkClosed()
1755
+ self._checkWritable()
1756
+ if size is None:
1757
+ size = self.tell()
1758
+ os.ftruncate(self._fd, size)
1759
+ return size
1760
+
1761
+ def close(self):
1762
+ """Close the file.
1763
+
1764
+ A closed file cannot be used for further I/O operations.
1765
+ close() may be called more than once without error.
1766
+ """
1767
+ if not self.closed:
1768
+ try:
1769
+ if self._closefd and self._fd >= 0:
1770
+ os.close(self._fd)
1771
+ finally:
1772
+ super().close()
1773
+
1774
+ def seekable(self):
1775
+ """True if file supports random-access."""
1776
+ self._checkClosed()
1777
+ if self._seekable is None:
1778
+ try:
1779
+ self.tell()
1780
+ except OSError:
1781
+ self._seekable = False
1782
+ else:
1783
+ self._seekable = True
1784
+ return self._seekable
1785
+
1786
+ def readable(self):
1787
+ """True if file was opened in a read mode."""
1788
+ self._checkClosed()
1789
+ return self._readable
1790
+
1791
+ def writable(self):
1792
+ """True if file was opened in a write mode."""
1793
+ self._checkClosed()
1794
+ return self._writable
1795
+
1796
+ def fileno(self):
1797
+ """Return the underlying file descriptor (an integer)."""
1798
+ self._checkClosed()
1799
+ return self._fd
1800
+
1801
+ def isatty(self):
1802
+ """True if the file is connected to a TTY device."""
1803
+ self._checkClosed()
1804
+ return os.isatty(self._fd)
1805
+
1806
+ @property
1807
+ def closefd(self):
1808
+ """True if the file descriptor will be closed by close()."""
1809
+ return self._closefd
1810
+
1811
+ @property
1812
+ def mode(self):
1813
+ """String giving the file mode"""
1814
+ if self._created:
1815
+ if self._readable:
1816
+ return 'xb+'
1817
+ else:
1818
+ return 'xb'
1819
+ elif self._appending:
1820
+ if self._readable:
1821
+ return 'ab+'
1822
+ else:
1823
+ return 'ab'
1824
+ elif self._readable:
1825
+ if self._writable:
1826
+ return 'rb+'
1827
+ else:
1828
+ return 'rb'
1829
+ else:
1830
+ return 'wb'
1831
+
1832
+
1833
+ class TextIOBase(IOBase):
1834
+
1835
+ """Base class for text I/O.
1836
+
1837
+ This class provides a character and line based interface to stream
1838
+ I/O.
1839
+ """
1840
+
1841
+ def read(self, size=-1):
1842
+ """Read at most size characters from stream, where size is an int.
1843
+
1844
+ Read from underlying buffer until we have size characters or we hit
1845
+ EOF. If size is negative or omitted, read until EOF.
1846
+
1847
+ Returns a string.
1848
+ """
1849
+ self._unsupported("read")
1850
+
1851
+ def write(self, s):
1852
+ """Write string s to stream and returning an int."""
1853
+ self._unsupported("write")
1854
+
1855
+ def truncate(self, pos=None):
1856
+ """Truncate size to pos, where pos is an int."""
1857
+ self._unsupported("truncate")
1858
+
1859
+ def readline(self, size=-1, /):
1860
+ """Read until newline or EOF.
1861
+
1862
+ Returns an empty string if EOF is hit immediately.
1863
+ """
1864
+ self._unsupported("readline")
1865
+
1866
+ def detach(self):
1867
+ """
1868
+ Separate the underlying buffer from the TextIOBase and return it.
1869
+
1870
+ After the underlying buffer has been detached, the TextIO is in an
1871
+ unusable state.
1872
+ """
1873
+ self._unsupported("detach")
1874
+
1875
+ @property
1876
+ def encoding(self):
1877
+ """Subclasses should override."""
1878
+ return None
1879
+
1880
+ @property
1881
+ def newlines(self):
1882
+ """Line endings translated so far.
1883
+
1884
+ Only line endings translated during reading are considered.
1885
+
1886
+ Subclasses should override.
1887
+ """
1888
+ return None
1889
+
1890
+ @property
1891
+ def errors(self):
1892
+ """Error setting of the decoder or encoder.
1893
+
1894
+ Subclasses should override."""
1895
+ return None
1896
+
1897
+ io.TextIOBase.register(TextIOBase)
1898
+
1899
+
1900
+ class IncrementalNewlineDecoder(codecs.IncrementalDecoder):
1901
+ r"""Codec used when reading a file in universal newlines mode. It wraps
1902
+ another incremental decoder, translating \r\n and \r into \n. It also
1903
+ records the types of newlines encountered. When used with
1904
+ translate=False, it ensures that the newline sequence is returned in
1905
+ one piece.
1906
+ """
1907
+ def __init__(self, decoder, translate, errors='strict'):
1908
+ codecs.IncrementalDecoder.__init__(self, errors=errors)
1909
+ self.translate = translate
1910
+ self.decoder = decoder
1911
+ self.seennl = 0
1912
+ self.pendingcr = False
1913
+
1914
+ def decode(self, input, final=False):
1915
+ # decode input (with the eventual \r from a previous pass)
1916
+ if self.decoder is None:
1917
+ output = input
1918
+ else:
1919
+ output = self.decoder.decode(input, final=final)
1920
+ if self.pendingcr and (output or final):
1921
+ output = "\r" + output
1922
+ self.pendingcr = False
1923
+
1924
+ # retain last \r even when not translating data:
1925
+ # then readline() is sure to get \r\n in one pass
1926
+ if output.endswith("\r") and not final:
1927
+ output = output[:-1]
1928
+ self.pendingcr = True
1929
+
1930
+ # Record which newlines are read
1931
+ crlf = output.count('\r\n')
1932
+ cr = output.count('\r') - crlf
1933
+ lf = output.count('\n') - crlf
1934
+ self.seennl |= (lf and self._LF) | (cr and self._CR) \
1935
+ | (crlf and self._CRLF)
1936
+
1937
+ if self.translate:
1938
+ if crlf:
1939
+ output = output.replace("\r\n", "\n")
1940
+ if cr:
1941
+ output = output.replace("\r", "\n")
1942
+
1943
+ return output
1944
+
1945
+ def getstate(self):
1946
+ if self.decoder is None:
1947
+ buf = b""
1948
+ flag = 0
1949
+ else:
1950
+ buf, flag = self.decoder.getstate()
1951
+ flag <<= 1
1952
+ if self.pendingcr:
1953
+ flag |= 1
1954
+ return buf, flag
1955
+
1956
+ def setstate(self, state):
1957
+ buf, flag = state
1958
+ self.pendingcr = bool(flag & 1)
1959
+ if self.decoder is not None:
1960
+ self.decoder.setstate((buf, flag >> 1))
1961
+
1962
+ def reset(self):
1963
+ self.seennl = 0
1964
+ self.pendingcr = False
1965
+ if self.decoder is not None:
1966
+ self.decoder.reset()
1967
+
1968
+ _LF = 1
1969
+ _CR = 2
1970
+ _CRLF = 4
1971
+
1972
+ @property
1973
+ def newlines(self):
1974
+ return (None,
1975
+ "\n",
1976
+ "\r",
1977
+ ("\r", "\n"),
1978
+ "\r\n",
1979
+ ("\n", "\r\n"),
1980
+ ("\r", "\r\n"),
1981
+ ("\r", "\n", "\r\n")
1982
+ )[self.seennl]
1983
+
1984
+
1985
+ class TextIOWrapper(TextIOBase):
1986
+
1987
+ r"""Character and line based layer over a BufferedIOBase object, buffer.
1988
+
1989
+ encoding gives the name of the encoding that the stream will be
1990
+ decoded or encoded with. It defaults to locale.getencoding().
1991
+
1992
+ errors determines the strictness of encoding and decoding (see the
1993
+ codecs.register) and defaults to "strict".
1994
+
1995
+ newline can be None, '', '\n', '\r', or '\r\n'. It controls the
1996
+ handling of line endings. If it is None, universal newlines is
1997
+ enabled. With this enabled, on input, the lines endings '\n', '\r',
1998
+ or '\r\n' are translated to '\n' before being returned to the
1999
+ caller. Conversely, on output, '\n' is translated to the system
2000
+ default line separator, os.linesep. If newline is any other of its
2001
+ legal values, that newline becomes the newline when the file is read
2002
+ and it is returned untranslated. On output, '\n' is converted to the
2003
+ newline.
2004
+
2005
+ If line_buffering is True, a call to flush is implied when a call to
2006
+ write contains a newline character.
2007
+ """
2008
+
2009
+ _CHUNK_SIZE = 2048
2010
+
2011
+ # Initialize _buffer as soon as possible since it's used by __del__()
2012
+ # which calls close()
2013
+ _buffer = None
2014
+
2015
+ # The write_through argument has no effect here since this
2016
+ # implementation always writes through. The argument is present only
2017
+ # so that the signature can match the signature of the C version.
2018
+ def __init__(self, buffer, encoding=None, errors=None, newline=None,
2019
+ line_buffering=False, write_through=False):
2020
+ self._check_newline(newline)
2021
+ encoding = text_encoding(encoding)
2022
+
2023
+ if encoding == "locale":
2024
+ encoding = self._get_locale_encoding()
2025
+
2026
+ if not isinstance(encoding, str):
2027
+ raise ValueError("invalid encoding: %r" % encoding)
2028
+
2029
+ if not codecs.lookup(encoding)._is_text_encoding:
2030
+ msg = ("%r is not a text encoding; "
2031
+ "use codecs.open() to handle arbitrary codecs")
2032
+ raise LookupError(msg % encoding)
2033
+
2034
+ if errors is None:
2035
+ errors = "strict"
2036
+ else:
2037
+ if not isinstance(errors, str):
2038
+ raise ValueError("invalid errors: %r" % errors)
2039
+ if _CHECK_ERRORS:
2040
+ codecs.lookup_error(errors)
2041
+
2042
+ self._buffer = buffer
2043
+ self._decoded_chars = '' # buffer for text returned from decoder
2044
+ self._decoded_chars_used = 0 # offset into _decoded_chars for read()
2045
+ self._snapshot = None # info for reconstructing decoder state
2046
+ self._seekable = self._telling = self.buffer.seekable()
2047
+ self._has_read1 = hasattr(self.buffer, 'read1')
2048
+ self._configure(encoding, errors, newline,
2049
+ line_buffering, write_through)
2050
+
2051
+ def _check_newline(self, newline):
2052
+ if newline is not None and not isinstance(newline, str):
2053
+ raise TypeError("illegal newline type: %r" % (type(newline),))
2054
+ if newline not in (None, "", "\n", "\r", "\r\n"):
2055
+ raise ValueError("illegal newline value: %r" % (newline,))
2056
+
2057
+ def _configure(self, encoding=None, errors=None, newline=None,
2058
+ line_buffering=False, write_through=False):
2059
+ self._encoding = encoding
2060
+ self._errors = errors
2061
+ self._encoder = None
2062
+ self._decoder = None
2063
+ self._b2cratio = 0.0
2064
+
2065
+ self._readuniversal = not newline
2066
+ self._readtranslate = newline is None
2067
+ self._readnl = newline
2068
+ self._writetranslate = newline != ''
2069
+ self._writenl = newline or os.linesep
2070
+
2071
+ self._line_buffering = line_buffering
2072
+ self._write_through = write_through
2073
+
2074
+ # don't write a BOM in the middle of a file
2075
+ if self._seekable and self.writable():
2076
+ position = self.buffer.tell()
2077
+ if position != 0:
2078
+ try:
2079
+ self._get_encoder().setstate(0)
2080
+ except LookupError:
2081
+ # Sometimes the encoder doesn't exist
2082
+ pass
2083
+
2084
+ # self._snapshot is either None, or a tuple (dec_flags, next_input)
2085
+ # where dec_flags is the second (integer) item of the decoder state
2086
+ # and next_input is the chunk of input bytes that comes next after the
2087
+ # snapshot point. We use this to reconstruct decoder states in tell().
2088
+
2089
+ # Naming convention:
2090
+ # - "bytes_..." for integer variables that count input bytes
2091
+ # - "chars_..." for integer variables that count decoded characters
2092
+
2093
+ def __repr__(self):
2094
+ result = "<{}.{}".format(self.__class__.__module__,
2095
+ self.__class__.__qualname__)
2096
+ try:
2097
+ name = self.name
2098
+ except AttributeError:
2099
+ pass
2100
+ else:
2101
+ result += " name={0!r}".format(name)
2102
+ try:
2103
+ mode = self.mode
2104
+ except AttributeError:
2105
+ pass
2106
+ else:
2107
+ result += " mode={0!r}".format(mode)
2108
+ return result + " encoding={0!r}>".format(self.encoding)
2109
+
2110
+ @property
2111
+ def encoding(self):
2112
+ return self._encoding
2113
+
2114
+ @property
2115
+ def errors(self):
2116
+ return self._errors
2117
+
2118
+ @property
2119
+ def line_buffering(self):
2120
+ return self._line_buffering
2121
+
2122
+ @property
2123
+ def write_through(self):
2124
+ return self._write_through
2125
+
2126
+ @property
2127
+ def buffer(self):
2128
+ return self._buffer
2129
+
2130
+ def reconfigure(self, *,
2131
+ encoding=None, errors=None, newline=Ellipsis,
2132
+ line_buffering=None, write_through=None):
2133
+ """Reconfigure the text stream with new parameters.
2134
+
2135
+ This also flushes the stream.
2136
+ """
2137
+ if (self._decoder is not None
2138
+ and (encoding is not None or errors is not None
2139
+ or newline is not Ellipsis)):
2140
+ raise UnsupportedOperation(
2141
+ "It is not possible to set the encoding or newline of stream "
2142
+ "after the first read")
2143
+
2144
+ if errors is None:
2145
+ if encoding is None:
2146
+ errors = self._errors
2147
+ else:
2148
+ errors = 'strict'
2149
+ elif not isinstance(errors, str):
2150
+ raise TypeError("invalid errors: %r" % errors)
2151
+
2152
+ if encoding is None:
2153
+ encoding = self._encoding
2154
+ else:
2155
+ if not isinstance(encoding, str):
2156
+ raise TypeError("invalid encoding: %r" % encoding)
2157
+ if encoding == "locale":
2158
+ encoding = self._get_locale_encoding()
2159
+
2160
+ if newline is Ellipsis:
2161
+ newline = self._readnl
2162
+ self._check_newline(newline)
2163
+
2164
+ if line_buffering is None:
2165
+ line_buffering = self.line_buffering
2166
+ if write_through is None:
2167
+ write_through = self.write_through
2168
+
2169
+ self.flush()
2170
+ self._configure(encoding, errors, newline,
2171
+ line_buffering, write_through)
2172
+
2173
+ def seekable(self):
2174
+ if self.closed:
2175
+ raise ValueError("I/O operation on closed file.")
2176
+ return self._seekable
2177
+
2178
+ def readable(self):
2179
+ return self.buffer.readable()
2180
+
2181
+ def writable(self):
2182
+ return self.buffer.writable()
2183
+
2184
+ def flush(self):
2185
+ self.buffer.flush()
2186
+ self._telling = self._seekable
2187
+
2188
+ def close(self):
2189
+ if self.buffer is not None and not self.closed:
2190
+ try:
2191
+ self.flush()
2192
+ finally:
2193
+ self.buffer.close()
2194
+
2195
+ @property
2196
+ def closed(self):
2197
+ return self.buffer.closed
2198
+
2199
+ @property
2200
+ def name(self):
2201
+ return self.buffer.name
2202
+
2203
+ def fileno(self):
2204
+ return self.buffer.fileno()
2205
+
2206
+ def isatty(self):
2207
+ return self.buffer.isatty()
2208
+
2209
+ def write(self, s):
2210
+ 'Write data, where s is a str'
2211
+ if self.closed:
2212
+ raise ValueError("write to closed file")
2213
+ if not isinstance(s, str):
2214
+ raise TypeError("can't write %s to text stream" %
2215
+ s.__class__.__name__)
2216
+ length = len(s)
2217
+ haslf = (self._writetranslate or self._line_buffering) and "\n" in s
2218
+ if haslf and self._writetranslate and self._writenl != "\n":
2219
+ s = s.replace("\n", self._writenl)
2220
+ encoder = self._encoder or self._get_encoder()
2221
+ # XXX What if we were just reading?
2222
+ b = encoder.encode(s)
2223
+ self.buffer.write(b)
2224
+ if self._line_buffering and (haslf or "\r" in s):
2225
+ self.flush()
2226
+ if self._snapshot is not None:
2227
+ self._set_decoded_chars('')
2228
+ self._snapshot = None
2229
+ if self._decoder:
2230
+ self._decoder.reset()
2231
+ return length
2232
+
2233
+ def _get_encoder(self):
2234
+ make_encoder = codecs.getincrementalencoder(self._encoding)
2235
+ self._encoder = make_encoder(self._errors)
2236
+ return self._encoder
2237
+
2238
+ def _get_decoder(self):
2239
+ make_decoder = codecs.getincrementaldecoder(self._encoding)
2240
+ decoder = make_decoder(self._errors)
2241
+ if self._readuniversal:
2242
+ decoder = IncrementalNewlineDecoder(decoder, self._readtranslate)
2243
+ self._decoder = decoder
2244
+ return decoder
2245
+
2246
+ # The following three methods implement an ADT for _decoded_chars.
2247
+ # Text returned from the decoder is buffered here until the client
2248
+ # requests it by calling our read() or readline() method.
2249
+ def _set_decoded_chars(self, chars):
2250
+ """Set the _decoded_chars buffer."""
2251
+ self._decoded_chars = chars
2252
+ self._decoded_chars_used = 0
2253
+
2254
+ def _get_decoded_chars(self, n=None):
2255
+ """Advance into the _decoded_chars buffer."""
2256
+ offset = self._decoded_chars_used
2257
+ if n is None:
2258
+ chars = self._decoded_chars[offset:]
2259
+ else:
2260
+ chars = self._decoded_chars[offset:offset + n]
2261
+ self._decoded_chars_used += len(chars)
2262
+ return chars
2263
+
2264
+ def _get_locale_encoding(self):
2265
+ try:
2266
+ import locale
2267
+ except ImportError:
2268
+ # Importing locale may fail if Python is being built
2269
+ return "utf-8"
2270
+ else:
2271
+ return locale.getencoding()
2272
+
2273
+ def _rewind_decoded_chars(self, n):
2274
+ """Rewind the _decoded_chars buffer."""
2275
+ if self._decoded_chars_used < n:
2276
+ raise AssertionError("rewind decoded_chars out of bounds")
2277
+ self._decoded_chars_used -= n
2278
+
2279
+ def _read_chunk(self):
2280
+ """
2281
+ Read and decode the next chunk of data from the BufferedReader.
2282
+ """
2283
+
2284
+ # The return value is True unless EOF was reached. The decoded
2285
+ # string is placed in self._decoded_chars (replacing its previous
2286
+ # value). The entire input chunk is sent to the decoder, though
2287
+ # some of it may remain buffered in the decoder, yet to be
2288
+ # converted.
2289
+
2290
+ if self._decoder is None:
2291
+ raise ValueError("no decoder")
2292
+
2293
+ if self._telling:
2294
+ # To prepare for tell(), we need to snapshot a point in the
2295
+ # file where the decoder's input buffer is empty.
2296
+
2297
+ dec_buffer, dec_flags = self._decoder.getstate()
2298
+ # Given this, we know there was a valid snapshot point
2299
+ # len(dec_buffer) bytes ago with decoder state (b'', dec_flags).
2300
+
2301
+ # Read a chunk, decode it, and put the result in self._decoded_chars.
2302
+ if self._has_read1:
2303
+ input_chunk = self.buffer.read1(self._CHUNK_SIZE)
2304
+ else:
2305
+ input_chunk = self.buffer.read(self._CHUNK_SIZE)
2306
+ eof = not input_chunk
2307
+ decoded_chars = self._decoder.decode(input_chunk, eof)
2308
+ self._set_decoded_chars(decoded_chars)
2309
+ if decoded_chars:
2310
+ self._b2cratio = len(input_chunk) / len(self._decoded_chars)
2311
+ else:
2312
+ self._b2cratio = 0.0
2313
+
2314
+ if self._telling:
2315
+ # At the snapshot point, len(dec_buffer) bytes before the read,
2316
+ # the next input to be decoded is dec_buffer + input_chunk.
2317
+ self._snapshot = (dec_flags, dec_buffer + input_chunk)
2318
+
2319
+ return not eof
2320
+
2321
+ def _pack_cookie(self, position, dec_flags=0,
2322
+ bytes_to_feed=0, need_eof=False, chars_to_skip=0):
2323
+ # The meaning of a tell() cookie is: seek to position, set the
2324
+ # decoder flags to dec_flags, read bytes_to_feed bytes, feed them
2325
+ # into the decoder with need_eof as the EOF flag, then skip
2326
+ # chars_to_skip characters of the decoded result. For most simple
2327
+ # decoders, tell() will often just give a byte offset in the file.
2328
+ return (position | (dec_flags<<64) | (bytes_to_feed<<128) |
2329
+ (chars_to_skip<<192) | bool(need_eof)<<256)
2330
+
2331
+ def _unpack_cookie(self, bigint):
2332
+ rest, position = divmod(bigint, 1<<64)
2333
+ rest, dec_flags = divmod(rest, 1<<64)
2334
+ rest, bytes_to_feed = divmod(rest, 1<<64)
2335
+ need_eof, chars_to_skip = divmod(rest, 1<<64)
2336
+ return position, dec_flags, bytes_to_feed, bool(need_eof), chars_to_skip
2337
+
2338
+ def tell(self):
2339
+ if not self._seekable:
2340
+ raise UnsupportedOperation("underlying stream is not seekable")
2341
+ if not self._telling:
2342
+ raise OSError("telling position disabled by next() call")
2343
+ self.flush()
2344
+ position = self.buffer.tell()
2345
+ decoder = self._decoder
2346
+ if decoder is None or self._snapshot is None:
2347
+ if self._decoded_chars:
2348
+ # This should never happen.
2349
+ raise AssertionError("pending decoded text")
2350
+ return position
2351
+
2352
+ # Skip backward to the snapshot point (see _read_chunk).
2353
+ dec_flags, next_input = self._snapshot
2354
+ position -= len(next_input)
2355
+
2356
+ # How many decoded characters have been used up since the snapshot?
2357
+ chars_to_skip = self._decoded_chars_used
2358
+ if chars_to_skip == 0:
2359
+ # We haven't moved from the snapshot point.
2360
+ return self._pack_cookie(position, dec_flags)
2361
+
2362
+ # Starting from the snapshot position, we will walk the decoder
2363
+ # forward until it gives us enough decoded characters.
2364
+ saved_state = decoder.getstate()
2365
+ try:
2366
+ # Fast search for an acceptable start point, close to our
2367
+ # current pos.
2368
+ # Rationale: calling decoder.decode() has a large overhead
2369
+ # regardless of chunk size; we want the number of such calls to
2370
+ # be O(1) in most situations (common decoders, sensible input).
2371
+ # Actually, it will be exactly 1 for fixed-size codecs (all
2372
+ # 8-bit codecs, also UTF-16 and UTF-32).
2373
+ skip_bytes = int(self._b2cratio * chars_to_skip)
2374
+ skip_back = 1
2375
+ assert skip_bytes <= len(next_input)
2376
+ while skip_bytes > 0:
2377
+ decoder.setstate((b'', dec_flags))
2378
+ # Decode up to temptative start point
2379
+ n = len(decoder.decode(next_input[:skip_bytes]))
2380
+ if n <= chars_to_skip:
2381
+ b, d = decoder.getstate()
2382
+ if not b:
2383
+ # Before pos and no bytes buffered in decoder => OK
2384
+ dec_flags = d
2385
+ chars_to_skip -= n
2386
+ break
2387
+ # Skip back by buffered amount and reset heuristic
2388
+ skip_bytes -= len(b)
2389
+ skip_back = 1
2390
+ else:
2391
+ # We're too far ahead, skip back a bit
2392
+ skip_bytes -= skip_back
2393
+ skip_back = skip_back * 2
2394
+ else:
2395
+ skip_bytes = 0
2396
+ decoder.setstate((b'', dec_flags))
2397
+
2398
+ # Note our initial start point.
2399
+ start_pos = position + skip_bytes
2400
+ start_flags = dec_flags
2401
+ if chars_to_skip == 0:
2402
+ # We haven't moved from the start point.
2403
+ return self._pack_cookie(start_pos, start_flags)
2404
+
2405
+ # Feed the decoder one byte at a time. As we go, note the
2406
+ # nearest "safe start point" before the current location
2407
+ # (a point where the decoder has nothing buffered, so seek()
2408
+ # can safely start from there and advance to this location).
2409
+ bytes_fed = 0
2410
+ need_eof = False
2411
+ # Chars decoded since `start_pos`
2412
+ chars_decoded = 0
2413
+ for i in range(skip_bytes, len(next_input)):
2414
+ bytes_fed += 1
2415
+ chars_decoded += len(decoder.decode(next_input[i:i+1]))
2416
+ dec_buffer, dec_flags = decoder.getstate()
2417
+ if not dec_buffer and chars_decoded <= chars_to_skip:
2418
+ # Decoder buffer is empty, so this is a safe start point.
2419
+ start_pos += bytes_fed
2420
+ chars_to_skip -= chars_decoded
2421
+ start_flags, bytes_fed, chars_decoded = dec_flags, 0, 0
2422
+ if chars_decoded >= chars_to_skip:
2423
+ break
2424
+ else:
2425
+ # We didn't get enough decoded data; signal EOF to get more.
2426
+ chars_decoded += len(decoder.decode(b'', final=True))
2427
+ need_eof = True
2428
+ if chars_decoded < chars_to_skip:
2429
+ raise OSError("can't reconstruct logical file position")
2430
+
2431
+ # The returned cookie corresponds to the last safe start point.
2432
+ return self._pack_cookie(
2433
+ start_pos, start_flags, bytes_fed, need_eof, chars_to_skip)
2434
+ finally:
2435
+ decoder.setstate(saved_state)
2436
+
2437
+ def truncate(self, pos=None):
2438
+ self.flush()
2439
+ if pos is None:
2440
+ pos = self.tell()
2441
+ return self.buffer.truncate(pos)
2442
+
2443
+ def detach(self):
2444
+ if self.buffer is None:
2445
+ raise ValueError("buffer is already detached")
2446
+ self.flush()
2447
+ buffer = self._buffer
2448
+ self._buffer = None
2449
+ return buffer
2450
+
2451
+ def seek(self, cookie, whence=0):
2452
+ def _reset_encoder(position):
2453
+ """Reset the encoder (merely useful for proper BOM handling)"""
2454
+ try:
2455
+ encoder = self._encoder or self._get_encoder()
2456
+ except LookupError:
2457
+ # Sometimes the encoder doesn't exist
2458
+ pass
2459
+ else:
2460
+ if position != 0:
2461
+ encoder.setstate(0)
2462
+ else:
2463
+ encoder.reset()
2464
+
2465
+ if self.closed:
2466
+ raise ValueError("tell on closed file")
2467
+ if not self._seekable:
2468
+ raise UnsupportedOperation("underlying stream is not seekable")
2469
+ if whence == SEEK_CUR:
2470
+ if cookie != 0:
2471
+ raise UnsupportedOperation("can't do nonzero cur-relative seeks")
2472
+ # Seeking to the current position should attempt to
2473
+ # sync the underlying buffer with the current position.
2474
+ whence = 0
2475
+ cookie = self.tell()
2476
+ elif whence == SEEK_END:
2477
+ if cookie != 0:
2478
+ raise UnsupportedOperation("can't do nonzero end-relative seeks")
2479
+ self.flush()
2480
+ position = self.buffer.seek(0, whence)
2481
+ self._set_decoded_chars('')
2482
+ self._snapshot = None
2483
+ if self._decoder:
2484
+ self._decoder.reset()
2485
+ _reset_encoder(position)
2486
+ return position
2487
+ if whence != 0:
2488
+ raise ValueError("unsupported whence (%r)" % (whence,))
2489
+ if cookie < 0:
2490
+ raise ValueError("negative seek position %r" % (cookie,))
2491
+ self.flush()
2492
+
2493
+ # The strategy of seek() is to go back to the safe start point
2494
+ # and replay the effect of read(chars_to_skip) from there.
2495
+ start_pos, dec_flags, bytes_to_feed, need_eof, chars_to_skip = \
2496
+ self._unpack_cookie(cookie)
2497
+
2498
+ # Seek back to the safe start point.
2499
+ self.buffer.seek(start_pos)
2500
+ self._set_decoded_chars('')
2501
+ self._snapshot = None
2502
+
2503
+ # Restore the decoder to its state from the safe start point.
2504
+ if cookie == 0 and self._decoder:
2505
+ self._decoder.reset()
2506
+ elif self._decoder or dec_flags or chars_to_skip:
2507
+ self._decoder = self._decoder or self._get_decoder()
2508
+ self._decoder.setstate((b'', dec_flags))
2509
+ self._snapshot = (dec_flags, b'')
2510
+
2511
+ if chars_to_skip:
2512
+ # Just like _read_chunk, feed the decoder and save a snapshot.
2513
+ input_chunk = self.buffer.read(bytes_to_feed)
2514
+ self._set_decoded_chars(
2515
+ self._decoder.decode(input_chunk, need_eof))
2516
+ self._snapshot = (dec_flags, input_chunk)
2517
+
2518
+ # Skip chars_to_skip of the decoded characters.
2519
+ if len(self._decoded_chars) < chars_to_skip:
2520
+ raise OSError("can't restore logical file position")
2521
+ self._decoded_chars_used = chars_to_skip
2522
+
2523
+ _reset_encoder(cookie)
2524
+ return cookie
2525
+
2526
+ def read(self, size=None):
2527
+ self._checkReadable()
2528
+ if size is None:
2529
+ size = -1
2530
+ else:
2531
+ try:
2532
+ size_index = size.__index__
2533
+ except AttributeError:
2534
+ raise TypeError(f"{size!r} is not an integer")
2535
+ else:
2536
+ size = size_index()
2537
+ decoder = self._decoder or self._get_decoder()
2538
+ if size < 0:
2539
+ # Read everything.
2540
+ result = (self._get_decoded_chars() +
2541
+ decoder.decode(self.buffer.read(), final=True))
2542
+ if self._snapshot is not None:
2543
+ self._set_decoded_chars('')
2544
+ self._snapshot = None
2545
+ return result
2546
+ else:
2547
+ # Keep reading chunks until we have size characters to return.
2548
+ eof = False
2549
+ result = self._get_decoded_chars(size)
2550
+ while len(result) < size and not eof:
2551
+ eof = not self._read_chunk()
2552
+ result += self._get_decoded_chars(size - len(result))
2553
+ return result
2554
+
2555
+ def __next__(self):
2556
+ self._telling = False
2557
+ line = self.readline()
2558
+ if not line:
2559
+ self._snapshot = None
2560
+ self._telling = self._seekable
2561
+ raise StopIteration
2562
+ return line
2563
+
2564
+ def readline(self, size=None):
2565
+ if self.closed:
2566
+ raise ValueError("read from closed file")
2567
+ if size is None:
2568
+ size = -1
2569
+ else:
2570
+ try:
2571
+ size_index = size.__index__
2572
+ except AttributeError:
2573
+ raise TypeError(f"{size!r} is not an integer")
2574
+ else:
2575
+ size = size_index()
2576
+
2577
+ # Grab all the decoded text (we will rewind any extra bits later).
2578
+ line = self._get_decoded_chars()
2579
+
2580
+ start = 0
2581
+ # Make the decoder if it doesn't already exist.
2582
+ if not self._decoder:
2583
+ self._get_decoder()
2584
+
2585
+ pos = endpos = None
2586
+ while True:
2587
+ if self._readtranslate:
2588
+ # Newlines are already translated, only search for \n
2589
+ pos = line.find('\n', start)
2590
+ if pos >= 0:
2591
+ endpos = pos + 1
2592
+ break
2593
+ else:
2594
+ start = len(line)
2595
+
2596
+ elif self._readuniversal:
2597
+ # Universal newline search. Find any of \r, \r\n, \n
2598
+ # The decoder ensures that \r\n are not split in two pieces
2599
+
2600
+ # In C we'd look for these in parallel of course.
2601
+ nlpos = line.find("\n", start)
2602
+ crpos = line.find("\r", start)
2603
+ if crpos == -1:
2604
+ if nlpos == -1:
2605
+ # Nothing found
2606
+ start = len(line)
2607
+ else:
2608
+ # Found \n
2609
+ endpos = nlpos + 1
2610
+ break
2611
+ elif nlpos == -1:
2612
+ # Found lone \r
2613
+ endpos = crpos + 1
2614
+ break
2615
+ elif nlpos < crpos:
2616
+ # Found \n
2617
+ endpos = nlpos + 1
2618
+ break
2619
+ elif nlpos == crpos + 1:
2620
+ # Found \r\n
2621
+ endpos = crpos + 2
2622
+ break
2623
+ else:
2624
+ # Found \r
2625
+ endpos = crpos + 1
2626
+ break
2627
+ else:
2628
+ # non-universal
2629
+ pos = line.find(self._readnl)
2630
+ if pos >= 0:
2631
+ endpos = pos + len(self._readnl)
2632
+ break
2633
+
2634
+ if size >= 0 and len(line) >= size:
2635
+ endpos = size # reached length size
2636
+ break
2637
+
2638
+ # No line ending seen yet - get more data'
2639
+ while self._read_chunk():
2640
+ if self._decoded_chars:
2641
+ break
2642
+ if self._decoded_chars:
2643
+ line += self._get_decoded_chars()
2644
+ else:
2645
+ # end of file
2646
+ self._set_decoded_chars('')
2647
+ self._snapshot = None
2648
+ return line
2649
+
2650
+ if size >= 0 and endpos > size:
2651
+ endpos = size # don't exceed size
2652
+
2653
+ # Rewind _decoded_chars to just after the line ending we found.
2654
+ self._rewind_decoded_chars(len(line) - endpos)
2655
+ return line[:endpos]
2656
+
2657
+ @property
2658
+ def newlines(self):
2659
+ return self._decoder.newlines if self._decoder else None
2660
+
2661
+ def _dealloc_warn(self, source):
2662
+ if dealloc_warn := getattr(self.buffer, "_dealloc_warn", None):
2663
+ dealloc_warn(source)
2664
+
2665
+
2666
+ class StringIO(TextIOWrapper):
2667
+ """Text I/O implementation using an in-memory buffer.
2668
+
2669
+ The initial_value argument sets the value of object. The newline
2670
+ argument is like the one of TextIOWrapper's constructor.
2671
+ """
2672
+
2673
+ def __init__(self, initial_value="", newline="\n"):
2674
+ super(StringIO, self).__init__(BytesIO(),
2675
+ encoding="utf-8",
2676
+ errors="surrogatepass",
2677
+ newline=newline)
2678
+ # Issue #5645: make universal newlines semantics the same as in the
2679
+ # C version, even under Windows.
2680
+ if newline is None:
2681
+ self._writetranslate = False
2682
+ if initial_value is not None:
2683
+ if not isinstance(initial_value, str):
2684
+ raise TypeError("initial_value must be str or None, not {0}"
2685
+ .format(type(initial_value).__name__))
2686
+ self.write(initial_value)
2687
+ self.seek(0)
2688
+
2689
+ def getvalue(self):
2690
+ self.flush()
2691
+ decoder = self._decoder or self._get_decoder()
2692
+ old_state = decoder.getstate()
2693
+ decoder.reset()
2694
+ try:
2695
+ return decoder.decode(self.buffer.getvalue(), final=True)
2696
+ finally:
2697
+ decoder.setstate(old_state)
2698
+
2699
+ def __repr__(self):
2700
+ # TextIOWrapper tells the encoding in its repr. In StringIO,
2701
+ # that's an implementation detail.
2702
+ return object.__repr__(self)
2703
+
2704
+ @property
2705
+ def errors(self):
2706
+ return None
2707
+
2708
+ @property
2709
+ def encoding(self):
2710
+ return None
2711
+
2712
+ def detach(self):
2713
+ # This doesn't make sense on StringIO.
2714
+ self._unsupported("detach")