Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_validity(self, offset=None):
errs = self.check_rec_head()
errs.extend(self.check_value('minorVersion', self.minor_version,
self.MINOR_VERSION))
errs.extend(self.check_value('majorVersion', self.major_version,
self.MAJOR_VERSION))
if offset is not None:
if self.offset_last_edit >= offset:
errs.append(PptUnexpectedData(
'PowerPoint Document', 'UserEditAtom.offsetLastEdit',
self.offset_last_edit, '< {0}'.format(offset)))
if self.offset_persist_directory >= offset or \
self.offset_persist_directory <= self.offset_last_edit:
errs.append(PptUnexpectedData(
'PowerPoint Document',
'UserEditAtom.offsetPersistDirectory',
self.offset_last_edit,
'in ({0}, {1})'.format(self.offset_last_edit, offset)))
errs.extend(self.check_value('docPersistIdRef',
self.doc_persist_id_ref, 1))
return errs
def check_validity(self, offset=None):
errs = self.check_rec_head()
errs.extend(self.check_value('minorVersion', self.minor_version,
self.MINOR_VERSION))
errs.extend(self.check_value('majorVersion', self.major_version,
self.MAJOR_VERSION))
if offset is not None:
if self.offset_last_edit >= offset:
errs.append(PptUnexpectedData(
'PowerPoint Document', 'UserEditAtom.offsetLastEdit',
self.offset_last_edit, '< {0}'.format(offset)))
if self.offset_persist_directory >= offset or \
self.offset_persist_directory <= self.offset_last_edit:
errs.append(PptUnexpectedData(
'PowerPoint Document',
'UserEditAtom.offsetPersistDirectory',
self.offset_last_edit,
'in ({0}, {1})'.format(self.offset_last_edit, offset)))
errs.extend(self.check_value('docPersistIdRef',
self.doc_persist_id_ref, 1))
return errs
def check_value(name, value, expected):
""" simplify verification of values in extract_from """
if isinstance(expected, (list, tuple)):
if value not in expected:
exp_str = '[' + ' OR '.join('{0:04X}'.format(val)
for val in expected) + ']'
raise PptUnexpectedData(
'Current User', name,
'{0:04X}'.format(value), exp_str)
elif expected != value:
raise PptUnexpectedData(
'Current User', name,
'{0:04X}'.format(value), '{0:04X}'.format(expected))
def check_value(self, name, value, expected):
""" simplify verification of values: check value equals/is in expected
:returns: list of PptUnexpectedData exceptions
"""
if isinstance(expected, (list, tuple)):
if value not in expected:
clz_name = self.__class__.__name__
exp_str = '[' + ' OR '.join('{0:04X}'.format(val)
for val in expected) + ']'
return [PptUnexpectedData(
self.stream_name, clz_name + '.' + name,
'{0:04X}'.format(value), exp_str), ]
elif expected != value:
clz_name = self.__class__.__name__
return [PptUnexpectedData(
self.stream_name, clz_name + '.' + name,
'{0:04X}'.format(value), '{0:04X}'.format(expected)), ]
return []
def check_value(self, name, value, expected):
""" simplify verification of values: check value equals/is in expected
:returns: list of PptUnexpectedData exceptions
"""
if isinstance(expected, (list, tuple)):
if value not in expected:
clz_name = self.__class__.__name__
exp_str = '[' + ' OR '.join('{0:04X}'.format(val)
for val in expected) + ']'
return [PptUnexpectedData(
self.stream_name, clz_name + '.' + name,
'{0:04X}'.format(value), exp_str), ]
elif expected != value:
clz_name = self.__class__.__name__
return [PptUnexpectedData(
self.stream_name, clz_name + '.' + name,
'{0:04X}'.format(value), '{0:04X}'.format(expected)), ]
return []
def _fail(self, *args):
""" depending on self.fast_fail raise PptUnexpectedData or just log err
args as for PptUnexpectedData
"""
if self.fast_fail:
raise PptUnexpectedData(*args)
else:
self._log_exception(PptUnexpectedData(*args).msg)
MAIN_STREAM_NAME, 'PersistDirectoryEntry.persist_id',
self.persist_id, '< 0xFFFFE (dec: {0})'.format(0xFFFFE)))
if self.c_persist == 0:
errs.append(PptUnexpectedData(
MAIN_STREAM_NAME, 'PersistDirectoryEntry.c_persist',
self.c_persist, '> 0'))
if user_edit_last_offset is not None \
and min(self.rg_persist_offset) < user_edit_last_offset:
errs.append(PptUnexpectedData(
MAIN_STREAM_NAME, 'PersistDirectoryEntry.rg_persist_offset',
min(self.rg_persist_offset),
'> UserEdit.offsetLastEdit ({0})'
.format(user_edit_last_offset)))
if persist_obj_dir_offset is not None \
and max(self.rg_persist_offset) > persist_obj_dir_offset:
errs.append(PptUnexpectedData(
MAIN_STREAM_NAME, 'PersistDirectoryEntry.rg_persist_offset',
max(self.rg_persist_offset),
'> PersistObjectDirectory offset ({0})'
.format(persist_obj_dir_offset)))
return errs
def check_value(name, value, expected):
""" simplify verification of values in extract_from """
if isinstance(expected, (list, tuple)):
if value not in expected:
exp_str = '[' + ' OR '.join('{0:04X}'.format(val)
for val in expected) + ']'
raise PptUnexpectedData(
'Current User', name,
'{0:04X}'.format(value), exp_str)
elif expected != value:
raise PptUnexpectedData(
'Current User', name,
'{0:04X}'.format(value), '{0:04X}'.format(expected))