[diffoscope] 09/10: Use Python OrderedDict instead of keeping a list of sections in ELF container

Jérémy Bobbio lunar at moszumanska.debian.org
Wed Jan 20 16:11:45 CET 2016


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository diffoscope.

commit 1a95b2f423e5a907bd5a69e07e27ecbe03dc6f61
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Wed Jan 20 14:55:21 2016 +0000

    Use Python OrderedDict instead of keeping a list of sections in ELF container
    
    Let's also instanciate our section object during init. It doesn't change
    much of the behavior but make some late minute specialization possible in the
    future.
---
 diffoscope/comparators/elf.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index bb1a9d5..3746f9f 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -17,6 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <http://www.gnu.org/licenses/>.
 
+from collections import OrderedDict
 import os.path
 import re
 import subprocess
@@ -274,8 +275,7 @@ class ElfContainer(Container):
                 output = output[2:]
             output = output[5:]
 
-            self._sections = {}
-            self._section_list = [] # using a list to store original order
+            self._sections = OrderedDict()
             # Entires of readelf --section-headers have the following columns:
             # [Nr]  Name  Type  Address  Off  Size  ES  Flg  Lk  Inf  Al
             for line in output:
@@ -289,8 +289,7 @@ class ElfContainer(Container):
                 # Use first match, with last option being '_' as fallback
                 elf_class = [ElfContainer.SECTION_FLAG_MAPPING[flag] for flag in flags if \
                              flag in ElfContainer.SECTION_FLAG_MAPPING][0]
-                self._sections[name] = elf_class
-                self._section_list.append(name)
+                self._sections[name] = elf_class(self, name)
                 logger.debug('adding section %s (%s) as %s', name, type, elf_class)
         except Exception as e:
             command = ' '.join(cmd)
@@ -299,10 +298,10 @@ class ElfContainer(Container):
             raise OutputParsingError(command, self)
 
     def get_member_names(self):
-        return self._section_list
+        return self._sections.keys()
 
     def get_member(self, member_name):
-        return self._sections[member_name](self, member_name)
+        return self._sections[member_name]
 
 class ElfFile(File):
     CONTAINER_CLASS = ElfContainer

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list