Commit 8be66d11bad052a5dfcf7b6ef3c56c2783641d88

Authored by Christian Herdtweck
1 parent 97035144

record_base: make pylint and pep8 happier

Showing 1 changed file with 19 additions and 16 deletions
oletools/record_base.py
... ... @@ -5,7 +5,7 @@ record_base.py
5 5  
6 6 Common stuff for ole files whose streams are a sequence of record structures.
7 7 This is the case for xls and ppt, so classes are bases for xls_parser.py and
8   -ppt_parser.py .
  8 +ppt_record_parser.py .
9 9 """
10 10  
11 11 # === LICENSE =================================================================
... ... @@ -33,11 +33,11 @@ ppt_parser.py .
33 33  
34 34 from __future__ import print_function
35 35  
36   -#------------------------------------------------------------------------------
  36 +# -----------------------------------------------------------------------------
37 37 # CHANGELOG:
38 38 # 2017-11-30 v0.01 CH: - first version based on xls_parser
39 39  
40   -#------------------------------------------------------------------------------
  40 +# -----------------------------------------------------------------------------
41 41 # TODO:
42 42 # - read DocumentSummaryInformation first to get more info about streams
43 43 # (maybe content type or so; identify streams that are never record-based)
... ... @@ -57,16 +57,17 @@ import os.path
57 57 from io import SEEK_CUR
58 58 import logging
59 59  
60   -# little hack to allow absolute imports even if oletools is not installed.
61   -# Copied from olevba.py
62   -_thismodule_dir = os.path.normpath(os.path.abspath(os.path.dirname(__file__))) # pylint: disable=invalid-name
63   -_parent_dir = os.path.normpath(os.path.join(_thismodule_dir, '..')) # pylint: disable=invalid-name
64   -del _thismodule_dir
65   -if _parent_dir not in sys.path:
66   - sys.path.insert(0, _parent_dir)
67   -del _parent_dir
68   -
69   -from oletools.thirdparty import olefile
  60 +try:
  61 + from oletools.thirdparty import olefile
  62 +except ImportError:
  63 + # little hack to allow absolute imports even if oletools is not installed.
  64 + # Copied from olevba.py
  65 + PARENT_DIR = os.path.normpath(os.path.dirname(os.path.dirname(
  66 + os.path.abspath(__file__))))
  67 + if PARENT_DIR not in sys.path:
  68 + sys.path.insert(0, PARENT_DIR)
  69 + del PARENT_DIR
  70 + from oletools.thirdparty import olefile
70 71  
71 72  
72 73 ###############################################################################
... ... @@ -100,6 +101,7 @@ ENTRY_TYPE2STR = {
100 101 SUMMARY_INFORMATION_STREAM_NAMES = ('\x05SummaryInformation',
101 102 '\x05DocumentSummaryInformation')
102 103  
  104 +
103 105 class OleRecordFile(olefile.OleFileIO):
104 106 """ an OLE compound file whose streams have (mostly) record structure
105 107  
... ... @@ -211,7 +213,7 @@ class OleRecordStream(object):
211 213 data = None
212 214 rec_object = rec_clz(rec_type, rec_size, other, pos, data)
213 215  
214   - # "We are microsoft, we do not have to adhere to our specifications"
  216 + # "We are microsoft, we do not always adhere to our specifications"
215 217 rec_object.read_some_more(self.stream)
216 218 yield rec_object
217 219  
... ... @@ -235,7 +237,7 @@ class OleSummaryInformationStream(OleRecordStream):
235 237 def iter_records(self, fill_data=False):
236 238 """ yields nothing, stops at once """
237 239 return
238   - yield
  240 + yield # required to make this a generator pylint: disable=unreachable
239 241  
240 242  
241 243 class OleRecordBase(object):
... ... @@ -327,7 +329,8 @@ def test(filenames, ole_file_class=OleRecordFile,
327 329 """
328 330 logging.basicConfig(level=logging.INFO)
329 331 if do_per_record is None:
330   - do_per_record = lambda record: None
  332 + def do_per_record(record):
  333 + pass # do nothing
331 334 if not filenames:
332 335 logging.info('need file name[s]')
333 336 return 2
... ...