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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (565) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +5 -0
  3. package/package.json +26 -0
  4. package/python/bin/python3.13 +0 -0
  5. package/python/bin/python3.13-config +122 -0
  6. package/python/lib/libpython3.13.so.1.0 +0 -0
  7. package/python/lib/libpython3.so +0 -0
  8. package/python/lib/python3.13/LICENSE.txt +277 -0
  9. package/python/lib/python3.13/__future__.py +147 -0
  10. package/python/lib/python3.13/__hello__.py +16 -0
  11. package/python/lib/python3.13/_aix_support.py +108 -0
  12. package/python/lib/python3.13/_android_support.py +192 -0
  13. package/python/lib/python3.13/_apple_support.py +66 -0
  14. package/python/lib/python3.13/_collections_abc.py +1187 -0
  15. package/python/lib/python3.13/_colorize.py +119 -0
  16. package/python/lib/python3.13/_compat_pickle.py +251 -0
  17. package/python/lib/python3.13/_compression.py +162 -0
  18. package/python/lib/python3.13/_ios_support.py +71 -0
  19. package/python/lib/python3.13/_markupbase.py +396 -0
  20. package/python/lib/python3.13/_opcode_metadata.py +343 -0
  21. package/python/lib/python3.13/_osx_support.py +579 -0
  22. package/python/lib/python3.13/_py_abc.py +147 -0
  23. package/python/lib/python3.13/_pydatetime.py +2640 -0
  24. package/python/lib/python3.13/_pydecimal.py +6356 -0
  25. package/python/lib/python3.13/_pyio.py +2714 -0
  26. package/python/lib/python3.13/_pylong.py +363 -0
  27. package/python/lib/python3.13/_pyrepl/__init__.py +19 -0
  28. package/python/lib/python3.13/_pyrepl/__main__.py +10 -0
  29. package/python/lib/python3.13/_pyrepl/_minimal_curses.py +68 -0
  30. package/python/lib/python3.13/_pyrepl/_threading_handler.py +74 -0
  31. package/python/lib/python3.13/_pyrepl/base_eventqueue.py +110 -0
  32. package/python/lib/python3.13/_pyrepl/commands.py +492 -0
  33. package/python/lib/python3.13/_pyrepl/completing_reader.py +295 -0
  34. package/python/lib/python3.13/_pyrepl/console.py +229 -0
  35. package/python/lib/python3.13/_pyrepl/curses.py +33 -0
  36. package/python/lib/python3.13/_pyrepl/fancy_termios.py +82 -0
  37. package/python/lib/python3.13/_pyrepl/historical_reader.py +419 -0
  38. package/python/lib/python3.13/_pyrepl/input.py +114 -0
  39. package/python/lib/python3.13/_pyrepl/keymap.py +213 -0
  40. package/python/lib/python3.13/_pyrepl/main.py +59 -0
  41. package/python/lib/python3.13/_pyrepl/mypy.ini +29 -0
  42. package/python/lib/python3.13/_pyrepl/pager.py +175 -0
  43. package/python/lib/python3.13/_pyrepl/reader.py +764 -0
  44. package/python/lib/python3.13/_pyrepl/readline.py +599 -0
  45. package/python/lib/python3.13/_pyrepl/simple_interact.py +180 -0
  46. package/python/lib/python3.13/_pyrepl/trace.py +21 -0
  47. package/python/lib/python3.13/_pyrepl/types.py +10 -0
  48. package/python/lib/python3.13/_pyrepl/unix_console.py +852 -0
  49. package/python/lib/python3.13/_pyrepl/unix_eventqueue.py +76 -0
  50. package/python/lib/python3.13/_pyrepl/utils.py +83 -0
  51. package/python/lib/python3.13/_pyrepl/windows_console.py +687 -0
  52. package/python/lib/python3.13/_pyrepl/windows_eventqueue.py +42 -0
  53. package/python/lib/python3.13/_sitebuiltins.py +91 -0
  54. package/python/lib/python3.13/_strptime.py +800 -0
  55. package/python/lib/python3.13/_sysconfigdata__linux_x86_64-linux-gnu.py +1079 -0
  56. package/python/lib/python3.13/_threading_local.py +120 -0
  57. package/python/lib/python3.13/_weakrefset.py +205 -0
  58. package/python/lib/python3.13/abc.py +188 -0
  59. package/python/lib/python3.13/antigravity.py +17 -0
  60. package/python/lib/python3.13/argparse.py +2690 -0
  61. package/python/lib/python3.13/ast.py +1865 -0
  62. package/python/lib/python3.13/asyncio/__init__.py +47 -0
  63. package/python/lib/python3.13/asyncio/__main__.py +211 -0
  64. package/python/lib/python3.13/asyncio/base_events.py +2086 -0
  65. package/python/lib/python3.13/asyncio/base_futures.py +67 -0
  66. package/python/lib/python3.13/asyncio/base_subprocess.py +312 -0
  67. package/python/lib/python3.13/asyncio/base_tasks.py +94 -0
  68. package/python/lib/python3.13/asyncio/constants.py +41 -0
  69. package/python/lib/python3.13/asyncio/coroutines.py +109 -0
  70. package/python/lib/python3.13/asyncio/events.py +885 -0
  71. package/python/lib/python3.13/asyncio/exceptions.py +62 -0
  72. package/python/lib/python3.13/asyncio/format_helpers.py +84 -0
  73. package/python/lib/python3.13/asyncio/futures.py +425 -0
  74. package/python/lib/python3.13/asyncio/locks.py +617 -0
  75. package/python/lib/python3.13/asyncio/log.py +7 -0
  76. package/python/lib/python3.13/asyncio/mixins.py +21 -0
  77. package/python/lib/python3.13/asyncio/proactor_events.py +891 -0
  78. package/python/lib/python3.13/asyncio/protocols.py +216 -0
  79. package/python/lib/python3.13/asyncio/queues.py +309 -0
  80. package/python/lib/python3.13/asyncio/runners.py +217 -0
  81. package/python/lib/python3.13/asyncio/selector_events.py +1328 -0
  82. package/python/lib/python3.13/asyncio/sslproto.py +929 -0
  83. package/python/lib/python3.13/asyncio/staggered.py +174 -0
  84. package/python/lib/python3.13/asyncio/streams.py +787 -0
  85. package/python/lib/python3.13/asyncio/subprocess.py +229 -0
  86. package/python/lib/python3.13/asyncio/taskgroups.py +278 -0
  87. package/python/lib/python3.13/asyncio/tasks.py +1121 -0
  88. package/python/lib/python3.13/asyncio/threads.py +26 -0
  89. package/python/lib/python3.13/asyncio/timeouts.py +185 -0
  90. package/python/lib/python3.13/asyncio/transports.py +337 -0
  91. package/python/lib/python3.13/asyncio/trsock.py +98 -0
  92. package/python/lib/python3.13/asyncio/unix_events.py +1550 -0
  93. package/python/lib/python3.13/asyncio/windows_events.py +906 -0
  94. package/python/lib/python3.13/asyncio/windows_utils.py +181 -0
  95. package/python/lib/python3.13/base64.py +628 -0
  96. package/python/lib/python3.13/bdb.py +973 -0
  97. package/python/lib/python3.13/bisect.py +118 -0
  98. package/python/lib/python3.13/bz2.py +352 -0
  99. package/python/lib/python3.13/cProfile.py +197 -0
  100. package/python/lib/python3.13/calendar.py +813 -0
  101. package/python/lib/python3.13/cmd.py +409 -0
  102. package/python/lib/python3.13/code.py +386 -0
  103. package/python/lib/python3.13/codecs.py +1132 -0
  104. package/python/lib/python3.13/codeop.py +155 -0
  105. package/python/lib/python3.13/collections/__init__.py +1603 -0
  106. package/python/lib/python3.13/colorsys.py +166 -0
  107. package/python/lib/python3.13/compileall.py +470 -0
  108. package/python/lib/python3.13/concurrent/__init__.py +1 -0
  109. package/python/lib/python3.13/concurrent/futures/__init__.py +54 -0
  110. package/python/lib/python3.13/concurrent/futures/_base.py +660 -0
  111. package/python/lib/python3.13/concurrent/futures/process.py +892 -0
  112. package/python/lib/python3.13/concurrent/futures/thread.py +240 -0
  113. package/python/lib/python3.13/configparser.py +1396 -0
  114. package/python/lib/python3.13/contextlib.py +814 -0
  115. package/python/lib/python3.13/contextvars.py +4 -0
  116. package/python/lib/python3.13/copy.py +306 -0
  117. package/python/lib/python3.13/copyreg.py +217 -0
  118. package/python/lib/python3.13/csv.py +527 -0
  119. package/python/lib/python3.13/ctypes/__init__.py +605 -0
  120. package/python/lib/python3.13/ctypes/_aix.py +327 -0
  121. package/python/lib/python3.13/ctypes/_endian.py +78 -0
  122. package/python/lib/python3.13/ctypes/macholib/README.ctypes +7 -0
  123. package/python/lib/python3.13/ctypes/macholib/__init__.py +9 -0
  124. package/python/lib/python3.13/ctypes/macholib/dyld.py +165 -0
  125. package/python/lib/python3.13/ctypes/macholib/dylib.py +42 -0
  126. package/python/lib/python3.13/ctypes/macholib/fetch_macholib +2 -0
  127. package/python/lib/python3.13/ctypes/macholib/fetch_macholib.bat +1 -0
  128. package/python/lib/python3.13/ctypes/macholib/framework.py +42 -0
  129. package/python/lib/python3.13/ctypes/util.py +387 -0
  130. package/python/lib/python3.13/ctypes/wintypes.py +202 -0
  131. package/python/lib/python3.13/curses/__init__.py +101 -0
  132. package/python/lib/python3.13/curses/ascii.py +99 -0
  133. package/python/lib/python3.13/curses/has_key.py +192 -0
  134. package/python/lib/python3.13/curses/panel.py +6 -0
  135. package/python/lib/python3.13/curses/textpad.py +236 -0
  136. package/python/lib/python3.13/dataclasses.py +1679 -0
  137. package/python/lib/python3.13/datetime.py +9 -0
  138. package/python/lib/python3.13/dbm/__init__.py +194 -0
  139. package/python/lib/python3.13/dbm/dumb.py +319 -0
  140. package/python/lib/python3.13/dbm/gnu.py +3 -0
  141. package/python/lib/python3.13/dbm/ndbm.py +3 -0
  142. package/python/lib/python3.13/dbm/sqlite3.py +144 -0
  143. package/python/lib/python3.13/decimal.py +109 -0
  144. package/python/lib/python3.13/difflib.py +2058 -0
  145. package/python/lib/python3.13/dis.py +1075 -0
  146. package/python/lib/python3.13/doctest.py +2919 -0
  147. package/python/lib/python3.13/email/__init__.py +61 -0
  148. package/python/lib/python3.13/email/_encoded_words.py +233 -0
  149. package/python/lib/python3.13/email/_header_value_parser.py +3153 -0
  150. package/python/lib/python3.13/email/_parseaddr.py +563 -0
  151. package/python/lib/python3.13/email/_policybase.py +382 -0
  152. package/python/lib/python3.13/email/architecture.rst +216 -0
  153. package/python/lib/python3.13/email/base64mime.py +115 -0
  154. package/python/lib/python3.13/email/charset.py +396 -0
  155. package/python/lib/python3.13/email/contentmanager.py +254 -0
  156. package/python/lib/python3.13/email/encoders.py +65 -0
  157. package/python/lib/python3.13/email/errors.py +117 -0
  158. package/python/lib/python3.13/email/feedparser.py +536 -0
  159. package/python/lib/python3.13/email/generator.py +530 -0
  160. package/python/lib/python3.13/email/header.py +582 -0
  161. package/python/lib/python3.13/email/headerregistry.py +618 -0
  162. package/python/lib/python3.13/email/iterators.py +68 -0
  163. package/python/lib/python3.13/email/message.py +1217 -0
  164. package/python/lib/python3.13/email/mime/__init__.py +0 -0
  165. package/python/lib/python3.13/email/mime/application.py +37 -0
  166. package/python/lib/python3.13/email/mime/audio.py +97 -0
  167. package/python/lib/python3.13/email/mime/base.py +29 -0
  168. package/python/lib/python3.13/email/mime/image.py +152 -0
  169. package/python/lib/python3.13/email/mime/message.py +33 -0
  170. package/python/lib/python3.13/email/mime/multipart.py +47 -0
  171. package/python/lib/python3.13/email/mime/nonmultipart.py +21 -0
  172. package/python/lib/python3.13/email/mime/text.py +40 -0
  173. package/python/lib/python3.13/email/parser.py +127 -0
  174. package/python/lib/python3.13/email/policy.py +232 -0
  175. package/python/lib/python3.13/email/quoprimime.py +300 -0
  176. package/python/lib/python3.13/email/utils.py +497 -0
  177. package/python/lib/python3.13/encodings/__init__.py +179 -0
  178. package/python/lib/python3.13/encodings/__pycache__/__init__.cpython-313.pyc +0 -0
  179. package/python/lib/python3.13/encodings/__pycache__/aliases.cpython-313.pyc +0 -0
  180. package/python/lib/python3.13/encodings/__pycache__/utf_8.cpython-313.pyc +0 -0
  181. package/python/lib/python3.13/encodings/aliases.py +560 -0
  182. package/python/lib/python3.13/encodings/ascii.py +50 -0
  183. package/python/lib/python3.13/encodings/base64_codec.py +55 -0
  184. package/python/lib/python3.13/encodings/big5.py +39 -0
  185. package/python/lib/python3.13/encodings/big5hkscs.py +39 -0
  186. package/python/lib/python3.13/encodings/bz2_codec.py +78 -0
  187. package/python/lib/python3.13/encodings/charmap.py +69 -0
  188. package/python/lib/python3.13/encodings/cp037.py +307 -0
  189. package/python/lib/python3.13/encodings/cp1006.py +307 -0
  190. package/python/lib/python3.13/encodings/cp1026.py +307 -0
  191. package/python/lib/python3.13/encodings/cp1125.py +698 -0
  192. package/python/lib/python3.13/encodings/cp1140.py +307 -0
  193. package/python/lib/python3.13/encodings/cp1250.py +307 -0
  194. package/python/lib/python3.13/encodings/cp1251.py +307 -0
  195. package/python/lib/python3.13/encodings/cp1252.py +307 -0
  196. package/python/lib/python3.13/encodings/cp1253.py +307 -0
  197. package/python/lib/python3.13/encodings/cp1254.py +307 -0
  198. package/python/lib/python3.13/encodings/cp1255.py +307 -0
  199. package/python/lib/python3.13/encodings/cp1256.py +307 -0
  200. package/python/lib/python3.13/encodings/cp1257.py +307 -0
  201. package/python/lib/python3.13/encodings/cp1258.py +307 -0
  202. package/python/lib/python3.13/encodings/cp273.py +307 -0
  203. package/python/lib/python3.13/encodings/cp424.py +307 -0
  204. package/python/lib/python3.13/encodings/cp437.py +698 -0
  205. package/python/lib/python3.13/encodings/cp500.py +307 -0
  206. package/python/lib/python3.13/encodings/cp720.py +309 -0
  207. package/python/lib/python3.13/encodings/cp737.py +698 -0
  208. package/python/lib/python3.13/encodings/cp775.py +697 -0
  209. package/python/lib/python3.13/encodings/cp850.py +698 -0
  210. package/python/lib/python3.13/encodings/cp852.py +698 -0
  211. package/python/lib/python3.13/encodings/cp855.py +698 -0
  212. package/python/lib/python3.13/encodings/cp856.py +307 -0
  213. package/python/lib/python3.13/encodings/cp857.py +694 -0
  214. package/python/lib/python3.13/encodings/cp858.py +698 -0
  215. package/python/lib/python3.13/encodings/cp860.py +698 -0
  216. package/python/lib/python3.13/encodings/cp861.py +698 -0
  217. package/python/lib/python3.13/encodings/cp862.py +698 -0
  218. package/python/lib/python3.13/encodings/cp863.py +698 -0
  219. package/python/lib/python3.13/encodings/cp864.py +690 -0
  220. package/python/lib/python3.13/encodings/cp865.py +698 -0
  221. package/python/lib/python3.13/encodings/cp866.py +698 -0
  222. package/python/lib/python3.13/encodings/cp869.py +689 -0
  223. package/python/lib/python3.13/encodings/cp874.py +307 -0
  224. package/python/lib/python3.13/encodings/cp875.py +307 -0
  225. package/python/lib/python3.13/encodings/cp932.py +39 -0
  226. package/python/lib/python3.13/encodings/cp949.py +39 -0
  227. package/python/lib/python3.13/encodings/cp950.py +39 -0
  228. package/python/lib/python3.13/encodings/euc_jis_2004.py +39 -0
  229. package/python/lib/python3.13/encodings/euc_jisx0213.py +39 -0
  230. package/python/lib/python3.13/encodings/euc_jp.py +39 -0
  231. package/python/lib/python3.13/encodings/euc_kr.py +39 -0
  232. package/python/lib/python3.13/encodings/gb18030.py +39 -0
  233. package/python/lib/python3.13/encodings/gb2312.py +39 -0
  234. package/python/lib/python3.13/encodings/gbk.py +39 -0
  235. package/python/lib/python3.13/encodings/hex_codec.py +55 -0
  236. package/python/lib/python3.13/encodings/hp_roman8.py +314 -0
  237. package/python/lib/python3.13/encodings/hz.py +39 -0
  238. package/python/lib/python3.13/encodings/idna.py +387 -0
  239. package/python/lib/python3.13/encodings/iso2022_jp.py +39 -0
  240. package/python/lib/python3.13/encodings/iso2022_jp_1.py +39 -0
  241. package/python/lib/python3.13/encodings/iso2022_jp_2.py +39 -0
  242. package/python/lib/python3.13/encodings/iso2022_jp_2004.py +39 -0
  243. package/python/lib/python3.13/encodings/iso2022_jp_3.py +39 -0
  244. package/python/lib/python3.13/encodings/iso2022_jp_ext.py +39 -0
  245. package/python/lib/python3.13/encodings/iso2022_kr.py +39 -0
  246. package/python/lib/python3.13/encodings/iso8859_1.py +307 -0
  247. package/python/lib/python3.13/encodings/iso8859_10.py +307 -0
  248. package/python/lib/python3.13/encodings/iso8859_11.py +307 -0
  249. package/python/lib/python3.13/encodings/iso8859_13.py +307 -0
  250. package/python/lib/python3.13/encodings/iso8859_14.py +307 -0
  251. package/python/lib/python3.13/encodings/iso8859_15.py +307 -0
  252. package/python/lib/python3.13/encodings/iso8859_16.py +307 -0
  253. package/python/lib/python3.13/encodings/iso8859_2.py +307 -0
  254. package/python/lib/python3.13/encodings/iso8859_3.py +307 -0
  255. package/python/lib/python3.13/encodings/iso8859_4.py +307 -0
  256. package/python/lib/python3.13/encodings/iso8859_5.py +307 -0
  257. package/python/lib/python3.13/encodings/iso8859_6.py +307 -0
  258. package/python/lib/python3.13/encodings/iso8859_7.py +307 -0
  259. package/python/lib/python3.13/encodings/iso8859_8.py +307 -0
  260. package/python/lib/python3.13/encodings/iso8859_9.py +307 -0
  261. package/python/lib/python3.13/encodings/johab.py +39 -0
  262. package/python/lib/python3.13/encodings/koi8_r.py +307 -0
  263. package/python/lib/python3.13/encodings/koi8_t.py +308 -0
  264. package/python/lib/python3.13/encodings/koi8_u.py +307 -0
  265. package/python/lib/python3.13/encodings/kz1048.py +307 -0
  266. package/python/lib/python3.13/encodings/latin_1.py +50 -0
  267. package/python/lib/python3.13/encodings/mac_arabic.py +698 -0
  268. package/python/lib/python3.13/encodings/mac_croatian.py +307 -0
  269. package/python/lib/python3.13/encodings/mac_cyrillic.py +307 -0
  270. package/python/lib/python3.13/encodings/mac_farsi.py +307 -0
  271. package/python/lib/python3.13/encodings/mac_greek.py +307 -0
  272. package/python/lib/python3.13/encodings/mac_iceland.py +307 -0
  273. package/python/lib/python3.13/encodings/mac_latin2.py +312 -0
  274. package/python/lib/python3.13/encodings/mac_roman.py +307 -0
  275. package/python/lib/python3.13/encodings/mac_romanian.py +307 -0
  276. package/python/lib/python3.13/encodings/mac_turkish.py +307 -0
  277. package/python/lib/python3.13/encodings/mbcs.py +47 -0
  278. package/python/lib/python3.13/encodings/oem.py +41 -0
  279. package/python/lib/python3.13/encodings/palmos.py +308 -0
  280. package/python/lib/python3.13/encodings/ptcp154.py +312 -0
  281. package/python/lib/python3.13/encodings/punycode.py +253 -0
  282. package/python/lib/python3.13/encodings/quopri_codec.py +56 -0
  283. package/python/lib/python3.13/encodings/raw_unicode_escape.py +46 -0
  284. package/python/lib/python3.13/encodings/rot_13.py +113 -0
  285. package/python/lib/python3.13/encodings/shift_jis.py +39 -0
  286. package/python/lib/python3.13/encodings/shift_jis_2004.py +39 -0
  287. package/python/lib/python3.13/encodings/shift_jisx0213.py +39 -0
  288. package/python/lib/python3.13/encodings/tis_620.py +307 -0
  289. package/python/lib/python3.13/encodings/undefined.py +49 -0
  290. package/python/lib/python3.13/encodings/unicode_escape.py +46 -0
  291. package/python/lib/python3.13/encodings/utf_16.py +155 -0
  292. package/python/lib/python3.13/encodings/utf_16_be.py +42 -0
  293. package/python/lib/python3.13/encodings/utf_16_le.py +42 -0
  294. package/python/lib/python3.13/encodings/utf_32.py +150 -0
  295. package/python/lib/python3.13/encodings/utf_32_be.py +37 -0
  296. package/python/lib/python3.13/encodings/utf_32_le.py +37 -0
  297. package/python/lib/python3.13/encodings/utf_7.py +38 -0
  298. package/python/lib/python3.13/encodings/utf_8.py +42 -0
  299. package/python/lib/python3.13/encodings/utf_8_sig.py +130 -0
  300. package/python/lib/python3.13/encodings/uu_codec.py +103 -0
  301. package/python/lib/python3.13/encodings/zlib_codec.py +77 -0
  302. package/python/lib/python3.13/enum.py +2183 -0
  303. package/python/lib/python3.13/filecmp.py +320 -0
  304. package/python/lib/python3.13/fileinput.py +442 -0
  305. package/python/lib/python3.13/fnmatch.py +192 -0
  306. package/python/lib/python3.13/fractions.py +1043 -0
  307. package/python/lib/python3.13/ftplib.py +975 -0
  308. package/python/lib/python3.13/functools.py +1036 -0
  309. package/python/lib/python3.13/genericpath.py +200 -0
  310. package/python/lib/python3.13/getopt.py +215 -0
  311. package/python/lib/python3.13/getpass.py +192 -0
  312. package/python/lib/python3.13/gettext.py +657 -0
  313. package/python/lib/python3.13/glob.py +572 -0
  314. package/python/lib/python3.13/graphlib.py +250 -0
  315. package/python/lib/python3.13/gzip.py +693 -0
  316. package/python/lib/python3.13/hashlib.py +255 -0
  317. package/python/lib/python3.13/heapq.py +603 -0
  318. package/python/lib/python3.13/hmac.py +220 -0
  319. package/python/lib/python3.13/html/__init__.py +132 -0
  320. package/python/lib/python3.13/html/entities.py +2513 -0
  321. package/python/lib/python3.13/html/parser.py +583 -0
  322. package/python/lib/python3.13/http/__init__.py +202 -0
  323. package/python/lib/python3.13/http/client.py +1598 -0
  324. package/python/lib/python3.13/http/cookiejar.py +2122 -0
  325. package/python/lib/python3.13/http/cookies.py +635 -0
  326. package/python/lib/python3.13/http/server.py +1355 -0
  327. package/python/lib/python3.13/imaplib.py +1769 -0
  328. package/python/lib/python3.13/importlib/__init__.py +136 -0
  329. package/python/lib/python3.13/importlib/_abc.py +39 -0
  330. package/python/lib/python3.13/importlib/_bootstrap.py +1559 -0
  331. package/python/lib/python3.13/importlib/_bootstrap_external.py +1826 -0
  332. package/python/lib/python3.13/importlib/abc.py +243 -0
  333. package/python/lib/python3.13/importlib/machinery.py +21 -0
  334. package/python/lib/python3.13/importlib/metadata/__init__.py +1093 -0
  335. package/python/lib/python3.13/importlib/metadata/_adapters.py +89 -0
  336. package/python/lib/python3.13/importlib/metadata/_collections.py +30 -0
  337. package/python/lib/python3.13/importlib/metadata/_functools.py +104 -0
  338. package/python/lib/python3.13/importlib/metadata/_itertools.py +73 -0
  339. package/python/lib/python3.13/importlib/metadata/_meta.py +67 -0
  340. package/python/lib/python3.13/importlib/metadata/_text.py +99 -0
  341. package/python/lib/python3.13/importlib/metadata/diagnose.py +21 -0
  342. package/python/lib/python3.13/importlib/readers.py +12 -0
  343. package/python/lib/python3.13/importlib/resources/__init__.py +43 -0
  344. package/python/lib/python3.13/importlib/resources/_adapters.py +168 -0
  345. package/python/lib/python3.13/importlib/resources/_common.py +211 -0
  346. package/python/lib/python3.13/importlib/resources/_functional.py +81 -0
  347. package/python/lib/python3.13/importlib/resources/_itertools.py +38 -0
  348. package/python/lib/python3.13/importlib/resources/abc.py +173 -0
  349. package/python/lib/python3.13/importlib/resources/readers.py +203 -0
  350. package/python/lib/python3.13/importlib/resources/simple.py +106 -0
  351. package/python/lib/python3.13/importlib/simple.py +14 -0
  352. package/python/lib/python3.13/importlib/util.py +274 -0
  353. package/python/lib/python3.13/inspect.py +3479 -0
  354. package/python/lib/python3.13/io.py +99 -0
  355. package/python/lib/python3.13/ipaddress.py +2440 -0
  356. package/python/lib/python3.13/json/__init__.py +365 -0
  357. package/python/lib/python3.13/json/decoder.py +364 -0
  358. package/python/lib/python3.13/json/encoder.py +446 -0
  359. package/python/lib/python3.13/json/scanner.py +73 -0
  360. package/python/lib/python3.13/json/tool.py +90 -0
  361. package/python/lib/python3.13/keyword.py +64 -0
  362. package/python/lib/python3.13/lib-dynload/.empty +0 -0
  363. package/python/lib/python3.13/lib-dynload/_dbm.cpython-313-x86_64-linux-gnu.so +0 -0
  364. package/python/lib/python3.13/linecache.py +236 -0
  365. package/python/lib/python3.13/locale.py +1987 -0
  366. package/python/lib/python3.13/logging/__init__.py +2330 -0
  367. package/python/lib/python3.13/logging/config.py +1080 -0
  368. package/python/lib/python3.13/logging/handlers.py +1629 -0
  369. package/python/lib/python3.13/lzma.py +364 -0
  370. package/python/lib/python3.13/mailbox.py +2219 -0
  371. package/python/lib/python3.13/mimetypes.py +679 -0
  372. package/python/lib/python3.13/modulefinder.py +671 -0
  373. package/python/lib/python3.13/multiprocessing/__init__.py +37 -0
  374. package/python/lib/python3.13/multiprocessing/connection.py +1216 -0
  375. package/python/lib/python3.13/multiprocessing/context.py +383 -0
  376. package/python/lib/python3.13/multiprocessing/dummy/__init__.py +126 -0
  377. package/python/lib/python3.13/multiprocessing/dummy/connection.py +75 -0
  378. package/python/lib/python3.13/multiprocessing/forkserver.py +373 -0
  379. package/python/lib/python3.13/multiprocessing/heap.py +337 -0
  380. package/python/lib/python3.13/multiprocessing/managers.py +1397 -0
  381. package/python/lib/python3.13/multiprocessing/pool.py +957 -0
  382. package/python/lib/python3.13/multiprocessing/popen_fork.py +97 -0
  383. package/python/lib/python3.13/multiprocessing/popen_forkserver.py +74 -0
  384. package/python/lib/python3.13/multiprocessing/popen_spawn_posix.py +76 -0
  385. package/python/lib/python3.13/multiprocessing/popen_spawn_win32.py +147 -0
  386. package/python/lib/python3.13/multiprocessing/process.py +436 -0
  387. package/python/lib/python3.13/multiprocessing/queues.py +399 -0
  388. package/python/lib/python3.13/multiprocessing/reduction.py +281 -0
  389. package/python/lib/python3.13/multiprocessing/resource_sharer.py +154 -0
  390. package/python/lib/python3.13/multiprocessing/resource_tracker.py +499 -0
  391. package/python/lib/python3.13/multiprocessing/shared_memory.py +544 -0
  392. package/python/lib/python3.13/multiprocessing/sharedctypes.py +240 -0
  393. package/python/lib/python3.13/multiprocessing/spawn.py +307 -0
  394. package/python/lib/python3.13/multiprocessing/synchronize.py +404 -0
  395. package/python/lib/python3.13/multiprocessing/util.py +562 -0
  396. package/python/lib/python3.13/netrc.py +199 -0
  397. package/python/lib/python3.13/ntpath.py +872 -0
  398. package/python/lib/python3.13/nturl2path.py +69 -0
  399. package/python/lib/python3.13/numbers.py +427 -0
  400. package/python/lib/python3.13/opcode.py +115 -0
  401. package/python/lib/python3.13/operator.py +467 -0
  402. package/python/lib/python3.13/optparse.py +1681 -0
  403. package/python/lib/python3.13/os.py +1184 -0
  404. package/python/lib/python3.13/pathlib/__init__.py +12 -0
  405. package/python/lib/python3.13/pathlib/_abc.py +930 -0
  406. package/python/lib/python3.13/pathlib/_local.py +861 -0
  407. package/python/lib/python3.13/pdb.py +2550 -0
  408. package/python/lib/python3.13/pickle.py +1860 -0
  409. package/python/lib/python3.13/pickletools.py +2904 -0
  410. package/python/lib/python3.13/pkgutil.py +529 -0
  411. package/python/lib/python3.13/platform.py +1454 -0
  412. package/python/lib/python3.13/plistlib.py +948 -0
  413. package/python/lib/python3.13/poplib.py +477 -0
  414. package/python/lib/python3.13/posixpath.py +578 -0
  415. package/python/lib/python3.13/pprint.py +658 -0
  416. package/python/lib/python3.13/profile.py +616 -0
  417. package/python/lib/python3.13/pstats.py +778 -0
  418. package/python/lib/python3.13/pty.py +211 -0
  419. package/python/lib/python3.13/py_compile.py +212 -0
  420. package/python/lib/python3.13/pyclbr.py +314 -0
  421. package/python/lib/python3.13/pydoc.py +2861 -0
  422. package/python/lib/python3.13/queue.py +383 -0
  423. package/python/lib/python3.13/quopri.py +237 -0
  424. package/python/lib/python3.13/random.py +1078 -0
  425. package/python/lib/python3.13/re/__init__.py +428 -0
  426. package/python/lib/python3.13/re/_casefix.py +106 -0
  427. package/python/lib/python3.13/re/_compiler.py +768 -0
  428. package/python/lib/python3.13/re/_constants.py +222 -0
  429. package/python/lib/python3.13/re/_parser.py +1081 -0
  430. package/python/lib/python3.13/reprlib.py +230 -0
  431. package/python/lib/python3.13/rlcompleter.py +222 -0
  432. package/python/lib/python3.13/runpy.py +326 -0
  433. package/python/lib/python3.13/sched.py +167 -0
  434. package/python/lib/python3.13/secrets.py +71 -0
  435. package/python/lib/python3.13/selectors.py +603 -0
  436. package/python/lib/python3.13/shelve.py +250 -0
  437. package/python/lib/python3.13/shlex.py +345 -0
  438. package/python/lib/python3.13/shutil.py +1569 -0
  439. package/python/lib/python3.13/signal.py +94 -0
  440. package/python/lib/python3.13/site.py +773 -0
  441. package/python/lib/python3.13/smtplib.py +1123 -0
  442. package/python/lib/python3.13/socket.py +988 -0
  443. package/python/lib/python3.13/socketserver.py +863 -0
  444. package/python/lib/python3.13/sqlite3/__init__.py +70 -0
  445. package/python/lib/python3.13/sqlite3/__main__.py +139 -0
  446. package/python/lib/python3.13/sqlite3/dbapi2.py +108 -0
  447. package/python/lib/python3.13/sqlite3/dump.py +118 -0
  448. package/python/lib/python3.13/sre_compile.py +7 -0
  449. package/python/lib/python3.13/sre_constants.py +7 -0
  450. package/python/lib/python3.13/sre_parse.py +7 -0
  451. package/python/lib/python3.13/ssl.py +1541 -0
  452. package/python/lib/python3.13/stat.py +212 -0
  453. package/python/lib/python3.13/statistics.py +1817 -0
  454. package/python/lib/python3.13/string.py +314 -0
  455. package/python/lib/python3.13/stringprep.py +272 -0
  456. package/python/lib/python3.13/struct.py +15 -0
  457. package/python/lib/python3.13/subprocess.py +2258 -0
  458. package/python/lib/python3.13/symtable.py +414 -0
  459. package/python/lib/python3.13/sysconfig/__init__.py +734 -0
  460. package/python/lib/python3.13/sysconfig/__main__.py +248 -0
  461. package/python/lib/python3.13/tabnanny.py +340 -0
  462. package/python/lib/python3.13/tarfile.py +3136 -0
  463. package/python/lib/python3.13/tempfile.py +958 -0
  464. package/python/lib/python3.13/textwrap.py +497 -0
  465. package/python/lib/python3.13/this.py +28 -0
  466. package/python/lib/python3.13/threading.py +1602 -0
  467. package/python/lib/python3.13/timeit.py +381 -0
  468. package/python/lib/python3.13/token.py +141 -0
  469. package/python/lib/python3.13/tokenize.py +592 -0
  470. package/python/lib/python3.13/tomllib/__init__.py +10 -0
  471. package/python/lib/python3.13/tomllib/_parser.py +703 -0
  472. package/python/lib/python3.13/tomllib/_re.py +107 -0
  473. package/python/lib/python3.13/tomllib/_types.py +10 -0
  474. package/python/lib/python3.13/tomllib/mypy.ini +15 -0
  475. package/python/lib/python3.13/trace.py +754 -0
  476. package/python/lib/python3.13/traceback.py +1639 -0
  477. package/python/lib/python3.13/tracemalloc.py +560 -0
  478. package/python/lib/python3.13/tty.py +73 -0
  479. package/python/lib/python3.13/types.py +346 -0
  480. package/python/lib/python3.13/typing.py +3846 -0
  481. package/python/lib/python3.13/unittest/__init__.py +80 -0
  482. package/python/lib/python3.13/unittest/__main__.py +18 -0
  483. package/python/lib/python3.13/unittest/_log.py +86 -0
  484. package/python/lib/python3.13/unittest/async_case.py +146 -0
  485. package/python/lib/python3.13/unittest/case.py +1478 -0
  486. package/python/lib/python3.13/unittest/loader.py +460 -0
  487. package/python/lib/python3.13/unittest/main.py +280 -0
  488. package/python/lib/python3.13/unittest/mock.py +3189 -0
  489. package/python/lib/python3.13/unittest/result.py +256 -0
  490. package/python/lib/python3.13/unittest/runner.py +292 -0
  491. package/python/lib/python3.13/unittest/signals.py +71 -0
  492. package/python/lib/python3.13/unittest/suite.py +379 -0
  493. package/python/lib/python3.13/unittest/util.py +170 -0
  494. package/python/lib/python3.13/urllib/__init__.py +0 -0
  495. package/python/lib/python3.13/urllib/error.py +74 -0
  496. package/python/lib/python3.13/urllib/parse.py +1264 -0
  497. package/python/lib/python3.13/urllib/request.py +2796 -0
  498. package/python/lib/python3.13/urllib/response.py +84 -0
  499. package/python/lib/python3.13/urllib/robotparser.py +363 -0
  500. package/python/lib/python3.13/uuid.py +784 -0
  501. package/python/lib/python3.13/warnings.py +735 -0
  502. package/python/lib/python3.13/wave.py +665 -0
  503. package/python/lib/python3.13/weakref.py +674 -0
  504. package/python/lib/python3.13/webbrowser.py +724 -0
  505. package/python/lib/python3.13/wsgiref/__init__.py +25 -0
  506. package/python/lib/python3.13/wsgiref/handlers.py +575 -0
  507. package/python/lib/python3.13/wsgiref/headers.py +192 -0
  508. package/python/lib/python3.13/wsgiref/simple_server.py +161 -0
  509. package/python/lib/python3.13/wsgiref/types.py +54 -0
  510. package/python/lib/python3.13/wsgiref/util.py +159 -0
  511. package/python/lib/python3.13/wsgiref/validate.py +438 -0
  512. package/python/lib/python3.13/xml/__init__.py +20 -0
  513. package/python/lib/python3.13/xml/dom/NodeFilter.py +27 -0
  514. package/python/lib/python3.13/xml/dom/__init__.py +140 -0
  515. package/python/lib/python3.13/xml/dom/domreg.py +99 -0
  516. package/python/lib/python3.13/xml/dom/expatbuilder.py +962 -0
  517. package/python/lib/python3.13/xml/dom/minicompat.py +109 -0
  518. package/python/lib/python3.13/xml/dom/minidom.py +2024 -0
  519. package/python/lib/python3.13/xml/dom/pulldom.py +336 -0
  520. package/python/lib/python3.13/xml/dom/xmlbuilder.py +389 -0
  521. package/python/lib/python3.13/xml/etree/ElementInclude.py +186 -0
  522. package/python/lib/python3.13/xml/etree/ElementPath.py +430 -0
  523. package/python/lib/python3.13/xml/etree/ElementTree.py +2116 -0
  524. package/python/lib/python3.13/xml/etree/__init__.py +33 -0
  525. package/python/lib/python3.13/xml/etree/cElementTree.py +3 -0
  526. package/python/lib/python3.13/xml/parsers/__init__.py +8 -0
  527. package/python/lib/python3.13/xml/parsers/expat.py +8 -0
  528. package/python/lib/python3.13/xml/sax/__init__.py +94 -0
  529. package/python/lib/python3.13/xml/sax/_exceptions.py +127 -0
  530. package/python/lib/python3.13/xml/sax/expatreader.py +454 -0
  531. package/python/lib/python3.13/xml/sax/handler.py +387 -0
  532. package/python/lib/python3.13/xml/sax/saxutils.py +369 -0
  533. package/python/lib/python3.13/xml/sax/xmlreader.py +378 -0
  534. package/python/lib/python3.13/xmlrpc/__init__.py +1 -0
  535. package/python/lib/python3.13/xmlrpc/client.py +1503 -0
  536. package/python/lib/python3.13/xmlrpc/server.py +1002 -0
  537. package/python/lib/python3.13/zipapp.py +229 -0
  538. package/python/lib/python3.13/zipfile/__init__.py +2391 -0
  539. package/python/lib/python3.13/zipfile/__main__.py +4 -0
  540. package/python/lib/python3.13/zipfile/_path/__init__.py +452 -0
  541. package/python/lib/python3.13/zipfile/_path/glob.py +113 -0
  542. package/python/lib/python3.13/zipimport.py +803 -0
  543. package/python/lib/python3.13/zoneinfo/__init__.py +34 -0
  544. package/python/lib/python3.13/zoneinfo/_common.py +172 -0
  545. package/python/lib/python3.13/zoneinfo/_tzpath.py +189 -0
  546. package/python/lib/python3.13/zoneinfo/_zoneinfo.py +779 -0
  547. package/python/licenses/LICENSE.bdb.txt +126 -0
  548. package/python/licenses/LICENSE.bzip2.txt +37 -0
  549. package/python/licenses/LICENSE.cpython.txt +771 -0
  550. package/python/licenses/LICENSE.expat.txt +21 -0
  551. package/python/licenses/LICENSE.libX11.txt +942 -0
  552. package/python/licenses/LICENSE.libXau.txt +21 -0
  553. package/python/licenses/LICENSE.libedit.txt +29 -0
  554. package/python/licenses/LICENSE.libffi.txt +21 -0
  555. package/python/licenses/LICENSE.liblzma.txt +13 -0
  556. package/python/licenses/LICENSE.libuuid.txt +27 -0
  557. package/python/licenses/LICENSE.libxcb.txt +30 -0
  558. package/python/licenses/LICENSE.mpdecimal.txt +24 -0
  559. package/python/licenses/LICENSE.ncurses.txt +29 -0
  560. package/python/licenses/LICENSE.openssl-1.1.txt +124 -0
  561. package/python/licenses/LICENSE.openssl-3.txt +177 -0
  562. package/python/licenses/LICENSE.sqlite.txt +23 -0
  563. package/python/licenses/LICENSE.tcl.txt +40 -0
  564. package/python/licenses/LICENSE.tix.txt +54 -0
  565. package/python/licenses/LICENSE.zlib.txt +21 -0
