pythonlib 1.0.1 → 2.0.0
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.
- package/README.md +3 -1
- package/dist/base64-C_am75Sv.d.ts +165 -0
- package/dist/base64.d.ts +1 -0
- package/dist/base64.js +37 -0
- package/dist/chunk-2YTO24B5.js +78 -0
- package/dist/chunk-3CLXPGAB.js +237 -0
- package/dist/{chunk-H76SKASU.js → chunk-3M3PB4RO.js} +4 -6
- package/dist/chunk-5OKGPZBQ.js +1106 -0
- package/dist/chunk-5VAHUJNC.js +348 -0
- package/dist/chunk-B5AUEOAH.js +193 -0
- package/dist/chunk-B5LQJODJ.js +37 -0
- package/dist/{chunk-HQ42WNKZ.js → chunk-BCMGGBWG.js} +2 -5
- package/dist/chunk-BCVIH2BN.js +175 -0
- package/dist/{chunk-EE7SK2GV.js → chunk-D35YI363.js} +15 -12
- package/dist/{chunk-7TH4FCVQ.js → chunk-ETBW6XNR.js} +3 -4
- package/dist/chunk-FCJ7E4OE.js +250 -0
- package/dist/chunk-HSTC277I.js +255 -0
- package/dist/chunk-IANXD4D4.js +250 -0
- package/dist/{chunk-4KYJT3DR.js → chunk-JAUU3HMH.js} +1 -2
- package/dist/chunk-JJKTRIVO.js +262 -0
- package/dist/chunk-KKHKTQNN.js +361 -0
- package/dist/chunk-KKJHGY4C.js +551 -0
- package/dist/chunk-LHPQS75Z.js +192 -0
- package/dist/{chunk-LWO6BIAD.js → chunk-LK2L2TFG.js} +5 -6
- package/dist/chunk-LLZFLQS6.js +280 -0
- package/dist/chunk-LTXTS7RP.js +154 -0
- package/dist/{chunk-4QG3772L.js → chunk-LWYBTWBZ.js} +2 -3
- package/dist/{chunk-6ZAJ37MR.js → chunk-MFKIEN7N.js} +3 -3
- package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
- package/dist/chunk-OZRS5PC4.js +312 -0
- package/dist/chunk-PWA3YQZU.js +346 -0
- package/dist/{chunk-6POEDI34.js → chunk-QKJBQKPY.js} +1 -2
- package/dist/chunk-RB6BYCIQ.js +141 -0
- package/dist/chunk-U4X5DEIP.js +188 -0
- package/dist/chunk-UGZ5OY5Z.js +165 -0
- package/dist/chunk-WTZSAITC.js +82 -0
- package/dist/{collections-CJur5Wg-.d.ts → collections-BthXtkEp.d.ts} +5 -1
- package/dist/collections.d.ts +1 -1
- package/dist/collections.js +2 -3
- package/dist/copy-6ZaZ__ge.d.ts +59 -0
- package/dist/copy.d.ts +1 -0
- package/dist/copy.js +9 -0
- package/dist/{datetime-Bpce8gG2.d.ts → datetime-BM_IjhTq.d.ts} +3 -1
- package/dist/datetime.d.ts +1 -1
- package/dist/datetime.js +2 -3
- package/dist/{functools-NrsZAqJk.d.ts → functools-uIa5g75p.d.ts} +3 -1
- package/dist/functools.d.ts +1 -1
- package/dist/functools.js +2 -3
- package/dist/glob.browser-B6d_YdV5.d.ts +50 -0
- package/dist/glob.browser.d.ts +1 -0
- package/dist/glob.browser.js +15 -0
- package/dist/glob.node-wn5ehtyM.d.ts +80 -0
- package/dist/glob.node.d.ts +1 -0
- package/dist/glob.node.js +15 -0
- package/dist/hashlib-vKP511NY.d.ts +205 -0
- package/dist/hashlib.d.ts +1 -0
- package/dist/hashlib.js +39 -0
- package/dist/index.browser.d.ts +172 -0
- package/dist/index.browser.js +304 -0
- package/dist/index.d.ts +61 -437
- package/dist/index.js +138 -1115
- package/dist/{itertools-Sjl1LB_0.d.ts → itertools-T0rwOk2j.d.ts} +2 -4
- package/dist/itertools.d.ts +1 -1
- package/dist/itertools.js +2 -3
- package/dist/{json-DAlvCadU.d.ts → json-DoWhX04T.d.ts} +1 -0
- package/dist/json.d.ts +1 -1
- package/dist/json.js +2 -3
- package/dist/logging.browser-Dux4L5kz.d.ts +185 -0
- package/dist/logging.browser.d.ts +1 -0
- package/dist/logging.browser.js +63 -0
- package/dist/logging.node-CH75bVdE.d.ts +185 -0
- package/dist/logging.node.d.ts +1 -0
- package/dist/logging.node.js +61 -0
- package/dist/{math-DwEGjjQ-.d.ts → math-D2NPMc-x.d.ts} +2 -1
- package/dist/math.d.ts +1 -1
- package/dist/math.js +2 -3
- package/dist/{os-C6Nt7Ijx.d.ts → os.browser-krjSx5kF.d.ts} +32 -54
- package/dist/os.browser.d.ts +2 -0
- package/dist/{os.js → os.browser.js} +41 -16
- package/dist/os.node-CQjch8Ht.d.ts +124 -0
- package/dist/os.node.d.ts +2 -0
- package/dist/os.node.js +83 -0
- package/dist/os.shared-C3x70nhO.d.ts +59 -0
- package/dist/pathlib.browser-NC7kKQYe.d.ts +91 -0
- package/dist/pathlib.browser.d.ts +1 -0
- package/dist/pathlib.browser.js +17 -0
- package/dist/pathlib.node-CY3yUFdT.d.ts +331 -0
- package/dist/pathlib.node.d.ts +2 -0
- package/dist/pathlib.node.js +17 -0
- package/dist/{random-BJv_rSpL.d.ts → random-DcS5jtEs.d.ts} +3 -5
- package/dist/random.d.ts +1 -1
- package/dist/random.js +2 -3
- package/dist/{re-B1CHCgyr.d.ts → re-Bo-IOqov.d.ts} +3 -7
- package/dist/re.d.ts +1 -1
- package/dist/re.js +2 -3
- package/dist/set-JQbLAq8B.d.ts +592 -0
- package/dist/shutil.browser-Ck5oWhnP.d.ts +113 -0
- package/dist/shutil.browser.d.ts +1 -0
- package/dist/shutil.browser.js +33 -0
- package/dist/shutil.node-C9kwvhAf.d.ts +160 -0
- package/dist/shutil.node.d.ts +2 -0
- package/dist/shutil.node.js +33 -0
- package/dist/string.d.ts +3 -1
- package/dist/string.js +2 -3
- package/dist/subprocess-CZVYzQ3V.d.ts +214 -0
- package/dist/subprocess.d.ts +1 -0
- package/dist/subprocess.js +29 -0
- package/dist/sys-IL8LgI_W.d.ts +212 -0
- package/dist/sys.d.ts +1 -0
- package/dist/sys.js +51 -0
- package/dist/tempfile.browser-DciOKfNm.d.ts +78 -0
- package/dist/tempfile.browser.d.ts +1 -0
- package/dist/tempfile.browser.js +19 -0
- package/dist/tempfile.node-bVMY60Cu.d.ts +195 -0
- package/dist/tempfile.node.d.ts +2 -0
- package/dist/tempfile.node.js +23 -0
- package/dist/time-CcYhdiSu.d.ts +245 -0
- package/dist/time.d.ts +1 -0
- package/dist/time.js +49 -0
- package/dist/urllib-DJtkj-0f.d.ts +198 -0
- package/dist/urllib.d.ts +1 -0
- package/dist/urllib.js +37 -0
- package/dist/uuid-C0ypmn56.d.ts +160 -0
- package/dist/uuid.d.ts +1 -0
- package/dist/uuid.js +23 -0
- package/package.json +127 -5
- package/dist/chunk-4KYJT3DR.js.map +0 -1
- package/dist/chunk-4QG3772L.js.map +0 -1
- package/dist/chunk-6POEDI34.js.map +0 -1
- package/dist/chunk-6ZAJ37MR.js.map +0 -1
- package/dist/chunk-7TH4FCVQ.js.map +0 -1
- package/dist/chunk-CXKGPD5D.js +0 -313
- package/dist/chunk-CXKGPD5D.js.map +0 -1
- package/dist/chunk-EE7SK2GV.js.map +0 -1
- package/dist/chunk-H76SKASU.js.map +0 -1
- package/dist/chunk-HQ42WNKZ.js.map +0 -1
- package/dist/chunk-LWO6BIAD.js.map +0 -1
- package/dist/chunk-PZ5AY32C.js.map +0 -1
- package/dist/collections.js.map +0 -1
- package/dist/datetime.js.map +0 -1
- package/dist/functools.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/itertools.js.map +0 -1
- package/dist/json.js.map +0 -1
- package/dist/math.js.map +0 -1
- package/dist/os.d.ts +0 -1
- package/dist/os.js.map +0 -1
- package/dist/random.js.map +0 -1
- package/dist/re.js.map +0 -1
- package/dist/string.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,90 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tempfile_node_exports
|
|
3
|
+
} from "./chunk-UGZ5OY5Z.js";
|
|
4
|
+
import {
|
|
5
|
+
os_node_exports
|
|
6
|
+
} from "./chunk-OZRS5PC4.js";
|
|
7
|
+
import {
|
|
8
|
+
pathlib_node_exports
|
|
9
|
+
} from "./chunk-KKJHGY4C.js";
|
|
10
|
+
import {
|
|
11
|
+
shutil_node_exports
|
|
12
|
+
} from "./chunk-B5AUEOAH.js";
|
|
13
|
+
import {
|
|
14
|
+
abs,
|
|
15
|
+
all,
|
|
16
|
+
any,
|
|
17
|
+
ascii,
|
|
18
|
+
at,
|
|
19
|
+
bin,
|
|
20
|
+
bool,
|
|
21
|
+
chr,
|
|
22
|
+
contains,
|
|
23
|
+
dict,
|
|
24
|
+
dict2,
|
|
25
|
+
divMod,
|
|
26
|
+
enumerate,
|
|
27
|
+
filter,
|
|
28
|
+
float,
|
|
29
|
+
floorDiv,
|
|
30
|
+
format,
|
|
31
|
+
getattr,
|
|
32
|
+
hasattr,
|
|
33
|
+
hex,
|
|
34
|
+
input,
|
|
35
|
+
int,
|
|
36
|
+
is,
|
|
37
|
+
isinstance,
|
|
38
|
+
iter,
|
|
39
|
+
len,
|
|
40
|
+
list,
|
|
41
|
+
list2,
|
|
42
|
+
map,
|
|
43
|
+
max,
|
|
44
|
+
min,
|
|
45
|
+
mod,
|
|
46
|
+
oct,
|
|
47
|
+
ord,
|
|
48
|
+
pow,
|
|
49
|
+
range,
|
|
50
|
+
repeat,
|
|
51
|
+
repr,
|
|
52
|
+
reversed,
|
|
53
|
+
round,
|
|
54
|
+
set,
|
|
55
|
+
set2,
|
|
56
|
+
setattr,
|
|
57
|
+
slice,
|
|
58
|
+
sorted,
|
|
59
|
+
sprintf,
|
|
60
|
+
str,
|
|
61
|
+
strFormat,
|
|
62
|
+
sum,
|
|
63
|
+
tuple,
|
|
64
|
+
type,
|
|
65
|
+
zip
|
|
66
|
+
} from "./chunk-5OKGPZBQ.js";
|
|
67
|
+
import {
|
|
68
|
+
subprocess_exports
|
|
69
|
+
} from "./chunk-LLZFLQS6.js";
|
|
70
|
+
import {
|
|
71
|
+
sys_exports
|
|
72
|
+
} from "./chunk-U4X5DEIP.js";
|
|
73
|
+
import {
|
|
74
|
+
time_exports
|
|
75
|
+
} from "./chunk-KKHKTQNN.js";
|
|
76
|
+
import {
|
|
77
|
+
urllib_exports
|
|
78
|
+
} from "./chunk-IANXD4D4.js";
|
|
79
|
+
import {
|
|
80
|
+
uuid_exports
|
|
81
|
+
} from "./chunk-FCJ7E4OE.js";
|
|
1
82
|
import {
|
|
2
83
|
random_exports
|
|
3
|
-
} from "./chunk-
|
|
84
|
+
} from "./chunk-3M3PB4RO.js";
|
|
4
85
|
import {
|
|
5
86
|
re_exports
|
|
6
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-ETBW6XNR.js";
|
|
7
88
|
import {
|
|
8
89
|
Template,
|
|
9
90
|
asciiLetters,
|
|
@@ -17,1124 +98,42 @@ import {
|
|
|
17
98
|
punctuation,
|
|
18
99
|
string,
|
|
19
100
|
whitespace
|
|
20
|
-
} from "./chunk-
|
|
101
|
+
} from "./chunk-LWYBTWBZ.js";
|
|
102
|
+
import {
|
|
103
|
+
itertools_exports
|
|
104
|
+
} from "./chunk-BCMGGBWG.js";
|
|
105
|
+
import {
|
|
106
|
+
json_exports
|
|
107
|
+
} from "./chunk-JAUU3HMH.js";
|
|
108
|
+
import {
|
|
109
|
+
logging_node_exports
|
|
110
|
+
} from "./chunk-PWA3YQZU.js";
|
|
111
|
+
import {
|
|
112
|
+
math_exports
|
|
113
|
+
} from "./chunk-QKJBQKPY.js";
|
|
114
|
+
import "./chunk-LHPQS75Z.js";
|
|
115
|
+
import {
|
|
116
|
+
base64_exports
|
|
117
|
+
} from "./chunk-3CLXPGAB.js";
|
|
21
118
|
import {
|
|
22
119
|
collections_exports
|
|
23
|
-
} from "./chunk-
|
|
120
|
+
} from "./chunk-MFKIEN7N.js";
|
|
121
|
+
import {
|
|
122
|
+
copy_exports
|
|
123
|
+
} from "./chunk-LTXTS7RP.js";
|
|
24
124
|
import {
|
|
25
125
|
datetime_exports
|
|
26
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-LK2L2TFG.js";
|
|
27
127
|
import {
|
|
28
128
|
functools_exports
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
import {
|
|
31
|
-
itertools_exports
|
|
32
|
-
} from "./chunk-HQ42WNKZ.js";
|
|
33
|
-
import {
|
|
34
|
-
json_exports
|
|
35
|
-
} from "./chunk-4KYJT3DR.js";
|
|
129
|
+
} from "./chunk-D35YI363.js";
|
|
36
130
|
import {
|
|
37
|
-
|
|
38
|
-
} from "./chunk-
|
|
131
|
+
glob_node_exports
|
|
132
|
+
} from "./chunk-RB6BYCIQ.js";
|
|
39
133
|
import {
|
|
40
|
-
|
|
41
|
-
} from "./chunk-
|
|
42
|
-
import "./chunk-
|
|
43
|
-
|
|
44
|
-
// src/core.ts
|
|
45
|
-
function floorDiv(a, b) {
|
|
46
|
-
return Math.floor(a / b);
|
|
47
|
-
}
|
|
48
|
-
function pow(base, exp) {
|
|
49
|
-
return Math.pow(base, exp);
|
|
50
|
-
}
|
|
51
|
-
function mod(a, b) {
|
|
52
|
-
return (a % b + b) % b;
|
|
53
|
-
}
|
|
54
|
-
function divMod(a, b) {
|
|
55
|
-
return [floorDiv(a, b), mod(a, b)];
|
|
56
|
-
}
|
|
57
|
-
function sprintf(template, args) {
|
|
58
|
-
const values = Array.isArray(args) ? args : [args];
|
|
59
|
-
let index = 0;
|
|
60
|
-
return template.replace(
|
|
61
|
-
/%([+-]?\d*\.?\d*)([sdifxXorec%])/g,
|
|
62
|
-
(match, flags, type3) => {
|
|
63
|
-
if (type3 === "%") return "%";
|
|
64
|
-
if (index >= values.length) return match;
|
|
65
|
-
const value = values[index++];
|
|
66
|
-
switch (type3) {
|
|
67
|
-
case "s":
|
|
68
|
-
return String(value);
|
|
69
|
-
case "d":
|
|
70
|
-
case "i":
|
|
71
|
-
return String(Math.floor(Number(value)));
|
|
72
|
-
case "f":
|
|
73
|
-
if (flags && flags.includes(".")) {
|
|
74
|
-
const precision = parseInt(flags.split(".")[1] ?? "6", 10);
|
|
75
|
-
return Number(value).toFixed(precision);
|
|
76
|
-
}
|
|
77
|
-
return String(Number(value));
|
|
78
|
-
case "x":
|
|
79
|
-
return Math.floor(Number(value)).toString(16);
|
|
80
|
-
case "X":
|
|
81
|
-
return Math.floor(Number(value)).toString(16).toUpperCase();
|
|
82
|
-
case "o":
|
|
83
|
-
return Math.floor(Number(value)).toString(8);
|
|
84
|
-
case "r":
|
|
85
|
-
return JSON.stringify(value);
|
|
86
|
-
case "e":
|
|
87
|
-
return Number(value).toExponential();
|
|
88
|
-
case "c":
|
|
89
|
-
return String.fromCharCode(Number(value));
|
|
90
|
-
/* v8 ignore next 2 -- unreachable: regex only matches handled cases @preserve */
|
|
91
|
-
default:
|
|
92
|
-
return String(value);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
function strFormat(template, ...args) {
|
|
98
|
-
let positionalIndex = 0;
|
|
99
|
-
const lastArg = args[args.length - 1];
|
|
100
|
-
const namedParams = lastArg && typeof lastArg === "object" && !Array.isArray(lastArg) ? lastArg : {};
|
|
101
|
-
return template.replace(/\{([^}]*)\}/g, (match, key) => {
|
|
102
|
-
if (key === "") {
|
|
103
|
-
if (positionalIndex < args.length) {
|
|
104
|
-
return String(args[positionalIndex++]);
|
|
105
|
-
}
|
|
106
|
-
return match;
|
|
107
|
-
}
|
|
108
|
-
const numIndex = parseInt(key, 10);
|
|
109
|
-
if (!isNaN(numIndex) && numIndex < args.length) {
|
|
110
|
-
return String(args[numIndex]);
|
|
111
|
-
}
|
|
112
|
-
if (key in namedParams) {
|
|
113
|
-
return String(namedParams[key]);
|
|
114
|
-
}
|
|
115
|
-
return match;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
function normalizeIndex(index, length, forNegativeStep = false) {
|
|
119
|
-
if (index < 0) {
|
|
120
|
-
index = length + index;
|
|
121
|
-
}
|
|
122
|
-
if (forNegativeStep) {
|
|
123
|
-
return Math.max(-1, Math.min(length - 1, index));
|
|
124
|
-
}
|
|
125
|
-
return Math.max(0, Math.min(length, index));
|
|
126
|
-
}
|
|
127
|
-
function slice(obj, start, stop, step) {
|
|
128
|
-
const len3 = obj.length;
|
|
129
|
-
const actualStep = step ?? 1;
|
|
130
|
-
if (actualStep === 0) {
|
|
131
|
-
throw new Error("slice step cannot be zero");
|
|
132
|
-
}
|
|
133
|
-
let actualStart;
|
|
134
|
-
let actualStop;
|
|
135
|
-
if (actualStep > 0) {
|
|
136
|
-
actualStart = start === void 0 ? 0 : normalizeIndex(start, len3);
|
|
137
|
-
actualStop = stop === void 0 ? len3 : normalizeIndex(stop, len3);
|
|
138
|
-
} else {
|
|
139
|
-
actualStart = start === void 0 ? len3 - 1 : normalizeIndex(start, len3, true);
|
|
140
|
-
actualStop = stop === void 0 ? -1 : normalizeIndex(stop, len3, true);
|
|
141
|
-
}
|
|
142
|
-
const result = [];
|
|
143
|
-
if (actualStep > 0) {
|
|
144
|
-
for (let i = actualStart; i < actualStop; i += actualStep) {
|
|
145
|
-
if (i >= 0 && i < len3) {
|
|
146
|
-
result.push(obj[i]);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else {
|
|
150
|
-
for (let i = actualStart; i > actualStop; i += actualStep) {
|
|
151
|
-
if (i >= 0 && i < len3) {
|
|
152
|
-
result.push(obj[i]);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
if (typeof obj === "string") {
|
|
157
|
-
return result.join("");
|
|
158
|
-
}
|
|
159
|
-
return result;
|
|
160
|
-
}
|
|
161
|
-
function at(obj, index) {
|
|
162
|
-
const len3 = obj.length;
|
|
163
|
-
const normalizedIndex = index < 0 ? len3 + index : index;
|
|
164
|
-
if (normalizedIndex < 0 || normalizedIndex >= len3) {
|
|
165
|
-
throw new Error("IndexError: list index out of range");
|
|
166
|
-
}
|
|
167
|
-
return obj[normalizedIndex];
|
|
168
|
-
}
|
|
169
|
-
function repeat(obj, count) {
|
|
170
|
-
if (count <= 0) {
|
|
171
|
-
return typeof obj === "string" ? "" : [];
|
|
172
|
-
}
|
|
173
|
-
if (typeof obj === "string") {
|
|
174
|
-
return obj.repeat(count);
|
|
175
|
-
}
|
|
176
|
-
const result = [];
|
|
177
|
-
for (let i = 0; i < count; i++) {
|
|
178
|
-
result.push(...obj);
|
|
179
|
-
}
|
|
180
|
-
return result;
|
|
181
|
-
}
|
|
182
|
-
function contains(item, container) {
|
|
183
|
-
if (typeof container === "string") {
|
|
184
|
-
return container.includes(item);
|
|
185
|
-
}
|
|
186
|
-
if (container instanceof Map) {
|
|
187
|
-
return container.has(item);
|
|
188
|
-
}
|
|
189
|
-
if (container instanceof Set) {
|
|
190
|
-
return container.has(item);
|
|
191
|
-
}
|
|
192
|
-
if (Array.isArray(container)) {
|
|
193
|
-
return container.includes(item);
|
|
194
|
-
}
|
|
195
|
-
for (const element of container) {
|
|
196
|
-
if (element === item) {
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
function is(a, b) {
|
|
203
|
-
return a === b;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// src/builtins.ts
|
|
207
|
-
function range(startOrStop, stop, step) {
|
|
208
|
-
let start;
|
|
209
|
-
let end;
|
|
210
|
-
let stepVal;
|
|
211
|
-
if (stop === void 0) {
|
|
212
|
-
start = 0;
|
|
213
|
-
end = startOrStop;
|
|
214
|
-
stepVal = 1;
|
|
215
|
-
} else {
|
|
216
|
-
start = startOrStop;
|
|
217
|
-
end = stop;
|
|
218
|
-
stepVal = step ?? 1;
|
|
219
|
-
}
|
|
220
|
-
if (stepVal === 0) {
|
|
221
|
-
throw new Error("range() arg 3 must not be zero");
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
*[Symbol.iterator]() {
|
|
225
|
-
if (stepVal > 0) {
|
|
226
|
-
for (let i = start; i < end; i += stepVal) {
|
|
227
|
-
yield i;
|
|
228
|
-
}
|
|
229
|
-
} else {
|
|
230
|
-
for (let i = start; i > end; i += stepVal) {
|
|
231
|
-
yield i;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function enumerate(iterable, start = 0) {
|
|
238
|
-
return {
|
|
239
|
-
*[Symbol.iterator]() {
|
|
240
|
-
let index = start;
|
|
241
|
-
for (const item of iterable) {
|
|
242
|
-
yield [index++, item];
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
function zip(...iterables) {
|
|
248
|
-
return {
|
|
249
|
-
*[Symbol.iterator]() {
|
|
250
|
-
const iterators = iterables.map((it) => it[Symbol.iterator]());
|
|
251
|
-
for (; ; ) {
|
|
252
|
-
const results = iterators.map((it) => it.next());
|
|
253
|
-
if (results.some((r) => r.done)) {
|
|
254
|
-
break;
|
|
255
|
-
}
|
|
256
|
-
yield results.map((r) => r.value);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function iter(obj) {
|
|
262
|
-
if (obj === null || obj === void 0) {
|
|
263
|
-
return [];
|
|
264
|
-
}
|
|
265
|
-
if (typeof obj[Symbol.iterator] === "function") {
|
|
266
|
-
return obj;
|
|
267
|
-
}
|
|
268
|
-
if (typeof obj === "object") {
|
|
269
|
-
return Object.keys(obj);
|
|
270
|
-
}
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
function reversed(iterable) {
|
|
274
|
-
const arr = Array.from(iterable);
|
|
275
|
-
return {
|
|
276
|
-
*[Symbol.iterator]() {
|
|
277
|
-
for (let i = arr.length - 1; i >= 0; i--) {
|
|
278
|
-
yield arr[i];
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
function sorted(iterable, options) {
|
|
284
|
-
const arr = Array.from(iterable);
|
|
285
|
-
const key = options?.key ?? ((x) => x);
|
|
286
|
-
const reverse = options?.reverse ?? false;
|
|
287
|
-
arr.sort((a, b) => {
|
|
288
|
-
const aKey = key(a);
|
|
289
|
-
const bKey = key(b);
|
|
290
|
-
let cmp;
|
|
291
|
-
if (typeof aKey === "string" && typeof bKey === "string") {
|
|
292
|
-
cmp = aKey.localeCompare(bKey);
|
|
293
|
-
} else {
|
|
294
|
-
cmp = aKey - bKey;
|
|
295
|
-
}
|
|
296
|
-
return reverse ? -cmp : cmp;
|
|
297
|
-
});
|
|
298
|
-
return arr;
|
|
299
|
-
}
|
|
300
|
-
function map(fn, iterable) {
|
|
301
|
-
return {
|
|
302
|
-
*[Symbol.iterator]() {
|
|
303
|
-
for (const item of iterable) {
|
|
304
|
-
yield fn(item);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
function filter(fn, iterable) {
|
|
310
|
-
return {
|
|
311
|
-
*[Symbol.iterator]() {
|
|
312
|
-
for (const item of iterable) {
|
|
313
|
-
if (fn === null ? bool(item) : fn(item)) {
|
|
314
|
-
yield item;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
function list(iterable) {
|
|
321
|
-
if (iterable === void 0) {
|
|
322
|
-
return [];
|
|
323
|
-
}
|
|
324
|
-
return Array.from(iterable);
|
|
325
|
-
}
|
|
326
|
-
function dict(entries) {
|
|
327
|
-
return new Map(entries);
|
|
328
|
-
}
|
|
329
|
-
function set(iterable) {
|
|
330
|
-
return new Set(iterable);
|
|
331
|
-
}
|
|
332
|
-
function tuple(...items) {
|
|
333
|
-
return Object.freeze([...items]);
|
|
334
|
-
}
|
|
335
|
-
function len(obj) {
|
|
336
|
-
if (typeof obj === "string" || Array.isArray(obj)) {
|
|
337
|
-
return obj.length;
|
|
338
|
-
}
|
|
339
|
-
if (obj instanceof Map || obj instanceof Set) {
|
|
340
|
-
return obj.size;
|
|
341
|
-
}
|
|
342
|
-
if (typeof obj === "object" && obj !== null && "length" in obj) {
|
|
343
|
-
return obj.length;
|
|
344
|
-
}
|
|
345
|
-
throw new TypeError("object has no len()");
|
|
346
|
-
}
|
|
347
|
-
function abs(x) {
|
|
348
|
-
return Math.abs(x);
|
|
349
|
-
}
|
|
350
|
-
function min(...args) {
|
|
351
|
-
const first = args[0];
|
|
352
|
-
if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
|
|
353
|
-
const arr = [...first];
|
|
354
|
-
if (arr.length === 0) {
|
|
355
|
-
throw new Error("min() arg is an empty sequence");
|
|
356
|
-
}
|
|
357
|
-
return arr.reduce((a, b) => a < b ? a : b);
|
|
358
|
-
}
|
|
359
|
-
if (args.length === 0) {
|
|
360
|
-
throw new Error("min expected at least 1 argument, got 0");
|
|
361
|
-
}
|
|
362
|
-
return args.reduce((a, b) => a < b ? a : b);
|
|
363
|
-
}
|
|
364
|
-
function max(...args) {
|
|
365
|
-
const first = args[0];
|
|
366
|
-
if (args.length === 1 && typeof first === "object" && first !== null && Symbol.iterator in first) {
|
|
367
|
-
const arr = [...first];
|
|
368
|
-
if (arr.length === 0) {
|
|
369
|
-
throw new Error("max() arg is an empty sequence");
|
|
370
|
-
}
|
|
371
|
-
return arr.reduce((a, b) => a > b ? a : b);
|
|
372
|
-
}
|
|
373
|
-
if (args.length === 0) {
|
|
374
|
-
throw new Error("max expected at least 1 argument, got 0");
|
|
375
|
-
}
|
|
376
|
-
return args.reduce((a, b) => a > b ? a : b);
|
|
377
|
-
}
|
|
378
|
-
function sum(iterable, start = 0) {
|
|
379
|
-
let total = start;
|
|
380
|
-
for (const item of iterable) {
|
|
381
|
-
total += item;
|
|
382
|
-
}
|
|
383
|
-
return total;
|
|
384
|
-
}
|
|
385
|
-
function all(iterable) {
|
|
386
|
-
for (const item of iterable) {
|
|
387
|
-
if (!bool(item)) return false;
|
|
388
|
-
}
|
|
389
|
-
return true;
|
|
390
|
-
}
|
|
391
|
-
function any(iterable) {
|
|
392
|
-
for (const item of iterable) {
|
|
393
|
-
if (bool(item)) return true;
|
|
394
|
-
}
|
|
395
|
-
return false;
|
|
396
|
-
}
|
|
397
|
-
function round(number, ndigits) {
|
|
398
|
-
if (ndigits === void 0 || ndigits === 0) {
|
|
399
|
-
const rounded = Math.round(number);
|
|
400
|
-
if (Math.abs(number % 1) === 0.5) {
|
|
401
|
-
return rounded % 2 === 0 ? rounded : rounded - Math.sign(number);
|
|
402
|
-
}
|
|
403
|
-
return rounded;
|
|
404
|
-
}
|
|
405
|
-
const factor = Math.pow(10, ndigits);
|
|
406
|
-
return Math.round(number * factor) / factor;
|
|
407
|
-
}
|
|
408
|
-
function ord(char) {
|
|
409
|
-
if (char.length !== 1) {
|
|
410
|
-
throw new Error("ord() expected a character");
|
|
411
|
-
}
|
|
412
|
-
return char.charCodeAt(0);
|
|
413
|
-
}
|
|
414
|
-
function chr(code) {
|
|
415
|
-
return String.fromCharCode(code);
|
|
416
|
-
}
|
|
417
|
-
function hex(x) {
|
|
418
|
-
const prefix = x < 0 ? "-0x" : "0x";
|
|
419
|
-
return prefix + Math.abs(Math.trunc(x)).toString(16);
|
|
420
|
-
}
|
|
421
|
-
function oct(x) {
|
|
422
|
-
const prefix = x < 0 ? "-0o" : "0o";
|
|
423
|
-
return prefix + Math.abs(Math.trunc(x)).toString(8);
|
|
424
|
-
}
|
|
425
|
-
function bin(x) {
|
|
426
|
-
const prefix = x < 0 ? "-0b" : "0b";
|
|
427
|
-
return prefix + Math.abs(Math.trunc(x)).toString(2);
|
|
428
|
-
}
|
|
429
|
-
function int(x, base) {
|
|
430
|
-
if (typeof x === "boolean") {
|
|
431
|
-
return x ? 1 : 0;
|
|
432
|
-
}
|
|
433
|
-
if (typeof x === "number") {
|
|
434
|
-
return Math.trunc(x);
|
|
435
|
-
}
|
|
436
|
-
const parsed = base !== void 0 ? parseInt(x, base) : parseInt(x, 10);
|
|
437
|
-
if (isNaN(parsed)) {
|
|
438
|
-
throw new Error(`invalid literal for int(): '${x}'`);
|
|
439
|
-
}
|
|
440
|
-
return parsed;
|
|
441
|
-
}
|
|
442
|
-
function float(x) {
|
|
443
|
-
if (typeof x === "number") {
|
|
444
|
-
return x;
|
|
445
|
-
}
|
|
446
|
-
const parsed = parseFloat(x);
|
|
447
|
-
if (isNaN(parsed)) {
|
|
448
|
-
throw new Error(`could not convert string to float: '${x}'`);
|
|
449
|
-
}
|
|
450
|
-
return parsed;
|
|
451
|
-
}
|
|
452
|
-
function str(x) {
|
|
453
|
-
if (x === null) {
|
|
454
|
-
return "None";
|
|
455
|
-
}
|
|
456
|
-
if (x === void 0) {
|
|
457
|
-
return "None";
|
|
458
|
-
}
|
|
459
|
-
if (typeof x === "boolean") {
|
|
460
|
-
return x ? "True" : "False";
|
|
461
|
-
}
|
|
462
|
-
if (Array.isArray(x)) {
|
|
463
|
-
return "[" + x.map((item) => repr(item)).join(", ") + "]";
|
|
464
|
-
}
|
|
465
|
-
if (x instanceof Map) {
|
|
466
|
-
const entries = Array.from(x.entries()).map(([k, v]) => `${repr(k)}: ${repr(v)}`).join(", ");
|
|
467
|
-
return "{" + entries + "}";
|
|
468
|
-
}
|
|
469
|
-
if (x instanceof Set) {
|
|
470
|
-
if (x.size === 0) {
|
|
471
|
-
return "set()";
|
|
472
|
-
}
|
|
473
|
-
return "{" + Array.from(x).map((item) => repr(item)).join(", ") + "}";
|
|
474
|
-
}
|
|
475
|
-
return String(x);
|
|
476
|
-
}
|
|
477
|
-
function repr(x) {
|
|
478
|
-
if (typeof x === "string") {
|
|
479
|
-
return `'${x}'`;
|
|
480
|
-
}
|
|
481
|
-
return str(x);
|
|
482
|
-
}
|
|
483
|
-
function bool(x) {
|
|
484
|
-
if (x === null || x === void 0) {
|
|
485
|
-
return false;
|
|
486
|
-
}
|
|
487
|
-
if (typeof x === "boolean") {
|
|
488
|
-
return x;
|
|
489
|
-
}
|
|
490
|
-
if (typeof x === "number") {
|
|
491
|
-
return x !== 0;
|
|
492
|
-
}
|
|
493
|
-
if (typeof x === "string") {
|
|
494
|
-
return x.length > 0;
|
|
495
|
-
}
|
|
496
|
-
if (Array.isArray(x)) {
|
|
497
|
-
return x.length > 0;
|
|
498
|
-
}
|
|
499
|
-
if (x instanceof Map || x instanceof Set) {
|
|
500
|
-
return x.size > 0;
|
|
501
|
-
}
|
|
502
|
-
return true;
|
|
503
|
-
}
|
|
504
|
-
function ascii(x) {
|
|
505
|
-
const s = repr(x);
|
|
506
|
-
let result = "";
|
|
507
|
-
for (const char of s) {
|
|
508
|
-
const code = char.charCodeAt(0);
|
|
509
|
-
if (code > 127) {
|
|
510
|
-
if (code > 65535) {
|
|
511
|
-
result += `\\U${code.toString(16).padStart(8, "0")}`;
|
|
512
|
-
} else {
|
|
513
|
-
result += `\\u${code.toString(16).padStart(4, "0")}`;
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
result += char;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return result;
|
|
520
|
-
}
|
|
521
|
-
function isinstance(obj, classInfo) {
|
|
522
|
-
if (classInfo === Number || classInfo === "int" || classInfo === "float") {
|
|
523
|
-
return typeof obj === "number";
|
|
524
|
-
}
|
|
525
|
-
if (classInfo === String || classInfo === "str") {
|
|
526
|
-
return typeof obj === "string";
|
|
527
|
-
}
|
|
528
|
-
if (classInfo === Boolean || classInfo === "bool") {
|
|
529
|
-
return typeof obj === "boolean";
|
|
530
|
-
}
|
|
531
|
-
if (classInfo === Array || classInfo === "list") {
|
|
532
|
-
return Array.isArray(obj);
|
|
533
|
-
}
|
|
534
|
-
if (classInfo === Map || classInfo === "dict") {
|
|
535
|
-
return obj instanceof Map;
|
|
536
|
-
}
|
|
537
|
-
if (classInfo === Set || classInfo === "set") {
|
|
538
|
-
return obj instanceof Set;
|
|
539
|
-
}
|
|
540
|
-
if (typeof classInfo === "function") {
|
|
541
|
-
return obj instanceof classInfo;
|
|
542
|
-
}
|
|
543
|
-
return false;
|
|
544
|
-
}
|
|
545
|
-
function type(obj) {
|
|
546
|
-
if (obj === null) return "NoneType";
|
|
547
|
-
if (typeof obj === "number") {
|
|
548
|
-
return Number.isInteger(obj) ? "int" : "float";
|
|
549
|
-
}
|
|
550
|
-
if (typeof obj === "string") return "str";
|
|
551
|
-
if (typeof obj === "boolean") return "bool";
|
|
552
|
-
if (Array.isArray(obj)) return "list";
|
|
553
|
-
if (obj instanceof Map) return "dict";
|
|
554
|
-
if (obj instanceof Set) return "set";
|
|
555
|
-
return typeof obj;
|
|
556
|
-
}
|
|
557
|
-
function input(prompt) {
|
|
558
|
-
if (prompt) {
|
|
559
|
-
process.stdout.write(prompt);
|
|
560
|
-
}
|
|
561
|
-
throw new Error("input() requires async implementation");
|
|
562
|
-
}
|
|
563
|
-
function formatNumber(num, sign, _hash, grouping, precision, isInteger = true) {
|
|
564
|
-
let result;
|
|
565
|
-
if (isInteger) {
|
|
566
|
-
result = Math.trunc(num).toString();
|
|
567
|
-
} else {
|
|
568
|
-
result = num.toFixed(precision ?? 6);
|
|
569
|
-
}
|
|
570
|
-
if (grouping) {
|
|
571
|
-
const sep = grouping === "_" ? "_" : ",";
|
|
572
|
-
const parts = result.split(".");
|
|
573
|
-
const intPart = parts[0];
|
|
574
|
-
const signChar = intPart[0] === "-" ? "-" : "";
|
|
575
|
-
const digits2 = signChar ? intPart.slice(1) : intPart;
|
|
576
|
-
const grouped = digits2.replace(/\B(?=(\d{3})+(?!\d))/g, sep);
|
|
577
|
-
parts[0] = signChar + grouped;
|
|
578
|
-
result = parts.join(".");
|
|
579
|
-
}
|
|
580
|
-
if (num >= 0) {
|
|
581
|
-
if (sign === "+") {
|
|
582
|
-
result = "+" + result;
|
|
583
|
-
} else if (sign === " ") {
|
|
584
|
-
result = " " + result;
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
return result;
|
|
588
|
-
}
|
|
589
|
-
function format(value, spec) {
|
|
590
|
-
if (spec === "") {
|
|
591
|
-
return str(value);
|
|
592
|
-
}
|
|
593
|
-
const match = spec.match(
|
|
594
|
-
/^(.?[<>=^])?([+\- ])?([#])?(0)?(\d+)?([,_])?(?:\.(\d+))?([bcdeEfFgGnosxX%])?$/
|
|
595
|
-
);
|
|
596
|
-
if (!match) {
|
|
597
|
-
return str(value);
|
|
598
|
-
}
|
|
599
|
-
const [, alignPart, sign, hash, zero, widthStr, grouping, precisionStr, typeChar] = match;
|
|
600
|
-
let fill = " ";
|
|
601
|
-
let align = "";
|
|
602
|
-
if (alignPart) {
|
|
603
|
-
if (alignPart.length === 2) {
|
|
604
|
-
fill = alignPart[0];
|
|
605
|
-
align = alignPart[1];
|
|
606
|
-
} else {
|
|
607
|
-
align = alignPart;
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
const width = widthStr ? parseInt(widthStr, 10) : 0;
|
|
611
|
-
const precision = precisionStr !== void 0 ? parseInt(precisionStr, 10) : void 0;
|
|
612
|
-
if (zero && !alignPart) {
|
|
613
|
-
fill = "0";
|
|
614
|
-
align = "=";
|
|
615
|
-
}
|
|
616
|
-
let result;
|
|
617
|
-
if (typeChar === "s" || !typeChar && typeof value === "string") {
|
|
618
|
-
result = str(value);
|
|
619
|
-
if (precision !== void 0) {
|
|
620
|
-
result = result.slice(0, precision);
|
|
621
|
-
}
|
|
622
|
-
} else if (typeChar === "d" || !typeChar && typeof value === "number" && Number.isInteger(value)) {
|
|
623
|
-
const num = typeof value === "number" ? value : int(value);
|
|
624
|
-
result = formatNumber(num, sign, "", grouping);
|
|
625
|
-
} else if (typeChar === "f" || typeChar === "F") {
|
|
626
|
-
const num = typeof value === "number" ? value : float(value);
|
|
627
|
-
const prec = precision ?? 6;
|
|
628
|
-
result = formatNumber(num, sign, "", grouping, prec, false);
|
|
629
|
-
if (typeChar === "F") result = result.toUpperCase();
|
|
630
|
-
} else if (typeChar === "e" || typeChar === "E") {
|
|
631
|
-
const num = typeof value === "number" ? value : float(value);
|
|
632
|
-
const prec = precision ?? 6;
|
|
633
|
-
result = num.toExponential(prec);
|
|
634
|
-
if (sign === "+" && num >= 0) result = "+" + result;
|
|
635
|
-
else if (sign === " " && num >= 0) result = " " + result;
|
|
636
|
-
if (typeChar === "E") result = result.toUpperCase();
|
|
637
|
-
} else if (typeChar === "g" || typeChar === "G") {
|
|
638
|
-
const num = typeof value === "number" ? value : float(value);
|
|
639
|
-
const prec = precision ?? 6;
|
|
640
|
-
result = num.toPrecision(prec);
|
|
641
|
-
if (sign === "+" && num >= 0) result = "+" + result;
|
|
642
|
-
else if (sign === " " && num >= 0) result = " " + result;
|
|
643
|
-
if (typeChar === "G") result = result.toUpperCase();
|
|
644
|
-
} else if (typeChar === "x" || typeChar === "X") {
|
|
645
|
-
const num = typeof value === "number" ? Math.trunc(value) : int(value);
|
|
646
|
-
result = Math.abs(num).toString(16);
|
|
647
|
-
if (hash) result = "0x" + result;
|
|
648
|
-
if (num < 0) result = "-" + result;
|
|
649
|
-
else if (sign === "+") result = "+" + result;
|
|
650
|
-
else if (sign === " ") result = " " + result;
|
|
651
|
-
if (typeChar === "X") result = result.toUpperCase();
|
|
652
|
-
} else if (typeChar === "o") {
|
|
653
|
-
const num = typeof value === "number" ? Math.trunc(value) : int(value);
|
|
654
|
-
result = Math.abs(num).toString(8);
|
|
655
|
-
if (hash) result = "0o" + result;
|
|
656
|
-
if (num < 0) result = "-" + result;
|
|
657
|
-
else if (sign === "+") result = "+" + result;
|
|
658
|
-
else if (sign === " ") result = " " + result;
|
|
659
|
-
} else if (typeChar === "b") {
|
|
660
|
-
const num = typeof value === "number" ? Math.trunc(value) : int(value);
|
|
661
|
-
result = Math.abs(num).toString(2);
|
|
662
|
-
if (hash) result = "0b" + result;
|
|
663
|
-
if (num < 0) result = "-" + result;
|
|
664
|
-
else if (sign === "+") result = "+" + result;
|
|
665
|
-
else if (sign === " ") result = " " + result;
|
|
666
|
-
} else if (typeChar === "c") {
|
|
667
|
-
const code = typeof value === "number" ? value : int(value);
|
|
668
|
-
result = String.fromCharCode(code);
|
|
669
|
-
} else if (typeChar === "%") {
|
|
670
|
-
const num = typeof value === "number" ? value : float(value);
|
|
671
|
-
const prec = precision ?? 6;
|
|
672
|
-
result = (num * 100).toFixed(prec) + "%";
|
|
673
|
-
if (sign === "+" && num >= 0) result = "+" + result;
|
|
674
|
-
else if (sign === " " && num >= 0) result = " " + result;
|
|
675
|
-
} else if (typeChar === "n") {
|
|
676
|
-
const num = typeof value === "number" ? value : float(value);
|
|
677
|
-
result = num.toLocaleString();
|
|
678
|
-
} else {
|
|
679
|
-
result = str(value);
|
|
680
|
-
}
|
|
681
|
-
if (width > result.length) {
|
|
682
|
-
const padding = fill.repeat(width - result.length);
|
|
683
|
-
if (align === "<") {
|
|
684
|
-
result = result + padding;
|
|
685
|
-
} else if (align === ">" || align === "") {
|
|
686
|
-
result = padding + result;
|
|
687
|
-
} else if (align === "^") {
|
|
688
|
-
const leftPad = Math.floor((width - result.length) / 2);
|
|
689
|
-
const rightPad = width - result.length - leftPad;
|
|
690
|
-
result = fill.repeat(leftPad) + result + fill.repeat(rightPad);
|
|
691
|
-
} else if (align === "=") {
|
|
692
|
-
const signMatch = result.match(/^([+\- ]|0[xXoObB])?(.*)$/);
|
|
693
|
-
if (signMatch) {
|
|
694
|
-
const signPart = signMatch[1] ?? "";
|
|
695
|
-
const numPart = signMatch[2] ?? "";
|
|
696
|
-
result = signPart + padding + numPart;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
}
|
|
700
|
-
return result;
|
|
701
|
-
}
|
|
702
|
-
function getattr(obj, name, defaultValue) {
|
|
703
|
-
if (obj === null || obj === void 0) {
|
|
704
|
-
if (arguments.length >= 3) {
|
|
705
|
-
return defaultValue;
|
|
706
|
-
}
|
|
707
|
-
throw new TypeError(
|
|
708
|
-
`'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
|
|
709
|
-
);
|
|
710
|
-
}
|
|
711
|
-
const target = obj;
|
|
712
|
-
if (name in target) {
|
|
713
|
-
return target[name];
|
|
714
|
-
}
|
|
715
|
-
if (arguments.length >= 3) {
|
|
716
|
-
return defaultValue;
|
|
717
|
-
}
|
|
718
|
-
throw new TypeError(`'${typeof obj}' object has no attribute '${name}'`);
|
|
719
|
-
}
|
|
720
|
-
function hasattr(obj, name) {
|
|
721
|
-
if (obj === null || obj === void 0) {
|
|
722
|
-
return false;
|
|
723
|
-
}
|
|
724
|
-
return name in obj;
|
|
725
|
-
}
|
|
726
|
-
function setattr(obj, name, value) {
|
|
727
|
-
if (obj === null || obj === void 0) {
|
|
728
|
-
throw new TypeError(
|
|
729
|
-
`'${obj === null ? "NoneType" : "undefined"}' object has no attribute '${name}'`
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
;
|
|
733
|
-
obj[name] = value;
|
|
734
|
-
}
|
|
735
|
-
|
|
736
|
-
// src/list.ts
|
|
737
|
-
var list2 = {
|
|
738
|
-
/**
|
|
739
|
-
* Python list.append() - modifies array in place
|
|
740
|
-
*/
|
|
741
|
-
append(arr, item) {
|
|
742
|
-
arr.push(item);
|
|
743
|
-
},
|
|
744
|
-
/**
|
|
745
|
-
* Python list.extend() - modifies array in place
|
|
746
|
-
*/
|
|
747
|
-
extend(arr, items) {
|
|
748
|
-
arr.push(...items);
|
|
749
|
-
},
|
|
750
|
-
/**
|
|
751
|
-
* Python list.insert() - modifies array in place
|
|
752
|
-
*/
|
|
753
|
-
insert(arr, index, item) {
|
|
754
|
-
arr.splice(index, 0, item);
|
|
755
|
-
},
|
|
756
|
-
/**
|
|
757
|
-
* Python list.remove() - removes first occurrence, modifies in place
|
|
758
|
-
*/
|
|
759
|
-
remove(arr, value) {
|
|
760
|
-
const index = arr.indexOf(value);
|
|
761
|
-
if (index === -1) {
|
|
762
|
-
throw new Error("list.remove(x): x not in list");
|
|
763
|
-
}
|
|
764
|
-
arr.splice(index, 1);
|
|
765
|
-
},
|
|
766
|
-
/**
|
|
767
|
-
* Python list.pop() - removes and returns item at index
|
|
768
|
-
*/
|
|
769
|
-
pop(arr, index) {
|
|
770
|
-
if (arr.length === 0) {
|
|
771
|
-
throw new Error("pop from empty list");
|
|
772
|
-
}
|
|
773
|
-
const i = index ?? arr.length - 1;
|
|
774
|
-
const normalizedIndex = i < 0 ? arr.length + i : i;
|
|
775
|
-
if (normalizedIndex < 0 || normalizedIndex >= arr.length) {
|
|
776
|
-
throw new Error("pop index out of range");
|
|
777
|
-
}
|
|
778
|
-
return arr.splice(normalizedIndex, 1)[0];
|
|
779
|
-
},
|
|
780
|
-
/**
|
|
781
|
-
* Python list.clear() - removes all items
|
|
782
|
-
*/
|
|
783
|
-
clear(arr) {
|
|
784
|
-
arr.length = 0;
|
|
785
|
-
},
|
|
786
|
-
/**
|
|
787
|
-
* Python list.index() - finds first occurrence
|
|
788
|
-
*/
|
|
789
|
-
index(arr, value, start, end) {
|
|
790
|
-
const searchStart = start ?? 0;
|
|
791
|
-
const searchEnd = end ?? arr.length;
|
|
792
|
-
for (let i = searchStart; i < searchEnd; i++) {
|
|
793
|
-
if (arr[i] === value) {
|
|
794
|
-
return i;
|
|
795
|
-
}
|
|
796
|
-
}
|
|
797
|
-
throw new Error("x not in list");
|
|
798
|
-
},
|
|
799
|
-
/**
|
|
800
|
-
* Python list.count() - counts occurrences
|
|
801
|
-
*/
|
|
802
|
-
count(arr, value) {
|
|
803
|
-
let count = 0;
|
|
804
|
-
for (const item of arr) {
|
|
805
|
-
if (item === value) count++;
|
|
806
|
-
}
|
|
807
|
-
return count;
|
|
808
|
-
},
|
|
809
|
-
/**
|
|
810
|
-
* Python list.sort() with key function - modifies in place
|
|
811
|
-
*/
|
|
812
|
-
sort(arr, options) {
|
|
813
|
-
const key = options?.key ?? ((x) => x);
|
|
814
|
-
const reverse = options?.reverse ?? false;
|
|
815
|
-
arr.sort((a, b) => {
|
|
816
|
-
const aKey = key(a);
|
|
817
|
-
const bKey = key(b);
|
|
818
|
-
let cmp = 0;
|
|
819
|
-
if (aKey < bKey) cmp = -1;
|
|
820
|
-
else if (aKey > bKey) cmp = 1;
|
|
821
|
-
return reverse ? -cmp : cmp;
|
|
822
|
-
});
|
|
823
|
-
},
|
|
824
|
-
/**
|
|
825
|
-
* Python list.reverse() - reverses in place
|
|
826
|
-
*/
|
|
827
|
-
reverse(arr) {
|
|
828
|
-
arr.reverse();
|
|
829
|
-
},
|
|
830
|
-
/**
|
|
831
|
-
* Python list.copy() - shallow copy
|
|
832
|
-
*/
|
|
833
|
-
copy(arr) {
|
|
834
|
-
return [...arr];
|
|
835
|
-
},
|
|
836
|
-
/**
|
|
837
|
-
* Python slice assignment: arr[start:end:step] = values
|
|
838
|
-
* Replaces a slice of the array with new values, modifying in place
|
|
839
|
-
*/
|
|
840
|
-
sliceAssign(arr, start, end, step, values) {
|
|
841
|
-
const len3 = arr.length;
|
|
842
|
-
const actualStep = step ?? 1;
|
|
843
|
-
let actualStart = start ?? (actualStep > 0 ? 0 : len3 - 1);
|
|
844
|
-
let actualEnd = end ?? (actualStep > 0 ? len3 : -len3 - 1);
|
|
845
|
-
if (actualStart < 0) actualStart = Math.max(0, len3 + actualStart);
|
|
846
|
-
if (actualEnd < 0) actualEnd = Math.max(0, len3 + actualEnd);
|
|
847
|
-
actualStart = Math.min(actualStart, len3);
|
|
848
|
-
actualEnd = Math.min(actualEnd, len3);
|
|
849
|
-
if (actualStep === 1) {
|
|
850
|
-
const deleteCount = Math.max(0, actualEnd - actualStart);
|
|
851
|
-
arr.splice(actualStart, deleteCount, ...values);
|
|
852
|
-
} else {
|
|
853
|
-
const indices = [];
|
|
854
|
-
if (actualStep > 0) {
|
|
855
|
-
for (let i = actualStart; i < actualEnd; i += actualStep) {
|
|
856
|
-
indices.push(i);
|
|
857
|
-
}
|
|
858
|
-
} else {
|
|
859
|
-
for (let i = actualStart; i > actualEnd; i += actualStep) {
|
|
860
|
-
indices.push(i);
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
if (indices.length !== values.length) {
|
|
864
|
-
throw new Error(
|
|
865
|
-
`attempt to assign sequence of size ${String(values.length)} to extended slice of size ${String(indices.length)}`
|
|
866
|
-
);
|
|
867
|
-
}
|
|
868
|
-
for (let i = 0; i < indices.length; i++) {
|
|
869
|
-
const idx = indices[i];
|
|
870
|
-
if (idx !== void 0) {
|
|
871
|
-
arr[idx] = values[i];
|
|
872
|
-
}
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
// src/dict.ts
|
|
879
|
-
var dict2 = {
|
|
880
|
-
/**
|
|
881
|
-
* Python dict.get() - get value with optional default
|
|
882
|
-
*/
|
|
883
|
-
get(obj, key, defaultValue) {
|
|
884
|
-
return key in obj ? obj[key] : defaultValue;
|
|
885
|
-
},
|
|
886
|
-
/**
|
|
887
|
-
* Python dict.setDefault() - get value or set default
|
|
888
|
-
*/
|
|
889
|
-
setDefault(obj, key, defaultValue) {
|
|
890
|
-
if (!(key in obj)) {
|
|
891
|
-
obj[key] = defaultValue;
|
|
892
|
-
}
|
|
893
|
-
return obj[key];
|
|
894
|
-
},
|
|
895
|
-
/**
|
|
896
|
-
* Python dict.pop() - remove and return value
|
|
897
|
-
*/
|
|
898
|
-
pop(obj, key, defaultValue) {
|
|
899
|
-
if (key in obj) {
|
|
900
|
-
const value = obj[key];
|
|
901
|
-
delete obj[key];
|
|
902
|
-
return value;
|
|
903
|
-
}
|
|
904
|
-
if (defaultValue !== void 0) {
|
|
905
|
-
return defaultValue;
|
|
906
|
-
}
|
|
907
|
-
throw new Error("KeyError");
|
|
908
|
-
},
|
|
909
|
-
/**
|
|
910
|
-
* Python dict.popItem() - remove and return last item
|
|
911
|
-
*/
|
|
912
|
-
popItem(obj) {
|
|
913
|
-
const keys = Object.keys(obj);
|
|
914
|
-
if (keys.length === 0) {
|
|
915
|
-
throw new Error("dictionary is empty");
|
|
916
|
-
}
|
|
917
|
-
const key = keys[keys.length - 1];
|
|
918
|
-
const value = obj[key];
|
|
919
|
-
delete obj[key];
|
|
920
|
-
return [key, value];
|
|
921
|
-
},
|
|
922
|
-
/**
|
|
923
|
-
* Python dict.update() - update with another dict
|
|
924
|
-
*/
|
|
925
|
-
update(obj, other) {
|
|
926
|
-
if (Symbol.iterator in other) {
|
|
927
|
-
for (const [k, v] of other) {
|
|
928
|
-
obj[k] = v;
|
|
929
|
-
}
|
|
930
|
-
} else {
|
|
931
|
-
Object.assign(obj, other);
|
|
932
|
-
}
|
|
933
|
-
},
|
|
934
|
-
/**
|
|
935
|
-
* Python dict.clear() - remove all items
|
|
936
|
-
*/
|
|
937
|
-
clear(obj) {
|
|
938
|
-
for (const key of Object.keys(obj)) {
|
|
939
|
-
delete obj[key];
|
|
940
|
-
}
|
|
941
|
-
},
|
|
942
|
-
/**
|
|
943
|
-
* Python dict.copy() - shallow copy
|
|
944
|
-
*/
|
|
945
|
-
copy(obj) {
|
|
946
|
-
return { ...obj };
|
|
947
|
-
},
|
|
948
|
-
/**
|
|
949
|
-
* Python dict.keys() - returns iterable of keys
|
|
950
|
-
*/
|
|
951
|
-
keys(obj) {
|
|
952
|
-
return Object.keys(obj);
|
|
953
|
-
},
|
|
954
|
-
/**
|
|
955
|
-
* Python dict.values() - returns iterable of values
|
|
956
|
-
*/
|
|
957
|
-
values(obj) {
|
|
958
|
-
return Object.values(obj);
|
|
959
|
-
},
|
|
960
|
-
/**
|
|
961
|
-
* Python dict.items() - returns iterable of [key, value] pairs
|
|
962
|
-
*/
|
|
963
|
-
items(obj) {
|
|
964
|
-
return Object.entries(obj);
|
|
965
|
-
},
|
|
966
|
-
/**
|
|
967
|
-
* Python dict.fromKeys() - create dict from keys
|
|
968
|
-
*/
|
|
969
|
-
fromKeys(keys, value) {
|
|
970
|
-
const result = {};
|
|
971
|
-
for (const key of keys) {
|
|
972
|
-
result[key] = value;
|
|
973
|
-
}
|
|
974
|
-
return result;
|
|
975
|
-
}
|
|
976
|
-
};
|
|
977
|
-
|
|
978
|
-
// src/set.ts
|
|
979
|
-
var set2 = {
|
|
980
|
-
/**
|
|
981
|
-
* Python set.add() - add element
|
|
982
|
-
*/
|
|
983
|
-
add(s, item) {
|
|
984
|
-
s.add(item);
|
|
985
|
-
},
|
|
986
|
-
/**
|
|
987
|
-
* Python set.remove() - remove element, raises error if not found
|
|
988
|
-
*/
|
|
989
|
-
remove(s, item) {
|
|
990
|
-
if (!s.has(item)) {
|
|
991
|
-
throw new Error("KeyError");
|
|
992
|
-
}
|
|
993
|
-
s.delete(item);
|
|
994
|
-
},
|
|
995
|
-
/**
|
|
996
|
-
* Python set.discard() - remove element if present
|
|
997
|
-
*/
|
|
998
|
-
discard(s, item) {
|
|
999
|
-
s.delete(item);
|
|
1000
|
-
},
|
|
1001
|
-
/**
|
|
1002
|
-
* Python set.pop() - remove and return arbitrary element
|
|
1003
|
-
*/
|
|
1004
|
-
pop(s) {
|
|
1005
|
-
if (s.size === 0) {
|
|
1006
|
-
throw new Error("pop from an empty set");
|
|
1007
|
-
}
|
|
1008
|
-
const item = s.values().next().value;
|
|
1009
|
-
s.delete(item);
|
|
1010
|
-
return item;
|
|
1011
|
-
},
|
|
1012
|
-
/**
|
|
1013
|
-
* Python set.clear() - remove all elements
|
|
1014
|
-
*/
|
|
1015
|
-
clear(s) {
|
|
1016
|
-
s.clear();
|
|
1017
|
-
},
|
|
1018
|
-
/**
|
|
1019
|
-
* Python set.copy() - shallow copy
|
|
1020
|
-
*/
|
|
1021
|
-
copy(s) {
|
|
1022
|
-
return new Set(s);
|
|
1023
|
-
},
|
|
1024
|
-
/**
|
|
1025
|
-
* Python set.update() - add elements from iterable
|
|
1026
|
-
*/
|
|
1027
|
-
update(s, ...iterables) {
|
|
1028
|
-
for (const iterable of iterables) {
|
|
1029
|
-
for (const item of iterable) {
|
|
1030
|
-
s.add(item);
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
},
|
|
1034
|
-
/**
|
|
1035
|
-
* Python set.union() - returns new set with all elements
|
|
1036
|
-
*/
|
|
1037
|
-
union(a, ...others) {
|
|
1038
|
-
const result = new Set(a);
|
|
1039
|
-
for (const other of others) {
|
|
1040
|
-
for (const item of other) {
|
|
1041
|
-
result.add(item);
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
return result;
|
|
1045
|
-
},
|
|
1046
|
-
/**
|
|
1047
|
-
* Python set.intersection() - returns new set with common elements
|
|
1048
|
-
*/
|
|
1049
|
-
intersection(a, b) {
|
|
1050
|
-
const result = /* @__PURE__ */ new Set();
|
|
1051
|
-
for (const item of a) {
|
|
1052
|
-
if (b.has(item)) result.add(item);
|
|
1053
|
-
}
|
|
1054
|
-
return result;
|
|
1055
|
-
},
|
|
1056
|
-
/**
|
|
1057
|
-
* Python set.intersection_update() - keep only common elements
|
|
1058
|
-
*/
|
|
1059
|
-
intersectionUpdate(a, b) {
|
|
1060
|
-
for (const item of a) {
|
|
1061
|
-
if (!b.has(item)) a.delete(item);
|
|
1062
|
-
}
|
|
1063
|
-
},
|
|
1064
|
-
/**
|
|
1065
|
-
* Python set.difference() - returns new set with elements in a but not in b
|
|
1066
|
-
*/
|
|
1067
|
-
difference(a, b) {
|
|
1068
|
-
const result = /* @__PURE__ */ new Set();
|
|
1069
|
-
for (const item of a) {
|
|
1070
|
-
if (!b.has(item)) result.add(item);
|
|
1071
|
-
}
|
|
1072
|
-
return result;
|
|
1073
|
-
},
|
|
1074
|
-
/**
|
|
1075
|
-
* Python set.difference_update() - remove elements found in b
|
|
1076
|
-
*/
|
|
1077
|
-
differenceUpdate(a, b) {
|
|
1078
|
-
for (const item of b) {
|
|
1079
|
-
a.delete(item);
|
|
1080
|
-
}
|
|
1081
|
-
},
|
|
1082
|
-
/**
|
|
1083
|
-
* Python set.symmetric_difference() - returns new set with elements in either but not both
|
|
1084
|
-
*/
|
|
1085
|
-
symmetricDifference(a, b) {
|
|
1086
|
-
const result = /* @__PURE__ */ new Set();
|
|
1087
|
-
for (const item of a) {
|
|
1088
|
-
if (!b.has(item)) result.add(item);
|
|
1089
|
-
}
|
|
1090
|
-
for (const item of b) {
|
|
1091
|
-
if (!a.has(item)) result.add(item);
|
|
1092
|
-
}
|
|
1093
|
-
return result;
|
|
1094
|
-
},
|
|
1095
|
-
/**
|
|
1096
|
-
* Python set.symmetric_difference_update() - update with symmetric difference
|
|
1097
|
-
*/
|
|
1098
|
-
symmetricDifferenceUpdate(a, b) {
|
|
1099
|
-
const toAdd = [];
|
|
1100
|
-
const toRemove = [];
|
|
1101
|
-
for (const item of a) {
|
|
1102
|
-
if (b.has(item)) toRemove.push(item);
|
|
1103
|
-
}
|
|
1104
|
-
for (const item of b) {
|
|
1105
|
-
if (!a.has(item)) toAdd.push(item);
|
|
1106
|
-
}
|
|
1107
|
-
for (const item of toRemove) a.delete(item);
|
|
1108
|
-
for (const item of toAdd) a.add(item);
|
|
1109
|
-
},
|
|
1110
|
-
/**
|
|
1111
|
-
* Python set.isSubset() - test if all elements are in other
|
|
1112
|
-
*/
|
|
1113
|
-
isSubset(a, b) {
|
|
1114
|
-
for (const item of a) {
|
|
1115
|
-
if (!b.has(item)) return false;
|
|
1116
|
-
}
|
|
1117
|
-
return true;
|
|
1118
|
-
},
|
|
1119
|
-
/**
|
|
1120
|
-
* Python set.isSuperset() - test if all other elements are in this set
|
|
1121
|
-
*/
|
|
1122
|
-
isSuperset(a, b) {
|
|
1123
|
-
for (const item of b) {
|
|
1124
|
-
if (!a.has(item)) return false;
|
|
1125
|
-
}
|
|
1126
|
-
return true;
|
|
1127
|
-
},
|
|
1128
|
-
/**
|
|
1129
|
-
* Python set.isDisjoint() - test if no common elements
|
|
1130
|
-
*/
|
|
1131
|
-
isDisjoint(a, b) {
|
|
1132
|
-
for (const item of a) {
|
|
1133
|
-
if (b.has(item)) return false;
|
|
1134
|
-
}
|
|
1135
|
-
return true;
|
|
1136
|
-
}
|
|
1137
|
-
};
|
|
134
|
+
hashlib_exports
|
|
135
|
+
} from "./chunk-JJKTRIVO.js";
|
|
136
|
+
import "./chunk-MLKGABMK.js";
|
|
1138
137
|
|
|
1139
138
|
// src/index.ts
|
|
1140
139
|
var itertools = itertools_exports;
|
|
@@ -1143,7 +142,7 @@ var collections = collections_exports;
|
|
|
1143
142
|
var math = math_exports;
|
|
1144
143
|
var random = random_exports;
|
|
1145
144
|
var json = json_exports;
|
|
1146
|
-
var os =
|
|
145
|
+
var os = os_node_exports;
|
|
1147
146
|
var datetime = datetime_exports;
|
|
1148
147
|
var re = re_exports;
|
|
1149
148
|
var string2 = {
|
|
@@ -1160,6 +159,19 @@ var string2 = {
|
|
|
1160
159
|
capWords,
|
|
1161
160
|
Template
|
|
1162
161
|
};
|
|
162
|
+
var sys = sys_exports;
|
|
163
|
+
var time = time_exports;
|
|
164
|
+
var copy = copy_exports;
|
|
165
|
+
var base64 = base64_exports;
|
|
166
|
+
var uuid = uuid_exports;
|
|
167
|
+
var hashlib = hashlib_exports;
|
|
168
|
+
var pathlib = pathlib_node_exports;
|
|
169
|
+
var glob = glob_node_exports;
|
|
170
|
+
var shutil = shutil_node_exports;
|
|
171
|
+
var tempfile = tempfile_node_exports;
|
|
172
|
+
var subprocess = subprocess_exports;
|
|
173
|
+
var urllib = urllib_exports;
|
|
174
|
+
var logging = logging_node_exports;
|
|
1163
175
|
var list3 = Object.assign(
|
|
1164
176
|
(iterable) => list(iterable),
|
|
1165
177
|
list2
|
|
@@ -1222,11 +234,13 @@ export {
|
|
|
1222
234
|
any2 as any,
|
|
1223
235
|
ascii2 as ascii,
|
|
1224
236
|
at2 as at,
|
|
237
|
+
base64,
|
|
1225
238
|
bin2 as bin,
|
|
1226
239
|
bool2 as bool,
|
|
1227
240
|
chr2 as chr,
|
|
1228
241
|
collections,
|
|
1229
242
|
contains2 as contains,
|
|
243
|
+
copy,
|
|
1230
244
|
datetime,
|
|
1231
245
|
dict3 as dict,
|
|
1232
246
|
divMod2 as divMod,
|
|
@@ -1237,7 +251,9 @@ export {
|
|
|
1237
251
|
format2 as format,
|
|
1238
252
|
functools,
|
|
1239
253
|
getattr2 as getattr,
|
|
254
|
+
glob,
|
|
1240
255
|
hasattr2 as hasattr,
|
|
256
|
+
hashlib,
|
|
1241
257
|
hex2 as hex,
|
|
1242
258
|
input2 as input,
|
|
1243
259
|
int2 as int,
|
|
@@ -1248,6 +264,7 @@ export {
|
|
|
1248
264
|
json,
|
|
1249
265
|
len2 as len,
|
|
1250
266
|
list3 as list,
|
|
267
|
+
logging,
|
|
1251
268
|
map2 as map,
|
|
1252
269
|
math,
|
|
1253
270
|
max2 as max,
|
|
@@ -1256,6 +273,7 @@ export {
|
|
|
1256
273
|
oct2 as oct,
|
|
1257
274
|
ord2 as ord,
|
|
1258
275
|
os,
|
|
276
|
+
pathlib,
|
|
1259
277
|
pow,
|
|
1260
278
|
random,
|
|
1261
279
|
range2 as range,
|
|
@@ -1266,16 +284,21 @@ export {
|
|
|
1266
284
|
round2 as round,
|
|
1267
285
|
set3 as set,
|
|
1268
286
|
setattr2 as setattr,
|
|
287
|
+
shutil,
|
|
1269
288
|
slice2 as slice,
|
|
1270
289
|
sorted2 as sorted,
|
|
1271
290
|
sprintf2 as sprintf,
|
|
1272
291
|
str2 as str,
|
|
1273
292
|
strFormat2 as strFormat,
|
|
1274
293
|
string2 as string,
|
|
294
|
+
subprocess,
|
|
1275
295
|
sum2 as sum,
|
|
296
|
+
sys,
|
|
297
|
+
tempfile,
|
|
298
|
+
time,
|
|
1276
299
|
tuple2 as tuple,
|
|
1277
300
|
type2 as type,
|
|
301
|
+
urllib,
|
|
302
|
+
uuid,
|
|
1278
303
|
zip2 as zip
|
|
1279
304
|
};
|
|
1280
|
-
/* v8 ignore next -- fallback for unrecognized format types @preserve */
|
|
1281
|
-
//# sourceMappingURL=index.js.map
|