From c9594acd0e1a1b87ab9a8b1de2b22c1411d617ff Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sat, 25 Jan 2014 06:45:37 -0800 Subject: [PATCH] Clean up the code after the previous pull request --- elftools/dwarf/dwarfinfo.py | 12 +++++++----- examples/dwarf_range_lists.py | 2 +- test/test_dwarf_range_lists.py | 8 ++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/elftools/dwarf/dwarfinfo.py b/elftools/dwarf/dwarfinfo.py index f9d1e32..1995fc8 100644 --- a/elftools/dwarf/dwarfinfo.py +++ b/elftools/dwarf/dwarfinfo.py @@ -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 ------# diff --git a/examples/dwarf_range_lists.py b/examples/dwarf_range_lists.py index f722d11..6e8998d 100644 --- a/examples/dwarf_range_lists.py +++ b/examples/dwarf_range_lists.py @@ -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 diff --git a/test/test_dwarf_range_lists.py b/test/test_dwarf_range_lists.py index 1ebd0c7..81dab9a 100644 --- a/test/test_dwarf_range_lists.py +++ b/test/test_dwarf_range_lists.py @@ -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() -- 2.30.2