@@ -241,7 +241,7 @@ def __init__(self, root, at=""):
241
241
self .root = FastLookup .make (root )
242
242
self .at = at
243
243
244
- def open (self , mode = 'r' , * args , pwd = None , ** kwargs ):
244
+ def open (self , mode = 'r' , encoding = None , * args , pwd = None , ** kwargs ):
245
245
"""
246
246
Open this entry as text or binary following the semantics
247
247
of ``pathlib.Path.open()`` by passing arguments through
@@ -254,13 +254,12 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
254
254
raise FileNotFoundError (self )
255
255
stream = self .root .open (self .at , zip_mode , pwd = pwd )
256
256
if 'b' in mode :
257
- if args or kwargs :
257
+ if encoding is not None or args or kwargs :
258
258
raise ValueError ("encoding args invalid for binary operation" )
259
259
return stream
260
260
else :
261
- if "encoding" in kwargs :
262
- kwargs ["encoding" ] = io .text_encoding (kwargs ["encoding" ])
263
- return io .TextIOWrapper (stream , * args , ** kwargs )
261
+ encoding = io .text_encoding (encoding )
262
+ return io .TextIOWrapper (stream , * args , encoding = encoding , ** kwargs )
264
263
265
264
@property
266
265
def name (self ):
@@ -282,10 +281,9 @@ def stem(self):
282
281
def filename (self ):
283
282
return pathlib .Path (self .root .filename ).joinpath (self .at )
284
283
285
- def read_text (self , * args , ** kwargs ):
286
- if "encoding" in kwargs :
287
- kwargs ["encoding" ] = io .text_encoding (kwargs ["encoding" ])
288
- with self .open ('r' , * args , ** kwargs ) as strm :
284
+ def read_text (self , encoding = None , * args , ** kwargs ):
285
+ encoding = io .text_encoding (encoding )
286
+ with self .open ('r' , * args , encoding = encoding , ** kwargs ) as strm :
289
287
return strm .read ()
290
288
291
289
def read_bytes (self ):
0 commit comments