Cosmetic fixups
authorEli Bendersky <eliben@gmail.com>
Sun, 2 Jul 2017 16:11:50 +0000 (09:11 -0700)
committerEli Bendersky <eliben@gmail.com>
Sun, 2 Jul 2017 16:11:50 +0000 (09:11 -0700)
elftools/elf/elffile.py
elftools/elf/structs.py
test/run_readelf_tests.py
test/test_core_notes.py

index e4b9f9618ae282887f380be497cd48cf6b2b1813..6fd2a7300850278ac7304405994ec67d5d8cf045 100644 (file)
@@ -52,8 +52,9 @@ class ELFFile(object):
                 boolean - specifies the target machine's endianness
 
             elftype:
-                string or int, either known value of E_TYPE enum defining ELF type
-                (e.g. executable, dynamic library or core dump) or integral unparsed value
+                string or int, either known value of E_TYPE enum defining ELF
+                type (e.g. executable, dynamic library or core dump) or integral
+                unparsed value
 
             header:
                 the complete ELF file header
@@ -159,17 +160,17 @@ class ELFFile(object):
         # Sections that aren't found will be passed as None to DWARFInfo.
         #
 
-        section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev', '.debug_str',
-                         '.debug_line', '.debug_frame',
+        section_names = ('.debug_info', '.debug_aranges', '.debug_abbrev',
+                         '.debug_str', '.debug_line', '.debug_frame',
                          '.debug_loc', '.debug_ranges')
 
         compressed = bool(self.get_section_by_name('.zdebug_info'))
         if compressed:
             section_names = tuple(map(lambda x: '.z' + x[1:], section_names))
 
-        debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name, debug_str_sec_name, \
-            debug_line_sec_name, debug_frame_sec_name, debug_loc_sec_name, \
-            debug_ranges_sec_name = section_names
+        (debug_info_sec_name, debug_aranges_sec_name, debug_abbrev_sec_name,
+         debug_str_sec_name, debug_line_sec_name, debug_frame_sec_name,
+         debug_loc_sec_name, debug_ranges_sec_name) = section_names
 
         debug_sections = {}
         for secname in section_names:
index b7a76eb5e449821114b3855c1b7d90e8fab1a037..7c2c5d16f61b1b22dc3cc0d0cdac08c977b6a215 100644 (file)
@@ -45,7 +45,7 @@ class ELFStructs(object):
         self.elfclass = elfclass
 
     def create_basic_structs(self):
-        """ Create word-size related structs and ehdr struct needed for 
+        """ Create word-size related structs and ehdr struct needed for
             initial determining of ELF type.
         """
         if self.little_endian:
@@ -72,7 +72,8 @@ class ELFStructs(object):
 
     def create_advanced_structs(self, elftype=None):
         """ Create all ELF structs except the ehdr. They may possibly depend
-            on provided #elftype previously parsed from ehdr. """
+            on provided #elftype previously parsed from ehdr.
+        """
         self._create_phdr()
         self._create_shdr()
         self._create_sym()
@@ -280,12 +281,14 @@ class ELFStructs(object):
         self.Elf_Nhdr = Struct('Elf_Nhdr',
             self.Elf_word('n_namesz'),
             self.Elf_word('n_descsz'),
-            Enum(self.Elf_word('n_type'), **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE" else ENUM_CORE_NOTE_N_TYPE)),
+            Enum(self.Elf_word('n_type'),
+                 **(ENUM_NOTE_N_TYPE if elftype != "ET_CORE"
+                    else ENUM_CORE_NOTE_N_TYPE)),
         )
 
         # A process psinfo structure according to
         # http://elixir.free-electrons.com/linux/v2.6.35/source/include/linux/elfcore.h#L84
-        if self.elfclass == 32: 
+        if self.elfclass == 32:
             self.Elf_Prpsinfo = Struct('Elf_Prpsinfo',
                 self.Elf_byte('pr_state'),
                 String('pr_sname', 1),
@@ -319,7 +322,6 @@ class ELFStructs(object):
                 String('pr_psargs', 80),
             )
 
-
     def _create_stabs(self):
         # Structure of one stabs entry, see binutils/bfd/stabs.c
         # Names taken from https://sourceware.org/gdb/current/onlinedocs/stabs.html#Overview
index f7eff8cc00bc9cd6e26037ee8e32b67f3cc5651a..f9991749799beb42434055937b47aa7ee24e0a83 100755 (executable)
@@ -56,9 +56,9 @@ def run_test_on_file(filename, verbose=False):
             '--debug-dump=aranges']:
         if verbose: testlog.info("..option='%s'" % option)
 
-        # TODO(zlobober): this is a dirty hack to make tests work for ELF core dump notes.
-        # Making it work properly requires a pretty deep investigation of how original readelf
-        # formats the output.
+        # TODO(zlobober): this is a dirty hack to make tests work for ELF core
+        # dump notes. Making it work properly requires a pretty deep
+        # investigation of how original readelf formats the output.
         if "core" in filename and option == "-n":
             if verbose:
                 testlog.warning("....will fail because corresponding part of readelf.py is not implemented yet")
@@ -205,7 +205,6 @@ def main():
 
     # If file names are given as command-line arguments, only these files
     # are taken as inputs. Otherwise, autodiscovery is performed.
-    #
     if len(args) > 0:
         filenames = args
     else:
index fd28e72642a1d5cf3089435328846f3e14297421..41ee6f8dd898c6fa943d6e4380c724545bf5bc9f 100644 (file)
@@ -12,13 +12,12 @@ from elftools.elf.segments import NoteSegment
 
 class TestCoreNotes(unittest.TestCase):
     """ This test makes sure than core dump specific
-        sections are properly analyzed. 
+        sections are properly analyzed.
     """
 
     def test_core_prpsinfo(self):
-        """ Test ...
-        """
-        with open(os.path.join('test', 'testfiles_for_unittests', 'core_linux64.elf'),
+        with open(os.path.join('test',
+                               'testfiles_for_unittests', 'core_linux64.elf'),
                   'rb') as f:
             elf = ELFFile(f)
             for segment in elf.iter_segments():
@@ -40,5 +39,9 @@ class TestCoreNotes(unittest.TestCase):
                     self.assertEquals(desc['pr_ppid'], 23187)
                     self.assertEquals(desc['pr_pgrp'], 23395)
                     self.assertEquals(desc['pr_sid'], 23187)
-                    self.assertEquals(desc['pr_fname'], b'coredump_self\x00\x00\x00')
-                    self.assertEquals(desc['pr_psargs'], b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27))
+                    self.assertEquals(
+                        desc['pr_fname'],
+                        b'coredump_self\x00\x00\x00')
+                    self.assertEquals(
+                        desc['pr_psargs'],
+                        b'./coredump_self foo bar 42 ' + b'\x00' * (80 - 27))