pathlib-next 0.1.0__py3-none-any.whl
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.
- pathlib_next/__init__.py +7 -0
- pathlib_next/fspath.py +103 -0
- pathlib_next/path.py +618 -0
- pathlib_next/uri/__init__.py +471 -0
- pathlib_next/uri/query.py +58 -0
- pathlib_next/uri/schemes/__init__.py +10 -0
- pathlib_next/uri/schemes/file.py +62 -0
- pathlib_next/uri/schemes/http.py +136 -0
- pathlib_next/uri/schemes/sftp.py +101 -0
- pathlib_next/uri/source.py +73 -0
- pathlib_next/utils/__init__.py +93 -0
- pathlib_next/utils/glob.py +145 -0
- pathlib_next/utils/stat.py +77 -0
- pathlib_next/utils/sync.py +91 -0
- pathlib_next-0.1.0.dist-info/METADATA +25 -0
- pathlib_next-0.1.0.dist-info/RECORD +18 -0
- pathlib_next-0.1.0.dist-info/WHEEL +4 -0
- pathlib_next-0.1.0.dist-info/licenses/LICENSE +21 -0
pathlib_next/__init__.py
ADDED
pathlib_next/fspath.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import pathlib as _path
|
|
2
|
+
import os as _os
|
|
3
|
+
import functools as _func
|
|
4
|
+
import typing as _ty
|
|
5
|
+
from . import path as _proto
|
|
6
|
+
import re as _re
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@_func.cache
|
|
10
|
+
def _is_case_sensitive(flavour: _os.path) -> bool:
|
|
11
|
+
return flavour.normcase("Aa") == "Aa"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _BaseFSPathname(_path.PurePath, _proto.Pathname):
|
|
15
|
+
__slots__ = ()
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def _parser(self) -> _os.path:
|
|
19
|
+
try:
|
|
20
|
+
return self.parser
|
|
21
|
+
except AttributeError:
|
|
22
|
+
return self._flavour
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def _path_separators(self) -> _ty.Sequence[str]:
|
|
26
|
+
return (self._parser.pathsep, self._parser.altsep)
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def _is_case_sensitive(self) -> bool:
|
|
30
|
+
return _is_case_sensitive(self._parser)
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def segments(self):
|
|
34
|
+
return self.parts
|
|
35
|
+
|
|
36
|
+
def with_segments(self, *args: str | _proto.FsPathLike):
|
|
37
|
+
return type(self)(*args)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PosixPathname(_path.PurePosixPath, _BaseFSPathname):
|
|
41
|
+
__slots__ = ()
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class WindowsPathname(_path.PureWindowsPath, _BaseFSPathname):
|
|
45
|
+
__slots__ = ()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class LocalPath(
|
|
49
|
+
_path.WindowsPath if _os.name == "nt" else _path.PosixPath,
|
|
50
|
+
_proto.Path,
|
|
51
|
+
_BaseFSPathname,
|
|
52
|
+
):
|
|
53
|
+
__slots__ = ()
|
|
54
|
+
|
|
55
|
+
def glob(
|
|
56
|
+
self,
|
|
57
|
+
pattern: str | _proto.FsPathLike,
|
|
58
|
+
*,
|
|
59
|
+
case_sensitive: bool = None,
|
|
60
|
+
include_hidden: bool = False,
|
|
61
|
+
recursive: bool = False,
|
|
62
|
+
dironly: bool = False,
|
|
63
|
+
):
|
|
64
|
+
"""Iterate over this subtree and yield all existing files (of any
|
|
65
|
+
kind, including directories) matching the given relative pattern.
|
|
66
|
+
"""
|
|
67
|
+
if not isinstance(pattern, (str, _re.Pattern)):
|
|
68
|
+
pattern = _os.fspath(pattern)
|
|
69
|
+
if dironly is None:
|
|
70
|
+
dironly = (
|
|
71
|
+
isinstance(pattern, str)
|
|
72
|
+
and pattern
|
|
73
|
+
and pattern[-1] in self._path_separators
|
|
74
|
+
)
|
|
75
|
+
yield from _proto.Path.glob(
|
|
76
|
+
self,
|
|
77
|
+
self,
|
|
78
|
+
pattern,
|
|
79
|
+
case_sensitive=case_sensitive,
|
|
80
|
+
include_hidden=include_hidden,
|
|
81
|
+
recursive=recursive,
|
|
82
|
+
dironly=dironly,
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
def rglob(
|
|
86
|
+
self,
|
|
87
|
+
pattern: str,
|
|
88
|
+
*,
|
|
89
|
+
case_sensitive: bool = None,
|
|
90
|
+
include_hidden: bool = False,
|
|
91
|
+
dironly: bool = False,
|
|
92
|
+
):
|
|
93
|
+
"""Recursively yield all existing files (of any kind, including
|
|
94
|
+
directories) matching the given relative pattern, anywhere in
|
|
95
|
+
this subtree.
|
|
96
|
+
"""
|
|
97
|
+
yield from self.glob(
|
|
98
|
+
pattern,
|
|
99
|
+
case_sensitive=case_sensitive,
|
|
100
|
+
include_hidden=include_hidden,
|
|
101
|
+
recursive=True,
|
|
102
|
+
dironly=dironly,
|
|
103
|
+
)
|