Minor stylistic fixes following up the previous commit
authorEli Bendersky <eliben@gmail.com>
Wed, 17 Aug 2022 12:46:40 +0000 (05:46 -0700)
committerEli Bendersky <eliben@gmail.com>
Wed, 17 Aug 2022 12:46:40 +0000 (05:46 -0700)
elftools/dwarf/structs.py
elftools/elf/elffile.py

index e0a67c4372da2de5d9477a14ea02388b4d99cfac..fe68d439236befc5a2f707e41ed1c0484f4df62d 100644 (file)
@@ -77,7 +77,10 @@ class DWARFStructs(object):
         See also the documentation of public methods.
     """
 
-    __StructsCache = {}
+    # Cache for structs instances based on creation parameters. Structs
+    # initialization is expensive and we don't won't to repeat it
+    # unnecessarily.
+    _structs_cache = {}
 
     def __new__(cls, little_endian, dwarf_format, address_size, dwarf_version=2):
         """ dwarf_version:
@@ -95,8 +98,8 @@ class DWARFStructs(object):
         """
         key = (little_endian, dwarf_format, address_size, dwarf_version)
 
-        if key in cls.__StructsCache:
-            return cls.__StructsCache[key]
+        if key in cls._structs_cache:
+            return cls._structs_cache[key]
 
         self = super().__new__(cls)
         assert dwarf_format == 32 or dwarf_format == 64
@@ -106,7 +109,7 @@ class DWARFStructs(object):
         self.address_size = address_size
         self.dwarf_version = dwarf_version
         self._create_structs()
-        cls.__StructsCache[key] = self
+        cls._structs_cache[key] = self
         return self
 
     def initial_length_field_size(self):
@@ -273,7 +276,7 @@ class DWARFStructs(object):
 
             # New forms in DWARFv5
             DW_FORM_loclistx=self.Dwarf_uleb128(''),
-            DW_FORM_rnglistx=self.Dwarf_uleb128('')            
+            DW_FORM_rnglistx=self.Dwarf_uleb128('')
         )
 
     def _create_aranges_header(self):
index bddb77e22797079807fe1265ceca993c8bf2f833..59f657b720624337d116c6d57b819d7b25fee05d 100644 (file)
@@ -626,7 +626,7 @@ class ELFFile(object):
         """
         if self._section_header_stringtable is None:
             raise ELFParseError("String Table not found")
-            
+
         name_offset = section_header['sh_name']
         return self._section_header_stringtable.get_string(name_offset)