Skip to content

Commit 623ea92

Browse files
committed
Merge branch 'release-7.0.4'
2 parents 2865174 + aa51ab6 commit 623ea92

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 7.0.4, 2024-03-26
2+
3+
* Fix wb mode with zstd compression (PR [#815](https://github.com/piskvorky/smart_open/pull/815), [@djudd](https://github.com/djudd))
4+
* Remove GCS bucket.exists call to avoid storage.buckets.get permission (PR [#813](https://github.com/piskvorky/smart_open/pull/813), [@ddelange](https://github.com/ddelange))
5+
16
# 7.0.3, 2024-03-21
27

38
* add support for zst writing (PR [#812](https://github.com/piskvorky/smart_open/pull/812), [@mpenkov](https://github.com/mpenkov))

smart_open/compression.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# from the MIT License (MIT).
77
#
88
"""Implements the compression layer of the ``smart_open`` library."""
9+
import io
910
import logging
1011
import os.path
1112

@@ -108,6 +109,17 @@ def _handle_gzip(file_obj, mode):
108109
def _handle_zstd(file_obj, mode):
109110
import zstandard # type: ignore
110111
result = zstandard.open(filename=file_obj, mode=mode)
112+
# zstandard.open returns an io.TextIOWrapper in text mode, but otherwise
113+
# returns a raw stream reader/writer, and we need the `io` wrapper
114+
# to make FileLikeProxy work correctly.
115+
#
116+
# See:
117+
#
118+
# https://github.com/indygreg/python-zstandard/blob/d7d81e79dbe74feb22fb73405ebfb3e20f4c4653/zstandard/__init__.py#L169-L174
119+
if "b" in mode and "w" in mode:
120+
result = io.BufferedWriter(result)
121+
elif "b" in mode and "r" in mode:
122+
result = io.BufferedReader(result)
111123
return result
112124

113125

smart_open/gcs.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,7 @@ def Writer(bucket,
152152

153153
blob_open_kwargs = {**_DEFAULT_WRITE_OPEN_KWARGS, **blob_open_kwargs}
154154

155-
g_bucket = client.bucket(bucket)
156-
if not g_bucket.exists():
157-
raise google.cloud.exceptions.NotFound(f'bucket {bucket} not found')
158-
159-
g_blob = g_bucket.blob(
155+
g_blob = client.bucket(bucket).blob(
160156
blob,
161157
chunk_size=min_part_size,
162158
)

smart_open/tests/test_smart_open.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ def test_zst_write():
8989
assert got == ["hello world\n", "this is a test\n"]
9090

9191

92+
def test_zst_write_binary():
93+
with named_temporary_file(suffix=".zst") as tmp:
94+
with smart_open.open(tmp.name, "wb") as fout:
95+
fout.write(b"hello world\n")
96+
fout.write(b"this is a test\n")
97+
98+
with smart_open.open(tmp.name, "rb") as fin:
99+
got = list(fin)
100+
101+
assert got == [b"hello world\n", b"this is a test\n"]
102+
103+
92104
class ParseUriTest(unittest.TestCase):
93105
"""
94106
Test ParseUri class.

smart_open/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '7.0.3'
1+
__version__ = '7.0.4'
22

33

44
if __name__ == '__main__':

0 commit comments

Comments
 (0)