@poe-platform/safe-bash 0.1.825 → 0.1.827

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 (155) hide show
  1. package/dist/image-ast/index.js +39 -18
  2. package/dist/pdf-ast/image.js +1 -1
  3. package/dist/pdf-ast/index.js +1 -1
  4. package/dist/pdf-ast/vendor/pdfjs-fonts.mjs +9 -3
  5. package/dist/safe-bash/chunks/{chunk-AGHV53VF.js → chunk-M6XFU6LQ.js} +3 -1
  6. package/dist/safe-bash/chunks/{chunk-363QOIDR.js → chunk-T6FHWSHM.js} +3 -1
  7. package/dist/safe-bash/command-chunks/{chunk-ZPBL7TYJ.js → chunk-2JRHCVMQ.js} +1 -1
  8. package/dist/safe-bash/command-chunks/{chunk-FMGNXOMV.js → chunk-2L3NMRLG.js} +7 -3
  9. package/dist/safe-bash/command-chunks/{chunk-DAQO64WC.js → chunk-2YKOJPIW.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-EPYJSPOY.js → chunk-3QCW4VQF.js} +12 -8
  11. package/dist/safe-bash/command-chunks/{chunk-YRBFNT5B.js → chunk-3YL2TMLA.js} +10 -1
  12. package/dist/safe-bash/command-chunks/{chunk-5H7ZHP7F.js → chunk-43NDRBKY.js} +1 -1
  13. package/dist/safe-bash/command-chunks/{chunk-BBOYR6LV.js → chunk-46GA576V.js} +3 -3
  14. package/dist/safe-bash/command-chunks/{chunk-WPT2FCHH.js → chunk-4SLPM2WM.js} +1 -1
  15. package/dist/safe-bash/command-chunks/{chunk-7ZQVMPSB.js → chunk-5CAXR62E.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-3DTHX5UU.js → chunk-66653AEZ.js} +40 -14
  17. package/dist/safe-bash/command-chunks/{chunk-ETFJ4L7F.js → chunk-6OLE6CLV.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-ZIDESNHW.js → chunk-7M3M6FKC.js} +1 -1
  19. package/dist/safe-bash/command-chunks/{chunk-2KMNVJB7.js → chunk-A7PKUIJT.js} +1 -1
  20. package/dist/safe-bash/command-chunks/{chunk-AVSINNZ6.js → chunk-DEQ47SBQ.js} +5 -5
  21. package/dist/safe-bash/command-chunks/{chunk-EV7A5FNN.js → chunk-FFFRLPXU.js} +2 -2
  22. package/dist/safe-bash/command-chunks/{chunk-4MVQE6CT.js → chunk-FYTBEGSY.js} +1 -1
  23. package/dist/safe-bash/command-chunks/{chunk-LFTGMUAV.js → chunk-HQIZR6EU.js} +192 -489
  24. package/dist/safe-bash/command-chunks/chunk-HS2L7I4N.js +219 -0
  25. package/dist/safe-bash/command-chunks/{chunk-WKS2PAZL.js → chunk-HUGKO4ZE.js} +10 -1
  26. package/dist/safe-bash/command-chunks/chunk-IGXH5W5Z.js +111 -0
  27. package/dist/safe-bash/command-chunks/{chunk-CMJBRGU2.js → chunk-IHQZKUBS.js} +1 -1
  28. package/dist/safe-bash/command-chunks/chunk-JADJ4BMN.js +1519 -0
  29. package/dist/safe-bash/command-chunks/{chunk-5AQAWIYK.js → chunk-JEZC5V3B.js} +4 -0
  30. package/dist/safe-bash/command-chunks/{chunk-YB5TNDY6.js → chunk-K5VJ4NNL.js} +39 -5
  31. package/dist/safe-bash/command-chunks/{chunk-7RQGRFHJ.js → chunk-KHWDEAE4.js} +2 -2
  32. package/dist/safe-bash/command-chunks/chunk-L54KVUSY.js +604 -0
  33. package/dist/safe-bash/command-chunks/{chunk-3NJETNC2.js → chunk-MBXNG6C3.js} +2 -2
  34. package/dist/safe-bash/command-chunks/{chunk-HCPEYQKT.js → chunk-N4SH6QY5.js} +285 -302
  35. package/dist/safe-bash/command-chunks/{chunk-3DID6MQY.js → chunk-OWTQYLID.js} +2 -2
  36. package/dist/safe-bash/command-chunks/{chunk-4EA7WI3L.js → chunk-QOOQD6BD.js} +42 -33
  37. package/dist/safe-bash/command-chunks/{chunk-RQTFK7AV.js → chunk-QZYEI4N6.js} +1 -1
  38. package/dist/safe-bash/command-chunks/{chunk-R3SLT3ZX.js → chunk-R6GON4H3.js} +11 -1
  39. package/dist/safe-bash/command-chunks/{chunk-2GILUQJY.js → chunk-R7ZGDHME.js} +3 -3
  40. package/dist/safe-bash/command-chunks/{chunk-HNEWGADJ.js → chunk-RUXOFW5G.js} +7 -6
  41. package/dist/safe-bash/command-chunks/{chunk-LKAFLJ5L.js → chunk-RWQKX44L.js} +1 -1
  42. package/dist/safe-bash/command-chunks/{chunk-PKH57OIC.js → chunk-SG2KOOD4.js} +2 -2
  43. package/dist/safe-bash/command-chunks/chunk-T4TGJYFV.js +60 -0
  44. package/dist/safe-bash/command-chunks/chunk-TGSNVLFZ.js +105 -0
  45. package/dist/safe-bash/command-chunks/{chunk-NXCJNPL3.js → chunk-UCE77LYV.js} +2 -1
  46. package/dist/safe-bash/command-chunks/{chunk-EWECMOQ5.js → chunk-UIHPHIKI.js} +1 -1
  47. package/dist/safe-bash/command-chunks/{chunk-XSZNL3GV.js → chunk-UJPWPRVB.js} +191 -146
  48. package/dist/safe-bash/command-chunks/{chunk-E5CDHXFA.js → chunk-VOR6YDZC.js} +26 -1
  49. package/dist/safe-bash/command-chunks/chunk-VSNVYOK2.js +30 -0
  50. package/dist/safe-bash/command-chunks/{chunk-4XYGJB24.js → chunk-VTH4AORO.js} +3 -3
  51. package/dist/safe-bash/command-chunks/{chunk-W5LH7D23.js → chunk-WKKJJBJQ.js} +8 -8
  52. package/dist/safe-bash/command-chunks/{chunk-OLXMWQJ5.js → chunk-WRO3PB2M.js} +1 -1
  53. package/dist/safe-bash/command-chunks/{chunk-RUAGHZNF.js → chunk-X5ODTF3E.js} +7 -5
  54. package/dist/safe-bash/command-chunks/{chunk-LH4VBNF6.js → chunk-XGTSP2CP.js} +84 -16
  55. package/dist/safe-bash/command-chunks/{chunk-K576GZED.js → chunk-XTHKXCF2.js} +2 -2
  56. package/dist/safe-bash/command-chunks/{chunk-J3VS55K4.js → chunk-YHRESVJ7.js} +9 -3
  57. package/dist/safe-bash/command-chunks/{chunk-UWIDPTOB.js → chunk-YSCKOUQP.js} +1 -1
  58. package/dist/safe-bash/command-chunks/{chunk-UYNJF5QN.js → chunk-ZALAWNOE.js} +76 -122
  59. package/dist/safe-bash/command-chunks/{chunk-OT75C5YS.js → chunk-ZYXKW2K7.js} +1 -1
  60. package/dist/safe-bash/command-chunks/{pdf-renderer-346WYKSZ.js → pdf-renderer-5QWOVFA4.js} +1 -1
  61. package/dist/safe-bash/command-chunks/{prompt-tool-debug-3POFNRYP.js → prompt-tool-debug-G7ATE7D5.js} +6 -4
  62. package/dist/safe-bash/commands/llm/index.browser.js +5 -1
  63. package/dist/safe-bash/commands/llm/index.js +1 -1
  64. package/dist/safe-bash/commands/python/executor.browser.js +3 -1
  65. package/dist/safe-bash/commands/python/executor.js +1 -1
  66. package/dist/safe-bash/commands/python/index.browser.js +5 -1
  67. package/dist/safe-bash/commands/python/index.js +1 -1
  68. package/dist/safe-bash/core.browser.js +2 -2
  69. package/dist/safe-bash/full-core.browser.js +10 -2
  70. package/dist/safe-bash-command-awk/awk-runtime.js +2 -2
  71. package/dist/safe-bash-command-awk/awk-syntax.js +1 -1
  72. package/dist/safe-bash-command-awk/awk.js +3 -3
  73. package/dist/safe-bash-command-awk/index.js +3 -3
  74. package/dist/safe-bash-command-gpg/index.js +11 -3
  75. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  76. package/dist/safe-bash-command-llm/collections.js +6 -4
  77. package/dist/safe-bash-command-llm/command.js +4 -4
  78. package/dist/safe-bash-command-llm/import-json-document.d.ts +9 -2
  79. package/dist/safe-bash-command-llm/index.d.ts +2 -1
  80. package/dist/safe-bash-command-llm/index.js +10 -4
  81. package/dist/safe-bash-command-llm/loader-provider.d.ts +5 -0
  82. package/dist/safe-bash-command-mcp/index.js +10 -13
  83. package/dist/safe-bash-command-pdftoppm/index.js +2 -2
  84. package/dist/safe-bash-command-playwright-cli/index.js +2 -2
  85. package/dist/safe-bash-command-playwright-cli/playwright/ability-execution.d.ts +1 -0
  86. package/dist/safe-bash-command-playwright-cli/playwright/ability-execution.js +1 -1
  87. package/dist/safe-bash-command-playwright-cli/playwright/controller.d.ts +2 -0
  88. package/dist/safe-bash-command-playwright-cli/playwright/controller.js +2 -2
  89. package/dist/safe-bash-command-playwright-cli/playwright/index.js +2 -2
  90. package/dist/safe-bash-command-python/build-backend.d.ts +2 -0
  91. package/dist/safe-bash-command-python/cache.d.ts +1 -1
  92. package/dist/safe-bash-command-python/executor.d.ts +5 -2
  93. package/dist/safe-bash-command-python/executor.js +11 -6
  94. package/dist/safe-bash-command-python/host-capabilities.js +1 -1
  95. package/dist/safe-bash-command-python/index.js +11 -6
  96. package/dist/safe-bash-command-python/jspi.js +5 -3
  97. package/dist/safe-bash-command-python/manifest-file.d.ts +44 -0
  98. package/dist/safe-bash-command-python/manifest.d.ts +45 -0
  99. package/dist/safe-bash-command-python/provisioning.d.ts +20 -1
  100. package/dist/safe-bash-command-python/provisioning.js +3 -2
  101. package/dist/safe-bash-command-python/reply.js +7 -11
  102. package/dist/safe-bash-command-python/source-archive.js +2 -2
  103. package/dist/safe-bash-command-python/source-zip.js +2 -2
  104. package/dist/safe-bash-command-python/worker.js +34 -21
  105. package/dist/safe-bash-command-sqlite3/engine.d.ts +4 -0
  106. package/dist/safe-bash-command-sqlite3/index.js +174 -18
  107. package/dist/safe-bash-command-svgo/index.js +1 -1
  108. package/dist/safe-bash-command-tar/create.js +3 -3
  109. package/dist/safe-bash-command-tar/extract.js +3 -3
  110. package/dist/safe-bash-command-tar/index.js +5 -5
  111. package/dist/safe-bash-command-tar/modes.js +5 -5
  112. package/dist/safe-bash-command-tar/options.d.ts +1 -1
  113. package/dist/safe-bash-command-tar/options.js +1 -1
  114. package/dist/safe-bash-command-tar/stream.js +1 -1
  115. package/dist/safe-bash-command-wkhtmltopdf/index.js +1 -1
  116. package/dist/safe-bash-command-xan/argv.js +1 -1
  117. package/dist/safe-bash-command-xan/commands.js +3 -3
  118. package/dist/safe-bash-command-xan/index.js +3 -3
  119. package/dist/safe-bash-command-xan/io.js +2 -2
  120. package/dist/safe-bash-compression-engine/bounded-codec.js +3 -3
  121. package/dist/safe-bash-compression-engine/codec-loader.js +2 -2
  122. package/dist/safe-bash-compression-engine/files.js +6 -6
  123. package/dist/safe-bash-compression-engine/index.js +5 -5
  124. package/dist/safe-bash-compression-engine/operand.js +6 -6
  125. package/dist/safe-bash-compression-engine/options.js +1 -1
  126. package/dist/safe-bash-compression-engine/stream.js +5 -5
  127. package/dist/safe-bash-compression-engine/zstd-decode.js +4 -4
  128. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  129. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  130. package/dist/safe-bash-csv-engine/index.js +6 -6
  131. package/dist/safe-bash-csv-engine/python-codec-aliases.js +1 -1
  132. package/dist/safe-bash-csv-engine/python-codepages.js +3 -3
  133. package/dist/safe-bash-csv-engine/python-file-codepages.js +2 -2
  134. package/dist/safe-bash-csv-engine/python-utf16.js +4 -4
  135. package/dist/safe-bash-csv-engine/text-decoder.js +6 -6
  136. package/dist/safe-bash-graphviz-engine/index.js +1 -1
  137. package/dist/safe-bash-pager-engine/index.js +2 -2
  138. package/dist/safe-bash-query-engine/capture.js +3 -3
  139. package/dist/safe-bash-query-engine/delpaths.js +3 -3
  140. package/dist/safe-bash-query-engine/formats.js +2 -2
  141. package/dist/safe-bash-query-engine/index.js +10 -10
  142. package/dist/safe-bash-query-engine/indices.js +3 -3
  143. package/dist/safe-bash-query-engine/input.d.ts +3 -3
  144. package/dist/safe-bash-query-engine/input.js +1 -1
  145. package/dist/safe-bash-query-engine/interpreter.js +9 -9
  146. package/dist/safe-bash-query-engine/query-core.js +10 -10
  147. package/dist/safe-bash-query-engine/regex.js +4 -4
  148. package/dist/safe-bash-query-engine/splits.js +5 -5
  149. package/dist/safe-bash-query-engine/values.js +2 -2
  150. package/package.json +2 -2
  151. package/dist/safe-bash/command-chunks/chunk-OOYVZAWL.js +0 -90
  152. package/dist/safe-bash/command-chunks/chunk-RZOHZGEZ.js +0 -772
  153. package/dist/safe-bash/command-chunks/chunk-WIUEM7HP.js +0 -58
  154. package/dist/safe-bash/command-chunks/chunk-WY6THI6J.js +0 -673
  155. package/dist/safe-bash/command-chunks/chunk-ZERCTWUI.js +0 -467
