@@ -354,7 +354,7 @@ def check_and_download_folder(local_path, remote_path, overwrite=True):
354
354
return remote_path
355
355
356
356
357
- def open_file (file_path , file_options = "r" ):
357
+ def open_file (file_path , file_options = "r" , encoding = None ):
358
358
"""Open a file and return the object.
359
359
360
360
Parameters
@@ -363,6 +363,10 @@ def open_file(file_path, file_options="r"):
363
363
Full absolute path to the file (either local or remote).
364
364
file_options : str, optional
365
365
Options for opening the file.
366
+ encoding : str, optional
367
+ Name of the encoding used to decode or encode the file.
368
+ The default used is platform dependent, but any encoding supported by Python can be
369
+ passed.
366
370
367
371
Returns
368
372
-------
@@ -373,15 +377,15 @@ def open_file(file_path, file_options="r"):
373
377
dir_name = os .path .dirname (file_path )
374
378
if "r" in file_options :
375
379
if os .path .exists (file_path ):
376
- return open (file_path , file_options )
380
+ return open (file_path , file_options , encoding )
377
381
elif settings .remote_rpc_session and settings .remote_rpc_session .filemanager .pathexists (
378
382
file_path
379
383
): # pragma: no cover
380
384
local_file = os .path .join (tempfile .gettempdir (), os .path .split (file_path )[- 1 ])
381
385
settings .remote_rpc_session .filemanager .download_file (file_path , local_file )
382
- return open (local_file , file_options )
386
+ return open (local_file , file_options , encoding )
383
387
elif os .path .exists (dir_name ):
384
- return open (file_path , file_options )
388
+ return open (file_path , file_options , encoding )
385
389
elif settings .remote_rpc_session and settings .remote_rpc_session .filemanager .pathexists (dir_name ):
386
390
return settings .remote_rpc_session .open_file (file_path , file_options )
387
391
else :
0 commit comments