Commit 8be66d11bad052a5dfcf7b6ef3c56c2783641d88
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,7 +5,7 @@ record_base.py | ||
| 5 | 5 | ||
| 6 | Common stuff for ole files whose streams are a sequence of record structures. | 6 | Common stuff for ole files whose streams are a sequence of record structures. |
| 7 | This is the case for xls and ppt, so classes are bases for xls_parser.py and | 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 | # === LICENSE ================================================================= | 11 | # === LICENSE ================================================================= |
| @@ -33,11 +33,11 @@ ppt_parser.py . | @@ -33,11 +33,11 @@ ppt_parser.py . | ||
| 33 | 33 | ||
| 34 | from __future__ import print_function | 34 | from __future__ import print_function |
| 35 | 35 | ||
| 36 | -#------------------------------------------------------------------------------ | 36 | +# ----------------------------------------------------------------------------- |
| 37 | # CHANGELOG: | 37 | # CHANGELOG: |
| 38 | # 2017-11-30 v0.01 CH: - first version based on xls_parser | 38 | # 2017-11-30 v0.01 CH: - first version based on xls_parser |
| 39 | 39 | ||
| 40 | -#------------------------------------------------------------------------------ | 40 | +# ----------------------------------------------------------------------------- |
| 41 | # TODO: | 41 | # TODO: |
| 42 | # - read DocumentSummaryInformation first to get more info about streams | 42 | # - read DocumentSummaryInformation first to get more info about streams |
| 43 | # (maybe content type or so; identify streams that are never record-based) | 43 | # (maybe content type or so; identify streams that are never record-based) |
| @@ -57,16 +57,17 @@ import os.path | @@ -57,16 +57,17 @@ import os.path | ||
| 57 | from io import SEEK_CUR | 57 | from io import SEEK_CUR |
| 58 | import logging | 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,6 +101,7 @@ ENTRY_TYPE2STR = { | ||
| 100 | SUMMARY_INFORMATION_STREAM_NAMES = ('\x05SummaryInformation', | 101 | SUMMARY_INFORMATION_STREAM_NAMES = ('\x05SummaryInformation', |
| 101 | '\x05DocumentSummaryInformation') | 102 | '\x05DocumentSummaryInformation') |
| 102 | 103 | ||
| 104 | + | ||
| 103 | class OleRecordFile(olefile.OleFileIO): | 105 | class OleRecordFile(olefile.OleFileIO): |
| 104 | """ an OLE compound file whose streams have (mostly) record structure | 106 | """ an OLE compound file whose streams have (mostly) record structure |
| 105 | 107 | ||
| @@ -211,7 +213,7 @@ class OleRecordStream(object): | @@ -211,7 +213,7 @@ class OleRecordStream(object): | ||
| 211 | data = None | 213 | data = None |
| 212 | rec_object = rec_clz(rec_type, rec_size, other, pos, data) | 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 | rec_object.read_some_more(self.stream) | 217 | rec_object.read_some_more(self.stream) |
| 216 | yield rec_object | 218 | yield rec_object |
| 217 | 219 | ||
| @@ -235,7 +237,7 @@ class OleSummaryInformationStream(OleRecordStream): | @@ -235,7 +237,7 @@ class OleSummaryInformationStream(OleRecordStream): | ||
| 235 | def iter_records(self, fill_data=False): | 237 | def iter_records(self, fill_data=False): |
| 236 | """ yields nothing, stops at once """ | 238 | """ yields nothing, stops at once """ |
| 237 | return | 239 | return |
| 238 | - yield | 240 | + yield # required to make this a generator pylint: disable=unreachable |
| 239 | 241 | ||
| 240 | 242 | ||
| 241 | class OleRecordBase(object): | 243 | class OleRecordBase(object): |
| @@ -327,7 +329,8 @@ def test(filenames, ole_file_class=OleRecordFile, | @@ -327,7 +329,8 @@ def test(filenames, ole_file_class=OleRecordFile, | ||
| 327 | """ | 329 | """ |
| 328 | logging.basicConfig(level=logging.INFO) | 330 | logging.basicConfig(level=logging.INFO) |
| 329 | if do_per_record is None: | 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 | if not filenames: | 334 | if not filenames: |
| 332 | logging.info('need file name[s]') | 335 | logging.info('need file name[s]') |
| 333 | return 2 | 336 | return 2 |