Clean up the code after the previous pull request
authorEli Bendersky <eliben@gmail.com>
Sat, 25 Jan 2014 14:45:37 +0000 (06:45 -0800)
committerEli Bendersky <eliben@gmail.com>
Sat, 25 Jan 2014 14:45:37 +0000 (06:45 -0800)
elftools/dwarf/dwarfinfo.py
examples/dwarf_range_lists.py
test/test_dwarf_range_lists.py

index f9d1e326267985a1d04d5e91e1032fdec46ed341..1995fc88f772efe9a169e058e6e3fc1712c6242a 100644 (file)
@@ -172,17 +172,19 @@ class DWARFInfo(object):
         """ Get a LocationLists object representing the .debug_loc section of
             the DWARF data, or None if this section doesn't exist.
         """
-        return LocationLists(self.debug_loc_sec.stream, self.structs)
+        if self.debug_loc_sec:
+            return LocationLists(self.debug_loc_sec.stream, self.structs)
+        else:
+            return None
 
     def range_lists(self):
         """ Get a RangeLists object representing the .debug_ranges section of
             the DWARF data, or None if this section doesn't exist.
         """
-        # ".debug_ranges" section is optional
-        if self.debug_ranges_sec == None:
-            return None
-        else:
+        if self.debug_ranges_sec:
             return RangeLists(self.debug_ranges_sec.stream, self.structs)
+        else:
+            return None
 
     #------ PRIVATE ------#
 
index f722d11a4340d18577cba7ba505f3a39a305d1d3..6e8998dfca45d0c816b6e24a50eec0521f066943 100644 (file)
@@ -37,7 +37,7 @@ def process_file(filename):
         # The range lists are extracted by DWARFInfo from the .debug_ranges
         # section, and returned here as a RangeLists object.
         range_lists = dwarfinfo.range_lists()
-        if range_lists == None:
+        if range_lists is None:
             print('  file has no .debug_ranges section')
             return
 
index 1ebd0c72ffffa0dc2feadff0eb9e63d4083f55d7..81dab9aa0c9d52ade148875ef947232c160e6958 100644 (file)
@@ -20,9 +20,7 @@ class TestRangeLists(unittest.TestCase):
                                'arm_with_form_indirect.elf'), 'rb') as f:
             elffile = ELFFile(f)
             self.assertTrue(elffile.has_dwarf_info())
-
-            dwarfinfo = elffile.get_dwarf_info()
-            self.assertEqual(dwarfinfo.range_lists(), None)
+            self.assertIsNone(elffile.get_dwarf_info().range_lists())
 
     # Test the presence of .debug_ranges section
     def test_range_list_presence(self):
@@ -30,9 +28,7 @@ class TestRangeLists(unittest.TestCase):
                                'sample_exe64.elf'), 'rb') as f:
             elffile = ELFFile(f)
             self.assertTrue(elffile.has_dwarf_info())
-
-            dwarfinfo = elffile.get_dwarf_info()
-            self.assertTrue(dwarfinfo.range_lists() != None)
+            self.assertIsNotNone(elffile.get_dwarf_info().range_lists())
 
 if __name__ == '__main__':
     unittest.main()