pythonlib 1.0.2 → 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.
Files changed (133) hide show
  1. package/README.md +3 -1
  2. package/dist/base64-C_am75Sv.d.ts +165 -0
  3. package/dist/base64.d.ts +1 -0
  4. package/dist/base64.js +37 -0
  5. package/dist/chunk-2YTO24B5.js +78 -0
  6. package/dist/chunk-3CLXPGAB.js +237 -0
  7. package/dist/{chunk-7BZB2TQF.js → chunk-3M3PB4RO.js} +4 -6
  8. package/dist/chunk-5OKGPZBQ.js +1106 -0
  9. package/dist/chunk-5VAHUJNC.js +348 -0
  10. package/dist/chunk-B5AUEOAH.js +193 -0
  11. package/dist/chunk-B5LQJODJ.js +37 -0
  12. package/dist/{chunk-CUP6EPDB.js → chunk-BCMGGBWG.js} +2 -5
  13. package/dist/chunk-BCVIH2BN.js +175 -0
  14. package/dist/{chunk-QURVRHY2.js → chunk-D35YI363.js} +15 -12
  15. package/dist/{chunk-RSBRI27Z.js → chunk-ETBW6XNR.js} +3 -4
  16. package/dist/chunk-FCJ7E4OE.js +250 -0
  17. package/dist/chunk-HSTC277I.js +255 -0
  18. package/dist/chunk-IANXD4D4.js +250 -0
  19. package/dist/{chunk-G6PUQTVZ.js → chunk-JAUU3HMH.js} +1 -2
  20. package/dist/chunk-JJKTRIVO.js +262 -0
  21. package/dist/chunk-KKHKTQNN.js +361 -0
  22. package/dist/chunk-KKJHGY4C.js +551 -0
  23. package/dist/chunk-LHPQS75Z.js +192 -0
  24. package/dist/{chunk-OSX7QZAW.js → chunk-LK2L2TFG.js} +5 -6
  25. package/dist/chunk-LLZFLQS6.js +280 -0
  26. package/dist/chunk-LTXTS7RP.js +154 -0
  27. package/dist/{chunk-CEZSBJJV.js → chunk-LWYBTWBZ.js} +2 -3
  28. package/dist/{chunk-TAYRRHJ3.js → chunk-MFKIEN7N.js} +1 -2
  29. package/dist/{chunk-PZ5AY32C.js → chunk-MLKGABMK.js} +0 -1
  30. package/dist/chunk-OZRS5PC4.js +312 -0
  31. package/dist/chunk-PWA3YQZU.js +346 -0
  32. package/dist/{chunk-56DGFWIJ.js → chunk-QKJBQKPY.js} +1 -2
  33. package/dist/chunk-RB6BYCIQ.js +141 -0
  34. package/dist/chunk-U4X5DEIP.js +188 -0
  35. package/dist/chunk-UGZ5OY5Z.js +165 -0
  36. package/dist/chunk-WTZSAITC.js +82 -0
  37. package/dist/collections.js +2 -3
  38. package/dist/copy-6ZaZ__ge.d.ts +59 -0
  39. package/dist/copy.d.ts +1 -0
  40. package/dist/copy.js +9 -0
  41. package/dist/datetime.js +2 -3
  42. package/dist/functools.js +2 -3
  43. package/dist/glob.browser-B6d_YdV5.d.ts +50 -0
  44. package/dist/glob.browser.d.ts +1 -0
  45. package/dist/glob.browser.js +15 -0
  46. package/dist/glob.node-wn5ehtyM.d.ts +80 -0
  47. package/dist/glob.node.d.ts +1 -0
  48. package/dist/glob.node.js +15 -0
  49. package/dist/hashlib-vKP511NY.d.ts +205 -0
  50. package/dist/hashlib.d.ts +1 -0
  51. package/dist/hashlib.js +39 -0
  52. package/dist/index.browser.d.ts +172 -0
  53. package/dist/index.browser.js +304 -0
  54. package/dist/index.d.ts +36 -602
  55. package/dist/index.js +138 -1073
  56. package/dist/itertools.js +2 -3
  57. package/dist/json.js +2 -3
  58. package/dist/logging.browser-Dux4L5kz.d.ts +185 -0
  59. package/dist/logging.browser.d.ts +1 -0
  60. package/dist/logging.browser.js +63 -0
  61. package/dist/logging.node-CH75bVdE.d.ts +185 -0
  62. package/dist/logging.node.d.ts +1 -0
  63. package/dist/logging.node.js +61 -0
  64. package/dist/math.js +2 -3
  65. package/dist/{os-CqGKe872.d.ts → os.browser-krjSx5kF.d.ts} +32 -55
  66. package/dist/os.browser.d.ts +2 -0
  67. package/dist/{os.js → os.browser.js} +41 -16
  68. package/dist/os.node-CQjch8Ht.d.ts +124 -0
  69. package/dist/os.node.d.ts +2 -0
  70. package/dist/os.node.js +83 -0
  71. package/dist/os.shared-C3x70nhO.d.ts +59 -0
  72. package/dist/pathlib.browser-NC7kKQYe.d.ts +91 -0
  73. package/dist/pathlib.browser.d.ts +1 -0
  74. package/dist/pathlib.browser.js +17 -0
  75. package/dist/pathlib.node-CY3yUFdT.d.ts +331 -0
  76. package/dist/pathlib.node.d.ts +2 -0
  77. package/dist/pathlib.node.js +17 -0
  78. package/dist/random.js +2 -3
  79. package/dist/re.js +2 -3
  80. package/dist/set-JQbLAq8B.d.ts +592 -0
  81. package/dist/shutil.browser-Ck5oWhnP.d.ts +113 -0
  82. package/dist/shutil.browser.d.ts +1 -0
  83. package/dist/shutil.browser.js +33 -0
  84. package/dist/shutil.node-C9kwvhAf.d.ts +160 -0
  85. package/dist/shutil.node.d.ts +2 -0
  86. package/dist/shutil.node.js +33 -0
  87. package/dist/string.js +2 -3
  88. package/dist/subprocess-CZVYzQ3V.d.ts +214 -0
  89. package/dist/subprocess.d.ts +1 -0
  90. package/dist/subprocess.js +29 -0
  91. package/dist/sys-IL8LgI_W.d.ts +212 -0
  92. package/dist/sys.d.ts +1 -0
  93. package/dist/sys.js +51 -0
  94. package/dist/tempfile.browser-DciOKfNm.d.ts +78 -0
  95. package/dist/tempfile.browser.d.ts +1 -0
  96. package/dist/tempfile.browser.js +19 -0
  97. package/dist/tempfile.node-bVMY60Cu.d.ts +195 -0
  98. package/dist/tempfile.node.d.ts +2 -0
  99. package/dist/tempfile.node.js +23 -0
  100. package/dist/time-CcYhdiSu.d.ts +245 -0
  101. package/dist/time.d.ts +1 -0
  102. package/dist/time.js +49 -0
  103. package/dist/urllib-DJtkj-0f.d.ts +198 -0
  104. package/dist/urllib.d.ts +1 -0
  105. package/dist/urllib.js +37 -0
  106. package/dist/uuid-C0ypmn56.d.ts +160 -0
  107. package/dist/uuid.d.ts +1 -0
  108. package/dist/uuid.js +23 -0
  109. package/package.json +127 -5
  110. package/dist/chunk-56DGFWIJ.js.map +0 -1
  111. package/dist/chunk-5AOJFFYN.js +0 -313
  112. package/dist/chunk-5AOJFFYN.js.map +0 -1
  113. package/dist/chunk-7BZB2TQF.js.map +0 -1
  114. package/dist/chunk-CEZSBJJV.js.map +0 -1
  115. package/dist/chunk-CUP6EPDB.js.map +0 -1
  116. package/dist/chunk-G6PUQTVZ.js.map +0 -1
  117. package/dist/chunk-OSX7QZAW.js.map +0 -1
  118. package/dist/chunk-PZ5AY32C.js.map +0 -1
  119. package/dist/chunk-QURVRHY2.js.map +0 -1
  120. package/dist/chunk-RSBRI27Z.js.map +0 -1
  121. package/dist/chunk-TAYRRHJ3.js.map +0 -1
  122. package/dist/collections.js.map +0 -1
  123. package/dist/datetime.js.map +0 -1
  124. package/dist/functools.js.map +0 -1
  125. package/dist/index.js.map +0 -1
  126. package/dist/itertools.js.map +0 -1
  127. package/dist/json.js.map +0 -1
  128. package/dist/math.js.map +0 -1
  129. package/dist/os.d.ts +0 -1
  130. package/dist/os.js.map +0 -1
  131. package/dist/random.js.map +0 -1
  132. package/dist/re.js.map +0 -1
  133. package/dist/string.js.map +0 -1
