idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
20,200
def track_rr_ce_entry ( self , extent , offset , length ) : # type: (int, int, int) -> rockridge.RockRidgeContinuationBlock if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Primary Volume Descriptor is not yet initialized' ) for block in self . rr_ce_blocks : if block . extent_location ( ) == extent : break else : # We didn't find it in the list, add it block = rockridge . RockRidgeContinuationBlock ( extent , self . log_block_size ) self . rr_ce_blocks . append ( block ) block . track_entry ( offset , length ) return block
Start tracking a new Rock Ridge Continuation Entry entry in this Volume Descriptor at the extent offset and length provided . Since Rock Ridge Continuation Blocks are shared across multiple Rock Ridge Directory Records the most logical place to track them is in the PVD . This method is expected to be used during parse time when an extent offset and length are already assigned to the entry .
157
74
20,201
def clear_rr_ce_entries ( self ) : # type: () -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Primary Volume Descriptor is not yet initialized' ) for block in self . rr_ce_blocks : block . set_extent_location ( - 1 )
A method to clear out all of the extent locations of all Rock Ridge Continuation Entries that the PVD is tracking . This can be used to reset all data before assigning new data .
77
38
20,202
def add_to_space_size ( self , addition_bytes ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) # The 'addition' parameter is expected to be in bytes, but the space # size we track is in extents. Round up to the next extent. self . space_size += utils . ceiling_div ( addition_bytes , self . log_block_size )
A method to add bytes to the space size tracked by this Volume Descriptor .
115
17
20,203
def remove_from_space_size ( self , removal_bytes ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) # The 'removal' parameter is expected to be in bytes, but the space # size we track is in extents. Round up to the next extent. self . space_size -= utils . ceiling_div ( removal_bytes , self . log_block_size )
Remove bytes from the volume descriptor .
115
7
20,204
def add_to_ptr_size ( self , ptr_size ) : # type: (int) -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) # First add to the path table size. self . path_tbl_size += ptr_size if ( utils . ceiling_div ( self . path_tbl_size , 4096 ) * 2 ) > self . path_table_num_extents : # If we overflowed the path table size, then we need to update the # space size. Since we always add two extents for the little and # two for the big, add four total extents. The locations will be # fixed up during reshuffle_extents. self . path_table_num_extents += 2 return True return False
Add the space for a path table record to the volume descriptor .
186
13
20,205
def remove_from_ptr_size ( self , ptr_size ) : # type: (int) -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) # Next remove from the Path Table Record size. self . path_tbl_size -= ptr_size new_extents = utils . ceiling_div ( self . path_tbl_size , 4096 ) * 2 need_remove_extents = False if new_extents > self . path_table_num_extents : # This should never happen. raise pycdlibexception . PyCdlibInvalidInput ( 'This should never happen' ) elif new_extents < self . path_table_num_extents : self . path_table_num_extents -= 2 need_remove_extents = True return need_remove_extents
Remove the space for a path table record from the volume descriptor .
201
13
20,206
def copy_sizes ( self , othervd ) : # type: (PrimaryOrSupplementaryVD) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor is not yet initialized' ) self . space_size = othervd . space_size self . path_tbl_size = othervd . path_tbl_size self . path_table_num_extents = othervd . path_table_num_extents
Copy the path_tbl_size path_table_num_extents and space_size from another volume descriptor .
109
25
20,207
def parse ( self , ident_str ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This File or Text identifier is already initialized' ) self . text = ident_str # FIXME: we do not support a file identifier here. In the future, we # might want to implement this. self . _initialized = True
Parse a file or text identifier out of a string .
87
12
20,208
def new ( self , text ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This File or Text identifier is already initialized' ) if len ( text ) != 128 : raise pycdlibexception . PyCdlibInvalidInput ( 'Length of text must be 128' ) self . text = text self . _initialized = True
Create a new file or text identifier .
89
8
20,209
def parse ( self , vd , extent_loc ) : # type: (bytes, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Volume Descriptor Set Terminator already initialized' ) ( descriptor_type , identifier , version , zero_unused ) = struct . unpack_from ( self . FMT , vd , 0 ) # According to Ecma-119, 8.3.1, the volume descriptor set terminator # type should be 255 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_SET_TERMINATOR : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST descriptor type' ) # According to Ecma-119, 8.3.2, the identifier should be 'CD001' if identifier != b'CD001' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST identifier' ) # According to Ecma-119, 8.3.3, the version should be 1 if version != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid VDST version' ) # According to Ecma-119, 8.3.4, the rest of the terminator should be 0; # however, we have seen ISOs in the wild that put stuff into this field. # Just ignore it. self . orig_extent_loc = extent_loc self . _initialized = True
A method to parse a Volume Descriptor Set Terminator out of a string .
318
16
20,210
def parse ( self , vd , extent_loc ) : # type: (bytes, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record already initialized' ) ( descriptor_type , identifier , version , self . boot_system_identifier , self . boot_identifier , self . boot_system_use ) = struct . unpack_from ( self . FMT , vd , 0 ) # According to Ecma-119, 8.2.1, the boot record type should be 0 if descriptor_type != VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record descriptor type' ) # According to Ecma-119, 8.2.2, the identifier should be 'CD001' if identifier != b'CD001' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record identifier' ) # According to Ecma-119, 8.2.3, the version should be 1 if version != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid boot record version' ) self . orig_extent_loc = extent_loc self . _initialized = True
A method to parse a Boot Record out of a string .
279
12
20,211
def new ( self , boot_system_id ) : # type: (bytes) -> None if self . _initialized : raise Exception ( 'Boot Record already initialized' ) self . boot_system_identifier = boot_system_id . ljust ( 32 , b'\x00' ) self . boot_identifier = b'\x00' * 32 self . boot_system_use = b'\x00' * 197 # This will be set later self . _initialized = True
A method to create a new Boot Record .
106
9
20,212
def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record not yet initialized' ) return struct . pack ( self . FMT , VOLUME_DESCRIPTOR_TYPE_BOOT_RECORD , b'CD001' , 1 , self . boot_system_identifier , self . boot_identifier , self . boot_system_use )
A method to generate a string representing this Boot Record .
98
11
20,213
def update_boot_system_use ( self , boot_sys_use ) : # type: (bytes) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Boot Record not yet initialized' ) self . boot_system_use = boot_sys_use . ljust ( 197 , b'\x00' )
A method to update the boot system use field of this Boot Record .
81
14
20,214
def parse ( self , data , extent ) : # type: (bytes, int) -> bool if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Version Volume Descriptor is already initialized' ) if data [ : 3 ] == b'MKI' or data == allzero : # OK, we have a version descriptor. self . _data = data self . orig_extent_loc = extent self . _initialized = True return True return False
Do a parse of a Version Volume Descriptor . This consists of seeing whether the data is either all zero or starts with MKI and if so setting the extent location of the Version Volume Descriptor properly .
105
43
20,215
def new ( self , log_block_size ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Version Volume Descriptor is already initialized' ) self . _data = b'\x00' * log_block_size self . _initialized = True
Create a new Version Volume Descriptor .
75
9
20,216
def parse ( self , vd , datastr , ino ) : # type: (headervd.PrimaryOrSupplementaryVD, bytes, inode.Inode) -> bool if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table is already initialized' ) ( pvd_extent , rec_extent , self . orig_len , self . csum ) = struct . unpack_from ( '=LLLL' , datastr , 0 ) if pvd_extent != vd . extent_location ( ) or rec_extent != ino . extent_location ( ) : return False self . vd = vd self . inode = ino self . _initialized = True return True
A method to parse a boot info table out of a string .
171
13
20,217
def new ( self , vd , ino , orig_len , csum ) : # type: (headervd.PrimaryOrSupplementaryVD, inode.Inode, int, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table is already initialized' ) self . vd = vd self . orig_len = orig_len self . csum = csum self . inode = ino self . _initialized = True
A method to create a new boot info table .
115
10
20,218
def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Eltorito Boot Info Table not yet initialized' ) return struct . pack ( '=LLLL' , self . vd . extent_location ( ) , self . inode . extent_location ( ) , self . orig_len , self . csum ) + b'\x00' * 40
A method to generate a string representing this boot info table .
100
12
20,219
def parse ( self , valstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Validation Entry already initialized' ) ( header_id , self . platform_id , reserved_unused , self . id_string , self . checksum , keybyte1 , keybyte2 ) = struct . unpack_from ( self . FMT , valstr , 0 ) if header_id != 1 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry header ID not 1' ) if self . platform_id not in ( 0 , 1 , 2 ) : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry platform ID not valid' ) if keybyte1 != 0x55 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry first keybyte not 0x55' ) if keybyte2 != 0xaa : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry second keybyte not 0xaa' ) # Now that we've done basic checking, calculate the checksum of the # validation entry and make sure it is right. if self . _checksum ( valstr ) != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Validation entry checksum not correct' ) self . _initialized = True
A method to parse an El Torito Validation Entry out of a string .
327
16
20,220
def new ( self , platform_id ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Validation Entry already initialized' ) self . platform_id = platform_id self . id_string = b'\x00' * 24 # FIXME: let the user set this self . checksum = 0 self . checksum = utils . swab_16bit ( self . _checksum ( self . _record ( ) ) - 1 ) self . _initialized = True
A method to create a new El Torito Validation Entry .
123
13
20,221
def _record ( self ) : # type: () -> bytes return struct . pack ( self . FMT , 1 , self . platform_id , 0 , self . id_string , self . checksum , 0x55 , 0xaa )
An internal method to generate a string representing this El Torito Validation Entry .
52
16
20,222
def parse ( self , valstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry already initialized' ) ( self . boot_indicator , self . boot_media_type , self . load_segment , self . system_type , unused1 , self . sector_count , self . load_rba , self . selection_criteria_type , self . selection_criteria ) = struct . unpack_from ( self . FMT , valstr , 0 ) if self . boot_indicator not in ( 0x88 , 0x00 ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito initial entry boot indicator' ) if self . boot_media_type > 4 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito boot media type' ) # FIXME: check that the system type matches the partition table if unused1 != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito unused field must be 0' ) # According to the specification, the El Torito unused end field (bytes # 0xc - 0x1f, unused2 field) should be all zero. However, we have found # ISOs in the wild where that is not the case, so skip that particular # check here. self . _initialized = True
A method to parse an El Torito Entry out of a string .
313
14
20,223
def new ( self , sector_count , load_seg , media_name , system_type , bootable ) : # type: (int, int, str, int, bool) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry already initialized' ) if media_name == 'noemul' : media_type = self . MEDIA_NO_EMUL elif media_name == 'floppy' : if sector_count == 2400 : media_type = self . MEDIA_12FLOPPY elif sector_count == 2880 : media_type = self . MEDIA_144FLOPPY elif sector_count == 5760 : media_type = self . MEDIA_288FLOPPY else : raise pycdlibexception . PyCdlibInvalidInput ( 'Invalid sector count for floppy media type; must be 2400, 2880, or 5760' ) # With floppy booting, the sector_count always ends up being 1 sector_count = 1 elif media_name == 'hdemul' : media_type = self . MEDIA_HD_EMUL # With HD emul booting, the sector_count always ends up being 1 sector_count = 1 else : raise pycdlibexception . PyCdlibInvalidInput ( "Invalid media name '%s'" % ( media_name ) ) if bootable : self . boot_indicator = 0x88 else : self . boot_indicator = 0 self . boot_media_type = media_type self . load_segment = load_seg self . system_type = system_type self . sector_count = sector_count self . load_rba = 0 # This will get set later self . selection_criteria_type = 0 # FIXME: allow the user to set this self . selection_criteria = b'' . ljust ( 19 , b'\x00' ) self . _initialized = True
A method to create a new El Torito Entry .
434
11
20,224
def set_inode ( self , ino ) : # type: (inode.Inode) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not yet initialized' ) self . inode = ino
A method to set the Inode associated with this El Torito Entry .
62
15
20,225
def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not yet initialized' ) return struct . pack ( self . FMT , self . boot_indicator , self . boot_media_type , self . load_segment , self . system_type , 0 , self . sector_count , self . load_rba , self . selection_criteria_type , self . selection_criteria )
A method to generate a string representing this El Torito Entry .
112
13
20,226
def set_data_length ( self , length ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Entry not initialized' ) self . sector_count = utils . ceiling_div ( length , 512 )
A method to set the length of data for this El Torito Entry .
67
15
20,227
def parse ( self , valstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header already initialized' ) ( self . header_indicator , self . platform_id , self . num_section_entries , self . id_string ) = struct . unpack_from ( self . FMT , valstr , 0 ) self . _initialized = True
Parse an El Torito section header from a string .
100
12
20,228
def new ( self , id_string , platform_id ) : # type: (bytes, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header already initialized' ) # We always assume this is the last section, until we are told otherwise # via set_record_not_last. self . header_indicator = 0x91 self . platform_id = platform_id self . num_section_entries = 0 self . id_string = id_string self . _initialized = True
Create a new El Torito section header .
123
9
20,229
def add_parsed_entry ( self , entry ) : # type: (EltoritoEntry) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) if len ( self . section_entries ) >= self . num_section_entries : raise pycdlibexception . PyCdlibInvalidInput ( 'Eltorito section had more entries than expected by section header; ISO is corrupt' ) self . section_entries . append ( entry )
A method to add a parsed entry to the list of entries of this header . If the number of parsed entries exceeds what was expected from the initial parsing of the header this method will throw an Exception .
123
40
20,230
def add_new_entry ( self , entry ) : # type: (EltoritoEntry) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) self . num_section_entries += 1 self . section_entries . append ( entry )
A method to add a completely new entry to the list of entries of this header .
77
17
20,231
def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Section Header not yet initialized' ) outlist = [ struct . pack ( self . FMT , self . header_indicator , self . platform_id , self . num_section_entries , self . id_string ) ] for entry in self . section_entries : outlist . append ( entry . record ( ) ) return b'' . join ( outlist )
Get a string representing this El Torito section header .
116
11
20,232
def parse ( self , valstr ) : # type: (bytes) -> bool if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog already initialized' ) if self . state == self . EXPECTING_VALIDATION_ENTRY : # The first entry in an El Torito boot catalog is the Validation # Entry. A Validation entry consists of 32 bytes (described in # detail in the parse_eltorito_validation_entry() method). self . validation_entry . parse ( valstr ) self . state = self . EXPECTING_INITIAL_ENTRY elif self . state == self . EXPECTING_INITIAL_ENTRY : # The next entry is the Initial/Default entry. An Initial/Default # entry consists of 32 bytes (described in detail in the # parse_eltorito_initial_entry() method). self . initial_entry . parse ( valstr ) self . state = self . EXPECTING_SECTION_HEADER_OR_DONE else : val = bytes ( bytearray ( [ valstr [ 0 ] ] ) ) if val == b'\x00' : # An empty entry tells us we are done parsing El Torito. Do # some sanity checks. last_section_index = len ( self . sections ) - 1 for index , sec in enumerate ( self . sections ) : if sec . num_section_entries != len ( sec . section_entries ) : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito section header specified %d entries, only saw %d' % ( sec . num_section_entries , len ( sec . section_entries ) ) ) if index != last_section_index : if sec . header_indicator != 0x90 : raise pycdlibexception . PyCdlibInvalidISO ( 'Intermediate El Torito section header not properly specified' ) # In theory, we should also make sure that the very last # section has a header_indicator of 0x91. However, we # have seen ISOs in the wild (FreeBSD 11.0 amd64) in which # this is not the case, so we skip that check. self . _initialized = True elif val in ( b'\x90' , b'\x91' ) : # A Section Header Entry section_header = EltoritoSectionHeader ( ) section_header . parse ( valstr ) self . sections . append ( section_header ) elif val in ( b'\x88' , b'\x00' ) : # A Section Entry. According to El Torito 2.4, a Section Entry # must follow a Section Header, but we have seen ISOs in the # wild that do not follow this (Mageia 4 ISOs, for instance). # To deal with this, we get a little complicated here. If there # is a previous section header, and the length of the entries # attached to it is less than the number of entries it should # have, then we attach this entry to that header. If there is # no previous section header, or if the previous section header # is already 'full', then we make this a standalone entry. secentry = EltoritoEntry ( ) secentry . parse ( valstr ) if self . sections and len ( self . sections [ - 1 ] . section_entries ) < self . sections [ - 1 ] . num_section_entries : self . sections [ - 1 ] . add_parsed_entry ( secentry ) else : self . standalone_entries . append ( secentry ) elif val == b'\x44' : # A Section Entry Extension self . sections [ - 1 ] . section_entries [ - 1 ] . selection_criteria += valstr [ 2 : ] else : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid El Torito Boot Catalog entry' ) return self . _initialized
A method to parse an El Torito Boot Catalog out of a string .
862
15
20,233
def new ( self , br , ino , sector_count , load_seg , media_name , system_type , platform_id , bootable ) : # type: (headervd.BootRecord, inode.Inode, int, int, str, int, int, bool) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog already initialized' ) # Create the El Torito validation entry self . validation_entry . new ( platform_id ) self . initial_entry . new ( sector_count , load_seg , media_name , system_type , bootable ) self . initial_entry . set_inode ( ino ) ino . linked_records . append ( self . initial_entry ) self . br = br self . _initialized = True
A method to create a new El Torito Boot Catalog .
185
12
20,234
def add_section ( self , ino , sector_count , load_seg , media_name , system_type , efi , bootable ) : # type: (inode.Inode, int, int, str, int, bool, bool) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) # The Eltorito Boot Catalog can only be 2048 bytes (1 extent). By # default, the first 64 bytes are used by the Validation Entry and the # Initial Entry, which leaves 1984 bytes. Each section takes up 32 # bytes for the Section Header and 32 bytes for the Section Entry, for # a total of 64 bytes, so we can have a maximum of 1984/64 = 31 # sections. if len ( self . sections ) == 31 : raise pycdlibexception . PyCdlibInvalidInput ( 'Too many Eltorito sections' ) sec = EltoritoSectionHeader ( ) platform_id = self . validation_entry . platform_id if efi : platform_id = 0xef sec . new ( b'\x00' * 28 , platform_id ) secentry = EltoritoEntry ( ) secentry . new ( sector_count , load_seg , media_name , system_type , bootable ) secentry . set_inode ( ino ) ino . linked_records . append ( secentry ) sec . add_new_entry ( secentry ) if self . sections : self . sections [ - 1 ] . set_record_not_last ( ) self . sections . append ( sec )
A method to add an section header and entry to this Boot Catalog .
360
14
20,235
def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) outlist = [ self . validation_entry . record ( ) , self . initial_entry . record ( ) ] for sec in self . sections : outlist . append ( sec . record ( ) ) for entry in self . standalone_entries : outlist . append ( entry . record ( ) ) return b'' . join ( outlist )
A method to generate a string representing this El Torito Boot Catalog .
116
14
20,236
def add_dirrecord ( self , rec ) : # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry]) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) self . dirrecords . append ( rec )
A method to set the Directory Record associated with this Boot Catalog .
75
13
20,237
def update_catalog_extent ( self , current_extent ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'El Torito Boot Catalog not yet initialized' ) self . br . update_boot_system_use ( struct . pack ( '=L' , current_extent ) )
A method to update the extent associated with this Boot Catalog .
84
12
20,238
def _check_d1_characters ( name ) : # type: (bytes) -> None bytename = bytearray ( name ) for char in bytename : if char not in _allowed_d1_characters : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must consist of characters A-Z, 0-9, and _' )
A function to check that a name only uses d1 characters as defined by ISO9660 .
89
19
20,239
def _split_iso9660_filename ( fullname ) : # type: (bytes) -> Tuple[bytes, bytes, bytes] namesplit = fullname . split ( b';' ) version = b'' if len ( namesplit ) > 1 : version = namesplit . pop ( ) rest = b';' . join ( namesplit ) dotsplit = rest . split ( b'.' ) if len ( dotsplit ) == 1 : name = dotsplit [ 0 ] extension = b'' else : name = b'.' . join ( dotsplit [ : - 1 ] ) extension = dotsplit [ - 1 ] return ( name , extension , version )
A function to split an ISO 9660 filename into its constituent parts . This is the name the extension and the version number .
148
25
20,240
def _check_iso9660_filename ( fullname , interchange_level ) : # type: (bytes, int) -> None # Check to ensure the name is a valid filename for the ISO according to # Ecma-119 7.5. ( name , extension , version ) = _split_iso9660_filename ( fullname ) # Ecma-119 says that filenames must end with a semicolon-number, but I have # found CDs (Ubuntu 14.04 Desktop i386, for instance) that do not follow # this. Thus we allow for names both with and without the semi+version. # Ecma-119 says that filenames must have a version number, but I have # found CDs (FreeBSD 10.1 amd64) that do not have any version number. # Allow for this. if version != b'' and ( int ( version ) < 1 or int ( version ) > 32767 ) : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must have a version between 1 and 32767' ) # Ecma-119 section 7.5.1 specifies that filenames must have at least one # character in either the name or the extension. if not name and not extension : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must have a non-empty name or extension' ) if b';' in name or b';' in extension : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames must contain exactly one semicolon' ) if interchange_level == 1 : # According to Ecma-119, section 10.1, at level 1 the filename can # only be up to 8 d-characters or d1-characters, and the extension can # only be up to 3 d-characters or 3 d1-characters. if len ( name ) > 8 or len ( extension ) > 3 : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 filenames at interchange level 1 cannot have more than 8 characters or 3 characters in the extension' ) else : # For all other interchange levels, the maximum filename length is # specified in Ecma-119 7.5.2. However, I have found CDs (Ubuntu 14.04 # Desktop i386, for instance) that don't conform to this. Skip the # check until we know how long is allowed. pass # Ecma-119 section 7.5.1 says that the file name and extension each contain # zero or more d-characters or d1-characters. While the definition of # d-characters and d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4 : _check_d1_characters ( name ) _check_d1_characters ( extension )
A function to check that a file identifier conforms to the ISO9660 rules for a particular interchange level .
663
22
20,241
def _check_iso9660_directory ( fullname , interchange_level ) : # type: (bytes, int) -> None # Check to ensure the directory name is valid for the ISO according to # Ecma-119 7.6. # Ecma-119 section 7.6.1 says that a directory identifier needs at least one # character if not fullname : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 directory names must be at least 1 character long' ) maxlen = float ( 'inf' ) if interchange_level == 1 : # Ecma-119 section 10.1 says that directory identifiers lengths cannot # exceed 8 at interchange level 1. maxlen = 8 elif interchange_level in ( 2 , 3 ) : # Ecma-119 section 7.6.3 says that directory identifiers lengths cannot # exceed 207. maxlen = 207 # for interchange_level 4, we allow any length if len ( fullname ) > maxlen : raise pycdlibexception . PyCdlibInvalidInput ( 'ISO9660 directory names at interchange level %d cannot exceed %d characters' % ( interchange_level , maxlen ) ) # Ecma-119 section 7.6.1 says that directory names consist of one or more # d-characters or d1-characters. While the definition of d-characters and # d1-characters is not specified in Ecma-119, # http://wiki.osdev.org/ISO_9660 suggests that this consists of A-Z, 0-9, _ # which seems to correlate with empirical evidence. Thus we check for that # here. if interchange_level < 4 : _check_d1_characters ( fullname )
A function to check that an directory identifier conforms to the ISO9660 rules for a particular interchange level .
369
22
20,242
def _interchange_level_from_filename ( fullname ) : # type: (bytes) -> int ( name , extension , version ) = _split_iso9660_filename ( fullname ) interchange_level = 1 if version != b'' and ( int ( version ) < 1 or int ( version ) > 32767 ) : interchange_level = 3 if b';' in name or b';' in extension : interchange_level = 3 if len ( name ) > 8 or len ( extension ) > 3 : interchange_level = 3 try : _check_d1_characters ( name ) _check_d1_characters ( extension ) except pycdlibexception . PyCdlibInvalidInput : interchange_level = 3 return interchange_level
A function to determine the ISO interchange level from the filename . In theory there are 3 levels but in practice we only deal with level 1 and level 3 .
161
31
20,243
def _interchange_level_from_directory ( name ) : # type: (bytes) -> int interchange_level = 1 if len ( name ) > 8 : interchange_level = 3 try : _check_d1_characters ( name ) except pycdlibexception . PyCdlibInvalidInput : interchange_level = 3 return interchange_level
A function to determine the ISO interchange level from the directory name . In theory there are 3 levels but in practice we only deal with level 1 and level 3 .
76
32
20,244
def _yield_children ( rec ) : # type: (dr.DirectoryRecord) -> Generator if not rec . is_dir ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Record is not a directory!' ) last = b'' for child in rec . children : # Check to see if the filename of this child is the same as the # last one, and if so, skip the child. This can happen if we # have very large files with more than one directory entry. fi = child . file_identifier ( ) if fi == last : continue last = fi if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) and child . rock_ridge . cl_to_moved_dr is not None and child . rock_ridge . cl_to_moved_dr . parent is not None : # If this is the case, this is a relocated entry. We actually # want to go find the entry this was relocated to; we do that # by following the child_link, then going up to the parent and # finding the entry that links to the same one as this one. cl_parent = child . rock_ridge . cl_to_moved_dr . parent for cl_child in cl_parent . children : if cl_child . rock_ridge is not None and cl_child . rock_ridge . name ( ) == child . rock_ridge . name ( ) : child = cl_child break # If we ended up not finding the right one in the parent of the # moved entry, weird, but just return the one we would have # anyway. yield child
An internal function to gather and yield all of the children of a Directory Record .
356
16
20,245
def _assign_udf_desc_extents ( descs , start_extent ) : # type: (PyCdlib._UDFDescriptors, int) -> None current_extent = start_extent descs . pvd . set_extent_location ( current_extent ) current_extent += 1 descs . impl_use . set_extent_location ( current_extent ) current_extent += 1 descs . partition . set_extent_location ( current_extent ) current_extent += 1 descs . logical_volume . set_extent_location ( current_extent ) current_extent += 1 descs . unallocated_space . set_extent_location ( current_extent ) current_extent += 1 descs . terminator . set_extent_location ( current_extent ) current_extent += 1
An internal function to assign a consecutive sequence of extents for the given set of UDF Descriptors starting at the given extent .
198
27
20,246
def _find_dr_record_by_name ( vd , path , encoding ) : # type: (headervd.PrimaryOrSupplementaryVD, bytes, str) -> dr.DirectoryRecord if not utils . starts_with_slash ( path ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Must be a path starting with /' ) root_dir_record = vd . root_directory_record ( ) # If the path is just the slash, we just want the root directory, so # get the child there and quit. if path == b'/' : return root_dir_record # Split the path along the slashes splitpath = utils . split_path ( path ) currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( encoding ) entry = root_dir_record tmpdr = dr . DirectoryRecord ( ) while True : child = None thelist = entry . children lo = 2 hi = len ( thelist ) while lo < hi : mid = ( lo + hi ) // 2 tmpdr . file_ident = currpath if thelist [ mid ] < tmpdr : lo = mid + 1 else : hi = mid index = lo if index != len ( thelist ) and thelist [ index ] . file_ident == currpath : child = thelist [ index ] if child is None : # We failed to find this component of the path, so break out of the # loop and fail break if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) : # Here, the rock ridge extension has a child link, so we # need to follow it. child = child . rock_ridge . cl_to_moved_dr if child is None : break # We found the child, and it is the last one we are looking for; # return it. if not splitpath : return child if not child . is_dir ( ) : break entry = child currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( encoding ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' )
An internal function to find an directory record on the ISO given an ISO or Joliet path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput exception is raised .
479
59
20,247
def read ( self , size = None ) : # type: (Optional[int]) -> bytes if not self . _open : raise pycdlibexception . PyCdlibInvalidInput ( 'I/O operation on closed file.' ) if self . _offset >= self . _length : return b'' if size is None or size < 0 : data = self . readall ( ) else : readsize = min ( self . _length - self . _offset , size ) data = self . _fp . read ( readsize ) self . _offset += readsize return data
A method to read and return up to size bytes .
122
11
20,248
def readall ( self ) : # type: () -> bytes if not self . _open : raise pycdlibexception . PyCdlibInvalidInput ( 'I/O operation on closed file.' ) readsize = self . _length - self . _offset if readsize > 0 : data = self . _fp . read ( readsize ) self . _offset += readsize else : data = b'' return data
A method to read and return the remaining bytes in the file .
89
13
20,249
def _seek_to_extent ( self , extent ) : # type: (int) -> None self . _cdfp . seek ( extent * self . pvd . logical_block_size ( ) )
An internal method to seek to a particular extent on the input ISO .
46
14
20,250
def _find_rr_record ( self , rr_path ) : # type: (bytes) -> dr.DirectoryRecord if not utils . starts_with_slash ( rr_path ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Must be a path starting with /' ) root_dir_record = self . pvd . root_directory_record ( ) # If the path is just the slash, we just want the root directory, so # get the child there and quit. if rr_path == b'/' : return root_dir_record # Split the path along the slashes splitpath = utils . split_path ( rr_path ) currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( 'utf-8' ) entry = root_dir_record while True : child = None thelist = entry . rr_children lo = 0 hi = len ( thelist ) while lo < hi : mid = ( lo + hi ) // 2 tmpchild = thelist [ mid ] if tmpchild . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Record without Rock Ridge entry on Rock Ridge ISO' ) if tmpchild . rock_ridge . name ( ) < currpath : lo = mid + 1 else : hi = mid index = lo tmpchild = thelist [ index ] if index != len ( thelist ) and tmpchild . rock_ridge is not None and tmpchild . rock_ridge . name ( ) == currpath : child = thelist [ index ] if child is None : # We failed to find this component of the path, so break out of the # loop and fail break if child . rock_ridge is not None and child . rock_ridge . child_link_record_exists ( ) : # Here, the rock ridge extension has a child link, so we # need to follow it. child = child . rock_ridge . cl_to_moved_dr if child is None : break # We found the child, and it is the last one we are looking for; # return it. if not splitpath : return child if not child . is_dir ( ) : break entry = child currpath = splitpath . pop ( 0 ) . decode ( 'utf-8' ) . encode ( 'utf-8' ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' )
An internal method to find an directory record on the ISO given a Rock Ridge path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised .
535
56
20,251
def _find_joliet_record ( self , joliet_path ) : # type: (bytes) -> dr.DirectoryRecord if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Joliet path requested on non-Joliet ISO' ) return _find_dr_record_by_name ( self . joliet_vd , joliet_path , 'utf-16_be' )
An internal method to find an directory record on the ISO given a Joliet path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised .
104
56
20,252
def _find_udf_record ( self , udf_path ) : # type: (bytes) -> Tuple[Optional[udfmod.UDFFileIdentifierDescriptor], udfmod.UDFFileEntry] # If the path is just the slash, we just want the root directory, so # get the child there and quit. if udf_path == b'/' : return None , self . udf_root # type: ignore # Split the path along the slashes splitpath = utils . split_path ( udf_path ) currpath = splitpath . pop ( 0 ) entry = self . udf_root while entry is not None : child = entry . find_file_ident_desc_by_name ( currpath ) # We found the child, and it is the last one we are looking for; # return it. if not splitpath : return child , child . file_entry # type: ignore if not child . is_dir ( ) : break entry = child . file_entry currpath = splitpath . pop ( 0 ) raise pycdlibexception . PyCdlibInvalidInput ( 'Could not find path' )
An internal method to find an directory record on the ISO given a UDF path . If the entry is found it returns the directory record object corresponding to that entry . If the entry could not be found a pycdlibexception . PyCdlibInvalidInput is raised .
255
56
20,253
def _iso_name_and_parent_from_path ( self , iso_path ) : # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] splitpath = utils . split_path ( iso_path ) name = splitpath . pop ( ) parent = self . _find_iso_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-8' ) , parent )
An internal method to find the parent directory record and name given an ISO path . If the parent is found return a tuple containing the basename of the path and the parent directory record object .
109
38
20,254
def _joliet_name_and_parent_from_path ( self , joliet_path ) : # type: (bytes) -> Tuple[bytes, dr.DirectoryRecord] splitpath = utils . split_path ( joliet_path ) name = splitpath . pop ( ) if len ( name ) > 64 : raise pycdlibexception . PyCdlibInvalidInput ( 'Joliet names can be a maximum of 64 characters' ) parent = self . _find_joliet_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-16_be' ) , parent )
An internal method to find the parent directory record and name given a Joliet path . If the parent is found return a tuple containing the basename of the path and the parent directory record object .
155
39
20,255
def _udf_name_and_parent_from_path ( self , udf_path ) : # type: (bytes) -> Tuple[bytes, udfmod.UDFFileEntry] splitpath = utils . split_path ( udf_path ) name = splitpath . pop ( ) ( parent_ident_unused , parent ) = self . _find_udf_record ( b'/' + b'/' . join ( splitpath ) ) return ( name . decode ( 'utf-8' ) . encode ( 'utf-8' ) , parent )
An internal method to find the parent directory record and name given a UDF path . If the parent is found return a tuple containing the basename of the path and the parent UDF File Entry object .
126
41
20,256
def _set_rock_ridge ( self , rr ) : # type: (str) -> None # We don't allow mixed Rock Ridge versions on the ISO, so apply some # checking. If the current overall Rock Ridge version on the ISO is # None, we upgrade it to whatever version we were given. Once we have # seen a particular version, we only allow records of that version or # None (to account for dotdot records which have no Rock Ridge). if not self . rock_ridge : self . rock_ridge = rr # type: str else : for ver in [ '1.09' , '1.10' , '1.12' ] : if self . rock_ridge == ver : if rr and rr != ver : raise pycdlibexception . PyCdlibInvalidISO ( 'Inconsistent Rock Ridge versions on the ISO!' )
An internal method to set the Rock Ridge version of the ISO given the Rock Ridge version of the previous entry .
186
22
20,257
def _parse_path_table ( self , ptr_size , extent ) : # type: (int, int) -> Tuple[List[path_table_record.PathTableRecord], Dict[int, path_table_record.PathTableRecord]] self . _seek_to_extent ( extent ) data = self . _cdfp . read ( ptr_size ) offset = 0 out = [ ] extent_to_ptr = { } while offset < ptr_size : ptr = path_table_record . PathTableRecord ( ) len_di_byte = bytearray ( [ data [ offset ] ] ) [ 0 ] read_len = path_table_record . PathTableRecord . record_length ( len_di_byte ) ptr . parse ( data [ offset : offset + read_len ] ) out . append ( ptr ) extent_to_ptr [ ptr . extent_location ] = ptr offset += read_len return out , extent_to_ptr
An internal method to parse a path table on an ISO . For each path table entry found a Path Table Record object is created and the callback is called .
211
31
20,258
def _check_and_parse_eltorito ( self , br ) : # type: (headervd.BootRecord) -> None if br . boot_system_identifier != b'EL TORITO SPECIFICATION' . ljust ( 32 , b'\x00' ) : return if self . eltorito_boot_catalog is not None : raise pycdlibexception . PyCdlibInvalidISO ( 'Only one El Torito boot record is allowed' ) # According to the El Torito specification, section 2.0, the El # Torito boot record must be at extent 17. if br . extent_location ( ) != 17 : raise pycdlibexception . PyCdlibInvalidISO ( 'El Torito Boot Record must be at extent 17' ) # Now that we have verified that the BootRecord is an El Torito one # and that it is sane, we go on to parse the El Torito Boot Catalog. # Note that the Boot Catalog is stored as a file in the ISO, though # we ignore that for the purposes of parsing. self . eltorito_boot_catalog = eltorito . EltoritoBootCatalog ( br ) eltorito_boot_catalog_extent , = struct . unpack_from ( '=L' , br . boot_system_use [ : 4 ] , 0 ) old = self . _cdfp . tell ( ) self . _cdfp . seek ( eltorito_boot_catalog_extent * self . pvd . logical_block_size ( ) ) data = self . _cdfp . read ( 32 ) while not self . eltorito_boot_catalog . parse ( data ) : data = self . _cdfp . read ( 32 ) self . _cdfp . seek ( old )
An internal method to examine a Boot Record and see if it is an El Torito Boot Record . If it is parse the El Torito Boot Catalog verification entry initial entry and any additional section entries .
396
40
20,259
def _remove_child_from_dr ( self , child , index , logical_block_size ) : # type: (dr.DirectoryRecord, int, int) -> int if child . parent is None : raise pycdlibexception . PyCdlibInternalError ( 'Trying to remove child from non-existent parent' ) self . _find_iso_record . cache_clear ( ) # pylint: disable=no-member self . _find_rr_record . cache_clear ( ) # pylint: disable=no-member self . _find_joliet_record . cache_clear ( ) # pylint: disable=no-member # The remove_child() method returns True if the parent no longer needs # the extent that the directory record for this child was on. Remove # the extent as appropriate here. if child . parent . remove_child ( child , index , logical_block_size ) : return self . pvd . logical_block_size ( ) return 0
An internal method to remove a child from a directory record shrinking the space in the Volume Descriptor if necessary .
217
23
20,260
def _add_to_ptr_size ( self , ptr ) : # type: (path_table_record.PathTableRecord) -> int num_bytes_to_add = 0 for pvd in self . pvds : # The add_to_ptr_size() method returns True if the PVD needs # additional space in the PTR to store this directory. We always # add 4 additional extents for that (2 for LE, 2 for BE). if pvd . add_to_ptr_size ( path_table_record . PathTableRecord . record_length ( ptr . len_di ) ) : num_bytes_to_add += 4 * self . pvd . logical_block_size ( ) return num_bytes_to_add
An internal method to add a PTR to a VD adding space to the VD if necessary .
163
21
20,261
def _remove_from_ptr_size ( self , ptr ) : # type: (path_table_record.PathTableRecord) -> int num_bytes_to_remove = 0 for pvd in self . pvds : # The remove_from_ptr_size() returns True if the PVD no longer # needs the extra extents in the PTR that stored this directory. # We always remove 4 additional extents for that. if pvd . remove_from_ptr_size ( path_table_record . PathTableRecord . record_length ( ptr . len_di ) ) : num_bytes_to_remove += 4 * self . pvd . logical_block_size ( ) return num_bytes_to_remove
An internal method to remove a PTR from a VD removing space from the VD if necessary .
158
21
20,262
def _calculate_eltorito_boot_info_table_csum ( self , data_fp , data_len ) : # type: (BinaryIO, int) -> int # Here we want to read the boot file so we can calculate the checksum # over it. num_sectors = utils . ceiling_div ( data_len , self . pvd . logical_block_size ( ) ) csum = 0 curr_sector = 0 while curr_sector < num_sectors : block = data_fp . read ( self . pvd . logical_block_size ( ) ) block = block . ljust ( 2048 , b'\x00' ) i = 0 if curr_sector == 0 : # The first 64 bytes are not included in the checksum, so skip # them here. i = 64 while i < len ( block ) : tmp , = struct . unpack_from ( '=L' , block [ : i + 4 ] , i ) csum += tmp csum = csum & 0xffffffff i += 4 curr_sector += 1 return csum
An internal method to calculate the checksum for an El Torito Boot Info Table . This checksum is a simple 32 - bit checksum over all of the data in the boot file starting right after the Boot Info Table itself .
241
46
20,263
def _check_for_eltorito_boot_info_table ( self , ino ) : # type: (inode.Inode) -> None orig = self . _cdfp . tell ( ) with inode . InodeOpenData ( ino , self . pvd . logical_block_size ( ) ) as ( data_fp , data_len ) : data_fp . seek ( 8 , os . SEEK_CUR ) bi_table = eltorito . EltoritoBootInfoTable ( ) if bi_table . parse ( self . pvd , data_fp . read ( eltorito . EltoritoBootInfoTable . header_length ( ) ) , ino ) : data_fp . seek ( - 24 , os . SEEK_CUR ) # OK, the rest of the stuff checks out; do a final # check to make sure the checksum is reasonable. csum = self . _calculate_eltorito_boot_info_table_csum ( data_fp , data_len ) if csum == bi_table . csum : ino . add_boot_info_table ( bi_table ) self . _cdfp . seek ( orig )
An internal method to check a boot directory record to see if it has an El Torito Boot Info Table embedded inside of it .
266
26
20,264
def _check_rr_name ( self , rr_name ) : # type: (Optional[str]) -> bytes if self . rock_ridge : if not rr_name : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name must be passed for a rock-ridge ISO' ) if rr_name . count ( '/' ) != 0 : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name must be relative' ) return rr_name . encode ( 'utf-8' ) if rr_name : raise pycdlibexception . PyCdlibInvalidInput ( 'A rock ridge name can only be specified for a rock-ridge ISO' ) return b''
An internal method to check whether this ISO requires or does not require a Rock Ridge path .
162
18
20,265
def _normalize_joliet_path ( self , joliet_path ) : # type: (str) -> bytes tmp_path = b'' if self . joliet_vd is not None : if not joliet_path : raise pycdlibexception . PyCdlibInvalidInput ( 'A Joliet path must be passed for a Joliet ISO' ) tmp_path = utils . normpath ( joliet_path ) else : if joliet_path : raise pycdlibexception . PyCdlibInvalidInput ( 'A Joliet path can only be specified for a Joliet ISO' ) return tmp_path
An internal method to check whether this ISO does or does not require a Joliet path . If a Joliet path is required the path is normalized and returned .
142
32
20,266
def _link_eltorito ( self , extent_to_inode ) : # type: (Dict[int, inode.Inode]) -> None if self . eltorito_boot_catalog is None : raise pycdlibexception . PyCdlibInternalError ( 'Trying to link El Torito entries on a non-El Torito ISO' ) log_block_size = self . pvd . logical_block_size ( ) entries_to_assign = [ self . eltorito_boot_catalog . initial_entry ] for sec in self . eltorito_boot_catalog . sections : for entry in sec . section_entries : entries_to_assign . append ( entry ) for entry in entries_to_assign : entry_extent = entry . get_rba ( ) if entry_extent in extent_to_inode : ino = extent_to_inode [ entry_extent ] else : ino = inode . Inode ( ) ino . parse ( entry_extent , entry . length ( ) , self . _cdfp , log_block_size ) extent_to_inode [ entry_extent ] = ino self . inodes . append ( ino ) ino . linked_records . append ( entry ) entry . set_inode ( ino )
An internal method to link the El Torito entries into their corresponding Directory Records creating new ones if they are hidden . Should only be called on an El Torito ISO .
299
34
20,267
def _parse_udf_vol_descs ( self , extent , length , descs ) : # type: (int, int, PyCdlib._UDFDescriptors) -> None # Read in the Volume Descriptor Sequence self . _seek_to_extent ( extent ) vd_data = self . _cdfp . read ( length ) # And parse it. Since the sequence doesn't have to be in any set order, # and since some of the entries may be missing, we parse the Descriptor # Tag (the first 16 bytes) to find out what kind of descriptor it is, # then construct the correct type based on that. We keep going until we # see a Terminating Descriptor. block_size = self . pvd . logical_block_size ( ) offset = 0 current_extent = extent done = False while not done : desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( vd_data [ offset : ] , current_extent ) if desc_tag . tag_ident == 1 : descs . pvd . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 4 : descs . impl_use . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 5 : descs . partition . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 6 : descs . logical_volume . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 7 : descs . unallocated_space . parse ( vd_data [ offset : offset + 512 ] , current_extent , desc_tag ) elif desc_tag . tag_ident == 8 : descs . terminator . parse ( current_extent , desc_tag ) done = True else : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF Tag identifier not %d' % ( desc_tag . tag_ident ) ) offset += block_size current_extent += 1
An internal method to parse a set of UDF Volume Descriptors .
509
15
20,268
def _parse_udf_file_entry ( self , abs_file_entry_extent , icb , parent ) : # type: (int, udfmod.UDFLongAD, Optional[udfmod.UDFFileEntry]) -> Optional[udfmod.UDFFileEntry] self . _seek_to_extent ( abs_file_entry_extent ) icbdata = self . _cdfp . read ( icb . extent_length ) if all ( v == 0 for v in bytearray ( icbdata ) ) : # We have seen ISOs in the wild (Windows 2008 Datacenter Enterprise # Standard SP2 x86 DVD) where the UDF File Identifier points to a # UDF File Entry of all zeros. In those cases, we just keep the # File Identifier, and keep the UDF File Entry blank. return None desc_tag = udfmod . UDFTag ( ) desc_tag . parse ( icbdata , icb . log_block_num ) if desc_tag . tag_ident != 261 : raise pycdlibexception . PyCdlibInvalidISO ( 'UDF File Entry Tag identifier not 261' ) file_entry = udfmod . UDFFileEntry ( ) file_entry . parse ( icbdata , abs_file_entry_extent , parent , desc_tag ) return file_entry
An internal method to parse a single UDF File Entry and return the corresponding object .
304
17
20,269
def _udf_get_file_from_iso_fp ( self , outfp , blocksize , udf_path ) : # type: (BinaryIO, int, bytes) -> None if self . udf_root is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot fetch a udf_path from a non-UDF ISO' ) ( ident_unused , found_file_entry ) = self . _find_udf_record ( udf_path ) if found_file_entry is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot get the contents of an empty UDF File Entry' ) if not found_file_entry . is_file ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Can only write out a file' ) if found_file_entry . inode is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot write out an entry without data' ) if found_file_entry . get_data_length ( ) > 0 : with inode . InodeOpenData ( found_file_entry . inode , self . pvd . logical_block_size ( ) ) as ( data_fp , data_len ) : utils . copy_data ( data_len , blocksize , data_fp , outfp )
An internal method to fetch a single UDF file from the ISO and write it out to the file object .
305
22
20,270
def _outfp_write_with_check ( self , outfp , data , enable_overwrite_check = True ) : # type: (BinaryIO, bytes, bool) -> None start = outfp . tell ( ) outfp . write ( data ) if self . _track_writes : # After the write, double check that we didn't write beyond the # boundary of the PVD, and raise a PyCdlibException if we do. end = outfp . tell ( ) if end > self . pvd . space_size * self . pvd . logical_block_size ( ) : raise pycdlibexception . PyCdlibInternalError ( 'Wrote past the end of the ISO! (%d > %d)' % ( end , self . pvd . space_size * self . pvd . logical_block_size ( ) ) ) if enable_overwrite_check : bisect . insort_left ( self . _write_check_list , self . _WriteRange ( start , end - 1 ) )
Internal method to write data out to the output file descriptor ensuring that it doesn t go beyond the bounds of the ISO .
227
24
20,271
def _output_file_data ( self , outfp , blocksize , ino ) : # type: (BinaryIO, int, inode.Inode) -> int log_block_size = self . pvd . logical_block_size ( ) outfp . seek ( ino . extent_location ( ) * log_block_size ) tmp_start = outfp . tell ( ) with inode . InodeOpenData ( ino , log_block_size ) as ( data_fp , data_len ) : utils . copy_data ( data_len , blocksize , data_fp , outfp ) utils . zero_pad ( outfp , data_len , log_block_size ) if self . _track_writes : end = outfp . tell ( ) bisect . insort_left ( self . _write_check_list , self . _WriteRange ( tmp_start , end - 1 ) ) # If this file is being used as a bootfile, and the user # requested that the boot info table be patched into it, # we patch the boot info table at offset 8 here. if ino . boot_info_table is not None : old = outfp . tell ( ) outfp . seek ( tmp_start + 8 ) self . _outfp_write_with_check ( outfp , ino . boot_info_table . record ( ) , enable_overwrite_check = False ) outfp . seek ( old ) return outfp . tell ( ) - tmp_start
Internal method to write a directory record entry out .
331
10
20,272
def _write_directory_records ( self , vd , outfp , progress ) : # type: (headervd.PrimaryOrSupplementaryVD, BinaryIO, PyCdlib._Progress) -> None log_block_size = vd . logical_block_size ( ) le_ptr_offset = 0 be_ptr_offset = 0 dirs = collections . deque ( [ vd . root_directory_record ( ) ] ) while dirs : curr = dirs . popleft ( ) curr_dirrecord_offset = 0 if curr . is_dir ( ) : if curr . ptr is None : raise pycdlibexception . PyCdlibInternalError ( 'Directory has no Path Table Record' ) # Little Endian PTR outfp . seek ( vd . path_table_location_le * log_block_size + le_ptr_offset ) ret = curr . ptr . record_little_endian ( ) self . _outfp_write_with_check ( outfp , ret ) le_ptr_offset += len ( ret ) # Big Endian PTR outfp . seek ( vd . path_table_location_be * log_block_size + be_ptr_offset ) ret = curr . ptr . record_big_endian ( ) self . _outfp_write_with_check ( outfp , ret ) be_ptr_offset += len ( ret ) progress . call ( curr . get_data_length ( ) ) dir_extent = curr . extent_location ( ) for child in curr . children : # No matter what type the child is, we need to first write # out the directory record entry. recstr = child . record ( ) if ( curr_dirrecord_offset + len ( recstr ) ) > log_block_size : dir_extent += 1 curr_dirrecord_offset = 0 outfp . seek ( dir_extent * log_block_size + curr_dirrecord_offset ) # Now write out the child self . _outfp_write_with_check ( outfp , recstr ) curr_dirrecord_offset += len ( recstr ) if child . rock_ridge is not None : if child . rock_ridge . dr_entries . ce_record is not None : # The child has a continue block, so write it out here. ce_rec = child . rock_ridge . dr_entries . ce_record outfp . seek ( ce_rec . bl_cont_area * self . pvd . logical_block_size ( ) + ce_rec . offset_cont_area ) rec = child . rock_ridge . record_ce_entries ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) if child . rock_ridge . child_link_record_exists ( ) : continue if child . is_dir ( ) : # If the child is a directory, and is not dot or dotdot, # we want to descend into it to look at the children. if not child . is_dot ( ) and not child . is_dotdot ( ) : dirs . append ( child )
An internal method to write out the directory records from a particular Volume Descriptor .
703
17
20,273
def _write_udf_descs ( self , descs , outfp , progress ) : # type: (PyCdlib._UDFDescriptors, BinaryIO, PyCdlib._Progress) -> None log_block_size = self . pvd . logical_block_size ( ) outfp . seek ( descs . pvd . extent_location ( ) * log_block_size ) rec = descs . pvd . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . impl_use . extent_location ( ) * log_block_size ) rec = descs . impl_use . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . partition . extent_location ( ) * log_block_size ) rec = descs . partition . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . logical_volume . extent_location ( ) * log_block_size ) rec = descs . logical_volume . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . unallocated_space . extent_location ( ) * log_block_size ) rec = descs . unallocated_space . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) ) outfp . seek ( descs . terminator . extent_location ( ) * log_block_size ) rec = descs . terminator . record ( ) self . _outfp_write_with_check ( outfp , rec ) progress . call ( len ( rec ) )
An internal method to write out a UDF Descriptor sequence .
434
14
20,274
def _update_rr_ce_entry ( self , rec ) : # type: (dr.DirectoryRecord) -> int if rec . rock_ridge is not None and rec . rock_ridge . dr_entries . ce_record is not None : celen = rec . rock_ridge . dr_entries . ce_record . len_cont_area added_block , block , offset = self . pvd . add_rr_ce_entry ( celen ) rec . rock_ridge . update_ce_block ( block ) rec . rock_ridge . dr_entries . ce_record . update_offset ( offset ) if added_block : return self . pvd . logical_block_size ( ) return 0
An internal method to update the Rock Ridge CE entry for the given record .
156
15
20,275
def _finish_add ( self , num_bytes_to_add , num_partition_bytes_to_add ) : # type: (int, int) -> None for pvd in self . pvds : pvd . add_to_space_size ( num_bytes_to_add + num_partition_bytes_to_add ) if self . joliet_vd is not None : self . joliet_vd . add_to_space_size ( num_bytes_to_add + num_partition_bytes_to_add ) if self . enhanced_vd is not None : self . enhanced_vd . copy_sizes ( self . pvd ) if self . udf_root is not None : num_extents_to_add = utils . ceiling_div ( num_partition_bytes_to_add , self . pvd . logical_block_size ( ) ) self . udf_main_descs . partition . part_length += num_extents_to_add self . udf_reserve_descs . partition . part_length += num_extents_to_add self . udf_logical_volume_integrity . size_table += num_extents_to_add if self . _always_consistent : self . _reshuffle_extents ( ) else : self . _needs_reshuffle = True
An internal method to do all of the accounting needed whenever something is added to the ISO . This method should only be called by public API implementations .
307
29
20,276
def _finish_remove ( self , num_bytes_to_remove , is_partition ) : # type: (int, bool) -> None for pvd in self . pvds : pvd . remove_from_space_size ( num_bytes_to_remove ) if self . joliet_vd is not None : self . joliet_vd . remove_from_space_size ( num_bytes_to_remove ) if self . enhanced_vd is not None : self . enhanced_vd . copy_sizes ( self . pvd ) if self . udf_root is not None and is_partition : num_extents_to_remove = utils . ceiling_div ( num_bytes_to_remove , self . pvd . logical_block_size ( ) ) self . udf_main_descs . partition . part_length -= num_extents_to_remove self . udf_reserve_descs . partition . part_length -= num_extents_to_remove self . udf_logical_volume_integrity . size_table -= num_extents_to_remove if self . _always_consistent : self . _reshuffle_extents ( ) else : self . _needs_reshuffle = True
An internal method to do all of the accounting needed whenever something is removed from the ISO . This method should only be called by public API implementations .
281
29
20,277
def _rm_dr_link ( self , rec ) : # type: (dr.DirectoryRecord) -> int if not rec . is_file ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot remove a directory with rm_hard_link (try rm_directory instead)' ) num_bytes_to_remove = 0 logical_block_size = rec . vd . logical_block_size ( ) done = False while not done : num_bytes_to_remove += self . _remove_child_from_dr ( rec , rec . index_in_parent , logical_block_size ) if rec . inode is not None : found_index = None for index , link in enumerate ( rec . inode . linked_records ) : if id ( link ) == id ( rec ) : found_index = index break else : # This should never happen raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del rec . inode . linked_records [ found_index ] # We only remove the size of the child from the ISO if there are no # other references to this file on the ISO. if not rec . inode . linked_records : found_index = None for index , ino in enumerate ( self . inodes ) : if id ( ino ) == id ( rec . inode ) : found_index = index break else : # This should never happen raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del self . inodes [ found_index ] num_bytes_to_remove += rec . get_data_length ( ) if rec . data_continuation is not None : rec = rec . data_continuation else : done = True return num_bytes_to_remove
An internal method to remove a Directory Record link given the record .
404
13
20,278
def _rm_udf_file_ident ( self , parent , fi ) : # type: (udfmod.UDFFileEntry, bytes) -> int logical_block_size = self . pvd . logical_block_size ( ) num_extents_to_remove = parent . remove_file_ident_desc_by_name ( fi , logical_block_size ) self . udf_logical_volume_integrity . logical_volume_impl_use . num_files -= 1 self . _find_udf_record . cache_clear ( ) # pylint: disable=no-member return num_extents_to_remove * logical_block_size
An internal method to remove a UDF File Identifier from the parent and remove any space from the Logical Volume as necessary .
150
26
20,279
def _rm_udf_link ( self , rec ) : # type: (udfmod.UDFFileEntry) -> int if not rec . is_file ( ) and not rec . is_symlink ( ) : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot remove a directory with rm_hard_link (try rm_directory instead)' ) # To remove something from UDF, we have to: # 1. Remove it from the list of linked_records on the Inode. # 2. If the number of links to the Inode is now 0, remove the Inode. # 3. If the number of links to the UDF File Entry this uses is 0, # remove the UDF File Entry. # 4. Remove the UDF File Identifier from the parent. logical_block_size = self . pvd . logical_block_size ( ) num_bytes_to_remove = 0 if rec . inode is not None : # Step 1. found_index = None for index , link in enumerate ( rec . inode . linked_records ) : if id ( link ) == id ( rec ) : found_index = index break else : # This should never happen raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del rec . inode . linked_records [ found_index ] rec . inode . num_udf -= 1 # Step 2. if not rec . inode . linked_records : found_index = None for index , ino in enumerate ( self . inodes ) : if id ( ino ) == id ( rec . inode ) : found_index = index break else : # This should never happen raise pycdlibexception . PyCdlibInternalError ( 'Could not find inode corresponding to record' ) del self . inodes [ found_index ] num_bytes_to_remove += rec . get_data_length ( ) # Step 3. if rec . inode . num_udf == 0 : num_bytes_to_remove += logical_block_size else : # If rec.inode is None, then we are just removing the UDF File # Entry. num_bytes_to_remove += logical_block_size # Step 4. if rec . parent is None : raise pycdlibexception . PyCdlibInternalError ( 'Cannot remove a UDF record with no parent' ) if rec . file_ident is None : raise pycdlibexception . PyCdlibInternalError ( 'Cannot remove a UDF record with no file identifier' ) return num_bytes_to_remove + self . _rm_udf_file_ident ( rec . parent , rec . file_ident . fi )
An internal method to remove a UDF File Entry link .
605
12
20,280
def _add_joliet_dir ( self , joliet_path ) : # type: (bytes) -> int if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Tried to add joliet dir to non-Joliet ISO' ) ( joliet_name , joliet_parent ) = self . _joliet_name_and_parent_from_path ( joliet_path ) log_block_size = self . joliet_vd . logical_block_size ( ) rec = dr . DirectoryRecord ( ) rec . new_dir ( self . joliet_vd , joliet_name , joliet_parent , self . joliet_vd . sequence_number ( ) , '' , b'' , log_block_size , False , False , False , - 1 ) num_bytes_to_add = self . _add_child_to_dr ( rec , log_block_size ) self . _create_dot ( self . joliet_vd , rec , '' , False , - 1 ) self . _create_dotdot ( self . joliet_vd , rec , '' , False , False , - 1 ) num_bytes_to_add += log_block_size if self . joliet_vd . add_to_ptr_size ( path_table_record . PathTableRecord . record_length ( len ( joliet_name ) ) ) : num_bytes_to_add += 4 * log_block_size # We always need to add an entry to the path table record ptr = path_table_record . PathTableRecord ( ) ptr . new_dir ( joliet_name ) rec . set_ptr ( ptr ) return num_bytes_to_add
An internal method to add a joliet directory to the ISO .
398
14
20,281
def _rm_joliet_dir ( self , joliet_path ) : # type: (bytes) -> int if self . joliet_vd is None : raise pycdlibexception . PyCdlibInternalError ( 'Tried to remove joliet dir from non-Joliet ISO' ) log_block_size = self . joliet_vd . logical_block_size ( ) joliet_child = self . _find_joliet_record ( joliet_path ) num_bytes_to_remove = joliet_child . get_data_length ( ) num_bytes_to_remove += self . _remove_child_from_dr ( joliet_child , joliet_child . index_in_parent , log_block_size ) if joliet_child . ptr is None : raise pycdlibexception . PyCdlibInternalError ( 'Joliet directory has no path table record; this should not be' ) if self . joliet_vd . remove_from_ptr_size ( path_table_record . PathTableRecord . record_length ( joliet_child . ptr . len_di ) ) : num_bytes_to_remove += 4 * log_block_size return num_bytes_to_remove
An internal method to remove a directory from the Joliet portion of the ISO .
288
16
20,282
def _get_entry ( self , iso_path , rr_path , joliet_path ) : # type: (Optional[bytes], Optional[bytes], Optional[bytes]) -> dr.DirectoryRecord if self . _needs_reshuffle : self . _reshuffle_extents ( ) rec = None if joliet_path is not None : rec = self . _find_joliet_record ( joliet_path ) elif rr_path is not None : rec = self . _find_rr_record ( rr_path ) elif iso_path is not None : rec = self . _find_iso_record ( iso_path ) else : raise pycdlibexception . PyCdlibInternalError ( 'get_entry called without legal argument' ) return rec
Internal method to get the directory record for a particular path .
174
12
20,283
def _get_udf_entry ( self , udf_path ) : # type: (str) -> udfmod.UDFFileEntry if self . _needs_reshuffle : self . _reshuffle_extents ( ) ( ident_unused , rec ) = self . _find_udf_record ( utils . normpath ( udf_path ) ) if rec is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot get entry for empty UDF File Entry' ) return rec
Internal method to get the UDF File Entry for a particular path .
116
14
20,284
def _create_dot ( self , vd , parent , rock_ridge , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, int) -> None dot = dr . DirectoryRecord ( ) dot . new_dot ( vd , parent , vd . sequence_number ( ) , rock_ridge , vd . logical_block_size ( ) , xa , file_mode ) self . _add_child_to_dr ( dot , vd . logical_block_size ( ) )
An internal method to create a new dot Directory Record .
126
11
20,285
def _create_dotdot ( self , vd , parent , rock_ridge , relocated , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, dr.DirectoryRecord, str, bool, bool, int) -> dr.DirectoryRecord dotdot = dr . DirectoryRecord ( ) dotdot . new_dotdot ( vd , parent , vd . sequence_number ( ) , rock_ridge , vd . logical_block_size ( ) , relocated , xa , file_mode ) self . _add_child_to_dr ( dotdot , vd . logical_block_size ( ) ) return dotdot
An internal method to create a new dotdot Directory Record .
143
12
20,286
def open ( self , filename ) : # type: (str) -> None if self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object already has an ISO; either close it or create a new object' ) fp = open ( filename , 'r+b' ) self . _managing_fp = True try : self . _open_fp ( fp ) except Exception : fp . close ( ) raise
Open up an existing ISO for inspection and modification .
98
10
20,287
def open_fp ( self , fp ) : # type: (BinaryIO) -> None if self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object already has an ISO; either close it or create a new object' ) self . _open_fp ( fp )
Open up an existing ISO for inspection and modification . Note that the file object passed in here must stay open for the lifetime of this object as the PyCdlib class uses it internally to do writing and reading operations . If you want PyCdlib to manage this for you use open instead .
69
60
20,288
def get_file_from_iso ( self , local_path , * * kwargs ) : # type: (str, Any) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) blocksize = 8192 joliet_path = None iso_path = None rr_path = None udf_path = None num_paths = 0 for key in kwargs : if key == 'blocksize' : blocksize = kwargs [ key ] elif key == 'iso_path' and kwargs [ key ] is not None : iso_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'rr_path' and kwargs [ key ] is not None : rr_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'joliet_path' and kwargs [ key ] is not None : joliet_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'udf_path' and kwargs [ key ] is not None : udf_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( 'Unknown keyword %s' % ( key ) ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Exactly one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path' must be passed" ) with open ( local_path , 'wb' ) as fp : if udf_path is not None : self . _udf_get_file_from_iso_fp ( fp , blocksize , udf_path ) else : self . _get_file_from_iso_fp ( fp , blocksize , iso_path , rr_path , joliet_path )
A method to fetch a single file from the ISO and write it out to a local file .
481
19
20,289
def get_file_from_iso_fp ( self , outfp , * * kwargs ) : # type: (BinaryIO, Any) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) blocksize = 8192 joliet_path = None iso_path = None rr_path = None udf_path = None num_paths = 0 for key in kwargs : if key == 'blocksize' : blocksize = kwargs [ key ] elif key == 'iso_path' and kwargs [ key ] is not None : iso_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'rr_path' and kwargs [ key ] is not None : rr_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'joliet_path' and kwargs [ key ] is not None : joliet_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 elif key == 'udf_path' and kwargs [ key ] is not None : udf_path = utils . normpath ( kwargs [ key ] ) num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( 'Unknown keyword %s' % ( key ) ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Exactly one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path' must be passed" ) if udf_path is not None : self . _udf_get_file_from_iso_fp ( outfp , blocksize , udf_path ) else : self . _get_file_from_iso_fp ( outfp , blocksize , iso_path , rr_path , joliet_path )
A method to fetch a single file from the ISO and write it out to the file object .
469
19
20,290
def write ( self , filename , blocksize = 32768 , progress_cb = None , progress_opaque = None ) : # type: (str, int, Optional[Callable[[int, int, Any], None]], Optional[Any]) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) with open ( filename , 'wb' ) as fp : self . _write_fp ( fp , blocksize , progress_cb , progress_opaque )
Write a properly formatted ISO out to the filename passed in . This also goes by the name of mastering .
132
21
20,291
def add_file ( self , filename , iso_path , rr_name = None , joliet_path = None , file_mode = None , udf_path = None ) : # type: (Any, str, Optional[str], str, Optional[int], Optional[str]) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) num_bytes_to_add = self . _add_fp ( filename , os . stat ( filename ) . st_size , True , iso_path , rr_name , joliet_path , udf_path , file_mode , False ) self . _finish_add ( 0 , num_bytes_to_add )
Add a file to the ISO . If the ISO is a Rock Ridge one then a Rock Ridge name must also be provided . If the ISO is a Joliet one then a Joliet path may also be provided ; while it is optional to do so it is highly recommended .
182
55
20,292
def get_record ( self , * * kwargs ) : # type: (str) -> Union[dr.DirectoryRecord, udfmod.UDFFileEntry] if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) num_paths = 0 for key in kwargs : if key in [ 'joliet_path' , 'rr_path' , 'iso_path' , 'udf_path' ] : if kwargs [ key ] is not None : num_paths += 1 else : raise pycdlibexception . PyCdlibInvalidInput ( "Invalid keyword, must be one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'" ) if num_paths != 1 : raise pycdlibexception . PyCdlibInvalidInput ( "Must specify one, and only one of 'iso_path', 'rr_path', 'joliet_path', or 'udf_path'" ) if 'joliet_path' in kwargs : return self . _get_entry ( None , None , self . _normalize_joliet_path ( kwargs [ 'joliet_path' ] ) ) if 'rr_path' in kwargs : return self . _get_entry ( None , utils . normpath ( kwargs [ 'rr_path' ] ) , None ) if 'udf_path' in kwargs : return self . _get_udf_entry ( kwargs [ 'udf_path' ] ) return self . _get_entry ( utils . normpath ( kwargs [ 'iso_path' ] ) , None , None )
Get the directory record for a particular path .
403
9
20,293
def full_path_from_dirrecord ( self , rec , rockridge = False ) : # type: (Union[dr.DirectoryRecord, udfmod.UDFFileEntry], bool) -> str if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) ret = b'' if isinstance ( rec , dr . DirectoryRecord ) : encoding = 'utf-8' if self . joliet_vd is not None and id ( rec . vd ) == id ( self . joliet_vd ) : encoding = 'utf-16_be' slash = '/' . encode ( encoding ) # A root entry has no Rock Ridge entry, even on a Rock Ridge ISO. Just # always return / here. if rec . is_root : return '/' if rockridge and rec . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidInput ( 'Cannot generate a Rock Ridge path on a non-Rock Ridge ISO' ) parent = rec # type: Optional[dr.DirectoryRecord] while parent is not None : if not parent . is_root : if rockridge and parent . rock_ridge is not None : ret = slash + parent . rock_ridge . name ( ) + ret else : ret = slash + parent . file_identifier ( ) + ret parent = parent . parent else : if rec . parent is None : return '/' if rec . file_ident is not None : encoding = rec . file_ident . encoding else : encoding = 'utf-8' slash = '/' . encode ( encoding ) udfparent = rec # type: Optional[udfmod.UDFFileEntry] while udfparent is not None : ident = udfparent . file_identifier ( ) if ident != b'/' : ret = slash + ident + ret udfparent = udfparent . parent if sys . version_info >= ( 3 , 0 ) : # Python 3, just return the encoded version return ret . decode ( encoding ) # Python 2. return ret . decode ( encoding ) . encode ( 'utf-8' )
A method to get the absolute path of a directory record .
471
12
20,294
def duplicate_pvd ( self ) : # type: () -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) pvd = headervd . PrimaryOrSupplementaryVD ( headervd . VOLUME_DESCRIPTOR_TYPE_PRIMARY ) pvd . copy ( self . pvd ) self . pvds . append ( pvd ) self . _finish_add ( self . pvd . logical_block_size ( ) , 0 )
A method to add a duplicate PVD to the ISO . This is a mostly useless feature allowed by Ecma - 119 to have duplicate PVDs to avoid possible corruption .
131
35
20,295
def clear_hidden ( self , iso_path = None , rr_path = None , joliet_path = None ) : # type: (Optional[str], Optional[str], Optional[str]) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if len ( [ x for x in ( iso_path , rr_path , joliet_path ) if x is not None ] ) != 1 : raise pycdlibexception . PyCdlibInvalidInput ( 'Must provide exactly one of iso_path, rr_path, or joliet_path' ) if iso_path is not None : rec = self . _find_iso_record ( utils . normpath ( iso_path ) ) elif rr_path is not None : rec = self . _find_rr_record ( utils . normpath ( rr_path ) ) elif joliet_path is not None : joliet_path_bytes = self . _normalize_joliet_path ( joliet_path ) rec = self . _find_joliet_record ( joliet_path_bytes ) rec . change_existence ( False )
Clear the ISO9660 hidden attribute on a file or directory . This will cause the file or directory to show up when listing entries on the ISO . Exactly one of iso_path rr_path or joliet_path must be specified .
289
50
20,296
def set_relocated_name ( self , name , rr_name ) : # type: (str, str) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if not self . rock_ridge : raise pycdlibexception . PyCdlibInvalidInput ( 'Can only set the relocated name on a Rock Ridge ISO' ) encoded_name = name . encode ( 'utf-8' ) encoded_rr_name = rr_name . encode ( 'utf-8' ) if self . _rr_moved_name is not None : if self . _rr_moved_name == encoded_name and self . _rr_moved_rr_name == encoded_rr_name : return raise pycdlibexception . PyCdlibInvalidInput ( 'Changing the existing rr_moved name is not allowed' ) _check_iso9660_directory ( encoded_name , self . interchange_level ) self . _rr_moved_name = encoded_name self . _rr_moved_rr_name = encoded_rr_name
Set the name of the relocated directory on a Rock Ridge ISO . The ISO must be a Rock Ridge one and must not have previously had the relocated name set .
265
32
20,297
def close ( self ) : # type: () -> None if not self . _initialized : raise pycdlibexception . PyCdlibInvalidInput ( 'This object is not yet initialized; call either open() or new() to create an ISO' ) if self . _managing_fp : # In this case, we are managing self._cdfp, so we need to close it self . _cdfp . close ( ) self . _initialize ( )
Close the PyCdlib object and re - initialize the object to the defaults . The object can then be re - used for manipulation of another ISO .
100
31
20,298
def make_arg_parser ( ) : parser = argparse . ArgumentParser ( formatter_class = argparse . RawTextHelpFormatter , usage = "vex [OPTIONS] VIRTUALENV_NAME COMMAND_TO_RUN ..." , ) make = parser . add_argument_group ( title = 'To make a new virtualenv' ) make . add_argument ( '-m' , '--make' , action = "store_true" , help = "make named virtualenv before running command" ) make . add_argument ( '--python' , help = "specify which python for virtualenv to be made" , action = "store" , default = None , ) make . add_argument ( '--site-packages' , help = "allow site package imports from new virtualenv" , action = "store_true" , ) make . add_argument ( '--always-copy' , help = "use copies instead of symlinks in new virtualenv" , action = "store_true" , ) remove = parser . add_argument_group ( title = 'To remove a virtualenv' ) remove . add_argument ( '-r' , '--remove' , action = "store_true" , help = "remove the named virtualenv after running command" ) parser . add_argument ( "--path" , metavar = "DIR" , help = "absolute path to virtualenv to use" , action = "store" ) parser . add_argument ( '--cwd' , metavar = "DIR" , action = "store" , default = '.' , help = "path to run command in (default: '.' aka $PWD)" , ) parser . add_argument ( "--config" , metavar = "FILE" , default = None , action = "store" , help = "path to config file to read (default: '~/.vexrc')" ) parser . add_argument ( '--shell-config' , metavar = "SHELL" , dest = "shell_to_configure" , action = "store" , default = None , help = "print optional config for the specified shell" ) parser . add_argument ( '--list' , metavar = "PREFIX" , nargs = "?" , const = "" , default = None , help = "print a list of available virtualenvs [matching PREFIX]" , action = "store" ) parser . add_argument ( '--version' , help = "print the version of vex that is being run" , action = "store_true" ) parser . add_argument ( "rest" , nargs = argparse . REMAINDER , help = argparse . SUPPRESS ) return parser
Return a standard ArgumentParser object .
597
7
20,299
def get_options ( argv ) : arg_parser = make_arg_parser ( ) options , unknown = arg_parser . parse_known_args ( argv ) if unknown : arg_parser . print_help ( ) raise exceptions . UnknownArguments ( "unknown args: {0!r}" . format ( unknown ) ) options . print_help = arg_parser . print_help return options
Called to parse the given list as command - line arguments .
86
13