Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f4cd026
Add Python files
emmatyping Apr 30, 2025
4168895
Fix byteswarning in test
emmatyping Apr 30, 2025
a22fa9b
Remove shape tests
emmatyping May 3, 2025
e70e03b
Make namedtuples dataclasses
emmatyping May 4, 2025
cbf0ef8
Apply suggestions from AA-Turner
emmatyping May 4, 2025
298b369
Clean up chunk calculations in train_dict
emmatyping May 4, 2025
a22be68
Fix _CLValues instantiation
emmatyping May 4, 2025
b30ed02
More cleanup of train_/finalize_dict
emmatyping May 4, 2025
307a894
Have train_/finalize_dict take tuple not list
emmatyping May 4, 2025
dd716a4
Ensure trailing data raises errors
emmatyping May 4, 2025
9b4765b
Remove paramter bounds caching and unsupported...
emmatyping May 4, 2025
214cd60
Use kwargs for code clarity
emmatyping May 4, 2025
e1f53b1
Clean up imports in zstd tests
emmatyping May 4, 2025
4c00026
Use _1K instead of 1024 in tests
emmatyping May 4, 2025
99653d2
Move compression.zstd.zstdfile to compression.zstd._zstdfile
emmatyping May 4, 2025
e403a25
Change compressLevel_values to COMPRESSION_LEVEL_DEFAULT
emmatyping May 4, 2025
63625bc
Fix tests for change in error message
emmatyping May 4, 2025
1ea4b9a
Make parameter names snake case
emmatyping May 4, 2025
ad05da8
Replace compressionLevel_values re-export with COMPRESSION_LEVEL_DEFAULT
emmatyping May 4, 2025
e82e23d
Move zstd_support_multithread to tests and rename
emmatyping May 4, 2025
7801b6b
Update module docstring for compression.zstd
emmatyping May 4, 2025
df5d827
Clarify Strategy stability in docstring
emmatyping May 4, 2025
4ff48da
Fix formatting in tarfile
emmatyping May 4, 2025
c68a896
Remove zstd_support_multithread from __all__
emmatyping May 4, 2025
326400d
Add test_name from upstream
emmatyping May 4, 2025
2c0c9a1
Don't close tarfile if there is a BaseException
emmatyping May 4, 2025
49f3821
Use options kwarg in tests
emmatyping May 4, 2025
8ba6bda
Use options kwarg in tests in more places
emmatyping May 4, 2025
129d5e6
Adopt suggestions by Tomas R. for _zstdfile
emmatyping May 4, 2025
7d54d35
Formatting fixes in zstd tests
emmatyping May 4, 2025
03795ec
Improve docstrings for (de)compress
emmatyping May 4, 2025
01fcfcb
Fix some line length issues
emmatyping May 4, 2025
f04494c
Improve docstring on C/DParameter.bounds()
emmatyping May 4, 2025
caa40b1
Improve docstrings and formatting
emmatyping May 4, 2025
4584ec5
Add missing f string prefix
emmatyping May 4, 2025
3cafdc6
Fix weird indent in _zstdfile.py
emmatyping May 4, 2025
8cb0846
Use io.open instead of builtins.open
emmatyping May 5, 2025
c7d5d67
Remove _READER_CLASS from ZstdFile
emmatyping May 5, 2025
a56a22e
Adopt many suggestions from AA-Turner for ZstdFile
emmatyping May 5, 2025
7e919c8
Set self._buffer to None
emmatyping May 5, 2025
389faed
Move _nbytes to _zstdfile.py
emmatyping May 5, 2025
006ef2e
Move test_zstd to file
emmatyping May 5, 2025
c846b78
Rename C/DParameter to (De)CompressionParameter
emmatyping May 5, 2025
fa0cb0c
regen clinic
AA-Turner May 5, 2025
74e4d2b
Fix whitespace issue
emmatyping May 5, 2025
03fff3d
Remove makefile test dir
emmatyping May 5, 2025
a99c5dd
swap order of parameters in _get_param_bounds
AA-Turner May 5, 2025
a12a031
Merge branch 'main' into 3.14-zstd-python-code
emmatyping May 5, 2025
bf94aad
Sort imports
AA-Turner May 5, 2025
5b45ec7
Improve docstrings
AA-Turner May 5, 2025
b0eca5a
Remove comments
AA-Turner May 5, 2025
c0d0e10
Remove unused private variables
AA-Turner May 5, 2025
10f0cff
Misc changes (positional-only, style, error messages)
AA-Turner May 5, 2025
7f8c350
whitespace
AA-Turner May 5, 2025
bf4b07d
Remove _set_parameter_types
AA-Turner May 5, 2025
eaf46a8
Revert "Remove _set_parameter_types"
emmatyping May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Misc changes (positional-only, style, error messages)
  • Loading branch information
