kisstdlib 0.0.3__tar.gz → 0.0.4__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.
Files changed (24) hide show
  1. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/PKG-INFO +1 -1
  2. kisstdlib-0.0.4/kisstdlib/path.py +163 -0
  3. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib.egg-info/PKG-INFO +1 -1
  4. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/pyproject.toml +1 -1
  5. kisstdlib-0.0.3/kisstdlib/path.py +0 -103
  6. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/README.md +0 -0
  7. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/__init__.py +0 -0
  8. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/argparse/__init__.py +0 -0
  9. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/argparse/better.py +0 -0
  10. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/exceptions.py +0 -0
  11. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/__init__.py +0 -0
  12. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/base.py +0 -0
  13. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/encoder/__init__.py +0 -0
  14. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/encoder/base.py +0 -0
  15. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/encoder/pyrepr.py +0 -0
  16. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/stdio.py +0 -0
  17. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/io/wrapper.py +0 -0
  18. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/logging.py +0 -0
  19. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib/py.typed +0 -0
  20. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib.egg-info/SOURCES.txt +0 -0
  21. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib.egg-info/dependency_links.txt +0 -0
  22. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/kisstdlib.egg-info/top_level.txt +0 -0
  23. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/setup.cfg +0 -0
  24. {kisstdlib-0.0.3 → kisstdlib-0.0.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kisstdlib
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Keep It Simple STandarD LIBraries set for Python
5
5
  Author-email: Jan Malakhovski <oxij@oxij.org>
6
6
  Keywords: sys,stdlib
@@ -0,0 +1,163 @@
1
+ # Copyright (c) 2018-2024 Jan Malakhovski <oxij@oxij.org>
2
+ #
3
+ # This file is a part of kisstdlib project.
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.
22
+
23
+ import errno as _errno
24
+ import os as _os
25
+ import os.path as _op
26
+ import stat as _stat
27
+ import typing as _t
28
+
29
+ IncludeFilesFunc = _t.Callable[[_t.AnyStr], bool]
30
+ IncludeDirectoriesFunc = _t.Callable[[_t.AnyStr, bool, list[tuple[_t.AnyStr, bool]]], bool | None]
31
+
32
+ def walk_orderly(path : _t.AnyStr,
33
+ *,
34
+ include_files : bool | IncludeFilesFunc[_t.AnyStr] = True,
35
+ include_directories : bool | IncludeDirectoriesFunc[_t.AnyStr] = True,
36
+ follow_symlinks : bool = True,
37
+ ordering : bool | None = True,
38
+ handle_error : _t.Callable[..., None] | None = None,
39
+ path_is_file_maybe : bool = True) -> _t.Iterable[tuple[_t.AnyStr, bool]]:
40
+ """Similar to os.walk, but produces an iterator over plain file paths, allows
41
+ non-directories as input (which will just output a single element), and
42
+ the output is guaranteed to be ordered if `ordering` is not `None`.
43
+ """
44
+
45
+ if path_is_file_maybe:
46
+ try:
47
+ fstat = _os.stat(path, follow_symlinks = follow_symlinks)
48
+ except OSError as exc:
49
+ if handle_error is not None:
50
+ eno = exc.errno
51
+ handle_error("failed to stat `%s`: [Errno %d, %s] %s: %s", eno, _errno.errorcode.get(eno, "?"), _os.strerror(eno), path)
52
+ return
53
+ raise
54
+
55
+ if not _stat.S_ISDIR(fstat.st_mode):
56
+ if isinstance(include_files, bool):
57
+ if not include_files:
58
+ return
59
+ elif not include_files(path):
60
+ return
61
+ yield path, False
62
+ return
63
+
64
+ try:
65
+ scandir_it = _os.scandir(path)
66
+ except OSError as exc:
67
+ if handle_error is not None:
68
+ eno = exc.errno
69
+ handle_error("failed to `scandir`: [Errno %d, %s] %s: %s", eno, _errno.errorcode.get(eno, "?"), _os.strerror(eno), path)
70
+ return
71
+ raise
72
+
73
+ complete = True
74
+ elements : list[tuple[_t.AnyStr, bool]] = []
75
+
76
+ with scandir_it:
77
+ while True:
78
+ try:
79
+ entry : _os.DirEntry[_t.AnyStr] = next(scandir_it)
80
+ except StopIteration:
81
+ break
82
+ except OSError as exc:
83
+ if handle_error is not None:
84
+ eno = exc.errno
85
+ handle_error("failed in `scandir`: [Errno %d, %s] %s: %s", eno, _errno.errorcode.get(eno, "?"), _os.strerror(eno), path)
86
+ return
87
+ raise
88
+ else:
89
+ try:
90
+ entry_is_dir = entry.is_dir(follow_symlinks = follow_symlinks)
91
+ except OSError as exc:
92
+ if handle_error is not None:
93
+ eno = exc.errno
94
+ handle_error("failed to `stat`: [Errno %d, %s] %s: %s", eno, _errno.errorcode.get(eno, "?"), _os.strerror(eno), path)
95
+ # NB: skip errors here
96
+ complete = False
97
+ continue
98
+ raise
99
+
100
+ elements.append((entry.path, entry_is_dir))
101
+
102
+ if ordering is not None:
103
+ elements.sort(reverse=not ordering)
104
+
105
+ if isinstance(include_directories, bool):
106
+ if include_directories:
107
+ yield path, True
108
+ else:
109
+ inc = include_directories(path, complete, elements)
110
+ if inc is None:
111
+ return
112
+ elif inc:
113
+ yield path, True
114
+
115
+ for epath, eis_dir in elements:
116
+ if eis_dir:
117
+ yield from walk_orderly(epath,
118
+ include_files=include_files,
119
+ include_directories=include_directories,
120
+ follow_symlinks=follow_symlinks,
121
+ ordering=ordering,
122
+ handle_error=handle_error,
123
+ path_is_file_maybe=False)
124
+ else:
125
+ yield epath, False
126
+
127
+ def as_include_directories(f : IncludeFilesFunc[_t.AnyStr]) -> IncludeDirectoriesFunc[_t.AnyStr]:
128
+ """`convert walk_orderly(..., include_files, ...)` filter to `include_directories` filter"""
129
+ def func(path : _t.AnyStr, complete : bool, elements : list[tuple[_t.AnyStr, bool]]) -> bool:
130
+ return f(path)
131
+ return func
132
+
133
+ def with_extension_in(exts : list[str | bytes] | set[str | bytes]) -> IncludeFilesFunc[_t.AnyStr]:
134
+ """`walk_orderly(..., include_files, ...)` (or `include_directories`) filter that makes it only include files that have one of the given extensions"""
135
+ def pred(path : _t.AnyStr) -> bool:
136
+ _, ext = _op.splitext(path)
137
+ return ext in exts
138
+ return pred
139
+
140
+ def with_extension_not_in(exts : list[str | bytes] | set[str | bytes]) -> IncludeFilesFunc[_t.AnyStr]:
141
+ """`walk_orderly(..., include_files, ...)` (or `include_directories`) filter that makes it only include files that do not have any of the given extensions"""
142
+ def pred(path : _t.AnyStr) -> bool:
143
+ _, ext = _op.splitext(path)
144
+ return ext not in exts
145
+ return pred
146
+
147
+ def not_empty_directories(path : _t.AnyStr, complete : bool, elements : list[tuple[_t.AnyStr, bool]]) -> bool:
148
+ """`walk_orderly(..., include_directories, ...)` filter that makes it print only non-empty directories"""
149
+ if len(elements) == 0:
150
+ return not complete
151
+ return True
152
+
153
+ def leaf_directories(path : _t.AnyStr, complete : bool, elements : list[tuple[_t.AnyStr, bool]]) -> bool:
154
+ """`walk_orderly(..., include_directories, ...)` filter that makes it print leaf directories only, i.e. only directories without sub-directories"""
155
+ if complete and all(map(lambda x: not x[1], elements)):
156
+ return True
157
+ return False
158
+
159
+ def not_empty_leaf_directories(path : _t.AnyStr, complete : bool, elements : list[tuple[_t.AnyStr, bool]]) -> bool:
160
+ """`walk_orderly(..., include_directories, ...)` filter that makes it print only non-empty leaf directories, i.e. non-empty directories without sub-directories"""
161
+ if not_empty_directories(path, complete, elements) and leaf_directories(path, complete, elements):
162
+ return True
163
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kisstdlib
3
- Version: 0.0.3
3
+ Version: 0.0.4
4
4
  Summary: Keep It Simple STandarD LIBraries set for Python
5
5
  Author-email: Jan Malakhovski <oxij@oxij.org>
6
6
  Keywords: sys,stdlib
@@ -3,7 +3,7 @@ requires = ["setuptools"]
3
3
  build-backend = "setuptools.build_meta"
4
4
  [project]
5
5
  name = "kisstdlib"
6
- version = "0.0.3"
6
+ version = "0.0.4"
7
7
  authors = [{ name = "Jan Malakhovski", email = "oxij@oxij.org" }]
8
8
  description = "Keep It Simple STandarD LIBraries set for Python"
9
9
  readme = "README.md"
@@ -1,103 +0,0 @@
1
- # Copyright (c) 2018-2024 Jan Malakhovski <oxij@oxij.org>
2
- #
3
- # This file is a part of kisstdlib project.
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.
22
-
23
- import logging as _logging
24
- import os as _os
25
- import stat as _stat
26
- import typing as _t
27
-
28
- def walk_orderly(path : _t.AnyStr,
29
- *,
30
- include_directories : bool = True,
31
- follow_symlinks : bool = True,
32
- ordering : bool | None = True,
33
- handle_error : _t.Callable[..., None] | None = _logging.error) -> _t.Iterable[_t.AnyStr]:
34
- """Similar to os.walk, but produces an iterator over plain file paths, allows
35
- non-directories as input (which will just output a single element), and
36
- the output is guaranteed to be ordered if `ordering` is not `None`.
37
- """
38
-
39
- try:
40
- fstat = _os.stat(path, follow_symlinks = follow_symlinks)
41
- except OSError:
42
- if handle_error is not None:
43
- handle_error("failed to stat: %s", path)
44
- return
45
- raise
46
-
47
- if not _stat.S_ISDIR(fstat.st_mode):
48
- yield path
49
- return
50
-
51
- try:
52
- scandir_it = _os.scandir(path)
53
- except OSError:
54
- if handle_error is not None:
55
- handle_error("failed to scandir: %s", path)
56
- return
57
- raise
58
-
59
- elements : list[_t.AnyStr] = []
60
-
61
- with scandir_it:
62
- while True:
63
- try:
64
- entry : _t.Any = next(scandir_it)
65
- except StopIteration:
66
- break
67
- except OSError:
68
- if handle_error is not None:
69
- handle_error("failed in scandir: %s", path)
70
- return
71
- raise
72
- else:
73
- try:
74
- is_dir = entry.is_dir(follow_symlinks = follow_symlinks)
75
- except OSError:
76
- if handle_error is not None:
77
- handle_error("failed to stat: %s", entry.path)
78
- return
79
- raise
80
-
81
- if is_dir:
82
- if isinstance(entry.path, bytes):
83
- elements.append(entry.path + b"/") # type: ignore
84
- else:
85
- elements.append(entry.path + "/")
86
- else:
87
- elements.append(entry.path)
88
-
89
- if ordering is not None:
90
- elements.sort(reverse=not ordering)
91
-
92
- for path in elements:
93
- lchar : _t.AnyStr = path[-1:]
94
- if lchar == "/" or lchar == b"/":
95
- if include_directories:
96
- yield path
97
- yield from walk_orderly(path,
98
- include_directories=include_directories,
99
- follow_symlinks=follow_symlinks,
100
- ordering=ordering,
101
- handle_error=handle_error)
102
- else:
103
- yield path
File without changes
File without changes
File without changes
File without changes