@@ -734,8 +734,8 @@ def _find_iso_record(self, iso_path, encoding='utf-8'):
734
734
return _find_dr_record_by_name (self .pvd , iso_path , encoding )
735
735
736
736
@lru_cache (maxsize = 256 )
737
- def _find_rr_record (self , rr_path ):
738
- # type: (bytes) -> dr.DirectoryRecord
737
+ def _find_rr_record (self , rr_path , encoding = 'utf-8' ):
738
+ # type: (bytes, str ) -> dr.DirectoryRecord
739
739
"""
740
740
An internal method to find a directory record on the ISO given a Rock
741
741
Ridge path. If the entry is found, it returns the directory record
@@ -755,7 +755,7 @@ def _find_rr_record(self, rr_path):
755
755
756
756
splitpath = utils .split_path (rr_path )
757
757
758
- currpath = splitpath .pop (0 ).decode ('utf-8' ).encode ('utf-8' )
758
+ currpath = splitpath .pop (0 ).decode ('utf-8' ).encode (encoding )
759
759
760
760
entry = root_dir_record
761
761
@@ -806,13 +806,13 @@ def _find_rr_record(self, rr_path):
806
806
if not child .is_dir ():
807
807
break
808
808
entry = child
809
- currpath = splitpath .pop (0 ).decode ('utf-8' ).encode ('utf-8' )
809
+ currpath = splitpath .pop (0 ).decode ('utf-8' ).encode (encoding )
810
810
811
811
raise pycdlibexception .PyCdlibInvalidInput ('Could not find path' )
812
812
813
813
@lru_cache (maxsize = 256 )
814
- def _find_joliet_record (self , joliet_path ):
815
- # type: (bytes) -> dr.DirectoryRecord
814
+ def _find_joliet_record (self , joliet_path , encoding = 'utf-16_be' ):
815
+ # type: (bytes, str ) -> dr.DirectoryRecord
816
816
"""
817
817
An internal method to find a directory record on the ISO given a Joliet
818
818
path. If the entry is found, it returns the directory record object
@@ -826,7 +826,7 @@ def _find_joliet_record(self, joliet_path):
826
826
"""
827
827
if self .joliet_vd is None :
828
828
raise pycdlibexception .PyCdlibInternalError ('Joliet path requested on non-Joliet ISO' )
829
- return _find_dr_record_by_name (self .joliet_vd , joliet_path , 'utf-16_be' )
829
+ return _find_dr_record_by_name (self .joliet_vd , joliet_path , encoding )
830
830
831
831
@lru_cache (maxsize = 256 )
832
832
def _find_udf_record (self , udf_path ):
@@ -2425,8 +2425,8 @@ def _udf_get_file_from_iso_fp(self, outfp, blocksize, udf_path):
2425
2425
utils .copy_data (data_len , blocksize , data_fp , outfp )
2426
2426
2427
2427
def _get_file_from_iso_fp (self , outfp , blocksize , iso_path , rr_path ,
2428
- joliet_path ):
2429
- # type: (BinaryIO, int, Optional[bytes], Optional[bytes], Optional[bytes]) -> None
2428
+ joliet_path , encoding = None ):
2429
+ # type: (BinaryIO, int, Optional[bytes], Optional[bytes], Optional[bytes], str ) -> None
2430
2430
"""
2431
2431
An internal method to fetch a single file from the ISO and write it out
2432
2432
to the file object.
@@ -2446,13 +2446,19 @@ def _get_file_from_iso_fp(self, outfp, blocksize, iso_path, rr_path,
2446
2446
if joliet_path is not None :
2447
2447
if self .joliet_vd is None :
2448
2448
raise pycdlibexception .PyCdlibInvalidInput ('Cannot fetch a joliet_path from a non-Joliet ISO' )
2449
- found_record = self ._find_joliet_record (joliet_path )
2449
+ if not encoding :
2450
+ encoding = 'utf-16_be'
2451
+ found_record = self ._find_joliet_record (joliet_path , encoding )
2450
2452
elif rr_path is not None :
2451
2453
if not self .rock_ridge :
2452
2454
raise pycdlibexception .PyCdlibInvalidInput ('Cannot fetch a rr_path from a non-Rock Ridge ISO' )
2453
- found_record = self ._find_rr_record (rr_path )
2455
+ if not encoding :
2456
+ encoding = 'utf-8'
2457
+ found_record = self ._find_rr_record (rr_path , encoding )
2454
2458
elif iso_path is not None :
2455
- found_record = self ._find_iso_record (iso_path )
2459
+ if not encoding :
2460
+ encoding = 'utf-8'
2461
+ found_record = self ._find_iso_record (iso_path , encoding )
2456
2462
else :
2457
2463
raise pycdlibexception .PyCdlibInternalError ('Invalid path passed to get_file_from_iso_fp' )
2458
2464
@@ -3502,7 +3508,7 @@ def _get_iso_entry(self, iso_path, encoding='utf-8'):
3502
3508
3503
3509
return self ._find_iso_record (iso_path , encoding )
3504
3510
3505
- def _get_rr_entry (self , rr_path ):
3511
+ def _get_rr_entry (self , rr_path , encoding = 'utf-8' ):
3506
3512
# type: (bytes) -> dr.DirectoryRecord
3507
3513
"""
3508
3514
Internal method to get the directory record for a Rock Ridge path.
@@ -3516,9 +3522,9 @@ def _get_rr_entry(self, rr_path):
3516
3522
if self ._needs_reshuffle :
3517
3523
self ._reshuffle_extents ()
3518
3524
3519
- return self ._find_rr_record (rr_path )
3525
+ return self ._find_rr_record (rr_path , encoding )
3520
3526
3521
- def _get_joliet_entry (self , joliet_path ):
3527
+ def _get_joliet_entry (self , joliet_path , encoding = 'utf-16_be' ):
3522
3528
# type: (bytes) -> dr.DirectoryRecord
3523
3529
"""
3524
3530
Internal method to get the directory record for a Joliet path.
@@ -3532,7 +3538,7 @@ def _get_joliet_entry(self, joliet_path):
3532
3538
if self ._needs_reshuffle :
3533
3539
self ._reshuffle_extents ()
3534
3540
3535
- return self ._find_joliet_record (joliet_path )
3541
+ return self ._find_joliet_record (joliet_path , encoding )
3536
3542
3537
3543
def _get_udf_entry (self , udf_path ):
3538
3544
# type: (str) -> udfmod.UDFFileEntry
@@ -4199,6 +4205,7 @@ def get_file_from_iso_fp(self, outfp, **kwargs):
4199
4205
iso_path = None
4200
4206
rr_path = None
4201
4207
udf_path = None
4208
+ encoding = None
4202
4209
num_paths = 0
4203
4210
for key , value in kwargs .items ():
4204
4211
if key == 'blocksize' :
@@ -4229,6 +4236,8 @@ def get_file_from_iso_fp(self, outfp, **kwargs):
4229
4236
num_paths += 1
4230
4237
elif value is not None :
4231
4238
raise pycdlibexception .PyCdlibInvalidInput ('udf_path must be a string' )
4239
+ elif key == 'encoding' :
4240
+ encoding = value
4232
4241
else :
4233
4242
raise pycdlibexception .PyCdlibInvalidInput ('Unknown keyword %s' % (key ))
4234
4243
@@ -4239,7 +4248,7 @@ def get_file_from_iso_fp(self, outfp, **kwargs):
4239
4248
self ._udf_get_file_from_iso_fp (outfp , blocksize , udf_path )
4240
4249
else :
4241
4250
self ._get_file_from_iso_fp (outfp , blocksize , iso_path , rr_path ,
4242
- joliet_path )
4251
+ joliet_path , encoding )
4243
4252
4244
4253
def get_and_write (self , iso_path , local_path , blocksize = 8192 ):
4245
4254
# type: (str, str, int) -> None
@@ -5494,9 +5503,9 @@ def list_children(self, **kwargs):
5494
5503
else :
5495
5504
use_rr = False
5496
5505
if 'joliet_path' in kwargs :
5497
- rec = self ._get_joliet_entry (self ._normalize_joliet_path (kwargs ['joliet_path' ]))
5506
+ rec = self ._get_joliet_entry (self ._normalize_joliet_path (kwargs ['joliet_path' ]), kwargs [ 'encoding' ] )
5498
5507
elif 'rr_path' in kwargs :
5499
- rec = self ._get_rr_entry (utils .normpath (kwargs ['rr_path' ]))
5508
+ rec = self ._get_rr_entry (utils .normpath (kwargs ['rr_path' ]), kwargs [ 'encoding' ] )
5500
5509
use_rr = True
5501
5510
else :
5502
5511
rec = self ._get_iso_entry (utils .normpath (kwargs ['iso_path' ]), kwargs ['encoding' ])
0 commit comments