@@ -0,0 +1,551 @@
1
+ import {
2
+ __export
3
+ } from "./chunk-MLKGABMK.js";
4
+
5
+ // src/pathlib.node.ts
6
+ var pathlib_node_exports = {};
7
+ __export(pathlib_node_exports, {
8
+ Path: () => Path,
9
+ PosixPath: () => PosixPath,
10
+ PurePath: () => PurePath,
11
+ PurePosixPath: () => PurePosixPath,
12
+ PureWindowsPath: () => PureWindowsPath,
13
+ WindowsPath: () => WindowsPath
14
+ });
15
+ import {
16
+ access,
17
+ chmod,
18
+ link,
19
+ lstat,
20
+ mkdir,
21
+ readdir,
22
+ readFile,
23
+ readlink,
24
+ rename,
25
+ rmdir,
26
+ stat,
27
+ symlink,
28
+ unlink,
29
+ utimes,
30
+ writeFile
31
+ } from "fs/promises";
32
+ import {
33
+ basename,
34
+ dirname,
35
+ extname,
36
+ isAbsolute,
37
+ join,
38
+ parse,
39
+ relative,
40
+ resolve,
41
+ sep
42
+ } from "path";
43
+ var Path = class _Path {
44
+ _path;
45
+ /**
46
+ * Create a new Path instance.
47
+ *
48
+ * @param pathSegments - Path segments to join
49
+ */
50
+ constructor(...pathSegments) {
51
+ if (pathSegments.length === 0) {
52
+ this._path = ".";
53
+ } else {
54
+ this._path = join(...pathSegments);
55
+ }
56
+ }
57
+ /**
58
+ * Static factory method to create a Path.
59
+ */
60
+ static of(...pathSegments) {
61
+ return new _Path(...pathSegments);
62
+ }
63
+ /**
64
+ * The final component of the path.
65
+ */
66
+ get name() {
67
+ return basename(this._path);
68
+ }
69
+ /**
70
+ * The final component without its suffix.
71
+ */
72
+ get stem() {
73
+ const base = basename(this._path);
74
+ const ext = extname(base);
75
+ return ext ? base.slice(0, -ext.length) : base;
76
+ }
77
+ /**
78
+ * The file extension of the final component.
79
+ */
80
+ get suffix() {
81
+ return extname(this._path);
82
+ }
83
+ /**
84
+ * A list of the path's file extensions.
85
+ */
86
+ get suffixes() {
87
+ const name = this.name;
88
+ const suffixes = [];
89
+ let remaining = name;
90
+ let ext = extname(remaining);
91
+ while (ext) {
92
+ suffixes.unshift(ext);
93
+ remaining = remaining.slice(0, -ext.length);
94
+ ext = extname(remaining);
95
+ }
96
+ return suffixes;
97
+ }
98
+ /**
99
+ * The logical parent of the path.
100
+ */
101
+ get parent() {
102
+ const parent = dirname(this._path);
103
+ return new _Path(parent);
104
+ }
105
+ /**
106
+ * An immutable sequence of the path's ancestors.
107
+ */
108
+ get parents() {
109
+ const parents = [];
110
+ let current = this._path;
111
+ let parent = dirname(current);
112
+ while (parent !== current) {
113
+ parents.push(new _Path(parent));
114
+ current = parent;
115
+ parent = dirname(current);
116
+ }
117
+ return parents;
118
+ }
119
+ /**
120
+ * The individual components of the path.
121
+ */
122
+ get parts() {
123
+ const parsed = parse(this._path);
124
+ const parts = [];
125
+ if (parsed.root) {
126
+ parts.push(parsed.root);
127
+ }
128
+ if (parsed.dir) {
129
+ const dirParts = parsed.dir.replace(parsed.root, "").split(sep).filter(Boolean);
130
+ parts.push(...dirParts);
131
+ }
132
+ if (parsed.base) {
133
+ parts.push(parsed.base);
134
+ }
135
+ return parts;
136
+ }
137
+ /**
138
+ * The drive or root (on Windows, the drive letter; on Unix, empty or /).
139
+ */
140
+ get anchor() {
141
+ const parsed = parse(this._path);
142
+ return parsed.root;
143
+ }
144
+ /**
145
+ * The drive letter (Windows only, empty on Unix).
146
+ */
147
+ get drive() {
148
+ if (process.platform === "win32") {
149
+ const match = /^([A-Za-z]:)/.exec(this._path);
150
+ return match ? match[1] ?? "" : "";
151
+ }
152
+ return "";
153
+ }
154
+ /**
155
+ * The root of the path (/ on Unix, \\ or drive:\\ on Windows).
156
+ */
157
+ get root() {
158
+ const parsed = parse(this._path);
159
+ return parsed.root;
160
+ }
161
+ /**
162
+ * Whether the path is absolute.
163
+ */
164
+ isAbsolute() {
165
+ return isAbsolute(this._path);
166
+ }
167
+ /**
168
+ * Combine this path with additional segments.
169
+ *
170
+ * @param pathSegments - Path segments to join
171
+ * @returns A new Path
172
+ */
173
+ joinpath(...pathSegments) {
174
+ return new _Path(this._path, ...pathSegments);
175
+ }
176
+ /**
177
+ * Division operator alternative: join paths.
178
+ *
179
+ * @param other - Path segment to join
180
+ * @returns A new Path
181
+ */
182
+ div(other) {
183
+ const otherPath = other instanceof _Path ? other.toString() : other;
184
+ return new _Path(this._path, otherPath);
185
+ }
186
+ /**
187
+ * Return a string representation of the path.
188
+ */
189
+ toString() {
190
+ return this._path;
191
+ }
192
+ /**
193
+ * Return the path as a POSIX path string.
194
+ */
195
+ asPosix() {
196
+ return this._path.split(sep).join("/");
197
+ }
198
+ /**
199
+ * Return the path as a URI.
200
+ */
201
+ asUri() {
202
+ const absolute = resolve(this._path);
203
+ return `file://${absolute}`;
204
+ }
205
+ // Filesystem operations (async)
206
+ /**
207
+ * Whether the path exists.
208
+ */
209
+ async exists() {
210
+ try {
211
+ await access(this._path);
212
+ return true;
213
+ } catch {
214
+ return false;
215
+ }
216
+ }
217
+ /**
218
+ * Whether the path is a file.
219
+ */
220
+ async isFile() {
221
+ try {
222
+ return (await stat(this._path)).isFile();
223
+ } catch {
224
+ return false;
225
+ }
226
+ }
227
+ /**
228
+ * Whether the path is a directory.
229
+ */
230
+ async isDir() {
231
+ try {
232
+ return (await stat(this._path)).isDirectory();
233
+ } catch {
234
+ return false;
235
+ }
236
+ }
237
+ /**
238
+ * Whether the path is a symbolic link.
239
+ */
240
+ async isSymlink() {
241
+ try {
242
+ return (await lstat(this._path)).isSymbolicLink();
243
+ } catch {
244
+ return false;
245
+ }
246
+ }
247
+ /**
248
+ * Read the file contents as text.
249
+ *
250
+ * @param encoding - Text encoding (default: utf-8)
251
+ * @returns File contents as string
252
+ */
253
+ async readText(encoding = "utf-8") {
254
+ return readFile(this._path, { encoding });
255
+ }
256
+ /**
257
+ * Write text to the file.
258
+ *
259
+ * @param data - Text to write
260
+ * @param encoding - Text encoding (default: utf-8)
261
+ */
262
+ async writeText(data, encoding = "utf-8") {
263
+ await writeFile(this._path, data, { encoding });
264
+ }
265
+ /**
266
+ * Read the file contents as bytes.
267
+ *
268
+ * @returns File contents as Uint8Array
269
+ */
270
+ async readBytes() {
271
+ return new Uint8Array(await readFile(this._path));
272
+ }
273
+ /**
274
+ * Write bytes to the file.
275
+ *
276
+ * @param data - Bytes to write
277
+ */
278
+ async writeBytes(data) {
279
+ await writeFile(this._path, data);
280
+ }
281
+ /**
282
+ * Create the directory (and parents if necessary).
283
+ *
284
+ * @param options - Options object
285
+ */
286
+ async mkdir(options) {
287
+ try {
288
+ await mkdir(this._path, { recursive: options?.parents ?? false });
289
+ } catch (err) {
290
+ if (!(options?.existOk && err.code === "EEXIST")) {
291
+ throw err;
292
+ }
293
+ }
294
+ }
295
+ /**
296
+ * Remove the directory.
297
+ */
298
+ async rmdir() {
299
+ await rmdir(this._path);
300
+ }
301
+ /**
302
+ * Remove the file or symbolic link.
303
+ */
304
+ async unlink() {
305
+ await unlink(this._path);
306
+ }
307
+ /**
308
+ * Rename the path to target.
309
+ *
310
+ * @param target - New path
311
+ * @returns The new Path
312
+ */
313
+ async rename(target) {
314
+ const targetPath = target instanceof _Path ? target.toString() : target;
315
+ await rename(this._path, targetPath);
316
+ return new _Path(targetPath);
317
+ }
318
+ /**
319
+ * Replace target with this file.
320
+ *
321
+ * @param target - Target path to replace
322
+ * @returns The new Path
323
+ */
324
+ async replace(target) {
325
+ return this.rename(target);
326
+ }
327
+ /**
328
+ * Make the path absolute.
329
+ *
330
+ * @returns Absolute path
331
+ */
332
+ resolve() {
333
+ return new _Path(resolve(this._path));
334
+ }
335
+ /**
336
+ * Return the absolute path.
337
+ *
338
+ * @returns Absolute path
339
+ */
340
+ absolute() {
341
+ return this.resolve();
342
+ }
343
+ /**
344
+ * Return the real path (resolving symlinks).
345
+ *
346
+ * @returns Real path
347
+ */
348
+ async readlink() {
349
+ return new _Path(await readlink(this._path));
350
+ }
351
+ /**
352
+ * Get file statistics.
353
+ *
354
+ * @returns File stat object
355
+ */
356
+ async stat() {
357
+ return stat(this._path);
358
+ }
359
+ /**
360
+ * Get symbolic link statistics.
361
+ *
362
+ * @returns Stat object for the symlink itself
363
+ */
364
+ async lstat() {
365
+ return lstat(this._path);
366
+ }
367
+ /**
368
+ * Iterate over directory contents.
369
+ *
370
+ * @returns Array of Path objects
371
+ */
372
+ async iterdir() {
373
+ const entries = await readdir(this._path);
374
+ return entries.map((name) => new _Path(this._path, name));
375
+ }
376
+ /**
377
+ * Glob pattern matching.
378
+ *
379
+ * @param pattern - Glob pattern
380
+ * @returns Array of matching Path objects
381
+ */
382
+ async glob(pattern) {
383
+ return this.matchGlob(pattern, false);
384
+ }
385
+ /**
386
+ * Recursive glob pattern matching.
387
+ *
388
+ * @param pattern - Glob pattern
389
+ * @returns Array of matching Path objects
390
+ */
391
+ async rglob(pattern) {
392
+ return this.matchGlob(pattern, true);
393
+ }
394
+ /**
395
+ * Internal glob matching implementation.
396
+ */
397
+ async matchGlob(pattern, recursive) {
398
+ const results = [];
399
+ const regex = this.globToRegex(pattern);
400
+ const walk = async (dir) => {
401
+ let entries;
402
+ try {
403
+ entries = await readdir(dir);
404
+ } catch {
405
+ return;
406
+ }
407
+ for (const entry of entries) {
408
+ const fullPath = join(dir, entry);
409
+ const relativePath = relative(this._path, fullPath);
410
+ if (regex.test(relativePath) || regex.test(entry)) {
411
+ results.push(new _Path(fullPath));
412
+ }
413
+ if (recursive) {
414
+ try {
415
+ if ((await stat(fullPath)).isDirectory()) {
416
+ await walk(fullPath);
417
+ }
418
+ } catch {
419
+ }
420
+ }
421
+ }
422
+ };
423
+ await walk(this._path);
424
+ return results;
425
+ }
426
+ /**
427
+ * Convert glob pattern to regex.
428
+ */
429
+ globToRegex(pattern) {
430
+ const regex = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, "<<<GLOBSTAR>>>").replace(/\*/g, "[^/]*").replace(/\?/g, "[^/]").replace(/<<<GLOBSTAR>>>/g, ".*");
431
+ return new RegExp(`^${regex}$`);
432
+ }
433
+ /**
434
+ * Create a symbolic link.
435
+ *
436
+ * @param target - Target of the symlink
437
+ */
438
+ async symlinkTo(target) {
439
+ const targetPath = target instanceof _Path ? target.toString() : target;
440
+ await symlink(targetPath, this._path);
441
+ }
442
+ /**
443
+ * Create a hard link.
444
+ *
445
+ * @param target - Target of the link
446
+ */
447
+ async linkTo(target) {
448
+ const targetPath = target instanceof _Path ? target.toString() : target;
449
+ await link(targetPath, this._path);
450
+ }
451
+ /**
452
+ * Change file permissions.
453
+ *
454
+ * @param mode - Permission mode
455
+ */
456
+ async chmod(mode) {
457
+ await chmod(this._path, mode);
458
+ }
459
+ /**
460
+ * Update access and modification times.
461
+ *
462
+ * @param atime - Access time
463
+ * @param mtime - Modification time
464
+ */
465
+ async touch(atime, mtime) {
466
+ const now = /* @__PURE__ */ new Date();
467
+ const accessTime = atime ?? now;
468
+ const modTime = mtime ?? now;
469
+ if (!await this.exists()) {
470
+ await writeFile(this._path, "");
471
+ }
472
+ await utimes(this._path, accessTime, modTime);
473
+ }
474
+ /**
475
+ * Check if path matches a pattern.
476
+ *
477
+ * @param pattern - Glob pattern
478
+ * @returns True if matches
479
+ */
480
+ match(pattern) {
481
+ const regex = this.globToRegex(pattern);
482
+ return regex.test(this.name) || regex.test(this._path);
483
+ }
484
+ /**
485
+ * Return path relative to another path.
486
+ *
487
+ * @param other - Base path
488
+ * @returns Relative path
489
+ */
490
+ relativeTo(other) {
491
+ const otherPath = other instanceof _Path ? other.toString() : other;
492
+ return new _Path(relative(otherPath, this._path));
493
+ }
494
+ /**
495
+ * Return a new path with a different suffix.
496
+ *
497
+ * @param suffix - New suffix
498
+ * @returns New Path
499
+ */
500
+ withSuffix(suffix) {
501
+ const parsed = parse(this._path);
502
+ return new _Path(join(parsed.dir, parsed.name + suffix));
503
+ }
504
+ /**
505
+ * Return a new path with a different name.
506
+ *
507
+ * @param name - New name
508
+ * @returns New Path
509
+ */
510
+ withName(name) {
511
+ const parent = dirname(this._path);
512
+ return new _Path(parent, name);
513
+ }
514
+ /**
515
+ * Return a new path with a different stem.
516
+ *
517
+ * @param stem - New stem
518
+ * @returns New Path
519
+ */
520
+ withStem(stem) {
521
+ const suffix = this.suffix;
522
+ return this.withName(stem + suffix);
523
+ }
524
+ /**
525
+ * Get the current working directory as a Path.
526
+ */
527
+ static cwd() {
528
+ return new _Path(process.cwd());
529
+ }
530
+ /**
531
+ * Get the home directory as a Path.
532
+ */
533
+ static home() {
534
+ return new _Path(process.env.HOME ?? process.env.USERPROFILE ?? "");
535
+ }
536
+ };
537
+ var PurePath = Path;
538
+ var PurePosixPath = Path;
539
+ var PureWindowsPath = Path;
540
+ var PosixPath = Path;
541
+ var WindowsPath = Path;
542
+
543
+ export {
544
+ Path,
545
+ PurePath,
546
+ PurePosixPath,
547
+ PureWindowsPath,
548
+ PosixPath,
549
+ WindowsPath,
550
+ pathlib_node_exports
551
+ };