Skip to content

Commit

Permalink
Code clean up (#4631)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Apr 16, 2023
1 parent 54e8c02 commit 6bad739
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions plaso/engine/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,14 @@ def _ParseFileEntryWithParser(

# We catch IOError so we can determine the parser that generated the error.
except (IOError, dfvfs_errors.BackEndError) as exception:
display_name = parser_mediator.GetDisplayName(file_entry)
display_name = parser_mediator.GetDisplayName(file_entry=file_entry)
logger.warning(
'{0:s} unable to parse file: {1:s} with error: {2!s}'.format(
parser.NAME, display_name, exception))
result = self._PARSE_RESULT_FAILURE

except errors.WrongParser as exception:
display_name = parser_mediator.GetDisplayName(file_entry)
display_name = parser_mediator.GetDisplayName(file_entry=file_entry)
logger.debug(
'{0:s} unable to parse file: {1:s} with error: {2!s}'.format(
parser.NAME, display_name, exception))
Expand Down Expand Up @@ -240,7 +240,7 @@ def _ParseFileEntryWithParsers(
parse_results = self._PARSE_RESULT_SUCCESS
continue

display_name = parser_mediator.GetDisplayName(file_entry)
display_name = parser_mediator.GetDisplayName(file_entry=file_entry)
logger.debug((
'[ParseFileEntryWithParsers] parsing file: {0:s} with parser: '
'{1:s}').format(display_name, parser_name))
Expand Down
4 changes: 1 addition & 3 deletions plaso/parsers/bencode_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ def ParseFileObject(self, parser_mediator, file_object):
if not self._BENCODE_RE.match(header_data):
raise errors.WrongParser('Not a valid Bencoded file.')

display_name = parser_mediator.GetDisplayName()
bencode_file = BencodeFile()

try:
bencode_file.Open(file_object)
except IOError as exception:
display_name = parser_mediator.GetDisplayName()
raise errors.WrongParser(
'[{0:s}] unable to parse file: {1:s} with error: {2!s}'.format(
self.NAME, display_name, exception))
Expand All @@ -186,8 +186,6 @@ def ParseFileObject(self, parser_mediator, file_object):
if parser_mediator.abort:
break

file_entry = parser_mediator.GetFileEntry()
display_name = parser_mediator.GetDisplayName(file_entry)
profiling_name = '/'.join([self.NAME, plugin.NAME])

parser_mediator.SampleFormatCheckStartTiming(profiling_name)
Expand Down
2 changes: 0 additions & 2 deletions plaso/parsers/czip.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ def ParseFileObject(self, parser_mediator, file_object):
if parser_mediator.abort:
break

file_entry = parser_mediator.GetFileEntry()
display_name = parser_mediator.GetDisplayName(file_entry)
profiling_name = '/'.join([self.NAME, plugin.NAME])

parser_mediator.SampleFormatCheckStartTiming(profiling_name)
Expand Down
4 changes: 2 additions & 2 deletions plaso/parsers/esedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ def ParseFileObject(self, parser_mediator, file_object):
'unable to open file with error: {0!s}'.format(exception))
return

display_name = parser_mediator.GetDisplayName()

# Compare the list of available plugin objects.
cache = ESEDBCache()
try:
for plugin_name, plugin in self._plugins_per_name.items():
if parser_mediator.abort:
break

file_entry = parser_mediator.GetFileEntry()
display_name = parser_mediator.GetDisplayName(file_entry)
profiling_name = '/'.join([self.NAME, plugin.NAME])

parser_mediator.SampleFormatCheckStartTiming(profiling_name)
Expand Down
4 changes: 2 additions & 2 deletions plaso/parsers/olecf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def ParseFileObject(self, parser_mediator, file_object):
if not root_item:
return

display_name = parser_mediator.GetDisplayName()

# Get a list of all items in the root item from the OLECF file.
item_names = [item.name for item in root_item.sub_items]

Expand All @@ -79,8 +81,6 @@ def ParseFileObject(self, parser_mediator, file_object):
if parser_mediator.abort:
break

file_entry = parser_mediator.GetFileEntry()
display_name = parser_mediator.GetDisplayName(file_entry)
profiling_name = '/'.join([self.NAME, plugin.NAME])

parser_mediator.SampleFormatCheckStartTiming(profiling_name)
Expand Down
3 changes: 1 addition & 2 deletions plaso/parsers/plist.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def ParseFileObject(self, parser_mediator, file_object):
parser_mediator.ProduceExtractionWarning(
'XML plist file with leading whitespace')

display_name = parser_mediator.GetDisplayName()
filename_lower_case = filename.lower()

try:
Expand All @@ -156,8 +157,6 @@ def ParseFileObject(self, parser_mediator, file_object):
if parser_mediator.abort:
break

file_entry = parser_mediator.GetFileEntry()
display_name = parser_mediator.GetDisplayName(file_entry)
profiling_name = '/'.join([self.NAME, plugin.NAME])

parser_mediator.SampleFormatCheckStartTiming(profiling_name)
Expand Down
4 changes: 2 additions & 2 deletions plaso/parsers/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def ParseFileEntry(self, parser_mediator, file_entry):
# Create a cache in which the resulting tables are cached.
cache = SQLiteCache()

display_name = parser_mediator.GetDisplayName(file_entry)
display_name = parser_mediator.GetDisplayName(file_entry=file_entry)

try:
for plugin in self._plugins_per_name.values():
Expand All @@ -465,7 +465,7 @@ def ParseFileEntry(self, parser_mediator, file_entry):
# Create a cache in which the resulting tables are cached.
cache = SQLiteCache()

display_name = parser_mediator.GetDisplayName(wal_file_entry)
display_name = parser_mediator.GetDisplayName(file_entry=wal_file_entry)

try:
for plugin in self._plugins_per_name.values():
Expand Down

0 comments on commit 6bad739

Please sign in to comment.