python-fsutil 0.16.0__py3-none-any.whl → 0.17.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.
- fsutil/converters.py +1 -1
- fsutil/info.py +21 -7
- fsutil/metadata.py +1 -1
- fsutil/operations.py +6 -2
- {python_fsutil-0.16.0.dist-info → python_fsutil-0.17.0.dist-info}/METADATA +2 -1
- {python_fsutil-0.16.0.dist-info → python_fsutil-0.17.0.dist-info}/RECORD +9 -9
- {python_fsutil-0.16.0.dist-info → python_fsutil-0.17.0.dist-info}/WHEEL +1 -1
- {python_fsutil-0.16.0.dist-info → python_fsutil-0.17.0.dist-info}/licenses/LICENSE.txt +0 -0
- {python_fsutil-0.16.0.dist-info → python_fsutil-0.17.0.dist-info}/top_level.txt +0 -0
fsutil/converters.py
CHANGED
|
@@ -11,7 +11,7 @@ def convert_size_bytes_to_string(size: int) -> str:
|
|
|
11
11
|
units = SIZE_UNITS
|
|
12
12
|
factor = 0
|
|
13
13
|
factor_limit = len(units) - 1
|
|
14
|
-
while (size_num >= 1024) and (factor
|
|
14
|
+
while (size_num >= 1024) and (factor < factor_limit):
|
|
15
15
|
size_num /= 1024
|
|
16
16
|
factor += 1
|
|
17
17
|
size_units = units[factor]
|
fsutil/info.py
CHANGED
|
@@ -2,7 +2,9 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import hashlib
|
|
4
4
|
import os
|
|
5
|
+
import pathlib
|
|
5
6
|
from datetime import datetime
|
|
7
|
+
from typing import IO
|
|
6
8
|
|
|
7
9
|
from fsutil.args import get_path as _get_path
|
|
8
10
|
from fsutil.checks import assert_dir, assert_file
|
|
@@ -129,17 +131,29 @@ def get_file_creation_date_formatted(
|
|
|
129
131
|
return date.strftime(format)
|
|
130
132
|
|
|
131
133
|
|
|
132
|
-
def get_file_hash(path: PathIn, *, func: str = "md5") -> str:
|
|
134
|
+
def get_file_hash(path: PathIn | IO[bytes], *, func: str = "md5") -> str:
|
|
133
135
|
"""
|
|
134
|
-
Get the hash of the file at the given path
|
|
135
|
-
|
|
136
|
+
Get the hash of the file at the given path (or of the given
|
|
137
|
+
binary file-like object) using the specified algorithm
|
|
138
|
+
function (md5 by default).
|
|
136
139
|
"""
|
|
137
|
-
path = _get_path(path)
|
|
138
|
-
assert_file(path)
|
|
139
140
|
hash = hashlib.new(func)
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
if isinstance(path, (str, pathlib.Path)):
|
|
142
|
+
path = _get_path(path)
|
|
143
|
+
assert_file(path)
|
|
144
|
+
with open(path, "rb") as file:
|
|
145
|
+
for chunk in iter(lambda: file.read(4096), b""):
|
|
146
|
+
hash.update(chunk)
|
|
147
|
+
else:
|
|
148
|
+
fileobj = path
|
|
149
|
+
position = None
|
|
150
|
+
if fileobj.seekable():
|
|
151
|
+
position = fileobj.tell()
|
|
152
|
+
fileobj.seek(0)
|
|
153
|
+
for chunk in iter(lambda: fileobj.read(4096), b""):
|
|
142
154
|
hash.update(chunk)
|
|
155
|
+
if position is not None:
|
|
156
|
+
fileobj.seek(position)
|
|
143
157
|
hash_hex = hash.hexdigest()
|
|
144
158
|
return hash_hex
|
|
145
159
|
|
fsutil/metadata.py
CHANGED
fsutil/operations.py
CHANGED
|
@@ -213,7 +213,9 @@ def download_file(
|
|
|
213
213
|
filename_pattern = r'filename="(.*)"'
|
|
214
214
|
filename_match = re.search(filename_pattern, content_disposition)
|
|
215
215
|
if filename_match:
|
|
216
|
-
filename
|
|
216
|
+
# sanitize Content-Disposition filename to prevent path traversal
|
|
217
|
+
filename = filename_match.group(1).replace("\\", "/")
|
|
218
|
+
filename = os.path.basename(filename)
|
|
217
219
|
# or detect filename from url
|
|
218
220
|
if not filename:
|
|
219
221
|
filename = get_filename(url)
|
|
@@ -518,7 +520,9 @@ def _search_paths(path: PathIn, pattern: str) -> list[str]:
|
|
|
518
520
|
pathname = os.path.join(path, pattern)
|
|
519
521
|
paths = glob.glob(pathname, recursive=True)
|
|
520
522
|
# normalize paths to use OS-specific separators
|
|
521
|
-
paths = [
|
|
523
|
+
paths = [
|
|
524
|
+
os.path.relpath(os.path.normpath(path_result), path) for path_result in paths
|
|
525
|
+
]
|
|
522
526
|
return paths
|
|
523
527
|
|
|
524
528
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-fsutil
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.17.0
|
|
4
4
|
Summary: high-level file-system operations for lazy devs.
|
|
5
5
|
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
6
|
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
@@ -69,6 +69,7 @@ Dynamic: license-file
|
|
|
69
69
|
[](https://www.codacy.com/app/fabiocaccamo/python-fsutil)
|
|
70
70
|
[](https://github.com/psf/black)
|
|
71
71
|
[](https://github.com/astral-sh/ruff)
|
|
72
|
+
[](https://securityscorecards.dev/viewer/?uri=github.com/fabiocaccamo/python-fsutil)
|
|
72
73
|
|
|
73
74
|
# python-fsutil
|
|
74
75
|
high-level file-system operations for lazy devs.
|
|
@@ -2,18 +2,18 @@ fsutil/__init__.py,sha256=FsRKd11udg0Y-ZS_r1WDpmd77B1VJ31ykbEBn_Kt_kQ,4223
|
|
|
2
2
|
fsutil/archives.py,sha256=bvFXaaXy5QBBwwBf2313XbCZ3XlSlCoHoVAFWD9WQ74,5027
|
|
3
3
|
fsutil/args.py,sha256=sNf6LlEM8m1XchfklaqidABct5A-V6DCIxLBiaIUCBU,246
|
|
4
4
|
fsutil/checks.py,sha256=LZHz3GsihLlat8Lz-CqQngXDEZfAidmxf8veu_de96I,2807
|
|
5
|
-
fsutil/converters.py,sha256=
|
|
5
|
+
fsutil/converters.py,sha256=7VjabLMSwznM9mOhUnSJUVY-qH5EOExCIvofZ8_SLPk,1012
|
|
6
6
|
fsutil/deps.py,sha256=-7eswE7fgHCmILC6GSLbipbuXp_aB3UfmkNRRGaHfgA,336
|
|
7
|
-
fsutil/info.py,sha256=
|
|
7
|
+
fsutil/info.py,sha256=nQRquIbuSCbM9cO-zQALMHGtYhAXihm8MyPtp3qQfR4,5807
|
|
8
8
|
fsutil/io.py,sha256=1AYC83lhwgNUFiT0BB-I0sDvncXAPopOtlYxzL0lEE4,6327
|
|
9
|
-
fsutil/metadata.py,sha256=
|
|
10
|
-
fsutil/operations.py,sha256=
|
|
9
|
+
fsutil/metadata.py,sha256=_tHK4wb02c2ISdGHCGtR-P5ka6pbuw-V9DiBlAqH-cw,266
|
|
10
|
+
fsutil/operations.py,sha256=eyT8qhRok9KQ_hVkMm4symkzMMSiG7_XWt5p_8zCzM8,15547
|
|
11
11
|
fsutil/paths.py,sha256=oxeJQgDJlU7a3xu9tThAhQw4LjxHQDjfmYkAcH6B784,5816
|
|
12
12
|
fsutil/perms.py,sha256=Yw0R3w-Bx94bek2sY8FlJ0KI6LGFPpxEpQ3n2ULOmos,669
|
|
13
13
|
fsutil/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
14
|
fsutil/types.py,sha256=scqjRct7dMNTmk_UgL1PMxRQktlnEMlSgvOy0MfqREg,111
|
|
15
|
-
python_fsutil-0.
|
|
16
|
-
python_fsutil-0.
|
|
17
|
-
python_fsutil-0.
|
|
18
|
-
python_fsutil-0.
|
|
19
|
-
python_fsutil-0.
|
|
15
|
+
python_fsutil-0.17.0.dist-info/licenses/LICENSE.txt,sha256=IcPfOD_lonKcLMnPRhiWdQUPW_LYW-5TTDljwi3UXQg,1078
|
|
16
|
+
python_fsutil-0.17.0.dist-info/METADATA,sha256=c0P6g3VQ8S-GGe8GvB-hrxI4-a5-VVn0xMmCtxCB8nE,24957
|
|
17
|
+
python_fsutil-0.17.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
18
|
+
python_fsutil-0.17.0.dist-info/top_level.txt,sha256=KGTSjNLPWmxnZt8BFMZQrpnhkO7DsKrYWoXK-Sf3wBQ,7
|
|
19
|
+
python_fsutil-0.17.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|