pathlib-next 0.1.0__tar.gz

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.
@@ -0,0 +1,5 @@
1
+ __pycache__
2
+ /_*
3
+ [a-zA-Z]*__
4
+ [a-zA-Z]*__.*
5
+ /dist
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Jose A
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.3
2
+ Name: pathlib_next
3
+ Version: 0.1.0
4
+ Summary: Generic Path Protocol based pathlib
5
+ Project-URL: Homepage, https://github.com/jose-pr/pathlib_next/
6
+ Project-URL: Issues, https://github.com/jose-pr/pathlib_next/issues
7
+ Author: Jose A
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.11
13
+ Provides-Extra: http
14
+ Requires-Dist: requests; extra == 'http'
15
+ Requires-Dist: uritools; extra == 'http'
16
+ Provides-Extra: sftp
17
+ Requires-Dist: paramiko; extra == 'sftp'
18
+ Requires-Dist: uritools; extra == 'sftp'
19
+ Provides-Extra: uri
20
+ Requires-Dist: uritools; extra == 'uri'
21
+ Description-Content-Type: text/markdown
22
+
23
+ Generic Path Protocol based pathlib
24
+
25
+ Implementation for URI paths, with file access support for sftp, http, file schemes
@@ -0,0 +1,3 @@
1
+ Generic Path Protocol based pathlib
2
+
3
+ Implementation for URI paths, with file access support for sftp, http, file schemes
@@ -0,0 +1,29 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "pathlib_next"
7
+ version = "0.1.0"
8
+ authors = [{ name = "Jose A" }]
9
+ description = "Generic Path Protocol based pathlib"
10
+ readme = "README.md"
11
+ requires-python = ">=3.11"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ dependencies = []
18
+ [project.optional-dependencies]
19
+ uri = ["uritools"]
20
+ http = ["requests", "pathlib_next[uri]"]
21
+ sftp = ["paramiko", "pathlib_next[uri]"]
22
+
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/jose-pr/pathlib_next/"
26
+ Issues = "https://github.com/jose-pr/pathlib_next/issues"
27
+
28
+ [tool.hatch.build.targets.sdist]
29
+ exclude = ["/.*"]
@@ -0,0 +1,54 @@
1
+ from pathlib_next.uri import UriPath, Query, Source
2
+ from pathlib_next.uri.schemes import *
3
+ from pathlib_next.utils.sync import PathSyncer
4
+ from pathlib_next import glob, Path
5
+
6
+ local = Path('./_ssh')
7
+ print(list(local.iterdir()))
8
+ query = Query({'test':'://$#!1', 'test2&': [1,2]})
9
+ q2 = Query(str(query)).to_dict()
10
+ for name, value in query:
11
+ print(f"{name}: {value}")
12
+ src = Source(scheme='scheme',userinfo='user', host='123.com', port=0)
13
+ test = {**src}
14
+ test2 = [*src]
15
+ dest = UriPath('file:./_ssh')
16
+
17
+ #
18
+ # Norm test
19
+ #
20
+ with_dots = UriPath('a/b/c/d/../../test/.')
21
+ print(with_dots.normalized_path)
22
+
23
+ source_host = UriPath('file://test.com/path1/path2/path3/path4')
24
+ source_host.is_local()
25
+
26
+ rel_to = source_host.relative_to('/path1/path2')
27
+ dest = UriPath(dest)
28
+ test_ = UriPath('file:') / 'test'
29
+ empty = UriPath()
30
+ uri = dest.as_uri()
31
+
32
+ test1 = dest / 'test' / 'test2/'
33
+ print(test1)
34
+
35
+ sftp_root = UriPath('sftp://root@sftpexample/')
36
+ print(sftp_root.as_posix())
37
+ authkeys = sftp_root / 'root/.ssh/authorized_keys'
38
+ print(authkeys.as_posix())
39
+
40
+ def checksum(uri:UriPath):
41
+ stat = uri.stat()
42
+ return hash(stat.st_size)
43
+ syncer =PathSyncer(checksum, remove_missing=False)
44
+ syncer.sync((sftp_root / 'root/.ssh'), dest, dry_run=True)
45
+
46
+ rocky_repo = UriPath('http://dl.rockylinux.org/pub')
47
+
48
+ glob_test = UriPath("file:./**/*.py")
49
+
50
+ for path in glob.glob(glob_test, recursive=True):
51
+ print(path)
52
+
53
+ print(rocky_repo.is_dir())
54
+ print(list(rocky_repo.iterdir()))
@@ -0,0 +1,7 @@
1
+ try:
2
+ from .uri import UriPath, Uri
3
+ except ImportError:
4
+ pass
5
+ from .path import *
6
+ from .fspath import *
7
+ from .utils import glob, sync
@@ -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
+ )