diff --git a/.coverage b/.coverage new file mode 100644 index 0000000..1ccf5a3 Binary files /dev/null and b/.coverage differ diff --git a/AUTHORS.rst b/AUTHORS.rst index 297e869..bdafa87 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -22,3 +22,4 @@ Contributors: * "durexyl" @ GitHub * "erki1993" @ GitHub * "mentaal" @ GitHub +* Léo Flaventin Hauchecorne diff --git a/NEWS.rst b/NEWS.rst index 80734ed..e2c4b9b 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -2,6 +2,11 @@ IntelHex releases ***************** +2.3 (2020-09-09) +------------------ +* API changes: ``IntelHex.__setitem__`` method: added support for slices + with any iterable values. (Léo Flaventin Hauchecorne) + 2.2.1 (2018-01-30) ------------------ * Fixes for PyPI. diff --git a/Readme.rst b/Readme.rst index e3808a2..f9619e1 100644 --- a/Readme.rst +++ b/Readme.rst @@ -24,7 +24,7 @@ restrictions. Supported Python versions ------------------------- -IntelHex library v.2.2 supports Python 2 (2.4-2.7) and Python 3 (3.2-3.5 or later) +IntelHex library v.2.3 supports Python 2 (2.4-2.7) and Python 3 (3.2-3.5 or later) without external libraries or 2to3 tool from the same codebase. Install diff --git a/intelhex.egg-info/PKG-INFO b/intelhex.egg-info/PKG-INFO new file mode 100644 index 0000000..22ec024 --- /dev/null +++ b/intelhex.egg-info/PKG-INFO @@ -0,0 +1,75 @@ +Metadata-Version: 1.2 +Name: intelhex +Version: 2.3 +Summary: Python library for Intel HEX files manipulations +Home-page: https://github.com/python-intelhex/intelhex +Author: Alexander Belchenko +Author-email: alexander.belchenko@gmail.com +Maintainer: Bert van Hall +Maintainer-email: bert.vanhall@gmx.de +License: BSD +Description: Python IntelHex library + *********************** + + Introduction + ------------ + The Intel HEX file format is widely used in microprocessors and microcontrollers + area (embedded systems etc) as the de facto standard + for representation of code to be programmed into microelectronic devices. + + This work implements an ``intelhex`` Python library to read, write, + create from scratch and manipulate data from Intel HEX file format. + + The distribution package also includes several convenience Python scripts, + including "classic" ``hex2bin`` and ``bin2hex`` converters and more, + those based on the library itself. Check the docs to know more. + + License + ------- + The code is distributed under BSD license, + see `LICENSE.txt `_. + + In short: you can use IntelHex library in your project without *any* + restrictions. + + Supported Python versions + ------------------------- + IntelHex library v.2.3 supports Python 2 (2.4-2.7) and Python 3 (3.2-3.5 or later) + without external libraries or 2to3 tool from the same codebase. + + Install + ------- + Install using ``pip`` (recommended, no separate download required):: + + pip install intelhex + + Download + -------- + * https://pypi.org/project/IntelHex/ + * https://github.com/python-intelhex/intelhex/releases + + Source code, bug reports, patches + --------------------------------- + IntelHex on GitHub: + + https://github.com/python-intelhex/intelhex + + User manual + ----------- + User manual for IntelHex is available in the sources ``docs/manual/`` directory. + You can browse User Manual online: + + https://readthedocs.org/projects/python-intelhex/ + + Changelog + --------- + See `NEWS.rst `_ + +Keywords: Intel HEX hex2bin HEX8 +Platform: UNKNOWN +Classifier: Development Status :: 5 - Production/Stable +Classifier: Environment :: Console +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Operating System :: OS Independent +Classifier: Programming Language :: Python diff --git a/intelhex.egg-info/SOURCES.txt b/intelhex.egg-info/SOURCES.txt new file mode 100644 index 0000000..97d80f5 --- /dev/null +++ b/intelhex.egg-info/SOURCES.txt @@ -0,0 +1,24 @@ +AUTHORS.rst +LICENSE.txt +MANIFEST.in +NEWS.rst +Readme.rst +setup.cfg +setup.py +intelhex/__init__.py +intelhex/__main__.py +intelhex/__version__.py +intelhex/bench.py +intelhex/compat.py +intelhex/getsizeof.py +intelhex/test.py +intelhex.egg-info/PKG-INFO +intelhex.egg-info/SOURCES.txt +intelhex.egg-info/dependency_links.txt +intelhex.egg-info/top_level.txt +scripts/bin2hex.py +scripts/hex2bin.py +scripts/hex2dump.py +scripts/hexdiff.py +scripts/hexinfo.py +scripts/hexmerge.py \ No newline at end of file diff --git a/intelhex.egg-info/dependency_links.txt b/intelhex.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/intelhex.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/intelhex.egg-info/top_level.txt b/intelhex.egg-info/top_level.txt new file mode 100644 index 0000000..a7dde12 --- /dev/null +++ b/intelhex.egg-info/top_level.txt @@ -0,0 +1 @@ +intelhex diff --git a/intelhex/__init__.py b/intelhex/__init__.py index 45188b0..be6646f 100644 --- a/intelhex/__init__.py +++ b/intelhex/__init__.py @@ -480,8 +480,22 @@ def __setitem__(self, addr, byte): raise TypeError('Address should be >= 0.') self._buf[addr] = byte elif t == slice: - if not isinstance(byte, (list, tuple)): - raise ValueError('Slice operation expects sequence of bytes') + slice_error = ValueError('Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes') # avoid duplication code + if not isinstance(byte, (bytes, bytearray)): + if isinstance(byte, (list, tuple)): + try: + check = all(0 <= x < 255 for x in byte) + except TypeError as exc: + raise slice_error from exc + if not check : + raise slice_error + if not all(isinstance(x, int) for x in byte) : + raise slice_error + else : + try: + byte = bytes(byte) # check for int + 0<=x<=255 + convert to something getitem works with + except TypeError as exc: + raise slice_error from exc start = addr.start stop = addr.stop step = addr.step or 1 diff --git a/intelhex/__version__.py b/intelhex/__version__.py index 5ce4f0b..d826775 100644 --- a/intelhex/__version__.py +++ b/intelhex/__version__.py @@ -1,3 +1,3 @@ # IntelHex library version information -version_info = (2, 2, 1) +version_info = (2, 3) version_str = '.'.join([str(i) for i in version_info]) diff --git a/intelhex/compat.py b/intelhex/compat.py index 194cd5d..6f95245 100644 --- a/intelhex/compat.py +++ b/intelhex/compat.py @@ -57,7 +57,7 @@ def asstr(s): return s return s.decode('latin1') - array_tobytes = getattr(array.array, "tobytes", array.array.tostring) + array_tobytes = getattr(array.array, "tobytes", array.array.tobytes) IntTypes = (int,) StrType = str diff --git a/intelhex/test.py b/intelhex/test.py index 84e771b..bde7b76 100755 --- a/intelhex/test.py +++ b/intelhex/test.py @@ -679,6 +679,8 @@ def setitem(a,b): # slice operations ih[0:4] = range_l(4) self.assertEqual({0:0, 1:1, 2:2, 3:3}, ih.todict()) + ih[0:4] = range_g(1,5) + self.assertEqual({0:1, 1:2, 2:3, 3:4}, ih.todict()) ih[0:] = range_l(5,9) self.assertEqual({0:5, 1:6, 2:7, 3:8}, ih.todict()) ih[:4] = range_l(9,13) @@ -687,11 +689,25 @@ def setitem(a,b): ih = IntelHex() ih[0:8:2] = range_l(4) self.assertEqual({0:0, 2:1, 4:2, 6:3}, ih.todict()) + ih[0:8:2] = b'\xDE\xAD\xBE\xEF' + self.assertEqual({0:0xDE, 2:0xAD, 4:0xBE, 6:0xEF}, ih.todict()) # errors in slice operations # ih[1:2] = 'a' self.assertRaisesMsg(ValueError, - 'Slice operation expects sequence of bytes', + 'Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes', setitem, slice(1,2,None), 'a') + self.assertRaisesMsg(ValueError, + 'Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes', + setitem, slice(1,4,None), [1,1.5,2]) + self.assertRaisesMsg(ValueError, + 'Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes', + setitem, slice(1,4,None), [1,object(),2]) + self.assertRaisesMsg(ValueError, + 'Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes', + setitem, slice(1,2,None), (i/2 for i in range(1))) + self.assertRaisesMsg(ValueError, + 'Slice operation expects either a bytes, a sequence of byte values (0 <= byte <= 255), or anything convertible to bytes', + setitem, slice(1,4,None), [1,2,256]) # ih[0:1] = [1,2,3] self.assertRaisesMsg(ValueError, 'Length of bytes sequence does not match address range', diff --git a/scripts/bin2hex.py b/scripts/bin2hex.py index 8a726f9..afc6ee4 100755 --- a/scripts/bin2hex.py +++ b/scripts/bin2hex.py @@ -35,7 +35,7 @@ '''Intel HEX file format bin2hex convertor utility.''' -VERSION = '2.2.1' +VERSION = '2.3' if __name__ == '__main__': import getopt diff --git a/scripts/hex2bin.py b/scripts/hex2bin.py index 3f56ec1..d534719 100755 --- a/scripts/hex2bin.py +++ b/scripts/hex2bin.py @@ -35,7 +35,7 @@ '''Intel HEX file format hex2bin convertor utility.''' -VERSION = '2.2.1' +VERSION = '2.3' if __name__ == '__main__': import getopt diff --git a/scripts/hex2dump.py b/scripts/hex2dump.py index 129b10c..0e83cc3 100755 --- a/scripts/hex2dump.py +++ b/scripts/hex2dump.py @@ -35,7 +35,7 @@ """Show content of hex file as hexdump.""" -VERSION = '2.2.1' +VERSION = '2.3' USAGE = '''hex2dump: show content of hex file as hexdump. Usage: diff --git a/scripts/hexdiff.py b/scripts/hexdiff.py index f9bb9db..52656ad 100755 --- a/scripts/hexdiff.py +++ b/scripts/hexdiff.py @@ -37,7 +37,7 @@ of compared data. """ -VERSION = '2.2.1' +VERSION = '2.3' USAGE = '''hexdiff: diff dumps of 2 hex files. Usage: diff --git a/scripts/hexinfo.py b/scripts/hexinfo.py index 03d4420..024c5bf 100755 --- a/scripts/hexinfo.py +++ b/scripts/hexinfo.py @@ -38,7 +38,7 @@ data (if any), in YAML format. """ -VERSION = '2.2.1' +VERSION = '2.3' USAGE = '''hexinfo: summarize a hex file's contents. Usage: diff --git a/scripts/hexmerge.py b/scripts/hexmerge.py index 9359662..4ce8d84 100755 --- a/scripts/hexmerge.py +++ b/scripts/hexmerge.py @@ -35,7 +35,7 @@ """Merge content of several hex files into one file.""" -VERSION = '2.2.1' +VERSION = '2.3' USAGE = '''hexmerge: merge content of hex files. Usage: