From 3853a40a7d3fa0dd03251b26a9334fa5c01aca18 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 26 Jan 2012 06:51:59 +0200 Subject: [PATCH] adding more construct's files --- elftools/construct/LICENSE | 19 ++++++++ elftools/construct/README | 9 ++-- elftools/construct/lib/py3compat.py | 70 +++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 elftools/construct/LICENSE create mode 100644 elftools/construct/lib/py3compat.py diff --git a/elftools/construct/LICENSE b/elftools/construct/LICENSE new file mode 100644 index 0000000..6529f04 --- /dev/null +++ b/elftools/construct/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2009 Tomer Filiba, 2010-2011 Corbin Simpson + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/elftools/construct/README b/elftools/construct/README index 88ba6e9..2c1b798 100644 --- a/elftools/construct/README +++ b/elftools/construct/README @@ -1,5 +1,8 @@ -'construct' is the actual library (version 2, downloaded on 15.09.2010) -Taken from http://construct.wikispaces.com/ -The code for version 2.00 has been released by the author into the public domain +'construct' is the actual library, with my modifications for Python 3 +compatibility and various bug fixes. + +Taken from my fork: https://github.com/eliben/construct + +Take a look at LICENSE for the original license diff --git a/elftools/construct/lib/py3compat.py b/elftools/construct/lib/py3compat.py new file mode 100644 index 0000000..4a52c29 --- /dev/null +++ b/elftools/construct/lib/py3compat.py @@ -0,0 +1,70 @@ +#------------------------------------------------------------------------------- +# py3compat.py +# +# Some Python2&3 compatibility code +#------------------------------------------------------------------------------- +import sys +PY3 = sys.version_info[0] == 3 + + +if PY3: + import io + StringIO = io.StringIO + BytesIO = io.BytesIO + + def bchr(i): + """ When iterating over b'...' in Python 2 you get single b'_' chars + and in Python 3 you get integers. Call bchr to always turn this + to single b'_' chars. + """ + return bytes((i,)) + + def u(s): + return s + + def int2byte(i): + return bytes((i,)) + + def byte2int(b): + return b + + def str2bytes(s): + return s.encode("latin-1") + + def str2unicode(s): + return s + + def bytes2str(b): + return b.decode('latin-1') + + def decodebytes(b, encoding): + return bytes(b, encoding) + + advance_iterator = next + +else: + import cStringIO + StringIO = BytesIO = cStringIO.StringIO + + int2byte = chr + byte2int = ord + bchr = lambda i: i + + def u(s): + return unicode(s, "unicode_escape") + + def str2bytes(s): + return s + + def str2unicode(s): + return unicode(s, "unicode_escape") + + def bytes2str(b): + return b + + def decodebytes(b, encoding): + return b.decode(encoding) + + def advance_iterator(it): + return it.next() + -- 2.30.2