AA-Turner committed May 5, 2025
commit 10f0cffbc04eea29fb7a88932a257cb2304d0971
4 changes: 2 additions & 2 deletions Lib/compression/zstd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def train_dict(samples, dict_size):
return ZstdDict(dict_content)


def finalize_dict(zstd_dict, samples, dict_size, level):
def finalize_dict(zstd_dict, /, samples, dict_size, level):
"""Return a ZstdDict representing a finalized Zstandard dictionary.

Given a custom content as a basis for dictionary, and a set of samples,
Expand Down Expand Up @@ -119,7 +119,7 @@ def finalize_dict(zstd_dict, samples, dict_size, level):
chunks = b''.join(samples)
chunk_sizes = tuple(_nbytes(sample) for sample in samples)
if not chunks:
raise ValueError("The samples are empty content, can't finalize"
raise ValueError("The samples are empty content, can't finalize the"
"dictionary.")
dict_content = _zstd._finalize_dict(zstd_dict.dict_content,
chunks, chunk_sizes,
Expand Down
49 changes: 15 additions & 34 deletions Lib/compression/zstd/_zstdfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
_MODE_WRITE = 2


def _nbytes(dat):
def _nbytes(dat, /):
if isinstance(dat, (bytes, bytearray)):
return len(dat)
with memoryview(dat) as mv:
Expand All @@ -33,16 +33,8 @@ class ZstdFile(_streams.BaseStream):
FLUSH_BLOCK = ZstdCompressor.FLUSH_BLOCK
FLUSH_FRAME = ZstdCompressor.FLUSH_FRAME

def __init__(
self,
file,
/,
mode="r",
*,
level=None,
options=None,
zstd_dict=None,
):
def __init__(self, file, /, mode="r", *,
level=None, options=None, zstd_dict=None):
"""Open a Zstandard compressed file in binary mode.

*file* can be either an file-like object, or a file name to open.
Expand Down Expand Up @@ -79,9 +71,8 @@ def __init__(
if level is not None and not isinstance(level, int):
raise TypeError("level must be int or None")
self._mode = _MODE_WRITE
self._compressor = ZstdCompressor(
level=level, options=options, zstd_dict=zstd_dict
)
self._compressor = ZstdCompressor(level=level, options=options,
zstd_dict=zstd_dict)
self._pos = 0
else:
raise ValueError(f"Invalid mode: {mode!r}")
Expand Down Expand Up @@ -131,7 +122,7 @@ def close(self):
self._fp = None
self._close_fp = False

def write(self, data):
def write(self, data, /):
"""Write a bytes-like object *data* to the file.

Returns the number of uncompressed bytes written, which is
Expand Down Expand Up @@ -305,19 +296,8 @@ def writable(self):
return self._mode == _MODE_WRITE


# Copied from lzma module
def open(
file,
/,
mode="rb",
*,
level=None,
options=None,
zstd_dict=None,
encoding=None,
errors=None,
newline=None,
):
def open(file, /, mode="rb", *, level=None, options=None, zstd_dict=None,
encoding=None, errors=None, newline=None):
"""Open a Zstandard compressed file in binary or text mode.

file can be either a file name (given as a str, bytes, or PathLike object),
Expand Down Expand Up @@ -346,7 +326,10 @@ def open(
behavior, and line ending(s).
"""

if "t" in mode:
text_mode = "t" in mode
mode = mode.replace("t", "")

if text_mode:
if "b" in mode:
raise ValueError(f"Invalid mode: {mode!r}")
else:
Expand All @@ -357,12 +340,10 @@ def open(
if newline is not None:
raise ValueError("Argument 'newline' not supported in binary mode")

zstd_mode = mode.replace("t", "")
binary_file = ZstdFile(
file, zstd_mode, level=level, options=options, zstd_dict=zstd_dict
)
binary_file = ZstdFile(file, mode, level=level, options=options,
zstd_dict=zstd_dict)

if "t" in mode:
if text_mode:
return io.TextIOWrapper(binary_file, encoding, errors, newline)
else:
return binary_file