Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_dirrecorddate_record_not_initialized():
drdate = pycdlib.dates.DirectoryRecordDate()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
drdate.record()
assert(str(excinfo.value) == 'Directory Record Date not initialized')
def test_dirrecorddate_new_after_new():
drdate = pycdlib.dates.DirectoryRecordDate()
drdate.new()
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
drdate.new()
assert(str(excinfo.value) == 'Directory Record Date already initialized')
def test_dirrecorddate_parse_after_parse():
drdate = pycdlib.dates.DirectoryRecordDate()
drdate.parse(b'\x76\x07\x12\x15\x21\x00\x00')
with pytest.raises(pycdlib.pycdlibexception.PyCdlibInternalError) as excinfo:
drdate.parse(b'\x76\x07\x12\x15\x21\x00\x00')
assert(str(excinfo.value) == 'Directory Record Date already initialized')
if extent_location_le != utils.swab_32bit(extent_location_be):
raise pycdlibexception.PyCdlibInvalidISO('Little-endian (%d) and big-endian (%d) extent location disagree' % (extent_location_le, utils.swab_32bit(extent_location_be)))
self.orig_extent_loc = extent_location_le
# Theoretically, we should check to make sure that the little endian
# data length is the same as the big endian data length. In practice,
# though, we've seen ISOs where this is wrong. Skip the check, and just
# pick the little-endian as the 'actual' size, and hope for the best.
self.data_length = data_length_le
if seqnum_le != utils.swab_16bit(seqnum_be):
raise pycdlibexception.PyCdlibInvalidISO('Little-endian and big-endian seqnum disagree')
self.seqnum = seqnum_le
self.date = dates.DirectoryRecordDate()
self.date.parse(dr_date)
# OK, we've unpacked what we can from the beginning of the string. Now
# we have to use the len_fi to get the rest.
self.parent = parent
self.vd = vd
if self.parent is None:
self.is_root = True
# A root directory entry should always be exactly 34 bytes.
# However, we have seen ISOs in the wild that get this wrong, so we
# elide a check for it.
self.file_ident = bytes(bytearray([record[33]]))
length - The length of the data for this directory record.
xa - True if this is an Extended Attribute record.
Returns:
Nothing.
'''
# 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)
# 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
Returns:
Nothing.
'''
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