@@ -0,0 +1,1569 @@
1
+ """Utility functions for copying and archiving files and directory trees.
2
+
3
+ XXX The functions here don't copy the resource fork or other metadata on Mac.
4
+
5
+ """
6
+
7
+ import os
8
+ import sys
9
+ import stat
10
+ import fnmatch
11
+ import collections
12
+ import errno
13
+
14
+ try:
15
+ import zlib
16
+ del zlib
17
+ _ZLIB_SUPPORTED = True
18
+ except ImportError:
19
+ _ZLIB_SUPPORTED = False
20
+
21
+ try:
22
+ import bz2
23
+ del bz2
24
+ _BZ2_SUPPORTED = True
25
+ except ImportError:
26
+ _BZ2_SUPPORTED = False
27
+
28
+ try:
29
+ import lzma
30
+ del lzma
31
+ _LZMA_SUPPORTED = True
32
+ except ImportError:
33
+ _LZMA_SUPPORTED = False
34
+
35
+ _WINDOWS = os.name == 'nt'
36
+ posix = nt = None
37
+ if os.name == 'posix':
38
+ import posix
39
+ elif _WINDOWS:
40
+ import nt
41
+
42
+ if sys.platform == 'win32':
43
+ import _winapi
44
+ else:
45
+ _winapi = None
46
+
47
+ COPY_BUFSIZE = 1024 * 1024 if _WINDOWS else 64 * 1024
48
+ # This should never be removed, see rationale in:
49
+ # https://bugs.python.org/issue43743#msg393429
50
+ _USE_CP_SENDFILE = (hasattr(os, "sendfile")
51
+ and sys.platform.startswith(("linux", "android")))
52
+ _HAS_FCOPYFILE = posix and hasattr(posix, "_fcopyfile") # macOS
53
+
54
+ # CMD defaults in Windows 10
55
+ _WIN_DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC"
56
+
57
+ __all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
58
+ "copytree", "move", "rmtree", "Error", "SpecialFileError",
59
+ "ExecError", "make_archive", "get_archive_formats",
60
+ "register_archive_format", "unregister_archive_format",
61
+ "get_unpack_formats", "register_unpack_format",
62
+ "unregister_unpack_format", "unpack_archive",
63
+ "ignore_patterns", "chown", "which", "get_terminal_size",
64
+ "SameFileError"]
65
+ # disk_usage is added later, if available on the platform
66
+
67
+ class Error(OSError):
68
+ pass
69
+
70
+ class SameFileError(Error):
71
+ """Raised when source and destination are the same file."""
72
+
73
+ class SpecialFileError(OSError):
74
+ """Raised when trying to do a kind of operation (e.g. copying) which is
75
+ not supported on a special file (e.g. a named pipe)"""
76
+
77
+ class ExecError(OSError):
78
+ """Raised when a command could not be executed"""
79
+
80
+ class ReadError(OSError):
81
+ """Raised when an archive cannot be read"""
82
+
83
+ class RegistryError(Exception):
84
+ """Raised when a registry operation with the archiving
85
+ and unpacking registries fails"""
86
+
87
+ class _GiveupOnFastCopy(Exception):
88
+ """Raised as a signal to fallback on using raw read()/write()
89
+ file copy when fast-copy functions fail to do so.
90
+ """
91
+
92
+ def _fastcopy_fcopyfile(fsrc, fdst, flags):
93
+ """Copy a regular file content or metadata by using high-performance
94
+ fcopyfile(3) syscall (macOS).
95
+ """
96
+ try:
97
+ infd = fsrc.fileno()
98
+ outfd = fdst.fileno()
99
+ except Exception as err:
100
+ raise _GiveupOnFastCopy(err) # not a regular file
101
+
102
+ try:
103
+ posix._fcopyfile(infd, outfd, flags)
104
+ except OSError as err:
105
+ err.filename = fsrc.name
106
+ err.filename2 = fdst.name
107
+ if err.errno in {errno.EINVAL, errno.ENOTSUP}:
108
+ raise _GiveupOnFastCopy(err)
109
+ else:
110
+ raise err from None
111
+
112
+ def _fastcopy_sendfile(fsrc, fdst):
113
+ """Copy data from one regular mmap-like fd to another by using
114
+ high-performance sendfile(2) syscall.
115
+ This should work on Linux >= 2.6.33 only.
116
+ """
117
+ # Note: copyfileobj() is left alone in order to not introduce any
118
+ # unexpected breakage. Possible risks by using zero-copy calls
119
+ # in copyfileobj() are:
120
+ # - fdst cannot be open in "a"(ppend) mode
121
+ # - fsrc and fdst may be open in "t"(ext) mode
122
+ # - fsrc may be a BufferedReader (which hides unread data in a buffer),
123
+ # GzipFile (which decompresses data), HTTPResponse (which decodes
124
+ # chunks).
125
+ # - possibly others (e.g. encrypted fs/partition?)
126
+ global _USE_CP_SENDFILE
127
+ try:
128
+ infd = fsrc.fileno()
129
+ outfd = fdst.fileno()
130
+ except Exception as err:
131
+ raise _GiveupOnFastCopy(err) # not a regular file
132
+
133
+ # Hopefully the whole file will be copied in a single call.
134
+ # sendfile() is called in a loop 'till EOF is reached (0 return)
135
+ # so a bufsize smaller or bigger than the actual file size
136
+ # should not make any difference, also in case the file content
137
+ # changes while being copied.
138
+ try:
139
+ blocksize = max(os.fstat(infd).st_size, 2 ** 23) # min 8MiB
140
+ except OSError:
141
+ blocksize = 2 ** 27 # 128MiB
142
+ # On 32-bit architectures truncate to 1GiB to avoid OverflowError,
143
+ # see bpo-38319.
144
+ if sys.maxsize < 2 ** 32:
145
+ blocksize = min(blocksize, 2 ** 30)
146
+
147
+ offset = 0
148
+ while True:
149
+ try:
150
+ sent = os.sendfile(outfd, infd, offset, blocksize)
151
+ except OSError as err:
152
+ # ...in oder to have a more informative exception.
153
+ err.filename = fsrc.name
154
+ err.filename2 = fdst.name
155
+
156
+ if err.errno == errno.ENOTSOCK:
157
+ # sendfile() on this platform (probably Linux < 2.6.33)
158
+ # does not support copies between regular files (only
159
+ # sockets).
160
+ _USE_CP_SENDFILE = False
161
+ raise _GiveupOnFastCopy(err)
162
+
163
+ if err.errno == errno.ENOSPC: # filesystem is full
164
+ raise err from None
165
+
166
+ # Give up on first call and if no data was copied.
167
+ if offset == 0 and os.lseek(outfd, 0, os.SEEK_CUR) == 0:
168
+ raise _GiveupOnFastCopy(err)
169
+
170
+ raise err
171
+ else:
172
+ if sent == 0:
173
+ break # EOF
174
+ offset += sent
175
+
176
+ def _copyfileobj_readinto(fsrc, fdst, length=COPY_BUFSIZE):
177
+ """readinto()/memoryview() based variant of copyfileobj().
178
+ *fsrc* must support readinto() method and both files must be
179
+ open in binary mode.
180
+ """
181
+ # Localize variable access to minimize overhead.
182
+ fsrc_readinto = fsrc.readinto
183
+ fdst_write = fdst.write
184
+ with memoryview(bytearray(length)) as mv:
185
+ while True:
186
+ n = fsrc_readinto(mv)
187
+ if not n:
188
+ break
189
+ elif n < length:
190
+ with mv[:n] as smv:
191
+ fdst_write(smv)
192
+ break
193
+ else:
194
+ fdst_write(mv)
195
+
196
+ def copyfileobj(fsrc, fdst, length=0):
197
+ """copy data from file-like object fsrc to file-like object fdst"""
198
+ if not length:
199
+ length = COPY_BUFSIZE
200
+ # Localize variable access to minimize overhead.
201
+ fsrc_read = fsrc.read
202
+ fdst_write = fdst.write
203
+ while buf := fsrc_read(length):
204
+ fdst_write(buf)
205
+
206
+ def _samefile(src, dst):
207
+ # Macintosh, Unix.
208
+ if isinstance(src, os.DirEntry) and hasattr(os.path, 'samestat'):
209
+ try:
210
+ return os.path.samestat(src.stat(), os.stat(dst))
211
+ except OSError:
212
+ return False
213
+
214
+ if hasattr(os.path, 'samefile'):
215
+ try:
216
+ return os.path.samefile(src, dst)
217
+ except OSError:
218
+ return False
219
+
220
+ # All other platforms: check for same pathname.
221
+ return (os.path.normcase(os.path.abspath(src)) ==
222
+ os.path.normcase(os.path.abspath(dst)))
223
+
224
+ def _stat(fn):
225
+ return fn.stat() if isinstance(fn, os.DirEntry) else os.stat(fn)
226
+
227
+ def _islink(fn):
228
+ return fn.is_symlink() if isinstance(fn, os.DirEntry) else os.path.islink(fn)
229
+
230
+ def copyfile(src, dst, *, follow_symlinks=True):
231
+ """Copy data from src to dst in the most efficient way possible.
232
+
233
+ If follow_symlinks is not set and src is a symbolic link, a new
234
+ symlink will be created instead of copying the file it points to.
235
+
236
+ """
237
+ sys.audit("shutil.copyfile", src, dst)
238
+
239
+ if _samefile(src, dst):
240
+ raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
241
+
242
+ file_size = 0
243
+ for i, fn in enumerate([src, dst]):
244
+ try:
245
+ st = _stat(fn)
246
+ except OSError:
247
+ # File most likely does not exist
248
+ pass
249
+ else:
250
+ # XXX What about other special files? (sockets, devices...)
251
+ if stat.S_ISFIFO(st.st_mode):
252
+ fn = fn.path if isinstance(fn, os.DirEntry) else fn
253
+ raise SpecialFileError("`%s` is a named pipe" % fn)
254
+ if _WINDOWS and i == 0:
255
+ file_size = st.st_size
256
+
257
+ if not follow_symlinks and _islink(src):
258
+ os.symlink(os.readlink(src), dst)
259
+ else:
260
+ with open(src, 'rb') as fsrc:
261
+ try:
262
+ with open(dst, 'wb') as fdst:
263
+ # macOS
264
+ if _HAS_FCOPYFILE:
265
+ try:
266
+ _fastcopy_fcopyfile(fsrc, fdst, posix._COPYFILE_DATA)
267
+ return dst
268
+ except _GiveupOnFastCopy:
269
+ pass
270
+ # Linux
271
+ elif _USE_CP_SENDFILE:
272
+ try:
273
+ _fastcopy_sendfile(fsrc, fdst)
274
+ return dst
275
+ except _GiveupOnFastCopy:
276
+ pass
277
+ # Windows, see:
278
+ # https://github.com/python/cpython/pull/7160#discussion_r195405230
279
+ elif _WINDOWS and file_size > 0:
280
+ _copyfileobj_readinto(fsrc, fdst, min(file_size, COPY_BUFSIZE))
281
+ return dst
282
+
283
+ copyfileobj(fsrc, fdst)
284
+
285
+ # Issue 43219, raise a less confusing exception
286
+ except IsADirectoryError as e:
287
+ if not os.path.exists(dst):
288
+ raise FileNotFoundError(f'Directory does not exist: {dst}') from e
289
+ else:
290
+ raise
291
+
292
+ return dst
293
+
294
+ def copymode(src, dst, *, follow_symlinks=True):
295
+ """Copy mode bits from src to dst.
296
+
297
+ If follow_symlinks is not set, symlinks aren't followed if and only
298
+ if both `src` and `dst` are symlinks. If `lchmod` isn't available
299
+ (e.g. Linux) this method does nothing.
300
+
301
+ """
302
+ sys.audit("shutil.copymode", src, dst)
303
+
304
+ if not follow_symlinks and _islink(src) and os.path.islink(dst):
305
+ if hasattr(os, 'lchmod'):
306
+ stat_func, chmod_func = os.lstat, os.lchmod
307
+ else:
308
+ return
309
+ else:
310
+ stat_func = _stat
311
+ if os.name == 'nt' and os.path.islink(dst):
312
+ def chmod_func(*args):
313
+ os.chmod(*args, follow_symlinks=True)
314
+ else:
315
+ chmod_func = os.chmod
316
+
317
+ st = stat_func(src)
318
+ chmod_func(dst, stat.S_IMODE(st.st_mode))
319
+
320
+ if hasattr(os, 'listxattr'):
321
+ def _copyxattr(src, dst, *, follow_symlinks=True):
322
+ """Copy extended filesystem attributes from `src` to `dst`.
323
+
324
+ Overwrite existing attributes.
325
+
326
+ If `follow_symlinks` is false, symlinks won't be followed.
327
+
328
+ """
329
+
330
+ try:
331
+ names = os.listxattr(src, follow_symlinks=follow_symlinks)
332
+ except OSError as e:
333
+ if e.errno not in (errno.ENOTSUP, errno.ENODATA, errno.EINVAL):
334
+ raise
335
+ return
336
+ for name in names:
337
+ try:
338
+ value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
339
+ os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
340
+ except OSError as e:
341
+ if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA,
342
+ errno.EINVAL, errno.EACCES):
343
+ raise
344
+ else:
345
+ def _copyxattr(*args, **kwargs):
346
+ pass
347
+
348
+ def copystat(src, dst, *, follow_symlinks=True):
349
+ """Copy file metadata
350
+
351
+ Copy the permission bits, last access time, last modification time, and
352
+ flags from `src` to `dst`. On Linux, copystat() also copies the "extended
353
+ attributes" where possible. The file contents, owner, and group are
354
+ unaffected. `src` and `dst` are path-like objects or path names given as
355
+ strings.
356
+
357
+ If the optional flag `follow_symlinks` is not set, symlinks aren't
358
+ followed if and only if both `src` and `dst` are symlinks.
359
+ """
360
+ sys.audit("shutil.copystat", src, dst)
361
+
362
+ def _nop(*args, ns=None, follow_symlinks=None):
363
+ pass
364
+
365
+ # follow symlinks (aka don't not follow symlinks)
366
+ follow = follow_symlinks or not (_islink(src) and os.path.islink(dst))
367
+ if follow:
368
+ # use the real function if it exists
369
+ def lookup(name):
370
+ return getattr(os, name, _nop)
371
+ else:
372
+ # use the real function only if it exists
373
+ # *and* it supports follow_symlinks
374
+ def lookup(name):
375
+ fn = getattr(os, name, _nop)
376
+ if fn in os.supports_follow_symlinks:
377
+ return fn
378
+ return _nop
379
+
380
+ if isinstance(src, os.DirEntry):
381
+ st = src.stat(follow_symlinks=follow)
382
+ else:
383
+ st = lookup("stat")(src, follow_symlinks=follow)
384
+ mode = stat.S_IMODE(st.st_mode)
385
+ lookup("utime")(dst, ns=(st.st_atime_ns, st.st_mtime_ns),
386
+ follow_symlinks=follow)
387
+ # We must copy extended attributes before the file is (potentially)
388
+ # chmod()'ed read-only, otherwise setxattr() will error with -EACCES.
389
+ _copyxattr(src, dst, follow_symlinks=follow)
390
+ try:
391
+ lookup("chmod")(dst, mode, follow_symlinks=follow)
392
+ except NotImplementedError:
393
+ # if we got a NotImplementedError, it's because
394
+ # * follow_symlinks=False,
395
+ # * lchown() is unavailable, and
396
+ # * either
397
+ # * fchownat() is unavailable or
398
+ # * fchownat() doesn't implement AT_SYMLINK_NOFOLLOW.
399
+ # (it returned ENOSUP.)
400
+ # therefore we're out of options--we simply cannot chown the
401
+ # symlink. give up, suppress the error.
402
+ # (which is what shutil always did in this circumstance.)
403
+ pass
404
+ if hasattr(st, 'st_flags'):
405
+ try:
406
+ lookup("chflags")(dst, st.st_flags, follow_symlinks=follow)
407
+ except OSError as why:
408
+ for err in 'EOPNOTSUPP', 'ENOTSUP':
409
+ if hasattr(errno, err) and why.errno == getattr(errno, err):
410
+ break
411
+ else:
412
+ raise
413
+
414
+ def copy(src, dst, *, follow_symlinks=True):
415
+ """Copy data and mode bits ("cp src dst"). Return the file's destination.
416
+
417
+ The destination may be a directory.
418
+
419
+ If follow_symlinks is false, symlinks won't be followed. This
420
+ resembles GNU's "cp -P src dst".
421
+
422
+ If source and destination are the same file, a SameFileError will be
423
+ raised.
424
+
425
+ """
426
+ if os.path.isdir(dst):
427
+ dst = os.path.join(dst, os.path.basename(src))
428
+ copyfile(src, dst, follow_symlinks=follow_symlinks)
429
+ copymode(src, dst, follow_symlinks=follow_symlinks)
430
+ return dst
431
+
432
+ def copy2(src, dst, *, follow_symlinks=True):
433
+ """Copy data and metadata. Return the file's destination.
434
+
435
+ Metadata is copied with copystat(). Please see the copystat function
436
+ for more information.
437
+
438
+ The destination may be a directory.
439
+
440
+ If follow_symlinks is false, symlinks won't be followed. This
441
+ resembles GNU's "cp -P src dst".
442
+ """
443
+ if os.path.isdir(dst):
444
+ dst = os.path.join(dst, os.path.basename(src))
445
+
446
+ if hasattr(_winapi, "CopyFile2"):
447
+ src_ = os.fsdecode(src)
448
+ dst_ = os.fsdecode(dst)
449
+ flags = _winapi.COPY_FILE_ALLOW_DECRYPTED_DESTINATION # for compat
450
+ if not follow_symlinks:
451
+ flags |= _winapi.COPY_FILE_COPY_SYMLINK
452
+ try:
453
+ _winapi.CopyFile2(src_, dst_, flags)
454
+ return dst
455
+ except OSError as exc:
456
+ if (exc.winerror == _winapi.ERROR_PRIVILEGE_NOT_HELD
457
+ and not follow_symlinks):
458
+ # Likely encountered a symlink we aren't allowed to create.
459
+ # Fall back on the old code
460
+ pass
461
+ elif exc.winerror == _winapi.ERROR_ACCESS_DENIED:
462
+ # Possibly encountered a hidden or readonly file we can't
463
+ # overwrite. Fall back on old code
464
+ pass
465
+ else:
466
+ raise
467
+
468
+ copyfile(src, dst, follow_symlinks=follow_symlinks)
469
+ copystat(src, dst, follow_symlinks=follow_symlinks)
470
+ return dst
471
+
472
+ def ignore_patterns(*patterns):
473
+ """Function that can be used as copytree() ignore parameter.
474
+
475
+ Patterns is a sequence of glob-style patterns
476
+ that are used to exclude files"""
477
+ def _ignore_patterns(path, names):
478
+ ignored_names = []
479
+ for pattern in patterns:
480
+ ignored_names.extend(fnmatch.filter(names, pattern))
481
+ return set(ignored_names)
482
+ return _ignore_patterns
483
+
484
+ def _copytree(entries, src, dst, symlinks, ignore, copy_function,
485
+ ignore_dangling_symlinks, dirs_exist_ok=False):
486
+ if ignore is not None:
487
+ ignored_names = ignore(os.fspath(src), [x.name for x in entries])
488
+ else:
489
+ ignored_names = ()
490
+
491
+ os.makedirs(dst, exist_ok=dirs_exist_ok)
492
+ errors = []
493
+ use_srcentry = copy_function is copy2 or copy_function is copy
494
+
495
+ for srcentry in entries:
496
+ if srcentry.name in ignored_names:
497
+ continue
498
+ srcname = os.path.join(src, srcentry.name)
499
+ dstname = os.path.join(dst, srcentry.name)
500
+ srcobj = srcentry if use_srcentry else srcname
501
+ try:
502
+ is_symlink = srcentry.is_symlink()
503
+ if is_symlink and os.name == 'nt':
504
+ # Special check for directory junctions, which appear as
505
+ # symlinks but we want to recurse.
506
+ lstat = srcentry.stat(follow_symlinks=False)
507
+ if lstat.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT:
508
+ is_symlink = False
509
+ if is_symlink:
510
+ linkto = os.readlink(srcname)
511
+ if symlinks:
512
+ # We can't just leave it to `copy_function` because legacy
513
+ # code with a custom `copy_function` may rely on copytree
514
+ # doing the right thing.
515
+ os.symlink(linkto, dstname)
516
+ copystat(srcobj, dstname, follow_symlinks=not symlinks)
517
+ else:
518
+ # ignore dangling symlink if the flag is on
519
+ if not os.path.exists(linkto) and ignore_dangling_symlinks:
520
+ continue
521
+ # otherwise let the copy occur. copy2 will raise an error
522
+ if srcentry.is_dir():
523
+ copytree(srcobj, dstname, symlinks, ignore,
524
+ copy_function, ignore_dangling_symlinks,
525
+ dirs_exist_ok)
526
+ else:
527
+ copy_function(srcobj, dstname)
528
+ elif srcentry.is_dir():
529
+ copytree(srcobj, dstname, symlinks, ignore, copy_function,
530
+ ignore_dangling_symlinks, dirs_exist_ok)
531
+ else:
532
+ # Will raise a SpecialFileError for unsupported file types
533
+ copy_function(srcobj, dstname)
534
+ # catch the Error from the recursive copytree so that we can
535
+ # continue with other files
536
+ except Error as err:
537
+ errors.extend(err.args[0])
538
+ except OSError as why:
539
+ errors.append((srcname, dstname, str(why)))
540
+ try:
541
+ copystat(src, dst)
542
+ except OSError as why:
543
+ # Copying file access times may fail on Windows
544
+ if getattr(why, 'winerror', None) is None:
545
+ errors.append((src, dst, str(why)))
546
+ if errors:
547
+ raise Error(errors)
548
+ return dst
549
+
550
+ def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
551
+ ignore_dangling_symlinks=False, dirs_exist_ok=False):
552
+ """Recursively copy a directory tree and return the destination directory.
553
+
554
+ If exception(s) occur, an Error is raised with a list of reasons.
555
+
556
+ If the optional symlinks flag is true, symbolic links in the
557
+ source tree result in symbolic links in the destination tree; if
558
+ it is false, the contents of the files pointed to by symbolic
559
+ links are copied. If the file pointed to by the symlink doesn't
560
+ exist, an exception will be added in the list of errors raised in
561
+ an Error exception at the end of the copy process.
562
+
563
+ You can set the optional ignore_dangling_symlinks flag to true if you
564
+ want to silence this exception. Notice that this has no effect on
565
+ platforms that don't support os.symlink.
566
+
567
+ The optional ignore argument is a callable. If given, it
568
+ is called with the `src` parameter, which is the directory
569
+ being visited by copytree(), and `names` which is the list of
570
+ `src` contents, as returned by os.listdir():
571
+
572
+ callable(src, names) -> ignored_names
573
+
574
+ Since copytree() is called recursively, the callable will be
575
+ called once for each directory that is copied. It returns a
576
+ list of names relative to the `src` directory that should
577
+ not be copied.
578
+
579
+ The optional copy_function argument is a callable that will be used
580
+ to copy each file. It will be called with the source path and the
581
+ destination path as arguments. By default, copy2() is used, but any
582
+ function that supports the same signature (like copy()) can be used.
583
+
584
+ If dirs_exist_ok is false (the default) and `dst` already exists, a
585
+ `FileExistsError` is raised. If `dirs_exist_ok` is true, the copying
586
+ operation will continue if it encounters existing directories, and files
587
+ within the `dst` tree will be overwritten by corresponding files from the
588
+ `src` tree.
589
+ """
590
+ sys.audit("shutil.copytree", src, dst)
591
+ with os.scandir(src) as itr:
592
+ entries = list(itr)
593
+ return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
594
+ ignore=ignore, copy_function=copy_function,
595
+ ignore_dangling_symlinks=ignore_dangling_symlinks,
596
+ dirs_exist_ok=dirs_exist_ok)
597
+
598
+ if hasattr(os.stat_result, 'st_file_attributes'):
599
+ def _rmtree_islink(st):
600
+ return (stat.S_ISLNK(st.st_mode) or
601
+ (st.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
602
+ and st.st_reparse_tag == stat.IO_REPARSE_TAG_MOUNT_POINT))
603
+ else:
604
+ def _rmtree_islink(st):
605
+ return stat.S_ISLNK(st.st_mode)
606
+
607
+ # version vulnerable to race conditions
608
+ def _rmtree_unsafe(path, onexc):
609
+ def onerror(err):
610
+ if not isinstance(err, FileNotFoundError):
611
+ onexc(os.scandir, err.filename, err)
612
+ results = os.walk(path, topdown=False, onerror=onerror, followlinks=os._walk_symlinks_as_files)
613
+ for dirpath, dirnames, filenames in results:
614
+ for name in dirnames:
615
+ fullname = os.path.join(dirpath, name)
616
+ try:
617
+ os.rmdir(fullname)
618
+ except FileNotFoundError:
619
+ continue
620
+ except OSError as err:
621
+ onexc(os.rmdir, fullname, err)
622
+ for name in filenames:
623
+ fullname = os.path.join(dirpath, name)
624
+ try:
625
+ os.unlink(fullname)
626
+ except FileNotFoundError:
627
+ continue
628
+ except OSError as err:
629
+ onexc(os.unlink, fullname, err)
630
+ try:
631
+ os.rmdir(path)
632
+ except FileNotFoundError:
633
+ pass
634
+ except OSError as err:
635
+ onexc(os.rmdir, path, err)
636
+
637
+ # Version using fd-based APIs to protect against races
638
+ def _rmtree_safe_fd(stack, onexc):
639
+ # Each stack item has four elements:
640
+ # * func: The first operation to perform: os.lstat, os.close or os.rmdir.
641
+ # Walking a directory starts with an os.lstat() to detect symlinks; in
642
+ # this case, func is updated before subsequent operations and passed to
643
+ # onexc() if an error occurs.
644
+ # * dirfd: Open file descriptor, or None if we're processing the top-level
645
+ # directory given to rmtree() and the user didn't supply dir_fd.
646
+ # * path: Path of file to operate upon. This is passed to onexc() if an
647
+ # error occurs.
648
+ # * orig_entry: os.DirEntry, or None if we're processing the top-level
649
+ # directory given to rmtree(). We used the cached stat() of the entry to
650
+ # save a call to os.lstat() when walking subdirectories.
651
+ func, dirfd, path, orig_entry = stack.pop()
652
+ name = path if orig_entry is None else orig_entry.name
653
+ try:
654
+ if func is os.close:
655
+ os.close(dirfd)
656
+ return
657
+ if func is os.rmdir:
658
+ os.rmdir(name, dir_fd=dirfd)
659
+ return
660
+
661
+ # Note: To guard against symlink races, we use the standard
662
+ # lstat()/open()/fstat() trick.
663
+ assert func is os.lstat
664
+ if orig_entry is None:
665
+ orig_st = os.lstat(name, dir_fd=dirfd)
666
+ else:
667
+ orig_st = orig_entry.stat(follow_symlinks=False)
668
+
669
+ func = os.open # For error reporting.
670
+ topfd = os.open(name, os.O_RDONLY | os.O_NONBLOCK, dir_fd=dirfd)
671
+
672
+ func = os.path.islink # For error reporting.
673
+ try:
674
+ if not os.path.samestat(orig_st, os.fstat(topfd)):
675
+ # Symlinks to directories are forbidden, see GH-46010.
676
+ raise OSError("Cannot call rmtree on a symbolic link")
677
+ stack.append((os.rmdir, dirfd, path, orig_entry))
678
+ finally:
679
+ stack.append((os.close, topfd, path, orig_entry))
680
+
681
+ func = os.scandir # For error reporting.
682
+ with os.scandir(topfd) as scandir_it:
683
+ entries = list(scandir_it)
684
+ for entry in entries:
685
+ fullname = os.path.join(path, entry.name)
686
+ try:
687
+ if entry.is_dir(follow_symlinks=False):
688
+ # Traverse into sub-directory.
689
+ stack.append((os.lstat, topfd, fullname, entry))
690
+ continue
691
+ except FileNotFoundError:
692
+ continue
693
+ except OSError:
694
+ pass
695
+ try:
696
+ os.unlink(entry.name, dir_fd=topfd)
697
+ except FileNotFoundError:
698
+ continue
699
+ except OSError as err:
700
+ onexc(os.unlink, fullname, err)
701
+ except FileNotFoundError as err:
702
+ if orig_entry is None or func is os.close:
703
+ err.filename = path
704
+ onexc(func, path, err)
705
+ except OSError as err:
706
+ err.filename = path
707
+ onexc(func, path, err)
708
+
709
+ _use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
710
+ os.supports_dir_fd and
711
+ os.scandir in os.supports_fd and
712
+ os.stat in os.supports_follow_symlinks)
713
+
714
+ def rmtree(path, ignore_errors=False, onerror=None, *, onexc=None, dir_fd=None):
715
+ """Recursively delete a directory tree.
716
+
717
+ If dir_fd is not None, it should be a file descriptor open to a directory;
718
+ path will then be relative to that directory.
719
+ dir_fd may not be implemented on your platform.
720
+ If it is unavailable, using it will raise a NotImplementedError.
721
+
722
+ If ignore_errors is set, errors are ignored; otherwise, if onexc or
723
+ onerror is set, it is called to handle the error with arguments (func,
724
+ path, exc_info) where func is platform and implementation dependent;
725
+ path is the argument to that function that caused it to fail; and
726
+ the value of exc_info describes the exception. For onexc it is the
727
+ exception instance, and for onerror it is a tuple as returned by
728
+ sys.exc_info(). If ignore_errors is false and both onexc and
729
+ onerror are None, the exception is reraised.
730
+
731
+ onerror is deprecated and only remains for backwards compatibility.
732
+ If both onerror and onexc are set, onerror is ignored and onexc is used.
733
+ """
734
+
735
+ sys.audit("shutil.rmtree", path, dir_fd)
736
+ if ignore_errors:
737
+ def onexc(*args):
738
+ pass
739
+ elif onerror is None and onexc is None:
740
+ def onexc(*args):
741
+ raise
742
+ elif onexc is None:
743
+ if onerror is None:
744
+ def onexc(*args):
745
+ raise
746
+ else:
747
+ # delegate to onerror
748
+ def onexc(*args):
749
+ func, path, exc = args
750
+ if exc is None:
751
+ exc_info = None, None, None
752
+ else:
753
+ exc_info = type(exc), exc, exc.__traceback__
754
+ return onerror(func, path, exc_info)
755
+
756
+ if _use_fd_functions:
757
+ # While the unsafe rmtree works fine on bytes, the fd based does not.
758
+ if isinstance(path, bytes):
759
+ path = os.fsdecode(path)
760
+ stack = [(os.lstat, dir_fd, path, None)]
761
+ try:
762
+ while stack:
763
+ _rmtree_safe_fd(stack, onexc)
764
+ finally:
765
+ # Close any file descriptors still on the stack.
766
+ while stack:
767
+ func, fd, path, entry = stack.pop()
768
+ if func is not os.close:
769
+ continue
770
+ try:
771
+ os.close(fd)
772
+ except OSError as err:
773
+ onexc(os.close, path, err)
774
+ else:
775
+ if dir_fd is not None:
776
+ raise NotImplementedError("dir_fd unavailable on this platform")
777
+ try:
778
+ st = os.lstat(path)
779
+ except OSError as err:
780
+ onexc(os.lstat, path, err)
781
+ return
782
+ try:
783
+ if _rmtree_islink(st):
784
+ # symlinks to directories are forbidden, see bug #1669
785
+ raise OSError("Cannot call rmtree on a symbolic link")
786
+ except OSError as err:
787
+ onexc(os.path.islink, path, err)
788
+ # can't continue even if onexc hook returns
789
+ return
790
+ return _rmtree_unsafe(path, onexc)
791
+
792
+ # Allow introspection of whether or not the hardening against symlink
793
+ # attacks is supported on the current platform
794
+ rmtree.avoids_symlink_attacks = _use_fd_functions
795
+
796
+ def _basename(path):
797
+ """A basename() variant which first strips the trailing slash, if present.
798
+ Thus we always get the last component of the path, even for directories.
799
+
800
+ path: Union[PathLike, str]
801
+
802
+ e.g.
803
+ >>> os.path.basename('/bar/foo')
804
+ 'foo'
805
+ >>> os.path.basename('/bar/foo/')
806
+ ''
807
+ >>> _basename('/bar/foo/')
808
+ 'foo'
809
+ """
810
+ path = os.fspath(path)
811
+ sep = os.path.sep + (os.path.altsep or '')
812
+ return os.path.basename(path.rstrip(sep))
813
+
814
+ def move(src, dst, copy_function=copy2):
815
+ """Recursively move a file or directory to another location. This is
816
+ similar to the Unix "mv" command. Return the file or directory's
817
+ destination.
818
+
819
+ If dst is an existing directory or a symlink to a directory, then src is
820
+ moved inside that directory. The destination path in that directory must
821
+ not already exist.
822
+
823
+ If dst already exists but is not a directory, it may be overwritten
824
+ depending on os.rename() semantics.
825
+
826
+ os.rename() is preferably used if the source and destination are on the
827
+ same filesystem. In case os.rename() fails due to OSError (e.g. the user
828
+ has write permission to *dst* file but not to its parent directory),
829
+ this method falls back to using *copy_function* silently.
830
+ Symlinks are also recreated under the new name if os.rename() fails
831
+ because of cross filesystem renames.
832
+
833
+ It's recommended to use os.rename() if atomic move is strictly required.
834
+
835
+ The optional `copy_function` argument is a callable that will be used
836
+ to copy the source or it will be delegated to `copytree`.
837
+ By default, copy2() is used, but any function that supports the same
838
+ signature (like copy()) can be used.
839
+
840
+ A lot more could be done here... A look at a mv.c shows a lot of
841
+ the issues this implementation glosses over.
842
+
843
+ """
844
+ sys.audit("shutil.move", src, dst)
845
+ real_dst = dst
846
+ if os.path.isdir(dst):
847
+ if _samefile(src, dst) and not os.path.islink(src):
848
+ # We might be on a case insensitive filesystem,
849
+ # perform the rename anyway.
850
+ os.rename(src, dst)
851
+ return
852
+
853
+ # Using _basename instead of os.path.basename is important, as we must
854
+ # ignore any trailing slash to avoid the basename returning ''
855
+ real_dst = os.path.join(dst, _basename(src))
856
+
857
+ if os.path.exists(real_dst):
858
+ raise Error("Destination path '%s' already exists" % real_dst)
859
+ try:
860
+ os.rename(src, real_dst)
861
+ except OSError:
862
+ if os.path.islink(src):
863
+ linkto = os.readlink(src)
864
+ os.symlink(linkto, real_dst)
865
+ os.unlink(src)
866
+ elif os.path.isdir(src):
867
+ if _destinsrc(src, dst):
868
+ raise Error("Cannot move a directory '%s' into itself"
869
+ " '%s'." % (src, dst))
870
+ if (_is_immutable(src)
871
+ or (not os.access(src, os.W_OK) and os.listdir(src)
872
+ and sys.platform == 'darwin')):
873
+ raise PermissionError("Cannot move the non-empty directory "
874
+ "'%s': Lacking write permission to '%s'."
875
+ % (src, src))
876
+ copytree(src, real_dst, copy_function=copy_function,
877
+ symlinks=True)
878
+ rmtree(src)
879
+ else:
880
+ copy_function(src, real_dst)
881
+ os.unlink(src)
882
+ return real_dst
883
+
884
+ def _destinsrc(src, dst):
885
+ src = os.path.realpath(src)
886
+ dst = os.path.realpath(dst)
887
+ if not src.endswith(os.path.sep):
888
+ src += os.path.sep
889
+ if not dst.endswith(os.path.sep):
890
+ dst += os.path.sep
891
+ return dst.startswith(src)
892
+
893
+ def _is_immutable(src):
894
+ st = _stat(src)
895
+ immutable_states = [stat.UF_IMMUTABLE, stat.SF_IMMUTABLE]
896
+ return hasattr(st, 'st_flags') and st.st_flags in immutable_states
897
+
898
+ def _get_gid(name):
899
+ """Returns a gid, given a group name."""
900
+ if name is None:
901
+ return None
902
+
903
+ try:
904
+ from grp import getgrnam
905
+ except ImportError:
906
+ return None
907
+
908
+ try:
909
+ result = getgrnam(name)
910
+ except KeyError:
911
+ result = None
912
+ if result is not None:
913
+ return result[2]
914
+ return None
915
+
916
+ def _get_uid(name):
917
+ """Returns an uid, given a user name."""
918
+ if name is None:
919
+ return None
920
+
921
+ try:
922
+ from pwd import getpwnam
923
+ except ImportError:
924
+ return None
925
+
926
+ try:
927
+ result = getpwnam(name)
928
+ except KeyError:
929
+ result = None
930
+ if result is not None:
931
+ return result[2]
932
+ return None
933
+
934
+ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
935
+ owner=None, group=None, logger=None, root_dir=None):
936
+ """Create a (possibly compressed) tar file from all the files under
937
+ 'base_dir'.
938
+
939
+ 'compress' must be "gzip" (the default), "bzip2", "xz", or None.
940
+
941
+ 'owner' and 'group' can be used to define an owner and a group for the
942
+ archive that is being built. If not provided, the current owner and group
943
+ will be used.
944
+
945
+ The output tar file will be named 'base_name' + ".tar", possibly plus
946
+ the appropriate compression extension (".gz", ".bz2", or ".xz").
947
+
948
+ Returns the output filename.
949
+ """
950
+ if compress is None:
951
+ tar_compression = ''
952
+ elif _ZLIB_SUPPORTED and compress == 'gzip':
953
+ tar_compression = 'gz'
954
+ elif _BZ2_SUPPORTED and compress == 'bzip2':
955
+ tar_compression = 'bz2'
956
+ elif _LZMA_SUPPORTED and compress == 'xz':
957
+ tar_compression = 'xz'
958
+ else:
959
+ raise ValueError("bad value for 'compress', or compression format not "
960
+ "supported : {0}".format(compress))
961
+
962
+ import tarfile # late import for breaking circular dependency
963
+
964
+ compress_ext = '.' + tar_compression if compress else ''
965
+ archive_name = base_name + '.tar' + compress_ext
966
+ archive_dir = os.path.dirname(archive_name)
967
+
968
+ if archive_dir and not os.path.exists(archive_dir):
969
+ if logger is not None:
970
+ logger.info("creating %s", archive_dir)
971
+ if not dry_run:
972
+ os.makedirs(archive_dir)
973
+
974
+ # creating the tarball
975
+ if logger is not None:
976
+ logger.info('Creating tar archive')
977
+
978
+ uid = _get_uid(owner)
979
+ gid = _get_gid(group)
980
+
981
+ def _set_uid_gid(tarinfo):
982
+ if gid is not None:
983
+ tarinfo.gid = gid
984
+ tarinfo.gname = group
985
+ if uid is not None:
986
+ tarinfo.uid = uid
987
+ tarinfo.uname = owner
988
+ return tarinfo
989
+
990
+ if not dry_run:
991
+ tar = tarfile.open(archive_name, 'w|%s' % tar_compression)
992
+ arcname = base_dir
993
+ if root_dir is not None:
994
+ base_dir = os.path.join(root_dir, base_dir)
995
+ try:
996
+ tar.add(base_dir, arcname, filter=_set_uid_gid)
997
+ finally:
998
+ tar.close()
999
+
1000
+ if root_dir is not None:
1001
+ archive_name = os.path.abspath(archive_name)
1002
+ return archive_name
1003
+
1004
+ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0,
1005
+ logger=None, owner=None, group=None, root_dir=None):
1006
+ """Create a zip file from all the files under 'base_dir'.
1007
+
1008
+ The output zip file will be named 'base_name' + ".zip". Returns the
1009
+ name of the output zip file.
1010
+ """
1011
+ import zipfile # late import for breaking circular dependency
1012
+
1013
+ zip_filename = base_name + ".zip"
1014
+ archive_dir = os.path.dirname(base_name)
1015
+
1016
+ if archive_dir and not os.path.exists(archive_dir):
1017
+ if logger is not None:
1018
+ logger.info("creating %s", archive_dir)
1019
+ if not dry_run:
1020
+ os.makedirs(archive_dir)
1021
+
1022
+ if logger is not None:
1023
+ logger.info("creating '%s' and adding '%s' to it",
1024
+ zip_filename, base_dir)
1025
+
1026
+ if not dry_run:
1027
+ with zipfile.ZipFile(zip_filename, "w",
1028
+ compression=zipfile.ZIP_DEFLATED) as zf:
1029
+ arcname = os.path.normpath(base_dir)
1030
+ if root_dir is not None:
1031
+ base_dir = os.path.join(root_dir, base_dir)
1032
+ base_dir = os.path.normpath(base_dir)
1033
+ if arcname != os.curdir:
1034
+ zf.write(base_dir, arcname)
1035
+ if logger is not None:
1036
+ logger.info("adding '%s'", base_dir)
1037
+ for dirpath, dirnames, filenames in os.walk(base_dir):
1038
+ arcdirpath = dirpath
1039
+ if root_dir is not None:
1040
+ arcdirpath = os.path.relpath(arcdirpath, root_dir)
1041
+ arcdirpath = os.path.normpath(arcdirpath)
1042
+ for name in sorted(dirnames):
1043
+ path = os.path.join(dirpath, name)
1044
+ arcname = os.path.join(arcdirpath, name)
1045
+ zf.write(path, arcname)
1046
+ if logger is not None:
1047
+ logger.info("adding '%s'", path)
1048
+ for name in filenames:
1049
+ path = os.path.join(dirpath, name)
1050
+ path = os.path.normpath(path)
1051
+ if os.path.isfile(path):
1052
+ arcname = os.path.join(arcdirpath, name)
1053
+ zf.write(path, arcname)
1054
+ if logger is not None:
1055
+ logger.info("adding '%s'", path)
1056
+
1057
+ if root_dir is not None:
1058
+ zip_filename = os.path.abspath(zip_filename)
1059
+ return zip_filename
1060
+
1061
+ _make_tarball.supports_root_dir = True
1062
+ _make_zipfile.supports_root_dir = True
1063
+
1064
+ # Maps the name of the archive format to a tuple containing:
1065
+ # * the archiving function
1066
+ # * extra keyword arguments
1067
+ # * description
1068
+ _ARCHIVE_FORMATS = {
1069
+ 'tar': (_make_tarball, [('compress', None)],
1070
+ "uncompressed tar file"),
1071
+ }
1072
+
1073
+ if _ZLIB_SUPPORTED:
1074
+ _ARCHIVE_FORMATS['gztar'] = (_make_tarball, [('compress', 'gzip')],
1075
+ "gzip'ed tar-file")
1076
+ _ARCHIVE_FORMATS['zip'] = (_make_zipfile, [], "ZIP file")
1077
+
1078
+ if _BZ2_SUPPORTED:
1079
+ _ARCHIVE_FORMATS['bztar'] = (_make_tarball, [('compress', 'bzip2')],
1080
+ "bzip2'ed tar-file")
1081
+
1082
+ if _LZMA_SUPPORTED:
1083
+ _ARCHIVE_FORMATS['xztar'] = (_make_tarball, [('compress', 'xz')],
1084
+ "xz'ed tar-file")
1085
+
1086
+ def get_archive_formats():
1087
+ """Returns a list of supported formats for archiving and unarchiving.
1088
+
1089
+ Each element of the returned sequence is a tuple (name, description)
1090
+ """
1091
+ formats = [(name, registry[2]) for name, registry in
1092
+ _ARCHIVE_FORMATS.items()]
1093
+ formats.sort()
1094
+ return formats
1095
+
1096
+ def register_archive_format(name, function, extra_args=None, description=''):
1097
+ """Registers an archive format.
1098
+
1099
+ name is the name of the format. function is the callable that will be
1100
+ used to create archives. If provided, extra_args is a sequence of
1101
+ (name, value) tuples that will be passed as arguments to the callable.
1102
+ description can be provided to describe the format, and will be returned
1103
+ by the get_archive_formats() function.
1104
+ """
1105
+ if extra_args is None:
1106
+ extra_args = []
1107
+ if not callable(function):
1108
+ raise TypeError('The %s object is not callable' % function)
1109
+ if not isinstance(extra_args, (tuple, list)):
1110
+ raise TypeError('extra_args needs to be a sequence')
1111
+ for element in extra_args:
1112
+ if not isinstance(element, (tuple, list)) or len(element) !=2:
1113
+ raise TypeError('extra_args elements are : (arg_name, value)')
1114
+
1115
+ _ARCHIVE_FORMATS[name] = (function, extra_args, description)
1116
+
1117
+ def unregister_archive_format(name):
1118
+ del _ARCHIVE_FORMATS[name]
1119
+
1120
+ def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
1121
+ dry_run=0, owner=None, group=None, logger=None):
1122
+ """Create an archive file (eg. zip or tar).
1123
+
1124
+ 'base_name' is the name of the file to create, minus any format-specific
1125
+ extension; 'format' is the archive format: one of "zip", "tar", "gztar",
1126
+ "bztar", or "xztar". Or any other registered format.
1127
+
1128
+ 'root_dir' is a directory that will be the root directory of the
1129
+ archive; ie. we typically chdir into 'root_dir' before creating the
1130
+ archive. 'base_dir' is the directory where we start archiving from;
1131
+ ie. 'base_dir' will be the common prefix of all files and
1132
+ directories in the archive. 'root_dir' and 'base_dir' both default
1133
+ to the current directory. Returns the name of the archive file.
1134
+
1135
+ 'owner' and 'group' are used when creating a tar archive. By default,
1136
+ uses the current owner and group.
1137
+ """
1138
+ sys.audit("shutil.make_archive", base_name, format, root_dir, base_dir)
1139
+ try:
1140
+ format_info = _ARCHIVE_FORMATS[format]
1141
+ except KeyError:
1142
+ raise ValueError("unknown archive format '%s'" % format) from None
1143
+
1144
+ kwargs = {'dry_run': dry_run, 'logger': logger,
1145
+ 'owner': owner, 'group': group}
1146
+
1147
+ func = format_info[0]
1148
+ for arg, val in format_info[1]:
1149
+ kwargs[arg] = val
1150
+
1151
+ if base_dir is None:
1152
+ base_dir = os.curdir
1153
+
1154
+ supports_root_dir = getattr(func, 'supports_root_dir', False)
1155
+ save_cwd = None
1156
+ if root_dir is not None:
1157
+ stmd = os.stat(root_dir).st_mode
1158
+ if not stat.S_ISDIR(stmd):
1159
+ raise NotADirectoryError(errno.ENOTDIR, 'Not a directory', root_dir)
1160
+
1161
+ if supports_root_dir:
1162
+ # Support path-like base_name here for backwards-compatibility.
1163
+ base_name = os.fspath(base_name)
1164
+ kwargs['root_dir'] = root_dir
1165
+ else:
1166
+ save_cwd = os.getcwd()
1167
+ if logger is not None:
1168
+ logger.debug("changing into '%s'", root_dir)
1169
+ base_name = os.path.abspath(base_name)
1170
+ if not dry_run:
1171
+ os.chdir(root_dir)
1172
+
1173
+ try:
1174
+ filename = func(base_name, base_dir, **kwargs)
1175
+ finally:
1176
+ if save_cwd is not None:
1177
+ if logger is not None:
1178
+ logger.debug("changing back to '%s'", save_cwd)
1179
+ os.chdir(save_cwd)
1180
+
1181
+ return filename
1182
+
1183
+
1184
+ def get_unpack_formats():
1185
+ """Returns a list of supported formats for unpacking.
1186
+
1187
+ Each element of the returned sequence is a tuple
1188
+ (name, extensions, description)
1189
+ """
1190
+ formats = [(name, info[0], info[3]) for name, info in
1191
+ _UNPACK_FORMATS.items()]
1192
+ formats.sort()
1193
+ return formats
1194
+
1195
+ def _check_unpack_options(extensions, function, extra_args):
1196
+ """Checks what gets registered as an unpacker."""
1197
+ # first make sure no other unpacker is registered for this extension
1198
+ existing_extensions = {}
1199
+ for name, info in _UNPACK_FORMATS.items():
1200
+ for ext in info[0]:
1201
+ existing_extensions[ext] = name
1202
+
1203
+ for extension in extensions:
1204
+ if extension in existing_extensions:
1205
+ msg = '%s is already registered for "%s"'
1206
+ raise RegistryError(msg % (extension,
1207
+ existing_extensions[extension]))
1208
+
1209
+ if not callable(function):
1210
+ raise TypeError('The registered function must be a callable')
1211
+
1212
+
1213
+ def register_unpack_format(name, extensions, function, extra_args=None,
1214
+ description=''):
1215
+ """Registers an unpack format.
1216
+
1217
+ `name` is the name of the format. `extensions` is a list of extensions
1218
+ corresponding to the format.
1219
+
1220
+ `function` is the callable that will be
1221
+ used to unpack archives. The callable will receive archives to unpack.
1222
+ If it's unable to handle an archive, it needs to raise a ReadError
1223
+ exception.
1224
+
1225
+ If provided, `extra_args` is a sequence of
1226
+ (name, value) tuples that will be passed as arguments to the callable.
1227
+ description can be provided to describe the format, and will be returned
1228
+ by the get_unpack_formats() function.
1229
+ """
1230
+ if extra_args is None:
1231
+ extra_args = []
1232
+ _check_unpack_options(extensions, function, extra_args)
1233
+ _UNPACK_FORMATS[name] = extensions, function, extra_args, description
1234
+
1235
+ def unregister_unpack_format(name):
1236
+ """Removes the pack format from the registry."""
1237
+ del _UNPACK_FORMATS[name]
1238
+
1239
+ def _ensure_directory(path):
1240
+ """Ensure that the parent directory of `path` exists"""
1241
+ dirname = os.path.dirname(path)
1242
+ if not os.path.isdir(dirname):
1243
+ os.makedirs(dirname)
1244
+
1245
+ def _unpack_zipfile(filename, extract_dir):
1246
+ """Unpack zip `filename` to `extract_dir`
1247
+ """
1248
+ import zipfile # late import for breaking circular dependency
1249
+
1250
+ if not zipfile.is_zipfile(filename):
1251
+ raise ReadError("%s is not a zip file" % filename)
1252
+
1253
+ with zipfile.ZipFile(filename) as zip:
1254
+ zip._ignore_invalid_names = True
1255
+ zip.extractall(extract_dir)
1256
+
1257
+ def _unpack_tarfile(filename, extract_dir, *, filter=None):
1258
+ """Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir`
1259
+ """
1260
+ import tarfile # late import for breaking circular dependency
1261
+ try:
1262
+ tarobj = tarfile.open(filename)
1263
+ except tarfile.TarError:
1264
+ raise ReadError(
1265
+ "%s is not a compressed or uncompressed tar file" % filename)
1266
+ try:
1267
+ tarobj.extractall(extract_dir, filter=filter)
1268
+ finally:
1269
+ tarobj.close()
1270
+
1271
+ # Maps the name of the unpack format to a tuple containing:
1272
+ # * extensions
1273
+ # * the unpacking function
1274
+ # * extra keyword arguments
1275
+ # * description
1276
+ _UNPACK_FORMATS = {
1277
+ 'tar': (['.tar'], _unpack_tarfile, [], "uncompressed tar file"),
1278
+ 'zip': (['.zip'], _unpack_zipfile, [], "ZIP file"),
1279
+ }
1280
+
1281
+ if _ZLIB_SUPPORTED:
1282
+ _UNPACK_FORMATS['gztar'] = (['.tar.gz', '.tgz'], _unpack_tarfile, [],
1283
+ "gzip'ed tar-file")
1284
+
1285
+ if _BZ2_SUPPORTED:
1286
+ _UNPACK_FORMATS['bztar'] = (['.tar.bz2', '.tbz2'], _unpack_tarfile, [],
1287
+ "bzip2'ed tar-file")
1288
+
1289
+ if _LZMA_SUPPORTED:
1290
+ _UNPACK_FORMATS['xztar'] = (['.tar.xz', '.txz'], _unpack_tarfile, [],
1291
+ "xz'ed tar-file")
1292
+
1293
+ def _find_unpack_format(filename):
1294
+ for name, info in _UNPACK_FORMATS.items():
1295
+ for extension in info[0]:
1296
+ if filename.endswith(extension):
1297
+ return name
1298
+ return None
1299
+
1300
+ def unpack_archive(filename, extract_dir=None, format=None, *, filter=None):
1301
+ """Unpack an archive.
1302
+
1303
+ `filename` is the name of the archive.
1304
+
1305
+ `extract_dir` is the name of the target directory, where the archive
1306
+ is unpacked. If not provided, the current working directory is used.
1307
+
1308
+ `format` is the archive format: one of "zip", "tar", "gztar", "bztar",
1309
+ or "xztar". Or any other registered format. If not provided,
1310
+ unpack_archive will use the filename extension and see if an unpacker
1311
+ was registered for that extension.
1312
+
1313
+ In case none is found, a ValueError is raised.
1314
+
1315
+ If `filter` is given, it is passed to the underlying
1316
+ extraction function.
1317
+ """
1318
+ sys.audit("shutil.unpack_archive", filename, extract_dir, format)
1319
+
1320
+ if extract_dir is None:
1321
+ extract_dir = os.getcwd()
1322
+
1323
+ extract_dir = os.fspath(extract_dir)
1324
+ filename = os.fspath(filename)
1325
+
1326
+ if filter is None:
1327
+ filter_kwargs = {}
1328
+ else:
1329
+ filter_kwargs = {'filter': filter}
1330
+ if format is not None:
1331
+ try:
1332
+ format_info = _UNPACK_FORMATS[format]
1333
+ except KeyError:
1334
+ raise ValueError("Unknown unpack format '{0}'".format(format)) from None
1335
+
1336
+ func = format_info[1]
1337
+ func(filename, extract_dir, **dict(format_info[2]), **filter_kwargs)
1338
+ else:
1339
+ # we need to look at the registered unpackers supported extensions
1340
+ format = _find_unpack_format(filename)
1341
+ if format is None:
1342
+ raise ReadError("Unknown archive format '{0}'".format(filename))
1343
+
1344
+ func = _UNPACK_FORMATS[format][1]
1345
+ kwargs = dict(_UNPACK_FORMATS[format][2]) | filter_kwargs
1346
+ func(filename, extract_dir, **kwargs)
1347
+
1348
+
1349
+ if hasattr(os, 'statvfs'):
1350
+
1351
+ __all__.append('disk_usage')
1352
+ _ntuple_diskusage = collections.namedtuple('usage', 'total used free')
1353
+ _ntuple_diskusage.total.__doc__ = 'Total space in bytes'
1354
+ _ntuple_diskusage.used.__doc__ = 'Used space in bytes'
1355
+ _ntuple_diskusage.free.__doc__ = 'Free space in bytes'
1356
+
1357
+ def disk_usage(path):
1358
+ """Return disk usage statistics about the given path.
1359
+
1360
+ Returned value is a named tuple with attributes 'total', 'used' and
1361
+ 'free', which are the amount of total, used and free space, in bytes.
1362
+ """
1363
+ st = os.statvfs(path)
1364
+ free = st.f_bavail * st.f_frsize
1365
+ total = st.f_blocks * st.f_frsize
1366
+ used = (st.f_blocks - st.f_bfree) * st.f_frsize
1367
+ return _ntuple_diskusage(total, used, free)
1368
+
1369
+ elif _WINDOWS:
1370
+
1371
+ __all__.append('disk_usage')
1372
+ _ntuple_diskusage = collections.namedtuple('usage', 'total used free')
1373
+
1374
+ def disk_usage(path):
1375
+ """Return disk usage statistics about the given path.
1376
+
1377
+ Returned values is a named tuple with attributes 'total', 'used' and
1378
+ 'free', which are the amount of total, used and free space, in bytes.
1379
+ """
1380
+ total, free = nt._getdiskusage(path)
1381
+ used = total - free
1382
+ return _ntuple_diskusage(total, used, free)
1383
+
1384
+
1385
+ def chown(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True):
1386
+ """Change owner user and group of the given path.
1387
+
1388
+ user and group can be the uid/gid or the user/group names, and in that case,
1389
+ they are converted to their respective uid/gid.
1390
+
1391
+ If dir_fd is set, it should be an open file descriptor to the directory to
1392
+ be used as the root of *path* if it is relative.
1393
+
1394
+ If follow_symlinks is set to False and the last element of the path is a
1395
+ symbolic link, chown will modify the link itself and not the file being
1396
+ referenced by the link.
1397
+ """
1398
+ sys.audit('shutil.chown', path, user, group)
1399
+
1400
+ if user is None and group is None:
1401
+ raise ValueError("user and/or group must be set")
1402
+
1403
+ _user = user
1404
+ _group = group
1405
+
1406
+ # -1 means don't change it
1407
+ if user is None:
1408
+ _user = -1
1409
+ # user can either be an int (the uid) or a string (the system username)
1410
+ elif isinstance(user, str):
1411
+ _user = _get_uid(user)
1412
+ if _user is None:
1413
+ raise LookupError("no such user: {!r}".format(user))
1414
+
1415
+ if group is None:
1416
+ _group = -1
1417
+ elif not isinstance(group, int):
1418
+ _group = _get_gid(group)
1419
+ if _group is None:
1420
+ raise LookupError("no such group: {!r}".format(group))
1421
+
1422
+ os.chown(path, _user, _group, dir_fd=dir_fd,
1423
+ follow_symlinks=follow_symlinks)
1424
+
1425
+ def get_terminal_size(fallback=(80, 24)):
1426
+ """Get the size of the terminal window.
1427
+
1428
+ For each of the two dimensions, the environment variable, COLUMNS
1429
+ and LINES respectively, is checked. If the variable is defined and
1430
+ the value is a positive integer, it is used.
1431
+
1432
+ When COLUMNS or LINES is not defined, which is the common case,
1433
+ the terminal connected to sys.__stdout__ is queried
1434
+ by invoking os.get_terminal_size.
1435
+
1436
+ If the terminal size cannot be successfully queried, either because
1437
+ the system doesn't support querying, or because we are not
1438
+ connected to a terminal, the value given in fallback parameter
1439
+ is used. Fallback defaults to (80, 24) which is the default
1440
+ size used by many terminal emulators.
1441
+
1442
+ The value returned is a named tuple of type os.terminal_size.
1443
+ """
1444
+ # columns, lines are the working values
1445
+ try:
1446
+ columns = int(os.environ['COLUMNS'])
1447
+ except (KeyError, ValueError):
1448
+ columns = 0
1449
+
1450
+ try:
1451
+ lines = int(os.environ['LINES'])
1452
+ except (KeyError, ValueError):
1453
+ lines = 0
1454
+
1455
+ # only query if necessary
1456
+ if columns <= 0 or lines <= 0:
1457
+ try:
1458
+ size = os.get_terminal_size(sys.__stdout__.fileno())
1459
+ except (AttributeError, ValueError, OSError):
1460
+ # stdout is None, closed, detached, or not a terminal, or
1461
+ # os.get_terminal_size() is unsupported
1462
+ size = os.terminal_size(fallback)
1463
+ if columns <= 0:
1464
+ columns = size.columns or fallback[0]
1465
+ if lines <= 0:
1466
+ lines = size.lines or fallback[1]
1467
+
1468
+ return os.terminal_size((columns, lines))
1469
+
1470
+
1471
+ # Check that a given file can be accessed with the correct mode.
1472
+ # Additionally check that `file` is not a directory, as on Windows
1473
+ # directories pass the os.access check.
1474
+ def _access_check(fn, mode):
1475
+ return (os.path.exists(fn) and os.access(fn, mode)
1476
+ and not os.path.isdir(fn))
1477
+
1478
+
1479
+ def _win_path_needs_curdir(cmd, mode):
1480
+ """
1481
+ On Windows, we can use NeedCurrentDirectoryForExePath to figure out
1482
+ if we should add the cwd to PATH when searching for executables if
1483
+ the mode is executable.
1484
+ """
1485
+ return (not (mode & os.X_OK)) or _winapi.NeedCurrentDirectoryForExePath(
1486
+ os.fsdecode(cmd))
1487
+
1488
+
1489
+ def which(cmd, mode=os.F_OK | os.X_OK, path=None):
1490
+ """Given a command, mode, and a PATH string, return the path which
1491
+ conforms to the given mode on the PATH, or None if there is no such
1492
+ file.
1493
+
1494
+ `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
1495
+ of os.environ.get("PATH"), or can be overridden with a custom search
1496
+ path.
1497
+
1498
+ """
1499
+ use_bytes = isinstance(cmd, bytes)
1500
+
1501
+ # If we're given a path with a directory part, look it up directly rather
1502
+ # than referring to PATH directories. This includes checking relative to
1503
+ # the current directory, e.g. ./script
1504
+ dirname, cmd = os.path.split(cmd)
1505
+ if dirname:
1506
+ path = [dirname]
1507
+ else:
1508
+ if path is None:
1509
+ path = os.environ.get("PATH", None)
1510
+ if path is None:
1511
+ try:
1512
+ path = os.confstr("CS_PATH")
1513
+ except (AttributeError, ValueError):
1514
+ # os.confstr() or CS_PATH is not available
1515
+ path = os.defpath
1516
+ # bpo-35755: Don't use os.defpath if the PATH environment variable
1517
+ # is set to an empty string
1518
+
1519
+ # PATH='' doesn't match, whereas PATH=':' looks in the current
1520
+ # directory
1521
+ if not path:
1522
+ return None
1523
+
1524
+ if use_bytes:
1525
+ path = os.fsencode(path)
1526
+ path = path.split(os.fsencode(os.pathsep))
1527
+ else:
1528
+ path = os.fsdecode(path)
1529
+ path = path.split(os.pathsep)
1530
+
1531
+ if sys.platform == "win32" and _win_path_needs_curdir(cmd, mode):
1532
+ curdir = os.curdir
1533
+ if use_bytes:
1534
+ curdir = os.fsencode(curdir)
1535
+ path.insert(0, curdir)
1536
+
1537
+ if sys.platform == "win32":
1538
+ # PATHEXT is necessary to check on Windows.
1539
+ pathext_source = os.getenv("PATHEXT") or _WIN_DEFAULT_PATHEXT
1540
+ pathext = pathext_source.split(os.pathsep)
1541
+ pathext = [ext.rstrip('.') for ext in pathext if ext]
1542
+
1543
+ if use_bytes:
1544
+ pathext = [os.fsencode(ext) for ext in pathext]
1545
+
1546
+ files = [cmd + ext for ext in pathext]
1547
+
1548
+ # If X_OK in mode, simulate the cmd.exe behavior: look at direct
1549
+ # match if and only if the extension is in PATHEXT.
1550
+ # If X_OK not in mode, simulate the first result of where.exe:
1551
+ # always look at direct match before a PATHEXT match.
1552
+ normcmd = cmd.upper()
1553
+ if not (mode & os.X_OK) or any(normcmd.endswith(ext.upper()) for ext in pathext):
1554
+ files.insert(0, cmd)
1555
+ else:
1556
+ # On other platforms you don't have things like PATHEXT to tell you
1557
+ # what file suffixes are executable, so just pass on cmd as-is.
1558
+ files = [cmd]
1559
+
1560
+ seen = set()
1561
+ for dir in path:
1562
+ normdir = os.path.normcase(dir)
1563
+ if normdir not in seen:
1564
+ seen.add(normdir)
1565
+ for thefile in files:
1566
+ name = os.path.join(dir, thefile)
1567
+ if _access_check(name, mode):
1568
+ return name
1569
+ return None