From 116899ebf685a25752301be930535798814f5050 Mon Sep 17 00:00:00 2001 From: eliben Date: Thu, 8 Sep 2011 17:15:53 +0300 Subject: [PATCH] moving stuff around --- elftools/common/utils.py | 9 ++++++++- elftools/elf/elffile.py | 10 ++-------- elftools/elf/sections.py | 4 +--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/elftools/common/utils.py b/elftools/common/utils.py index 716bebd..230ba96 100644 --- a/elftools/common/utils.py +++ b/elftools/common/utils.py @@ -6,7 +6,7 @@ # Eli Bendersky (eliben@gmail.com) # This code is in the public domain #------------------------------------------------------------------------------- -from .exceptions import ELFParseError +from .exceptions import ELFParseError, ELFError def struct_parse(struct, stream, stream_pos=None): @@ -23,3 +23,10 @@ def struct_parse(struct, stream, stream_pos=None): except ConstructError as e: raise ELFParseError(e.message) + +def elf_assert(cond, msg=''): + """ Assert that cond is True, otherwise raise ELFError(msg) + """ + if not cond: + raise ELFError(msg) + diff --git a/elftools/elf/elffile.py b/elftools/elf/elffile.py index 045e1c4..6f2e723 100644 --- a/elftools/elf/elffile.py +++ b/elftools/elf/elffile.py @@ -7,7 +7,7 @@ # This code is in the public domain #------------------------------------------------------------------------------- from ..common.exceptions import ELFError -from ..common.utils import struct_parse +from ..common.utils import struct_parse, elf_assert from ..construct import ConstructError from .structs import ELFStructs from .sections import Section, StringTableSection, SymbolTableSection @@ -87,7 +87,7 @@ class ELFFile(object): # self.stream.seek(0) magic = self.stream.read(4) - self._assert(magic == '\x7fELF', 'Magic number does not match') + elf_assert(magic == '\x7fELF', 'Magic number does not match') ei_class = self.stream.read(1) if ei_class == '\x01': @@ -174,10 +174,4 @@ class ELFFile(object): of this object. """ return struct_parse(self.structs.Elf_Ehdr, self.stream, stream_pos=0) - - def _assert(self, cond, msg=''): - """ Assert that cond is True, otherwise raise ELFError(msg) - """ - if not cond: - raise ELFError(msg) diff --git a/elftools/elf/sections.py b/elftools/elf/sections.py index 931095f..6accf11 100644 --- a/elftools/elf/sections.py +++ b/elftools/elf/sections.py @@ -7,7 +7,7 @@ # This code is in the public domain #------------------------------------------------------------------------------- from ..construct import CString -from ..common.utils import struct_parse +from ..common.utils import struct_parse, elf_assert class Section(object): @@ -58,5 +58,3 @@ class SymbolTableSection(Section): def __init__(self, header, name, stream, stringtable): super(SymbolTableSection, self).__init__(header, name, stream) self.stringtable = stringtable - - -- 2.30.2