python-fsutil 0.16.1__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 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 <= factor_limit):
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 using
135
- the specified algorithm function (md5 by default).
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
- with open(path, "rb") as file:
141
- for chunk in iter(lambda: file.read(4096), b""):
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
@@ -4,4 +4,4 @@ __description__ = "high-level file-system operations for lazy devs."
4
4
  __email__ = "fabio.caccamo@gmail.com"
5
5
  __license__ = "MIT"
6
6
  __title__ = "python-fsutil"
7
- __version__ = "0.16.1"
7
+ __version__ = "0.17.0"
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 = filename_match.group(1)
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-fsutil
3
- Version: 0.16.1
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://img.shields.io/codacy/grade/fc40788ae7d74d1fb34a38934113c4e5?logo=codacy)](https://www.codacy.com/app/fabiocaccamo/python-fsutil)
70
70
  [![](https://img.shields.io/badge/code%20style-black-000000.svg?logo=python&logoColor=black)](https://github.com/psf/black)
71
71
  [![](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
72
+ [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/fabiocaccamo/python-fsutil/badge)](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=7YoaIg-_XuYzXo0IhjEAZUWasaIbPA67aAL5z_T3IRg,1013
5
+ fsutil/converters.py,sha256=7VjabLMSwznM9mOhUnSJUVY-qH5EOExCIvofZ8_SLPk,1012
6
6
  fsutil/deps.py,sha256=-7eswE7fgHCmILC6GSLbipbuXp_aB3UfmkNRRGaHfgA,336
7
- fsutil/info.py,sha256=yVoWPtAc_WOj0WVpRIGkq0TTj8xB6W4l-mVUKaB7Bu8,5333
7
+ fsutil/info.py,sha256=nQRquIbuSCbM9cO-zQALMHGtYhAXihm8MyPtp3qQfR4,5807
8
8
  fsutil/io.py,sha256=1AYC83lhwgNUFiT0BB-I0sDvncXAPopOtlYxzL0lEE4,6327
9
- fsutil/metadata.py,sha256=EoL0z8zCATBEmBnt5PkNxVe_T2F613PqRjK0eHPOqvI,266
10
- fsutil/operations.py,sha256=Itwgl-fONd6RWnlNKqHMvntDg4FKeP_cqrtmqInc8Fs,15392
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.1.dist-info/licenses/LICENSE.txt,sha256=IcPfOD_lonKcLMnPRhiWdQUPW_LYW-5TTDljwi3UXQg,1078
16
- python_fsutil-0.16.1.dist-info/METADATA,sha256=zdVFuadNBZwBBsR0s_9kjqv302fzZgaEbDixgpGQjfA,24763
17
- python_fsutil-0.16.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
18
- python_fsutil-0.16.1.dist-info/top_level.txt,sha256=KGTSjNLPWmxnZt8BFMZQrpnhkO7DsKrYWoXK-Sf3wBQ,7
19
- python_fsutil-0.16.1.dist-info/RECORD,,
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,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (83.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5