Commit db990feade91f26ca6ffcb9366fe96569fbab99b

Authored by Philippe Lagadec
Committed by GitHub
2 parents 5525fef1 97f3b648

Merge pull request #128 from williamgibb/wg_fix_exception

Update __init__ of UnexpectedDataError exception
Showing 1 changed file with 9 additions and 2 deletions
oletools/olevba.py
... ... @@ -385,10 +385,17 @@ class UnexpectedDataError(OlevbaBaseException):
385 385 """ raised when parsing is strict (=not relaxed) and data is unexpected """
386 386  
387 387 def __init__(self, stream_path, variable, expected, value):
  388 + if isinstance(expected, int):
  389 + es = '{0:04X}'.format(expected)
  390 + elif isinstance(expected, tuple):
  391 + es = ','.join('{0:04X}'.format(e) for e in expected)
  392 + es = '({0})'.format(es)
  393 + else:
  394 + raise ValueError('Unknown type encountered: {0}'.format(type(expected)))
388 395 super(UnexpectedDataError, self).__init__(
389 396 'Unexpected value in {0} for variable {1}: '
390   - 'expected {2:04X} but found {3:04X}!'
391   - .format(stream_path, variable, expected, value))
  397 + 'expected {2} but found {3:04X}!'
  398 + .format(stream_path, variable, es, value))
392 399 self.stream_path = stream_path
393 400 self.variable = variable
394 401 self.expected = expected
... ...