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,000 | def update_extent_location ( self , extent_loc ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Path Table Record not yet initialized' ) self . extent_location = extent_loc | A method to update the extent location for this Path Table Record . | 62 | 13 |
20,001 | def update_parent_directory_number ( self , parent_dir_num ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Path Table Record not yet initialized' ) self . parent_directory_num = parent_dir_num | A method to update the parent directory number for this Path Table Record from the directory record . | 69 | 18 |
20,002 | def equal_to_be ( self , be_record ) : # type: (PathTableRecord) -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Path Table Record is not yet initialized' ) if be_record . len_di != self . len_di or be_record . xattr_length != self . xattr_length or utils . swab_32bit ( be_record . extent_location ) != self . extent_location or utils . swab_16bit ( be_record . parent_directory_num ) != self . parent_directory_num or be_record . directory_identifier != self . directory_identifier : return False return True | A method to compare a little - endian path table record to its big - endian counterpart . This is used to ensure that the ISO is sane . | 159 | 31 |
20,003 | def copy_data ( data_length , blocksize , infp , outfp ) : # type: (int, int, BinaryIO, BinaryIO) -> None use_sendfile = False if have_sendfile : # Python 3 implements the fileno method for all file-like objects, so # we can't just use the existence of the method to tell whether it is # available. Instead, we try to assign it, and if we fail, then we # assume it is not available. try : x_unused = infp . fileno ( ) # NOQA y_unused = outfp . fileno ( ) # NOQA use_sendfile = True except ( AttributeError , io . UnsupportedOperation ) : pass if use_sendfile : # This is one of those instances where using the file object and the # file descriptor causes problems. The sendfile() call actually updates # the underlying file descriptor, but the file object does not know # about it. To get around this, we instead get the offset, allow # sendfile() to update the offset, then manually seek the file object # to the right location. This ensures that the file object gets updated # properly. in_offset = infp . tell ( ) out_offset = outfp . tell ( ) sendfile ( outfp . fileno ( ) , infp . fileno ( ) , in_offset , data_length ) infp . seek ( in_offset + data_length ) outfp . seek ( out_offset + data_length ) else : left = data_length readsize = blocksize while left > 0 : if left < readsize : readsize = left data = infp . read ( readsize ) # We have seen ISOs in the wild (Tribes Vengeance 1of4.iso) that # lie about the size of their files, causing reads to fail (since # we hit EOF before the supposed end of the file). If we are using # sendfile above, sendfile just silently returns as much data as it # can, with no additional checking. We should do the same here, so # if we got less data than we asked for, abort the loop silently. data_len = len ( data ) if data_len != readsize : data_len = left outfp . write ( data ) left -= data_len | A utility function to copy data from the input file object to the output file object . This function will use the most efficient copy method available which is often sendfile . | 494 | 33 |
20,004 | def encode_space_pad ( instr , length , encoding ) : # type: (bytes, int, str) -> bytes output = instr . decode ( 'utf-8' ) . encode ( encoding ) if len ( output ) > length : raise pycdlibexception . PyCdlibInvalidInput ( 'Input string too long!' ) encoded_space = ' ' . encode ( encoding ) left = length - len ( output ) while left > 0 : output += encoded_space left -= len ( encoded_space ) if left < 0 : output = output [ : left ] return output | A function to pad out an input string with spaces to the length specified . The space is first encoded into the specified encoding then appended to the input string until the length is reached . | 123 | 37 |
20,005 | def gmtoffset_from_tm ( tm , local ) : # type: (float, time.struct_time) -> int gmtime = time . gmtime ( tm ) tmpyear = gmtime . tm_year - local . tm_year tmpyday = gmtime . tm_yday - local . tm_yday tmphour = gmtime . tm_hour - local . tm_hour tmpmin = gmtime . tm_min - local . tm_min if tmpyday < 0 : tmpyday = - 1 else : if tmpyear > 0 : tmpyday = 1 return - ( tmpmin + 60 * ( tmphour + 24 * tmpyday ) ) // 15 | A function to compute the GMT offset from the time in seconds since the epoch and the local time object . | 168 | 21 |
20,006 | def zero_pad ( fp , data_size , pad_size ) : # type: (BinaryIO, int, int) -> None padbytes = pad_size - ( data_size % pad_size ) if padbytes == pad_size : # Nothing to pad, get out. return fp . seek ( padbytes - 1 , os . SEEK_CUR ) fp . write ( b'\x00' ) | A function to write padding out from data_size up to pad_size efficiently . | 94 | 17 |
20,007 | def file_object_supports_binary ( fp ) : # type: (BinaryIO) -> bool if hasattr ( fp , 'mode' ) : return 'b' in fp . mode # Python 3 if sys . version_info >= ( 3 , 0 ) : return isinstance ( fp , ( io . RawIOBase , io . BufferedIOBase ) ) # Python 2 return isinstance ( fp , ( cStringIO . OutputType , cStringIO . InputType , io . RawIOBase , io . BufferedIOBase ) ) | A function to check whether a file - like object supports binary mode . | 122 | 14 |
20,008 | def parse ( self , instr ) : # type: (bytes) -> bool if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This IsoHybrid object is already initialized' ) if len ( instr ) != 512 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid size of the instr' ) if instr [ 0 : 32 ] == self . ORIG_HEADER : self . header = self . ORIG_HEADER elif instr [ 0 : 32 ] == self . MAC_AFP : self . header = self . MAC_AFP else : # If we didn't see anything that we expected, then this is not an # IsoHybrid ISO, so just quietly return False return False ( self . mbr , self . rba , unused1 , self . mbr_id , unused2 ) = struct . unpack_from ( self . FMT , instr [ : 32 + struct . calcsize ( self . FMT ) ] , 32 ) if unused1 != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid IsoHybrid section' ) if unused2 != 0 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid IsoHybrid section' ) offset = 32 + struct . calcsize ( self . FMT ) for i in range ( 1 , 5 ) : if bytes ( bytearray ( [ instr [ offset ] ] ) ) == b'\x80' : self . part_entry = i ( const_unused , self . bhead , self . bsect , self . bcyle , self . ptype , self . ehead , self . esect , self . ecyle , self . part_offset , self . psize ) = struct . unpack_from ( '=BBBBBBBBLL' , instr [ : offset + 16 ] , offset ) break offset += 16 else : raise pycdlibexception . PyCdlibInvalidISO ( 'No valid partition found in IsoHybrid!' ) if bytes ( bytearray ( [ instr [ - 2 ] ] ) ) != b'\x55' or bytes ( bytearray ( [ instr [ - 1 ] ] ) ) != b'\xaa' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid tail on isohybrid section' ) self . geometry_heads = self . ehead + 1 # FIXME: I can't see any way to compute the number of sectors from the # available information. For now, we just hard-code this at 32 and # hope for the best. self . geometry_sectors = 32 self . _initialized = True return True | A method to parse ISO hybridization info out of an existing ISO . | 585 | 14 |
20,009 | def _calc_cc ( self , iso_size ) : # type: (int) -> Tuple[int, int] cylsize = self . geometry_heads * self . geometry_sectors * 512 frac = iso_size % cylsize padding = 0 if frac > 0 : padding = cylsize - frac cc = ( iso_size + padding ) // cylsize if cc > 1024 : cc = 1024 return ( cc , padding ) | A method to calculate the cc and the padding values for this hybridization . | 96 | 15 |
20,010 | def record ( self , iso_size ) : # type: (int) -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This IsoHybrid object is not yet initialized' ) outlist = [ struct . pack ( '=32s400sLLLH' , self . header , self . mbr , self . rba , 0 , self . mbr_id , 0 ) ] for i in range ( 1 , 5 ) : if i == self . part_entry : cc , padding_unused = self . _calc_cc ( iso_size ) esect = self . geometry_sectors + ( ( ( cc - 1 ) & 0x300 ) >> 2 ) ecyle = ( cc - 1 ) & 0xff psize = cc * self . geometry_heads * self . geometry_sectors - self . part_offset outlist . append ( struct . pack ( '=BBBBBBBBLL' , 0x80 , self . bhead , self . bsect , self . bcyle , self . ptype , self . ehead , esect , ecyle , self . part_offset , psize ) ) else : outlist . append ( b'\x00' * 16 ) outlist . append ( b'\x55\xaa' ) return b'' . join ( outlist ) | A method to generate a string containing the ISO hybridization . | 300 | 12 |
20,011 | def record_padding ( self , iso_size ) : # type: (int) -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This IsoHybrid object is not yet initialized' ) return b'\x00' * self . _calc_cc ( iso_size ) [ 1 ] | A method to record padding for the ISO hybridization . | 77 | 11 |
20,012 | def update_rba ( self , current_extent ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This IsoHybrid object is not yet initialized' ) self . rba = current_extent | A method to update the current rba for the ISO hybridization . | 65 | 14 |
20,013 | def parse ( self , xastr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This XARecord is already initialized!' ) ( self . _group_id , self . _user_id , self . _attributes , signature , self . _filenum , unused ) = struct . unpack_from ( self . FMT , xastr , 0 ) if signature != b'XA' : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid signature on the XARecord!' ) if unused != b'\x00\x00\x00\x00\x00' : raise pycdlibexception . PyCdlibInvalidISO ( 'Unused fields should be 0' ) self . _initialized = True | Parse an Extended Attribute Record out of a string . | 184 | 12 |
20,014 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This XARecord is already initialized!' ) # FIXME: we should allow the user to set these self . _group_id = 0 self . _user_id = 0 self . _attributes = 0 self . _filenum = 0 self . _initialized = True | Create a new Extended Attribute Record . | 91 | 8 |
20,015 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This XARecord is not yet initialized!' ) return struct . pack ( self . FMT , self . _group_id , self . _user_id , self . _attributes , b'XA' , self . _filenum , b'\x00' * 5 ) | Record this Extended Attribute Record . | 96 | 7 |
20,016 | def _new ( self , vd , name , parent , seqnum , isdir , length , xa ) : # type: (headervd.PrimaryOrSupplementaryVD, bytes, Optional[DirectoryRecord], int, bool, int, bool) -> None # Adding a new time should really be done when we are going to write # the ISO (in record()). Ecma-119 9.1.5 says: # # 'This field shall indicate the date and the time of the day at which # the information in the Extent described by the Directory Record was # recorded.' # # We create it here just to have something in the field, but we'll # redo the whole thing when we are mastering. self . date = dates . DirectoryRecordDate ( ) self . date . new ( ) if length > 2 ** 32 - 1 : raise pycdlibexception . PyCdlibInvalidInput ( 'Maximum supported file length is 2^32-1' ) self . data_length = length self . file_ident = name self . isdir = isdir self . seqnum = seqnum # For a new directory record entry, there is no original_extent_loc, # so we leave it at None. self . orig_extent_loc = None self . len_fi = len ( self . file_ident ) self . dr_len = struct . calcsize ( self . FMT ) + self . len_fi # From Ecma-119, 9.1.6, the file flag bits are: # # Bit 0 - Existence - 0 for existence known, 1 for hidden # Bit 1 - Directory - 0 for file, 1 for directory # Bit 2 - Associated File - 0 for not associated, 1 for associated # Bit 3 - Record - 0=structure not in xattr, 1=structure in xattr # Bit 4 - Protection - 0=no owner and group, 1=owner and group in xattr # Bit 5 - Reserved # Bit 6 - Reserved # Bit 7 - Multi-extent - 0=final directory record, 1=not final directory record self . file_flags = 0 if self . isdir : self . file_flags |= ( 1 << self . FILE_FLAG_DIRECTORY_BIT ) self . file_unit_size = 0 # FIXME: we don't support setting file unit size for now self . interleave_gap_size = 0 # FIXME: we don't support setting interleave gap size for now self . xattr_len = 0 # FIXME: we don't support xattrs for now self . parent = parent if parent is None : # If no parent, then this is the root self . is_root = True if xa : self . xa_record = XARecord ( ) self . xa_record . new ( ) self . dr_len += XARecord . length ( ) self . dr_len += ( self . dr_len % 2 ) if self . is_root : self . _printable_name = b'/' elif self . file_ident == b'\x00' : self . _printable_name = b'.' elif self . file_ident == b'\x01' : self . _printable_name = b'..' else : self . _printable_name = self . file_ident self . vd = vd self . _initialized = True | Internal method to create a new Directory Record . | 729 | 9 |
20,017 | def new_symlink ( self , vd , name , parent , rr_target , seqnum , rock_ridge , rr_name , xa ) : # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, bytes, int, str, bytes, bool) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , name , parent , seqnum , False , 0 , xa ) if rock_ridge : self . _rr_new ( rock_ridge , rr_name , rr_target , False , False , False , 0o0120555 ) | Create a new symlink Directory Record . This implies that the new record will be Rock Ridge . | 155 | 20 |
20,018 | def new_file ( self , vd , length , isoname , parent , seqnum , rock_ridge , rr_name , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, int, bytes, DirectoryRecord, int, str, bytes, bool, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , isoname , parent , seqnum , False , length , xa ) if rock_ridge : self . _rr_new ( rock_ridge , rr_name , b'' , False , False , False , file_mode ) | Create a new file Directory Record . | 156 | 7 |
20,019 | def new_root ( self , vd , seqnum , log_block_size ) : # type: (headervd.PrimaryOrSupplementaryVD, int, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , b'\x00' , None , seqnum , True , log_block_size , False ) | Create a new root Directory Record . | 97 | 7 |
20,020 | def new_dot ( self , vd , parent , seqnum , rock_ridge , log_block_size , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , b'\x00' , parent , seqnum , True , log_block_size , xa ) if rock_ridge : self . _rr_new ( rock_ridge , b'' , b'' , False , False , False , file_mode ) | Create a new dot Directory Record . | 152 | 7 |
20,021 | def new_dotdot ( self , vd , parent , seqnum , rock_ridge , log_block_size , rr_relocated_parent , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, DirectoryRecord, int, str, int, bool, bool, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , b'\x01' , parent , seqnum , True , log_block_size , xa ) if rock_ridge : self . _rr_new ( rock_ridge , b'' , b'' , False , False , rr_relocated_parent , file_mode ) | Create a new dotdot Directory Record . | 169 | 8 |
20,022 | def new_dir ( self , vd , name , parent , seqnum , rock_ridge , rr_name , log_block_size , rr_relocated_child , rr_relocated , xa , file_mode ) : # type: (headervd.PrimaryOrSupplementaryVD, bytes, DirectoryRecord, int, str, bytes, int, bool, bool, bool, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record already initialized' ) self . _new ( vd , name , parent , seqnum , True , log_block_size , xa ) if rock_ridge : self . _rr_new ( rock_ridge , rr_name , b'' , rr_relocated_child , rr_relocated , False , file_mode ) if rr_relocated_child and self . rock_ridge : # Relocated Rock Ridge entries are not exactly treated as directories, so # fix things up here. self . isdir = False self . file_flags = 0 self . rock_ridge . add_to_file_links ( ) | Create a new directory Directory Record . | 251 | 7 |
20,023 | def change_existence ( self , is_hidden ) : # type: (bool) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) if is_hidden : self . file_flags |= ( 1 << self . FILE_FLAG_EXISTENCE_BIT ) else : self . file_flags &= ~ ( 1 << self . FILE_FLAG_EXISTENCE_BIT ) | Change the ISO9660 existence flag of this Directory Record . | 101 | 12 |
20,024 | def _recalculate_extents_and_offsets ( self , index , logical_block_size ) : # type: (int, int) -> Tuple[int, int] if index == 0 : dirrecord_offset = 0 num_extents = 1 else : dirrecord_offset = self . children [ index - 1 ] . offset_to_here num_extents = self . children [ index - 1 ] . extents_to_here for i in range ( index , len ( self . children ) ) : c = self . children [ i ] dirrecord_len = c . dr_len if ( dirrecord_offset + dirrecord_len ) > logical_block_size : num_extents += 1 dirrecord_offset = 0 dirrecord_offset += dirrecord_len c . extents_to_here = num_extents c . offset_to_here = dirrecord_offset c . index_in_parent = i return num_extents , dirrecord_offset | Internal method to recalculate the extents and offsets associated with children of this directory record . | 217 | 19 |
20,025 | def _add_child ( self , child , logical_block_size , allow_duplicate , check_overflow ) : # type: (DirectoryRecord, int, bool, bool) -> bool if not self . isdir : raise pycdlibexception . PyCdlibInvalidInput ( 'Trying to add a child to a record that is not a directory' ) # First ensure that this is not a duplicate. For speed purposes, we # recognize that bisect_left will always choose an index to the *left* # of a duplicate child. Thus, to check for duplicates we only need to # see if the child to be added is a duplicate with the entry that # bisect_left returned. index = bisect . bisect_left ( self . children , child ) if index != len ( self . children ) and self . children [ index ] . file_ident == child . file_ident : if not self . children [ index ] . is_associated_file ( ) and not child . is_associated_file ( ) : if not ( self . rock_ridge is not None and self . file_identifier ( ) == b'RR_MOVED' ) : if not allow_duplicate : raise pycdlibexception . PyCdlibInvalidInput ( 'Failed adding duplicate name to parent' ) else : self . children [ index ] . data_continuation = child index += 1 self . children . insert ( index , child ) if child . rock_ridge is not None and not child . is_dot ( ) and not child . is_dotdot ( ) : lo = 0 hi = len ( self . rr_children ) while lo < hi : mid = ( lo + hi ) // 2 rr = self . rr_children [ mid ] . rock_ridge if rr is not None : if rr . name ( ) < child . rock_ridge . name ( ) : lo = mid + 1 else : hi = mid else : raise pycdlibexception . PyCdlibInternalError ( 'Expected all children to have Rock Ridge, but one did not' ) rr_index = lo self . rr_children . insert ( rr_index , child ) # We now have to check if we need to add another logical block. # We have to iterate over the entire list again, because where we # placed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents , offset_unused = self . _recalculate_extents_and_offsets ( index , logical_block_size ) overflowed = False if check_overflow and ( num_extents * logical_block_size > self . data_length ) : overflowed = True # When we overflow our data length, we always add a full block. self . data_length += logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self . children [ 0 ] . data_length = self . data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self . parent is None : self . children [ 1 ] . data_length = self . data_length for c in self . children : if not c . is_dir ( ) : continue if len ( c . children ) > 1 : c . children [ 1 ] . data_length = self . data_length return overflowed | An internal method to add a child to this object . Note that this is called both during parsing and when adding a new object to the system so it it shouldn t have any functionality that is not appropriate for both . | 784 | 43 |
20,026 | def add_child ( self , child , logical_block_size , allow_duplicate = False ) : # type: (DirectoryRecord, int, bool) -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) return self . _add_child ( child , logical_block_size , allow_duplicate , True ) | A method to add a new child to this directory record . | 90 | 12 |
20,027 | def track_child ( self , child , logical_block_size , allow_duplicate = False ) : # type: (DirectoryRecord, int, bool) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) self . _add_child ( child , logical_block_size , allow_duplicate , False ) | A method to track an existing child of this directory record . | 89 | 12 |
20,028 | def remove_child ( self , child , index , logical_block_size ) : # type: (DirectoryRecord, int, int) -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) if index < 0 : # This should never happen raise pycdlibexception . PyCdlibInternalError ( 'Invalid child index to remove' ) # Unfortunately, Rock Ridge specifies that a CL 'directory' is replaced # by a *file*, not another directory. Thus, we can't just depend on # whether this child is marked as a directory by the file flags during # parse time. Instead, we check if this is either a true directory, # or a Rock Ridge CL entry, and in either case try to manipulate the # file links. if child . rock_ridge is not None : if child . isdir or child . rock_ridge . child_link_record_exists ( ) : if len ( self . children ) < 2 : raise pycdlibexception . PyCdlibInvalidISO ( 'Expected a dot and dotdot entry, but missing; ISO is corrupt' ) if self . children [ 0 ] . rock_ridge is None or self . children [ 1 ] . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidISO ( 'Missing Rock Ridge entry on dot or dotdot; ISO is corrupt' ) if self . parent is None : self . children [ 0 ] . rock_ridge . remove_from_file_links ( ) self . children [ 1 ] . rock_ridge . remove_from_file_links ( ) else : if self . rock_ridge is None : raise pycdlibexception . PyCdlibInvalidISO ( 'Child has Rock Ridge, but parent does not; ISO is corrupt' ) self . rock_ridge . remove_from_file_links ( ) self . children [ 0 ] . rock_ridge . remove_from_file_links ( ) del self . children [ index ] # We now have to check if we need to remove a logical block. # We have to iterate over the entire list again, because where we # removed this last entry may rearrange the empty spaces in the blocks # that we've already allocated. num_extents , dirrecord_offset = self . _recalculate_extents_and_offsets ( index , logical_block_size ) underflow = False total_size = ( num_extents - 1 ) * logical_block_size + dirrecord_offset if ( self . data_length - total_size ) > logical_block_size : self . data_length -= logical_block_size # We also have to make sure to update the length of the dot child, # as that should always reflect the length. self . children [ 0 ] . data_length = self . data_length # We also have to update all of the dotdot entries. If this is # the root directory record (no parent), we first update the root # dotdot entry. In all cases, we update the dotdot entry of all # children that are directories. if self . parent is None : self . children [ 1 ] . data_length = self . data_length for c in self . children : if not c . is_dir ( ) : continue if len ( c . children ) > 1 : c . children [ 1 ] . data_length = self . data_length underflow = True return underflow | A method to remove a child from this Directory Record . | 746 | 11 |
20,029 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) # Ecma-119 9.1.5 says the date should reflect the time when the # record was written, so we make a new date now and use that to # write out the record. self . date = dates . DirectoryRecordDate ( ) self . date . new ( ) padlen = struct . calcsize ( self . FMT ) + self . len_fi padstr = b'\x00' * ( padlen % 2 ) extent_loc = self . _extent_location ( ) xa_rec = b'' if self . xa_record is not None : xa_rec = b'\x00' * self . xa_pad_size + self . xa_record . record ( ) rr_rec = b'' if self . rock_ridge is not None : rr_rec = self . rock_ridge . record_dr_entries ( ) outlist = [ struct . pack ( self . FMT , self . dr_len , self . xattr_len , extent_loc , utils . swab_32bit ( extent_loc ) , self . data_length , utils . swab_32bit ( self . data_length ) , self . date . record ( ) , self . file_flags , self . file_unit_size , self . interleave_gap_size , self . seqnum , utils . swab_16bit ( self . seqnum ) , self . len_fi ) + self . file_ident + padstr + xa_rec + rr_rec ] outlist . append ( b'\x00' * ( len ( outlist [ 0 ] ) % 2 ) ) return b'' . join ( outlist ) | A method to generate the string representing this Directory Record . | 411 | 11 |
20,030 | def is_associated_file ( self ) : # type: () -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) return self . file_flags & ( 1 << self . FILE_FLAG_ASSOCIATED_FILE_BIT ) | A method to determine whether this file is associated with another file on the ISO . | 70 | 16 |
20,031 | def set_ptr ( self , ptr ) : # type: (path_table_record.PathTableRecord) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) self . ptr = ptr | A method to set the Path Table Record associated with this Directory Record . | 60 | 14 |
20,032 | def set_data_location ( self , current_extent , tag_location ) : # pylint: disable=unused-argument # type: (int, int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) self . new_extent_loc = current_extent if self . ptr is not None : self . ptr . update_extent_location ( current_extent ) | A method to set the new extent location that the data for this Directory Record should live at . | 106 | 19 |
20,033 | def get_data_length ( self ) : # type: () -> int if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) if self . inode is not None : return self . inode . get_data_length ( ) return self . data_length | A method to get the length of the data that this Directory Record points to . | 73 | 16 |
20,034 | def set_data_length ( self , length ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record not yet initialized' ) self . data_length = length | A method to set the length of the data that this Directory Record points to . | 56 | 16 |
20,035 | def new ( self , length , fp , manage_fp , offset ) : # type: (int, BinaryIO, bool, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Inode is already initialized' ) self . data_length = length self . data_fp = fp self . manage_fp = manage_fp self . fp_offset = offset self . original_data_location = self . DATA_IN_EXTERNAL_FP self . _initialized = True | Initialize a new Inode . | 117 | 7 |
20,036 | def parse ( self , extent , length , fp , log_block_size ) : # type: (int, int, BinaryIO, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Inode is already initialized' ) self . orig_extent_loc = extent self . data_length = length self . data_fp = fp self . manage_fp = False self . fp_offset = extent * log_block_size self . original_data_location = self . DATA_ON_ORIGINAL_ISO self . _initialized = True | Parse an existing Inode . This just saves off the extent for later use . | 133 | 17 |
20,037 | def add_boot_info_table ( self , boot_info_table ) : # type: (eltorito.EltoritoBootInfoTable) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Inode is not yet initialized' ) self . boot_info_table = boot_info_table | A method to add a boot info table to this Inode . | 79 | 13 |
20,038 | def update_fp ( self , fp , length ) : # type: (BinaryIO, int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Inode is not yet initialized' ) self . original_data_location = self . DATA_IN_EXTERNAL_FP self . data_fp = fp self . data_length = length self . fp_offset = 0 | Update the Inode to use a different file object and length . | 97 | 13 |
20,039 | def string_to_timestruct ( input_string ) : # type: (bytes) -> time.struct_time try : timestruct = time . strptime ( input_string . decode ( 'utf-8' ) , VolumeDescriptorDate . TIME_FMT ) except ValueError : # Ecma-119, 8.4.26.1 specifies that if the string was all the digit # zero, with the last byte 0, the time wasn't specified. In that # case, time.strptime() with our format will raise a ValueError. # In practice we have found that some ISOs specify various wacky # things in this field, so if we see *any* ValueError, we just # assume the date is unspecified and go with that. timestruct = time . struct_time ( ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) return timestruct | A cacheable function to take an input string and decode it into a time . struct_time from the time module . If the string cannot be decoded because of an illegal value then the all - zero time . struct_time will be returned instead . | 200 | 51 |
20,040 | def parse ( self , datestr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record Date already initialized' ) ( self . years_since_1900 , self . month , self . day_of_month , self . hour , self . minute , self . second , self . gmtoffset ) = struct . unpack_from ( self . FMT , datestr , 0 ) self . _initialized = True | Parse a Directory Record date out of a string . | 112 | 11 |
20,041 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record Date already initialized' ) # This algorithm was ported from cdrkit, genisoimage.c:iso9660_date() tm = time . time ( ) local = time . localtime ( tm ) self . years_since_1900 = local . tm_year - 1900 self . month = local . tm_mon self . day_of_month = local . tm_mday self . hour = local . tm_hour self . minute = local . tm_min self . second = local . tm_sec self . gmtoffset = utils . gmtoffset_from_tm ( tm , local ) self . _initialized = True | Create a new Directory Record date based on the current time . | 183 | 12 |
20,042 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Directory Record Date not initialized' ) return struct . pack ( self . FMT , self . years_since_1900 , self . month , self . day_of_month , self . hour , self . minute , self . second , self . gmtoffset ) | Return a string representation of the Directory Record date . | 91 | 10 |
20,043 | def parse ( self , datestr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'This Volume Descriptor Date object is already initialized' ) if len ( datestr ) != 17 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid ISO9660 date string' ) timestruct = string_to_timestruct ( datestr [ : - 3 ] ) self . year = timestruct . tm_year self . month = timestruct . tm_mon self . dayofmonth = timestruct . tm_mday self . hour = timestruct . tm_hour self . minute = timestruct . tm_min self . second = timestruct . tm_sec if timestruct . tm_year == 0 and timestruct . tm_mon == 0 and timestruct . tm_mday == 0 and timestruct . tm_hour == 0 and timestruct . tm_min == 0 and timestruct . tm_sec == 0 : self . hundredthsofsecond = 0 self . gmtoffset = 0 self . date_str = self . EMPTY_STRING else : self . hundredthsofsecond = int ( datestr [ 14 : 15 ] ) self . gmtoffset , = struct . unpack_from ( '=b' , datestr , 16 ) self . date_str = datestr self . _initialized = True | Parse a Volume Descriptor Date out of a string . A string of all zeros is valid which means that the date in this field was not specified . | 342 | 33 |
20,044 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SP record already initialized!' ) ( su_len , su_entry_version_unused , check_byte1 , check_byte2 , self . bytes_to_skip ) = struct . unpack_from ( '=BBBBB' , rrstr [ : 7 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRSPRecord . length ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) if check_byte1 != 0xbe or check_byte2 != 0xef : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid check bytes on rock ridge extension' ) self . _initialized = True | Parse a Rock Ridge Sharing Protocol record out of a string . | 210 | 13 |
20,045 | def new ( self , bytes_to_skip ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SP record already initialized!' ) self . bytes_to_skip = bytes_to_skip self . _initialized = True | Create a new Rock Ridge Sharing Protocol record . | 66 | 9 |
20,046 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SP record not yet initialized!' ) return b'SP' + struct . pack ( '=BBBBB' , RRSPRecord . length ( ) , SU_ENTRY_VERSION , 0xbe , 0xef , self . bytes_to_skip ) | Generate a string representing the Rock Ridge Sharing Protocol record . | 89 | 12 |
20,047 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'RR record already initialized!' ) self . rr_flags = 0 self . _initialized = True | Create a new Rock Ridge Rock Ridge record . | 53 | 9 |
20,048 | def append_field ( self , fieldname ) : # type: (str) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'RR record not yet initialized!' ) if fieldname == 'PX' : bit = 0 elif fieldname == 'PN' : bit = 1 elif fieldname == 'SL' : bit = 2 elif fieldname == 'NM' : bit = 3 elif fieldname == 'CL' : bit = 4 elif fieldname == 'PL' : bit = 5 elif fieldname == 'RE' : bit = 6 elif fieldname == 'TF' : bit = 7 else : raise pycdlibexception . PyCdlibInternalError ( 'Unknown RR field name %s' % ( fieldname ) ) self . rr_flags |= ( 1 << bit ) | Mark a field as present in the Rock Ridge records . | 187 | 11 |
20,049 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'RR record not yet initialized!' ) return b'RR' + struct . pack ( '=BBB' , RRRRRecord . length ( ) , SU_ENTRY_VERSION , self . rr_flags ) | Generate a string representing the Rock Ridge Rock Ridge record . | 80 | 12 |
20,050 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CE record already initialized!' ) ( su_len , su_entry_version_unused , bl_cont_area_le , bl_cont_area_be , offset_cont_area_le , offset_cont_area_be , len_cont_area_le , len_cont_area_be ) = struct . unpack_from ( '=BBLLLLLL' , rrstr [ : 28 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRCERecord . length ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) if bl_cont_area_le != utils . swab_32bit ( bl_cont_area_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'CE record big and little endian continuation area do not agree' ) if offset_cont_area_le != utils . swab_32bit ( offset_cont_area_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'CE record big and little endian continuation area offset do not agree' ) if len_cont_area_le != utils . swab_32bit ( len_cont_area_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'CE record big and little endian continuation area length do not agree' ) self . bl_cont_area = bl_cont_area_le self . offset_cont_area = offset_cont_area_le self . len_cont_area = len_cont_area_le self . _initialized = True | Parse a Rock Ridge Continuation Entry record out of a string . | 415 | 14 |
20,051 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CE record already initialized!' ) self . bl_cont_area = 0 # This will get set during reshuffle_extents self . offset_cont_area = 0 # This will get set during reshuffle_extents self . len_cont_area = 0 # This will be calculated based on fields put in self . _initialized = True | Create a new Rock Ridge Continuation Entry record . | 104 | 10 |
20,052 | def update_extent ( self , extent ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CE record not yet initialized!' ) self . bl_cont_area = extent | Update the extent for this CE record . | 57 | 8 |
20,053 | def update_offset ( self , offset ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CE record not yet initialized!' ) self . offset_cont_area = offset | Update the offset for this CE record . | 56 | 8 |
20,054 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CE record not yet initialized!' ) return b'CE' + struct . pack ( '=BBLLLLLL' , RRCERecord . length ( ) , SU_ENTRY_VERSION , self . bl_cont_area , utils . swab_32bit ( self . bl_cont_area ) , self . offset_cont_area , utils . swab_32bit ( self . offset_cont_area ) , self . len_cont_area , utils . swab_32bit ( self . len_cont_area ) ) | Generate a string representing the Rock Ridge Continuation Entry record . | 154 | 13 |
20,055 | def parse ( self , rrstr ) : # type: (bytes) -> int if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PX record already initialized!' ) ( su_len , su_entry_version_unused , posix_file_mode_le , posix_file_mode_be , posix_file_links_le , posix_file_links_be , posix_file_user_id_le , posix_file_user_id_be , posix_file_group_id_le , posix_file_group_id_be ) = struct . unpack_from ( '=BBLLLLLLLL' , rrstr [ : 38 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if posix_file_mode_le != utils . swab_32bit ( posix_file_mode_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'PX record big and little-endian file mode do not agree' ) if posix_file_links_le != utils . swab_32bit ( posix_file_links_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'PX record big and little-endian file links do not agree' ) if posix_file_user_id_le != utils . swab_32bit ( posix_file_user_id_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'PX record big and little-endian file user ID do not agree' ) if posix_file_group_id_le != utils . swab_32bit ( posix_file_group_id_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'PX record big and little-endian file group ID do not agree' ) # In Rock Ridge 1.09 and 1.10, there is no serial number so the su_len # is 36, while in Rock Ridge 1.12, there is an 8-byte serial number so # su_len is 44. if su_len == 36 : posix_file_serial_number_le = 0 elif su_len == 44 : ( posix_file_serial_number_le , posix_file_serial_number_be ) = struct . unpack_from ( '=LL' , rrstr [ : 44 ] , 36 ) if posix_file_serial_number_le != utils . swab_32bit ( posix_file_serial_number_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'PX record big and little-endian file serial number do not agree' ) else : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on Rock Ridge PX record' ) self . posix_file_mode = posix_file_mode_le self . posix_file_links = posix_file_links_le self . posix_user_id = posix_file_user_id_le self . posix_group_id = posix_file_group_id_le self . posix_serial_number = posix_file_serial_number_le self . _initialized = True return su_len | Parse a Rock Ridge POSIX File Attributes record out of a string . | 756 | 15 |
20,056 | def new ( self , mode ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PX record already initialized!' ) self . posix_file_mode = mode self . posix_file_links = 1 self . posix_user_id = 0 self . posix_group_id = 0 self . posix_serial_number = 0 self . _initialized = True | Create a new Rock Ridge POSIX File Attributes record . | 100 | 11 |
20,057 | def record ( self , rr_version ) : # type: (str) -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PX record not yet initialized!' ) outlist = [ b'PX' , struct . pack ( '=BBLLLLLLLL' , RRPXRecord . length ( rr_version ) , SU_ENTRY_VERSION , self . posix_file_mode , utils . swab_32bit ( self . posix_file_mode ) , self . posix_file_links , utils . swab_32bit ( self . posix_file_links ) , self . posix_user_id , utils . swab_32bit ( self . posix_user_id ) , self . posix_group_id , utils . swab_32bit ( self . posix_group_id ) ) ] if rr_version == '1.12' : outlist . append ( struct . pack ( '=LL' , self . posix_serial_number , utils . swab_32bit ( self . posix_serial_number ) ) ) # The rr_version can never be "wrong" at this point; if it was, it would # have thrown an exception earlier when calling length(). So just skip # any potential checks here. return b'' . join ( outlist ) | Generate a string representing the Rock Ridge POSIX File Attributes record . | 310 | 14 |
20,058 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ER record already initialized!' ) ( su_len , su_entry_version_unused , len_id , len_des , len_src , self . ext_ver ) = struct . unpack_from ( '=BBBBBB' , rrstr [ : 8 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. # Ensure that the length isn't crazy if su_len > len ( rrstr ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Length of ER record much too long' ) # Also ensure that the combination of len_id, len_des, and len_src # doesn't overrun su_len; because of the check above, this means it # can't overrun len(rrstr) either total_length = len_id + len_des + len_src if total_length > su_len : raise pycdlibexception . PyCdlibInvalidISO ( 'Combined length of ER ID, des, and src longer than record' ) fmtstr = '=%ds%ds%ds' % ( len_id , len_des , len_src ) ( self . ext_id , self . ext_des , self . ext_src ) = struct . unpack_from ( fmtstr , rrstr , 8 ) self . _initialized = True | Parse a Rock Ridge Extensions Reference record out of a string . | 338 | 13 |
20,059 | def new ( self , ext_id , ext_des , ext_src ) : # type: (bytes, bytes, bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ER record already initialized!' ) self . ext_id = ext_id self . ext_des = ext_des self . ext_src = ext_src self . ext_ver = 1 self . _initialized = True | Create a new Rock Ridge Extensions Reference record . | 97 | 9 |
20,060 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ER record not yet initialized!' ) return b'ER' + struct . pack ( '=BBBBBB' , RRERRecord . length ( self . ext_id , self . ext_des , self . ext_src ) , SU_ENTRY_VERSION , len ( self . ext_id ) , len ( self . ext_des ) , len ( self . ext_src ) , self . ext_ver ) + self . ext_id + self . ext_des + self . ext_src | Generate a string representing the Rock Ridge Extensions Reference record . | 141 | 12 |
20,061 | def length ( ext_id , ext_des , ext_src ) : # type: (bytes, bytes, bytes) -> int return 8 + len ( ext_id ) + len ( ext_des ) + len ( ext_src ) | Static method to return the length of the Rock Ridge Extensions Reference record . | 51 | 14 |
20,062 | def new ( self , extension_sequence ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ES record already initialized!' ) self . extension_sequence = extension_sequence self . _initialized = True | Create a new Rock Ridge Extension Selector record . | 60 | 10 |
20,063 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ES record not yet initialized!' ) return b'ES' + struct . pack ( '=BBB' , RRESRecord . length ( ) , SU_ENTRY_VERSION , self . extension_sequence ) | Generate a string representing the Rock Ridge Extension Selector record . | 78 | 13 |
20,064 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PN record already initialized!' ) ( su_len , su_entry_version_unused , dev_t_high_le , dev_t_high_be , dev_t_low_le , dev_t_low_be ) = struct . unpack_from ( '=BBLLLL' , rrstr [ : 20 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != RRPNRecord . length ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) if dev_t_high_le != utils . swab_32bit ( dev_t_high_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Dev_t high little-endian does not match big-endian' ) if dev_t_low_le != utils . swab_32bit ( dev_t_low_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Dev_t low little-endian does not match big-endian' ) self . dev_t_high = dev_t_high_le self . dev_t_low = dev_t_low_le self . _initialized = True | Parse a Rock Ridge POSIX Device Number record out of a string . | 329 | 15 |
20,065 | def new ( self , dev_t_high , dev_t_low ) : # type: (int, int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PN record already initialized!' ) self . dev_t_high = dev_t_high self . dev_t_low = dev_t_low self . _initialized = True | Create a new Rock Ridge POSIX device number record . | 87 | 11 |
20,066 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PN record not yet initialized!' ) return b'PN' + struct . pack ( '=BBLLLL' , RRPNRecord . length ( ) , SU_ENTRY_VERSION , self . dev_t_high , utils . swab_32bit ( self . dev_t_high ) , self . dev_t_low , utils . swab_32bit ( self . dev_t_low ) ) | Generate a string representing the Rock Ridge POSIX Device Number record . | 125 | 14 |
20,067 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record already initialized!' ) ( su_len , su_entry_version_unused , self . flags ) = struct . unpack_from ( '=BBB' , rrstr [ : 5 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. cr_offset = 5 data_len = su_len - 5 while data_len > 0 : ( cr_flags , len_cp ) = struct . unpack_from ( '=BB' , rrstr [ : cr_offset + 2 ] , cr_offset ) data_len -= 2 cr_offset += 2 self . symlink_components . append ( self . Component ( cr_flags , len_cp , rrstr [ cr_offset : cr_offset + len_cp ] ) ) # FIXME: if this is the last component in this SL record, # but the component continues on in the next SL record, we will # fail to record this bit. We should fix that. cr_offset += len_cp data_len -= len_cp self . _initialized = True | Parse a Rock Ridge Symbolic Link record out of a string . | 281 | 14 |
20,068 | def add_component ( self , symlink_comp ) : # type: (bytes) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) if ( self . current_length ( ) + RRSLRecord . Component . length ( symlink_comp ) ) > 255 : raise pycdlibexception . PyCdlibInvalidInput ( 'Symlink would be longer than 255' ) self . symlink_components . append ( self . Component . factory ( symlink_comp ) ) | Add a new component to this symlink record . | 129 | 11 |
20,069 | def current_length ( self ) : # type: () -> int if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) strlist = [ ] for comp in self . symlink_components : strlist . append ( comp . name ( ) ) return RRSLRecord . length ( strlist ) | Calculate the current length of this symlink record . | 82 | 13 |
20,070 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) outlist = [ b'SL' , struct . pack ( '=BBB' , self . current_length ( ) , SU_ENTRY_VERSION , self . flags ) ] for comp in self . symlink_components : outlist . append ( comp . record ( ) ) return b'' . join ( outlist ) | Generate a string representing the Rock Ridge Symbolic Link record . | 112 | 13 |
20,071 | def name ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) outlist = [ ] # type: List[bytes] continued = False for comp in self . symlink_components : name = comp . name ( ) if name == b'/' : outlist = [ ] continued = False name = b'' if not continued : outlist . append ( name ) else : outlist [ - 1 ] += name continued = comp . is_continued ( ) return b'/' . join ( outlist ) | Generate a string that contains all components of the symlink . | 135 | 14 |
20,072 | def set_last_component_continued ( self ) : # type: () -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) if not self . symlink_components : raise pycdlibexception . PyCdlibInternalError ( 'Trying to set continued on a non-existent component!' ) self . symlink_components [ - 1 ] . set_continued ( ) | Set the previous component of this SL record to continued . | 106 | 11 |
20,073 | def last_component_continued ( self ) : # type: () -> bool if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SL record not yet initialized!' ) if not self . symlink_components : raise pycdlibexception . PyCdlibInternalError ( 'Trying to get continued on a non-existent component!' ) return self . symlink_components [ - 1 ] . is_continued ( ) | Determines whether the previous component of this SL record is a continued one or not . | 105 | 18 |
20,074 | def length ( symlink_components ) : # type: (List[bytes]) -> int length = RRSLRecord . header_length ( ) for comp in symlink_components : length += RRSLRecord . Component . length ( comp ) return length | Static method to return the length of the Rock Ridge Symbolic Link record . | 58 | 15 |
20,075 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'NM record already initialized!' ) ( su_len , su_entry_version_unused , self . posix_name_flags ) = struct . unpack_from ( '=BBB' , rrstr [ : 5 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. name_len = su_len - 5 if ( self . posix_name_flags & 0x7 ) not in ( 0 , 1 , 2 , 4 ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid Rock Ridge NM flags' ) if name_len != 0 : if ( self . posix_name_flags & ( 1 << 1 ) ) or ( self . posix_name_flags & ( 1 << 2 ) ) or ( self . posix_name_flags & ( 1 << 5 ) ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid name in Rock Ridge NM entry (0x%x %d)' % ( self . posix_name_flags , name_len ) ) self . posix_name += rrstr [ 5 : 5 + name_len ] self . _initialized = True | Parse a Rock Ridge Alternate Name record out of a string . | 303 | 13 |
20,076 | def new ( self , rr_name ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'NM record already initialized!' ) self . posix_name = rr_name self . posix_name_flags = 0 self . _initialized = True | Create a new Rock Ridge Alternate Name record . | 73 | 9 |
20,077 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'NM record not yet initialized!' ) return b'NM' + struct . pack ( b'=BBB' , RRNMRecord . length ( self . posix_name ) , SU_ENTRY_VERSION , self . posix_name_flags ) + self . posix_name | Generate a string representing the Rock Ridge Alternate Name record . | 95 | 12 |
20,078 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CL record already initialized!' ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. ( su_len , su_entry_version_unused , child_log_block_num_le , child_log_block_num_be ) = struct . unpack_from ( '=BBLL' , rrstr [ : 12 ] , 2 ) if su_len != RRCLRecord . length ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) if child_log_block_num_le != utils . swab_32bit ( child_log_block_num_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Little endian block num does not equal big endian; corrupt ISO' ) self . child_log_block_num = child_log_block_num_le self . _initialized = True | Parse a Rock Ridge Child Link record out of a string . | 249 | 13 |
20,079 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CL record already initialized!' ) self . child_log_block_num = 0 # This gets set later self . _initialized = True | Create a new Rock Ridge Child Link record . | 61 | 9 |
20,080 | def set_log_block_num ( self , bl ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'CL record not yet initialized!' ) self . child_log_block_num = bl | Set the logical block number for the child . | 62 | 9 |
20,081 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PL record already initialized!' ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. ( su_len , su_entry_version_unused , parent_log_block_num_le , parent_log_block_num_be ) = struct . unpack_from ( '=BBLL' , rrstr [ : 12 ] , 2 ) if su_len != RRPLRecord . length ( ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) if parent_log_block_num_le != utils . swab_32bit ( parent_log_block_num_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Little endian block num does not equal big endian; corrupt ISO' ) self . parent_log_block_num = parent_log_block_num_le self . _initialized = True | Parse a Rock Ridge Parent Link record out of a string . | 249 | 13 |
20,082 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PL record already initialized!' ) self . parent_log_block_num = 0 # This will get set later self . _initialized = True | Generate a string representing the Rock Ridge Parent Link record . | 62 | 12 |
20,083 | def set_log_block_num ( self , bl ) : # type: (int) -> None if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PL record not yet initialized!' ) self . parent_log_block_num = bl | Set the logical block number for the parent . | 62 | 9 |
20,084 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'TF record already initialized!' ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. ( su_len , su_entry_version_unused , self . time_flags , ) = struct . unpack_from ( '=BBB' , rrstr [ : 5 ] , 2 ) if su_len < 5 : raise pycdlibexception . PyCdlibInvalidISO ( 'Not enough bytes in the TF record' ) tflen = 7 if self . time_flags & ( 1 << 7 ) : tflen = 17 offset = 5 for index , fieldname in enumerate ( self . FIELDNAMES ) : if self . time_flags & ( 1 << index ) : if tflen == 7 : setattr ( self , fieldname , dates . DirectoryRecordDate ( ) ) elif tflen == 17 : setattr ( self , fieldname , dates . VolumeDescriptorDate ( ) ) getattr ( self , fieldname ) . parse ( rrstr [ offset : offset + tflen ] ) offset += tflen self . _initialized = True | Parse a Rock Ridge Time Stamp record out of a string . | 284 | 13 |
20,085 | def new ( self , time_flags ) : # type: (int) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'TF record already initialized!' ) self . time_flags = time_flags tflen = 7 if self . time_flags & ( 1 << 7 ) : tflen = 17 for index , fieldname in enumerate ( self . FIELDNAMES ) : if self . time_flags & ( 1 << index ) : if tflen == 7 : setattr ( self , fieldname , dates . DirectoryRecordDate ( ) ) elif tflen == 17 : setattr ( self , fieldname , dates . VolumeDescriptorDate ( ) ) getattr ( self , fieldname ) . new ( ) self . _initialized = True | Create a new Rock Ridge Time Stamp record . | 174 | 9 |
20,086 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'TF record not yet initialized!' ) outlist = [ b'TF' , struct . pack ( '=BBB' , RRTFRecord . length ( self . time_flags ) , SU_ENTRY_VERSION , self . time_flags ) ] for fieldname in self . FIELDNAMES : field = getattr ( self , fieldname ) if field is not None : outlist . append ( field . record ( ) ) return b'' . join ( outlist ) | Generate a string representing the Rock Ridge Time Stamp record . | 134 | 12 |
20,087 | def length ( time_flags ) : # type: (int) -> int tf_each_size = 7 if time_flags & ( 1 << 7 ) : tf_each_size = 17 time_flags &= 0x7f tf_num = 0 while time_flags : time_flags &= time_flags - 1 tf_num += 1 return 5 + tf_each_size * tf_num | Static method to return the length of the Rock Ridge Time Stamp record . | 87 | 14 |
20,088 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SF record already initialized!' ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. ( su_len , su_entry_version_unused , ) = struct . unpack_from ( '=BB' , rrstr [ : 4 ] , 2 ) if su_len == 12 : # This is a Rock Ridge version 1.10 SF Record, which is 12 bytes. ( virtual_file_size_le , virtual_file_size_be ) = struct . unpack_from ( '=LL' , rrstr [ : 12 ] , 4 ) if virtual_file_size_le != utils . swab_32bit ( virtual_file_size_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Virtual file size little-endian does not match big-endian' ) self . virtual_file_size_low = virtual_file_size_le elif su_len == 21 : # This is a Rock Ridge version 1.12 SF Record, which is 21 bytes. ( virtual_file_size_high_le , virtual_file_size_high_be , virtual_file_size_low_le , virtual_file_size_low_be , self . table_depth ) = struct . unpack_from ( '=LLLLB' , rrstr [ : 21 ] , 4 ) if virtual_file_size_high_le != utils . swab_32bit ( virtual_file_size_high_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Virtual file size high little-endian does not match big-endian' ) if virtual_file_size_low_le != utils . swab_32bit ( virtual_file_size_low_be ) : raise pycdlibexception . PyCdlibInvalidISO ( 'Virtual file size low little-endian does not match big-endian' ) self . virtual_file_size_low = virtual_file_size_low_le self . virtual_file_size_high = virtual_file_size_high_le else : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on Rock Ridge SF record (expected 12 or 21)' ) self . _initialized = True | Parse a Rock Ridge Sparse File record out of a string . | 545 | 14 |
20,089 | def new ( self , file_size_high , file_size_low , table_depth ) : # type: (Optional[int], int, Optional[int]) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SF record already initialized!' ) self . virtual_file_size_high = file_size_high self . virtual_file_size_low = file_size_low self . table_depth = table_depth self . _initialized = True | Create a new Rock Ridge Sparse File record . | 110 | 10 |
20,090 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'SF record not yet initialized!' ) length = 12 if self . virtual_file_size_high is not None : length = 21 ret = b'SF' + struct . pack ( '=BB' , length , SU_ENTRY_VERSION ) if self . virtual_file_size_high is not None and self . table_depth is not None : ret += struct . pack ( '=LLLLB' , self . virtual_file_size_high , utils . swab_32bit ( self . virtual_file_size_high ) , self . virtual_file_size_low , utils . swab_32bit ( self . virtual_file_size_low ) , self . table_depth ) else : ret += struct . pack ( '=LL' , self . virtual_file_size_low , utils . swab_32bit ( self . virtual_file_size_low ) ) return ret | Generate a string representing the Rock Ridge Sparse File record . | 233 | 13 |
20,091 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'RE record not yet initialized!' ) return b'RE' + struct . pack ( '=BB' , RRRERecord . length ( ) , SU_ENTRY_VERSION ) | Generate a string representing the Rock Ridge Relocated Directory record . | 73 | 13 |
20,092 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ST record already initialized!' ) ( su_len , su_entry_version_unused ) = struct . unpack_from ( '=BB' , rrstr [ : 4 ] , 2 ) # We assume that the caller has already checked the su_entry_version, # so we don't bother. if su_len != 4 : raise pycdlibexception . PyCdlibInvalidISO ( 'Invalid length on rock ridge extension' ) self . _initialized = True | Parse a Rock Ridge System Terminator record out of a string . | 141 | 13 |
20,093 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'ST record not yet initialized!' ) return b'ST' + struct . pack ( '=BB' , RRSTRecord . length ( ) , SU_ENTRY_VERSION ) | Generate a string representing the Rock Ridge System Terminator record . | 71 | 12 |
20,094 | def parse ( self , rrstr ) : # type: (bytes) -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PD record already initialized!' ) ( su_len_unused , su_entry_version_unused ) = struct . unpack_from ( '=BB' , rrstr [ : 4 ] , 2 ) self . padding = rrstr [ 4 : ] # We assume that the caller has already checked the su_entry_version, # so we don't bother. self . _initialized = True | Parse a Rock Ridge Platform Dependent record out of a string . | 125 | 14 |
20,095 | def new ( self ) : # type: () -> None if self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PD record already initialized!' ) self . _initialized = True self . padding = b'' | Create a new Rock Ridge Platform Dependent record . | 51 | 10 |
20,096 | def record ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'PD record not yet initialized!' ) return b'PD' + struct . pack ( '=BB' , RRPDRecord . length ( self . padding ) , SU_ENTRY_VERSION ) + self . padding | Generate a string representing the Rock Ridge Platform Dependent record . | 78 | 13 |
20,097 | def has_entry ( self , name ) : # type: (str) -> bool return getattr ( self . dr_entries , name ) or getattr ( self . ce_entries , name ) | An internal method to tell if we have already parsed an entry of the named type . | 44 | 17 |
20,098 | def _record ( self , entries ) : # type: (RockRidgeEntries) -> bytes outlist = [ ] if entries . sp_record is not None : outlist . append ( entries . sp_record . record ( ) ) if entries . rr_record is not None : outlist . append ( entries . rr_record . record ( ) ) for nm_record in entries . nm_records : outlist . append ( nm_record . record ( ) ) if entries . px_record is not None : outlist . append ( entries . px_record . record ( self . rr_version ) ) for sl_record in entries . sl_records : outlist . append ( sl_record . record ( ) ) if entries . tf_record is not None : outlist . append ( entries . tf_record . record ( ) ) if entries . cl_record is not None : outlist . append ( entries . cl_record . record ( ) ) if entries . pl_record is not None : outlist . append ( entries . pl_record . record ( ) ) if entries . re_record is not None : outlist . append ( entries . re_record . record ( ) ) for es_record in entries . es_records : outlist . append ( es_record . record ( ) ) if entries . er_record is not None : outlist . append ( entries . er_record . record ( ) ) if entries . ce_record is not None : outlist . append ( entries . ce_record . record ( ) ) for pd_record in entries . pd_records : outlist . append ( pd_record . record ( ) ) if entries . st_record is not None : outlist . append ( entries . st_record . record ( ) ) if entries . sf_record is not None : outlist . append ( entries . sf_record . record ( ) ) return b'' . join ( outlist ) | Return a string representing the Rock Ridge entry . | 425 | 9 |
20,099 | def record_dr_entries ( self ) : # type: () -> bytes if not self . _initialized : raise pycdlibexception . PyCdlibInternalError ( 'Rock Ridge extension not yet initialized' ) return self . _record ( self . dr_entries ) | Return a string representing the Rock Ridge entries in the Directory Record . | 60 | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.