Skip to content

Commit 399de70

Browse files
committed
Merge commit '009fcee154'
2 parents 952b20e + 009fcee commit 399de70

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

test_zipp.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_subdir_is_dir(self, alpharep):
138138
def test_open(self, alpharep):
139139
root = zipp.Path(alpharep)
140140
a, b, g = root.iterdir()
141-
with a.open() as strm:
141+
with a.open(encoding="utf-8") as strm:
142142
data = strm.read()
143143
assert data == "content of a"
144144

@@ -150,7 +150,7 @@ def test_open_write(self):
150150
zf = zipp.Path(zipfile.ZipFile(io.BytesIO(), mode='w'))
151151
with zf.joinpath('file.bin').open('wb') as strm:
152152
strm.write(b'binary contents')
153-
with zf.joinpath('file.txt').open('w') as strm:
153+
with zf.joinpath('file.txt').open('w', encoding="utf-8") as strm:
154154
strm.write('text file')
155155

156156
def test_open_extant_directory(self):
@@ -181,7 +181,7 @@ def test_open_missing_directory(self):
181181
def test_read(self, alpharep):
182182
root = zipp.Path(alpharep)
183183
a, b, g = root.iterdir()
184-
assert a.read_text() == "content of a"
184+
assert a.read_text(encoding="utf-8") == "content of a"
185185
assert a.read_bytes() == b"content of a"
186186

187187
@pass_alpharep
@@ -190,21 +190,21 @@ def test_joinpath(self, alpharep):
190190
a = root.joinpath("a.txt")
191191
assert a.is_file()
192192
e = root.joinpath("b").joinpath("d").joinpath("e.txt")
193-
assert e.read_text() == "content of e"
193+
assert e.read_text(encoding="utf-8") == "content of e"
194194

195195
@pass_alpharep
196196
def test_joinpath_multiple(self, alpharep):
197197
root = zipp.Path(alpharep)
198198
e = root.joinpath("b", "d", "e.txt")
199-
assert e.read_text() == "content of e"
199+
assert e.read_text(encoding="utf-8") == "content of e"
200200

201201
@pass_alpharep
202202
def test_traverse_truediv(self, alpharep):
203203
root = zipp.Path(alpharep)
204204
a = root / "a.txt"
205205
assert a.is_file()
206206
e = root / "b" / "d" / "e.txt"
207-
assert e.read_text() == "content of e"
207+
assert e.read_text(encoding="utf-8") == "content of e"
208208

209209
@pass_alpharep
210210
def test_traverse_simplediv(self, alpharep):
@@ -261,9 +261,9 @@ def test_mutability(self, alpharep):
261261
alpharep.writestr('foo.txt', 'foo')
262262
alpharep.writestr('bar/baz.txt', 'baz')
263263
assert any(child.name == 'foo.txt' for child in root.iterdir())
264-
assert (root / 'foo.txt').read_text() == 'foo'
264+
assert (root / 'foo.txt').read_text(encoding="utf-8") == 'foo'
265265
(baz,) = (root / 'bar').iterdir()
266-
assert baz.read_text() == 'baz'
266+
assert baz.read_text(encoding="utf-8") == 'baz'
267267

268268
HUGE_ZIPFILE_NUM_ENTRIES = 2**13
269269

@@ -297,7 +297,7 @@ def test_read_does_not_close(self, alpharep):
297297
alpharep = self.zipfile_ondisk(alpharep)
298298
with zipfile.ZipFile(alpharep) as file:
299299
for rep in range(2):
300-
zipp.Path(file, 'a.txt').read_text()
300+
zipp.Path(file, 'a.txt').read_text(encoding="utf-8")
301301

302302
@pass_alpharep
303303
def test_subclass(self, alpharep):

zipp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
257257
if args or kwargs:
258258
raise ValueError("encoding args invalid for binary operation")
259259
return stream
260+
else:
261+
kwargs["encoding"] = io.text_encoding(kwargs.get("encoding"))
260262
return io.TextIOWrapper(stream, *args, **kwargs)
261263

262264
@property
@@ -280,6 +282,7 @@ def filename(self):
280282
return pathlib.Path(self.root.filename).joinpath(self.at)
281283

282284
def read_text(self, *args, **kwargs):
285+
kwargs["encoding"] = io.text_encoding(kwargs.get("encoding"))
283286
with self.open('r', *args, **kwargs) as strm:
284287
return strm.read()
285288

0 commit comments

Comments
 (0)