@@ -1,673 +0,0 @@
1
- // packages/safe-bash-command-python/src/invocation.ts
2
- var PythonInvocationError = class extends Error {
3
- constructor(message) {
4
- super(message);
5
- this.name = "PythonInvocationError";
6
- }
7
- };
8
- function parsePythonInvocation(args, env) {
9
- const startupArgs = [];
10
- let informational = false;
11
- let module;
12
- scan: for (let index = 0; index < args.length; index++) {
13
- const option = args[index];
14
- if (option === "--" || option === "-" || !option.startsWith("-")) break;
15
- if (option === "--help") {
16
- informational = true;
17
- break;
18
- }
19
- if (option === "--version") {
20
- informational = true;
21
- continue;
22
- }
23
- if (option.startsWith("--")) throw new PythonInvocationError("unsupported option " + option);
24
- for (let offset = 1; offset < option.length; offset++) {
25
- const flag = option[offset];
26
- if (flag === "h" || flag === "?") {
27
- informational = true;
28
- break scan;
29
- }
30
- if (flag === "V") {
31
- informational = true;
32
- continue;
33
- }
34
- if ("cmWX".includes(flag)) {
35
- const operand = option.slice(offset + 1) || args[++index];
36
- if (operand === void 0) throw new PythonInvocationError("argument expected for -" + flag);
37
- if (flag === "m" && !informational) module = { name: operand, args: args.slice(index + 1) };
38
- if (flag === "c" || flag === "m") break scan;
39
- if (flag === "X") {
40
- const separator = operand.indexOf("=");
41
- const name = separator < 0 ? operand : operand.slice(0, separator);
42
- const value = separator < 0 ? void 0 : operand.slice(separator + 1);
43
- let decimal = value ?? "";
44
- while (decimal.length && " \n\r\v\f".includes(decimal[0])) decimal = decimal.slice(1);
45
- if (decimal[0] === "+" || decimal[0] === "-") decimal = decimal.slice(1);
46
- const digits = decimal.length > 0 && [...decimal].every((character) => character >= "0" && character <= "9");
47
- const supported = name === "utf8" && (value === void 0 || value === "0" || value === "1") || (name === "dev" || name === "warn_default_encoding") && value === void 0 || name === "int_max_str_digits" && digits && Number.isSafeInteger(Number(value)) && Number(value) <= 2147483647 && (Number(value) === 0 || Number(value) >= 640);
48
- if (!supported) throw new PythonInvocationError("unsupported -X option " + operand);
49
- startupArgs.push("-X", operand);
50
- }
51
- break;
52
- }
53
- if (!"BEPOusISbdvqR".includes(flag)) throw new PythonInvocationError("unsupported option -" + flag);
54
- startupArgs.push("-" + flag);
55
- }
56
- }
57
- if (!informational && !startupArgs.includes("-E") && !startupArgs.includes("-I")) {
58
- if (env.PYTHONINSPECT) throw new PythonInvocationError("PYTHONINSPECT requires an interactive terminal, which the shell does not expose");
59
- if (env.PYTHONHOME) throw new PythonInvocationError("PYTHONHOME cannot replace the configured Pyodide runtime");
60
- }
61
- const runtimeEnv = { ...env };
62
- delete runtimeEnv.PYTHONPATH;
63
- delete runtimeEnv.PYTHONHOME;
64
- delete runtimeEnv.PYTHONWARNINGS;
65
- runtimeEnv.PYTHONINSPECT = "";
66
- startupArgs.push("-c", "");
67
- return { startupArgs, env: runtimeEnv, module };
68
- }
69
-
70
- // packages/safe-bash-command-python/src/package-program.generated.ts
71
- var pythonPackageProgramGzip = "H4sIAAAAAAACA7U7a4/cNpLf9Su4uMVKijVy4j0vdhtoJEbs3BlInNzY2SDX7hU4EnuaGbWkkGyPO5P574cqvvWYae8hn7pFkVXFYr2LatiOCEabSvZHUbOqF/yad5lgvx6ZVPkqIfww9EIRwQryi+y7hOxEfyBH0bb8qhyokMxOOYpWDi1XBfw7dvg/IRowWRMDc5PqkXSbEL4zr0upqFDylqt9lj5NAa/GM1C1b/mVRfEDVfuEeJjwnOmnvKSyOgqe5QngJ2tHj52QkI6ptq/1q1I/IBHpVynhnXkNuGvBGtYpTltZkH0vFVmbt6UGmX6VFuSLPCGwvOuBP+WBqnqfifRf7//8/m7z4uJ/6cVvn1/846LaPnl/n63mRvMv/5wWIbZ85YkEvAkRTB5bwH+XHkWbrgLmZhnsQ9Z7dmCFWYfML4Ft+t+vRyZOBUnTPL9PiDxeN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7KHx3VOVFjDeY6cx8jRGzJ4zB53AgP+WynmrxLR46259DRNijLb7bJubdb/OjizYb5olDwUYxfPRfhjcpn0VUU2phCW1S4m9bLArUx24/lyVPgr7GH662pjkAv+nQHbdmtBwRFzB9fJ5kpizvoaICcpnonGjYTI95PbQdyD76yMm3xG3bCyAkZoD881V4SpRfe8o5sUmuxLv6pZRtcDB5rQdJgyKQT8kLbjGgIaovGi37gDZMXr7D8oavvGrMTBrMprC2DGb5hp4Jstnn+CBPHDCvmdl+QqCaKHdLU+eaCfPZo7FUsyOSkDru1KniukltVfUI2cf4c2hS9M3cLpIt7ee5qiWkB6M70nK5tR+25R2iLOD5uzp3r0+zVhNrHAtd1Yv+Udd/CBZ8sT/4PYSKnnZ1EAAA=";
72
-
73
- // packages/safe-bash-command-python/src/package-program.ts
74
- var decoded;
75
- function loadPythonPackageProgram() {
76
- return decoded ??= new Response(new Blob([Uint8Array.from(atob(pythonPackageProgramGzip), (character) => character.charCodeAt(0))]).stream().pipeThrough(new DecompressionStream("gzip"))).text();
77
- }
78
-
79
- // packages/safe-bash-command-python/src/native-wheel.generated.ts
80
- var pythonNativeWheelGzip = "H4sIAAAAAAACA61YW4/dthF+P79imjxIgrXK2q2NYGEFtR23MIrahrNpABsLgSuOjpilSIGkfPb41xdDUhJ19lIk6JtEcr65X8gdxw4ayzps8NYZ1rpGMSe+YnPoEWVukPESLBrBpPiGvLjYgRhGbRwIDczCfFzoEn63WqVr9F+C7ScnZLoeVnbQGT3AyFwvxfWM+pG53p9978/Sbzz4TYydkDgf/CzGf9DvevazGGfMo+aCL0ebkbU3bI+N1IyjSUUJK1uyquvETGom1dijajfiH1W720ErmV14/+attRqj+sQO7z68ZhbJYuCt3AglXNPkFmVXghXfwh7Qf0W/ZfgctRVOaAU1hNXziEDOYNcSPUKgNegmo+DSTBgPWcSb/3nIoZR3D2y4J3BRYt11Fl0Jhx5Vi/V5oBVdXAClHQgF+XkJT0t4FrbBMGER/sPkhG+N0SbPhPrKpOC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m+cNFloIkNaGOjmUmQhOxxV75quCGSkRmqNjW9I1HOUnDoG/+7IQrPe1UzKQr+JkbFqY/LEyYhc/9MXIjuUfMR8+jryk5dJ26paWXVoZex/53ayqILz59LWD0CWsK94RaUejj8sqviXt6Lj5hjfqD4s6w3Lgmzkk3qaxIWcfMeB/0hq94nwCOJtJWs2D3yCB220qUmvEvfsxHkK3b/BV4ZQfjZFgAA";
81
-
82
- // packages/safe-bash-command-python/src/native-wheel.ts
83
- var decoded2;
84
- function loadPythonNativeWheel() {
85
- return decoded2 ??= new Response(new Blob([Uint8Array.from(atob(pythonNativeWheelGzip), (character) => character.charCodeAt(0))]).stream().pipeThrough(new DecompressionStream("gzip"))).text();
86
- }
87
-
88
- // packages/safe-bash-command-python/src/package-url-hash.ts
89
- function pythonPackageUrlHash(url) {
90
- const match = /(sha1|sha224|sha384|sha256|sha512|md5)=([a-f0-9]+)/.exec(url);
91
- return match ? [match[1], match[2]] : void 0;
92
- }
93
-
94
- // packages/safe-bash-command-python/src/provisioning-runtime.ts
95
- async function installPythonPackages(supplied, start, request, maxTransferBytes) {
96
- if (!start.requirements.length && !start.uninstall && !start.bootstrap) return;
97
- const runtime = supplied;
98
- if (runtime.version !== "314.0.6" || !runtime._api?.packageManager || !runtime._api.lockfile_packages || typeof runtime._api.packageManager.installPackage !== "function" || typeof runtime.loadPackage !== "function" || typeof runtime.runPythonAsync !== "function") throw new Error("Python package installer ABI requires Pyodide 314.0.6");
99
- let transportFailure;
100
- let accepting = true;
101
- let pending = Promise.resolve();
102
- let installing = Promise.resolve();
103
- const manager = runtime._api.packageManager;
104
- const transfer = (consume) => {
105
- if (!accepting) return Promise.reject(new Error("Python package transport is only available during installation"));
106
- const work = pending.then(async () => {
107
- if (transportFailure) throw transportFailure.error;
108
- try {
109
- return await consume();
110
- } catch (error) {
111
- transportFailure ??= { error };
112
- throw error;
113
- }
114
- });
115
- pending = work.then(() => {
116
- }, () => {
117
- });
118
- return work;
119
- };
120
- const readArtifact = (operation, key, offset, length) => {
121
- const failed = (error) => {
122
- transportFailure ??= { error };
123
- throw error;
124
- };
125
- try {
126
- const result = request(operation, start.session, key, offset, Math.min(length, maxTransferBytes, 65536));
127
- return result instanceof Promise ? result.catch(failed) : result;
128
- } catch (error) {
129
- return failed(error);
130
- }
131
- };
132
- const withArtifact = (url, expected, metadata, consume) => transfer(async () => {
133
- const opened = await request("package-open", start.session, url, expected, ...metadata ? [metadata] : []);
134
- try {
135
- return await consume(opened, (offset, length) => readArtifact("package-read", opened.key, offset, length));
136
- } finally {
137
- await request("package-close", start.session, opened.key);
138
- }
139
- });
140
- const wheel = async (size, read, configuration) => {
141
- const globals = ["_safe_native_wheel_read", "_safe_native_wheel_config", "_safe_extract_native_wheel"];
142
- try {
143
- runtime.globals.set(globals[0], read);
144
- runtime.globals.set(globals[1], JSON.stringify({ ...configuration, size }));
145
- const result = JSON.parse(await runtime.runPythonAsync(await loadPythonNativeWheel()));
146
- if (Array.isArray(result)) for (const path of result) await runtime._api.loadDynlib(path);
147
- return result;
148
- } finally {
149
- for (const name of globals) runtime.globals.delete(name);
150
- }
151
- };
152
- const fetch = (url, expected, metadata) => withArtifact(url, expected, metadata, async (opened, read) => {
153
- const bytes = new Uint8Array(opened.size);
154
- for (let offset = 0; offset < bytes.length; ) {
155
- const chunk = await read(offset, bytes.length - offset);
156
- if (!Array.isArray(chunk) || chunk.length === 0 || offset + chunk.length > bytes.length) throw new Error("Invalid Python package chunk");
157
- bytes.set(chunk, offset);
158
- offset += chunk.length;
159
- }
160
- return { bytes, headers: opened.headers };
161
- });
162
- manager.downloadPackage = async (metadata) => {
163
- if (!accepting) throw new Error("Python package transport is only available during installation");
164
- if (metadata.channel === manager.defaultChannel) {
165
- const pkg = runtime._api.lockfile_packages[metadata.normalizedName];
166
- if (!pkg) throw new Error(`Missing matching Pyodide package: ${metadata.normalizedName}`);
167
- return { url: new URL(pkg.file_name, "https://cdn.jsdelivr.net/pyodide/v314.0.6/full/").href, expected: pkg.sha256 };
168
- }
169
- return { url: metadata.channel };
170
- };
171
- manager.installPackage = (metadata, source) => {
172
- if (!accepting) return Promise.reject(new Error("Python package transport is only available during installation"));
173
- const work = installing.then(async () => {
174
- if (source instanceof Uint8Array) throw new Error("Expected retained Python package source");
175
- const pkg = runtime._api.lockfile_packages[metadata.normalizedName] ?? metadata.packageData;
176
- if (!pkg) throw new Error(`Missing matching Pyodide package: ${metadata.normalizedName}`);
177
- return withArtifact(source.url, source.expected, void 0, (opened, read) => wheel(opened.size, read, {
178
- filename: pkg.file_name,
179
- target: pkg.install_dir ?? null,
180
- metadata: { INSTALLER: "pyodide.loadPackage", PYODIDE_SOURCE: metadata.channel === manager.defaultChannel ? "pyodide" : metadata.channel }
181
- }));
182
- });
183
- installing = work.then(() => {
184
- }, () => {
185
- });
186
- return work;
187
- };
188
- const loadPackages = async (names) => {
189
- const errors = [];
190
- await runtime.loadPackage(names, { messageCallback() {
191
- }, errorCallback(message) {
192
- errors.push(message);
193
- } });
194
- if (errors.length) throw new Error(errors.join("\n"));
195
- };
196
- const installedGlobals = [];
197
- const bind = (name, value) => {
198
- runtime.globals.set(name, value);
199
- installedGlobals.push(name);
200
- };
201
- try {
202
- await loadPackages(["micropip", ...start.bootstrapPackages ?? []]);
203
- bind("_safe_package_native", loadPackages);
204
- bind("_safe_package_bytes", async (url, hash) => (await fetch(url, hash)).bytes);
205
- bind("_safe_package_metadata", async (url) => {
206
- const result = await fetch(url, void 0, "metadata");
207
- return JSON.stringify({ text: new TextDecoder().decode(result.bytes), headers: Object.fromEntries(result.headers.map(([name, value]) => [name.toLowerCase(), value])) });
208
- });
209
- bind("_safe_package_wheel_download", async (url, expected) => withArtifact(url, expected, void 0, async (opened, read) => {
210
- const hash = pythonPackageUrlHash(url);
211
- if (hash) await wheel(opened.size, read, { integrity: hash });
212
- return JSON.stringify(await request("package-retain", start.session, opened.key));
213
- }));
214
- bind("_safe_package_wheel_metadata", async (serialized) => transfer(async () => {
215
- const { source, name } = JSON.parse(serialized);
216
- return wheel(source.size, (offset, length) => readArtifact("package-read-retained", source.token, offset, length), { metadata_name: name });
217
- }));
218
- bind("_safe_package_wheel_install", async (serialized) => transfer(async () => {
219
- const { source, ...configuration } = JSON.parse(serialized);
220
- await wheel(source.size, (offset, length) => readArtifact("package-read-retained", source.token, offset, length), configuration);
221
- }));
222
- bind("_safe_package_requirements_json", JSON.stringify(start.requested ?? start.requirements));
223
- for (const key of ["pre", "upgrade", "forceReinstall", "legacy"]) {
224
- bind("_safe_package_" + key, !!start[key]);
225
- }
226
- bind("_safe_package_restore_json", JSON.stringify(start.restore ?? []));
227
- bind("_safe_package_records_json", JSON.stringify(start.records ?? null));
228
- bind("_safe_package_uninstall_json", JSON.stringify(start.uninstall ?? null));
229
- bind("_safe_package_emit", async (stream, message) => {
230
- if (stream !== "stdout" && stream !== "stderr") throw new Error("Invalid package output stream");
231
- const bytes = new TextEncoder().encode(message);
232
- for (let offset = 0; offset < bytes.length; offset += maxTransferBytes) await request(stream, Array.from(bytes.subarray(offset, offset + maxTransferBytes)));
233
- });
234
- bind("_safe_package_line", async () => {
235
- const bytes = [];
236
- while (true) {
237
- const chunk = await request("stdin", 1);
238
- if (!chunk.length) {
239
- if (!bytes.length) throw new Error("EOF when reading package confirmation");
240
- break;
241
- }
242
- if (chunk[0] === 10) break;
243
- bytes.push(chunk[0]);
244
- }
245
- return new TextDecoder().decode(Uint8Array.from(bytes));
246
- });
247
- await runtime.runPythonAsync(await loadPythonPackageProgram());
248
- await installing;
249
- accepting = false;
250
- await pending;
251
- if (transportFailure) throw transportFailure.error;
252
- const pinned = JSON.parse(runtime.runPython("_safe_installed_json"));
253
- await request("package-commit", start.session, start.restore === void 0 ? pinned : { version: 3, installed: pinned, records: JSON.parse(runtime.runPython("_safe_records_json")) });
254
- if (start.uninstall) {
255
- const removed = JSON.parse(runtime.runPython("_safe_uninstalled_json"));
256
- for (const name of removed) {
257
- const bytes = new TextEncoder().encode(" Successfully uninstalled " + name + "\n");
258
- for (let offset = 0; offset < bytes.length; offset += maxTransferBytes) await request("stdout", Array.from(bytes.subarray(offset, offset + maxTransferBytes)));
259
- }
260
- }
261
- } catch (error) {
262
- await installing;
263
- accepting = false;
264
- await pending;
265
- throw transportFailure ? transportFailure.error : error;
266
- } finally {
267
- await installing;
268
- accepting = false;
269
- await pending;
270
- manager.downloadPackage = manager.installPackage = async () => {
271
- throw new Error("Python package transport is only available during installation");
272
- };
273
- for (const name of installedGlobals) runtime.globals.delete(name);
274
- }
275
- }
276
-
277
- // packages/safe-bash-command-python/src/execution.ts
278
- var pythonExecution = `
279
- import sys, os, json, runpy, traceback, types, warnings, textwrap, io, struct, linecache
280
- _safe_invocation = json.loads(_safe_invocation_json)
281
- os.environ.clear()
282
- os.environ.update(_safe_invocation['env'])
283
- _safe_args = list(_safe_invocation['args'])
284
- sys.orig_argv = [_safe_invocation.get('command', 'python')] + _safe_args
285
- _safe_exit = 0
286
-
287
- class _SafeOptionError(ValueError):
288
- pass
289
-
290
- def _safe_system_exit(_error):
291
- if isinstance(_error.code, int):
292
- _status = int.__index__(_error.code)
293
- _long_bound = 1 << (8 * struct.calcsize('@l') - 1)
294
- status = (_status & 255) if -_long_bound <= _status < _long_bound else 255
295
- else:
296
- status = 0 if _error.code is None else 1
297
- if _error.code is not None and not isinstance(_error.code, int):
298
- print(_error.code, file=sys.stderr)
299
- return status
300
-
301
- def _safe_launch():
302
- args = list(_safe_args)
303
- unbuffered = False
304
- ignore_env = bool(sys.flags.ignore_environment)
305
- safe_path = bool(sys.flags.safe_path)
306
- native_warning_options = list(sys.warnoptions)
307
- # Pyodide adds a bootstrap cwd entry even when CPython safe-path mode is set.
308
- # Each execution mode below supplies its own entry after explicit PYTHONPATH.
309
- sys.path[:] = [entry for entry in sys.path if entry != '']
310
- warning_options = []
311
- version_count = 0
312
- options_terminated = False
313
- while args and args[0].startswith('-') and args[0] != '-':
314
- option = args.pop(0)
315
- if option == '--':
316
- options_terminated = True
317
- break
318
- if option in ('--help', '-h', '-?'):
319
- print('usage: python [-uBEPOsSIbdvqR] [-W filter] [-X option] [-c code | -m module | file | -] [args ...]')
320
- print('Dedicated Pyodide interpreter; stdin is noninteractive.')
321
- print('-u: unbuffered binary output; -B: disable bytecode writes; -E: ignore PYTHON* settings')
322
- print('-P: omit automatic unsafe sys.path entry; -W: Python warning filter')
323
- print('-O/-OO, -S/-s/-I, -b/-bb, -d/-v/-q/-R: CPython startup flags')
324
- print('-X: utf8, dev, warn_default_encoding, int_max_str_digits; interactive flags are unsupported.')
325
- return
326
- if option == '--version':
327
- version_count += 1
328
- continue
329
- if option.startswith('--'):
330
- raise _SafeOptionError('unsupported option ' + option)
331
- index = 1
332
- while index < len(option):
333
- flag = option[index]
334
- if flag in ('h', '?'):
335
- args = ['--help']
336
- break
337
- if flag == 'V':
338
- version_count += 1
339
- index += 1
340
- continue
341
- if flag in ('c', 'm', 'W', 'X'):
342
- operand = option[index + 1:] if index + 1 < len(option) else args.pop(0) if args else None
343
- if operand is None:
344
- raise _SafeOptionError('argument expected for -' + flag)
345
- if flag in ('W', 'X'):
346
- if flag == 'W': warning_options.append(operand)
347
- break
348
- args = ['-' + flag, operand] + args
349
- break
350
- elif flag in ('O', 'S', 's', 'I', 'b', 'd', 'v', 'q', 'R'):
351
- pass # Applied by CPython startup configuration before bootstrap.
352
- elif flag == 'u':
353
- unbuffered = True
354
- elif flag == 'B':
355
- sys.dont_write_bytecode = True
356
- elif flag == 'E':
357
- ignore_env = True
358
- elif flag == 'P':
359
- safe_path = True
360
- else:
361
- raise _SafeOptionError('unsupported option -' + flag)
362
- index += 1
363
- if args and args[0] in ('-c', '-m'):
364
- break
365
- if version_count:
366
- print('Python ' + (sys.version if version_count > 1 else sys.version.split()[0]))
367
- return
368
- if not ignore_env:
369
- unbuffered = unbuffered or bool(os.environ.get('PYTHONUNBUFFERED'))
370
- sys.dont_write_bytecode = sys.dont_write_bytecode or bool(os.environ.get('PYTHONDONTWRITEBYTECODE'))
371
- safe_path = safe_path or bool(os.environ.get('PYTHONSAFEPATH'))
372
- path = os.environ.get('PYTHONPATH')
373
- if path:
374
- sys.path[0:0] = [os.path.abspath(entry) for entry in path.split(os.pathsep)]
375
- if os.environ.get('PYTHONWARNINGS'):
376
- warning_options[0:0] = os.environ['PYTHONWARNINGS'].split(',')
377
- encoding = os.environ.get('PYTHONIOENCODING')
378
- if encoding:
379
- name, separator, errors = encoding.partition(':')
380
- for stream in (sys.stdin, sys.stdout):
381
- stream.reconfigure(encoding=name or None, errors=(errors or 'strict'))
382
- sys.stderr.reconfigure(encoding=name or None, errors='backslashreplace')
383
- # CPython's -b/-bb filter follows environment and command-line -W filters.
384
- byte_warning = ('error' if sys.flags.bytes_warning > 1 else 'default') + '::BytesWarning'
385
- native_before = [value for value in native_warning_options if not (sys.flags.bytes_warning and value == byte_warning)]
386
- warning_options = native_before + warning_options + ([byte_warning] if sys.flags.bytes_warning else [])
387
- warnings._processoptions(warning_options)
388
- sys.warnoptions[:] = warning_options
389
- if unbuffered:
390
- for name in ('stdout', 'stderr'):
391
- stream = getattr(sys, name)
392
- stream.flush()
393
- encoding, errors = stream.encoding, stream.errors
394
- binary = stream.detach()
395
- raw = binary.detach() if hasattr(binary, 'detach') else binary
396
- replacement = io.TextIOWrapper(raw, encoding=encoding, errors=errors, write_through=True)
397
- setattr(sys, name, replacement)
398
- setattr(sys, '__' + name + '__', replacement)
399
- main = types.ModuleType('__main__')
400
- main.__dict__.update(__package__=None, __spec__=None, __loader__=__import__('importlib.machinery', fromlist=['BuiltinImporter']).BuiltinImporter, __builtins__=__builtins__)
401
- sys.modules['__main__'] = main
402
- if not sys.flags.no_site:
403
- sys.argv = [args[0]] + args[2:] if not options_terminated and args and args[0] in ('-c', '-m') else args or ['']
404
- import site
405
- site.addsitepackages(site.addusersitepackages(None), [_safe_runtime_mount])
406
- if not options_terminated and args and args[0] == '-c':
407
- sys.argv = ['-c'] + args[2:]
408
- if not safe_path: sys.path.insert(0, '')
409
- source = textwrap.dedent(args[1])
410
- code = compile(source, '<string>', 'exec')
411
- # CPython 3.14 retains -c source for both top-level and nested tracebacks.
412
- linecache._register_code(code, source, '<string>')
413
- exec(code, main.__dict__)
414
- elif not options_terminated and args and args[0] == '-m':
415
- sys.argv = args[1:]
416
- if not safe_path: sys.path.insert(0, os.getcwd())
417
- runpy._run_module_as_main(args[1], alter_argv=True)
418
- elif not args or args[0] == '-':
419
- sys.argv = (['-'] + args[1:]) if args else ['']
420
- if not safe_path: sys.path.insert(0, '')
421
- main.__file__ = '<stdin>'
422
- exec(compile(sys.stdin.buffer.read(), '<stdin>', 'exec'), main.__dict__)
423
- else:
424
- sys.argv = args
425
- # CPython makes __file__ absolute without collapsing ./ or ../ components.
426
- path = args[0] if os.path.isabs(args[0]) else os.path.join(os.getcwd(), args[0])
427
- importer = __import__('pkgutil').get_importer(path)
428
- if importer is not None:
429
- sys.path.insert(0, path)
430
- runpy._run_module_as_main('__main__', alter_argv=False)
431
- else:
432
- if not safe_path: sys.path.insert(0, os.path.dirname(os.path.realpath(path)))
433
- try:
434
- with open(path, 'rb') as source:
435
- code = source.read()
436
- except OSError as error:
437
- print("python: can't open file " + repr(path) + ': [Errno ' + str(error.errno) + '] ' + error.strerror, file=sys.stderr)
438
- return 2
439
- main.__file__ = path
440
- main.__loader__ = __import__('importlib.machinery', fromlist=['SourceFileLoader']).SourceFileLoader('__main__', path)
441
- exec(compile(code, path, 'exec'), main.__dict__)
442
- return 0
443
-
444
- try:
445
- _safe_exit = _safe_launch() or 0
446
- except SystemExit as _error:
447
- _safe_exit = _safe_system_exit(_error)
448
- except _SafeOptionError as _error:
449
- print('python: ' + str(_error), file=sys.stderr)
450
- _safe_exit = 2
451
- except BaseException as _error:
452
- # Hide bridge frames while preserving actual Python frames and chained errors.
453
- _trace = _error.__traceback__
454
- while _trace is not None and _trace.tb_frame.f_code.co_filename == '<exec>':
455
- _trace = _trace.tb_next
456
- _error.__traceback__ = _trace
457
- sys.last_exc = _error
458
- _safe_exit = 130 if isinstance(_error, KeyboardInterrupt) else 1
459
- try:
460
- sys.excepthook(type(_error), _error, _trace)
461
- except SystemExit as _hook_error:
462
- _safe_exit = _safe_system_exit(_hook_error)
463
- except BaseException as _hook_error:
464
- print('Error in sys.excepthook:', file=sys.stderr)
465
- traceback.print_exception(type(_hook_error), _hook_error, _hook_error.__traceback__.tb_next)
466
- print('\\nOriginal exception was:', file=sys.stderr)
467
- sys.__excepthook__(type(_error), _error, _trace)
468
- finally:
469
- for _stream in (sys.stdout, sys.stderr):
470
- if _stream is not None and not getattr(_stream, 'closed', False):
471
- try:
472
- _stream.flush()
473
- except BaseException:
474
- _safe_exit = 120
475
- _safe_exit
476
- `;
477
-
478
- // packages/safe-bash-command-python/src/runtime-scripts.ts
479
- var pythonRuntimeRelocation = `
480
- import sys, zipimport, importlib.machinery
481
-
482
- def _rebase_runtime_path(value):
483
- return _safe_runtime_mount + value if isinstance(value, str) and (value == '/lib' or value.startswith('/lib/')) else value
484
-
485
- def _rebase_runtime_loader(loader):
486
- if isinstance(loader, zipimport.zipimporter):
487
- archive = _rebase_runtime_path(loader.archive)
488
- if archive != loader.archive:
489
- return zipimport.zipimporter(archive + '/' + loader.prefix)
490
- elif isinstance(loader, (importlib.machinery.SourceFileLoader, importlib.machinery.SourcelessFileLoader, importlib.machinery.ExtensionFileLoader)):
491
- path = _rebase_runtime_path(loader.path)
492
- if path != loader.path:
493
- return type(loader)(loader.name, path)
494
- return loader
495
- sys.path[:] = [_rebase_runtime_path(value) for value in sys.path]
496
- for _module in list(sys.modules.values()):
497
- if _module is None:
498
- continue
499
- for _attribute in ('__file__', '__cached__'):
500
- if hasattr(_module, _attribute):
501
- setattr(_module, _attribute, _rebase_runtime_path(getattr(_module, _attribute)))
502
- if hasattr(_module, '__path__'):
503
- _module.__path__ = [_rebase_runtime_path(value) for value in _module.__path__]
504
- if hasattr(_module, '__loader__'):
505
- _module.__loader__ = _rebase_runtime_loader(_module.__loader__)
506
- _spec = getattr(_module, '__spec__', None)
507
- if _spec is not None:
508
- _spec.origin = _rebase_runtime_path(_spec.origin)
509
- _spec.loader = _rebase_runtime_loader(_spec.loader)
510
- if _spec.submodule_search_locations is not None:
511
- _spec.submodule_search_locations = [_rebase_runtime_path(value) for value in _spec.submodule_search_locations]
512
- sys.path_importer_cache.clear()
513
- `;
514
- var pythonImportMetadata = `
515
- import importlib._bootstrap_external, types, json
516
- _safe_import_stat_callback = _safe_import_stat
517
- _safe_original_import_stat = importlib._bootstrap_external._path_stat
518
- def _safe_import_path_stat(path):
519
- if path == _safe_runtime_mount or path.startswith(_safe_runtime_mount + '/'):
520
- return _safe_original_import_stat(path)
521
- value = json.loads(_safe_import_stat_callback(path))
522
- if 'errno' in value:
523
- raise OSError(value['errno'], 'filesystem import metadata unavailable', path)
524
- return types.SimpleNamespace(st_mode=value['mode'], st_size=value['size'], st_mtime=value['mtimeMs'] / 1000)
525
- importlib._bootstrap_external._path_stat = _safe_import_path_stat
526
- `;
527
- var pythonDirectoryEntries = `
528
- import os, json, errno
529
- _safe_directory_callback = _safe_directory_entries
530
- def _safe_listdir(path='.'):
531
- if isinstance(path, int):
532
- raise OSError(errno.ENOTSUP, 'retained directory descriptors are unsupported')
533
- original = os.fspath(path) if path is not None else '.'
534
- value = json.loads(_safe_directory_callback(os.fsdecode(original)))
535
- if 'errno' in value:
536
- raise OSError(value['errno'], 'directory enumeration failed', path)
537
- return [os.fsencode(name) for name in value['entries']] if isinstance(original, bytes) else value['entries']
538
- os.listdir = _safe_listdir
539
- # The frozen importer holds the posix module separately from os.
540
- importlib._bootstrap_external._os.listdir = _safe_listdir
541
- `;
542
- var pythonStatProjection = `
543
- import os, json, errno
544
- _safe_stat_callback = _safe_stat_projection
545
- _safe_stat_type = os.stat_result
546
- _safe_fspath = os.fspath
547
- _safe_fsdecode = os.fsdecode
548
-
549
- def _safe_stat(path, *, dir_fd=None, follow_symlinks=True):
550
- if dir_fd is not None:
551
- raise OSError(errno.ENOTSUP, 'dir_fd metadata is unsupported')
552
- if isinstance(path, int):
553
- if not follow_symlinks:
554
- raise ValueError('stat: cannot use fd and follow_symlinks together')
555
- else:
556
- path = _safe_fsdecode(_safe_fspath(path))
557
- value = json.loads(_safe_stat_callback(path, follow_symlinks))
558
- if 'errno' in value:
559
- raise OSError(value['errno'], 'filesystem metadata unavailable', path)
560
- keys = ('mode','ino','dev','nlink','uid','gid','size')
561
- if any(key not in value for key in keys):
562
- raise OSError(errno.EOVERFLOW, 'canonical identity or required stat metadata unavailable', path)
563
- times = [value[key] / 1000 for key in ('atimeMs','mtimeMs','ctimeMs')]
564
- extras = dict(zip(('st_atime','st_mtime','st_ctime'), times))
565
- for name, milliseconds in zip(('atime','mtime','ctime'), (value['atimeMs'],value['mtimeMs'],value['ctimeMs'])):
566
- seconds = int(milliseconds // 1000)
567
- extras['st_' + name + '_ns'] = seconds * 1000000000 + round((milliseconds - seconds * 1000) * 1000000)
568
- for key in ('blocks','blksize','rdev'):
569
- if key in value:
570
- extras['st_' + key] = value[key]
571
- return _safe_stat_type(tuple(value[key] for key in keys) + tuple(int(time // 1) for time in times), extras)
572
-
573
- def _safe_lstat(path, *, dir_fd=None):
574
- return _safe_stat(path, dir_fd=dir_fd, follow_symlinks=False)
575
-
576
- def _safe_fstat(fd):
577
- if not isinstance(fd, int):
578
- raise TypeError('file descriptor must be an integer')
579
- return _safe_stat(fd)
580
- os.stat = _safe_stat
581
- os.lstat = _safe_lstat
582
- os.fstat = _safe_fstat
583
- import stat as _safe_stat_module
584
- class _SafeDirEntry:
585
- def __init__(self, root, name):
586
- self.name = name
587
- self.path = os.path.join(root, name)
588
- self._cache = {}
589
- def __fspath__(self):
590
- return self.path
591
- def stat(self, *, follow_symlinks=True):
592
- if follow_symlinks not in self._cache:
593
- self._cache[follow_symlinks] = os.stat(self.path, follow_symlinks=follow_symlinks)
594
- return self._cache[follow_symlinks]
595
- def inode(self):
596
- return self.stat(follow_symlinks=False).st_ino
597
- def is_dir(self, *, follow_symlinks=True):
598
- try:
599
- return _safe_stat_module.S_ISDIR(self.stat(follow_symlinks=follow_symlinks).st_mode)
600
- except FileNotFoundError:
601
- return False
602
- def is_file(self, *, follow_symlinks=True):
603
- try:
604
- return _safe_stat_module.S_ISREG(self.stat(follow_symlinks=follow_symlinks).st_mode)
605
- except FileNotFoundError:
606
- return False
607
- def is_symlink(self):
608
- try:
609
- return _safe_stat_module.S_ISLNK(self.stat(follow_symlinks=False).st_mode)
610
- except FileNotFoundError:
611
- return False
612
- class _SafeScandir:
613
- def __init__(self, path):
614
- self._entries = iter([_SafeDirEntry(path, name) for name in os.listdir(path)])
615
- def __iter__(self):
616
- return self
617
- def __next__(self):
618
- return next(self._entries)
619
- def close(self):
620
- self._entries = iter(())
621
- def __enter__(self):
622
- return self
623
- def __exit__(self, *args):
624
- self.close()
625
- def _safe_scandir(path='.'):
626
- if isinstance(path, int):
627
- raise OSError(errno.ENOTSUP, 'retained directory descriptors are unsupported')
628
- return _SafeScandir(os.fspath(path) if path is not None else '.')
629
- os.scandir = _safe_scandir
630
-
631
- `;
632
- var pythonHardLinks = `
633
- import os, json, errno
634
- _safe_link_callback = _safe_hard_link
635
- def _safe_link(src, dst, *, src_dir_fd=None, dst_dir_fd=None, follow_symlinks=True):
636
- if src_dir_fd is not None or dst_dir_fd is not None:
637
- raise OSError(errno.ENOTSUP, 'dir_fd hard links are unsupported')
638
- source = os.fsdecode(os.fspath(src))
639
- destination = os.fsdecode(os.fspath(dst))
640
- value = json.loads(_safe_link_callback(source, destination, bool(follow_symlinks)))
641
- if 'errno' in value:
642
- raise OSError(value['errno'], 'hard link creation failed', src, None, dst)
643
- os.link = _safe_link
644
- os.supports_follow_symlinks.add(_safe_link)
645
- `;
646
- var pythonTreeCleanup = `
647
- import shutil, os, json
648
- _safe_tree_callback = _safe_tree_cleanup
649
- _safe_original_rmtree_impl = shutil._rmtree_impl
650
- def _safe_rmtree_impl(path, dir_fd, onexc):
651
- if dir_fd is not None:
652
- return _safe_original_rmtree_impl(path, dir_fd, onexc)
653
- value = json.loads(_safe_tree_callback(os.fsdecode(path)))
654
- if not value['supported']:
655
- return _safe_original_rmtree_impl(path, dir_fd, onexc)
656
- if 'errno' in value:
657
- onexc(os.rmdir, path, OSError(value['errno'], 'directory cleanup failed', path))
658
- shutil._rmtree_impl = _safe_rmtree_impl
659
- `;
660
-
661
- export {
662
- PythonInvocationError,
663
- parsePythonInvocation,
664
- pythonPackageUrlHash,
665
- installPythonPackages,
666
- pythonExecution,
667
- pythonRuntimeRelocation,
668
- pythonImportMetadata,
669
- pythonDirectoryEntries,
670
- pythonStatProjection,
671
- pythonHardLinks,
672
- pythonTreeCleanup
673
- };