diff -Nru python-bitstring-3.1.4/bitstring.py python-bitstring-3.1.5/bitstring.py --- python-bitstring-3.1.4/bitstring.py 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/bitstring.py 2016-05-17 17:43:58.000000000 +0000 @@ -59,7 +59,7 @@ THE SOFTWARE. """ -__version__ = "3.1.4" +__version__ = "3.1.5" __author__ = "Scott Griffiths" @@ -73,6 +73,7 @@ import struct import operator import collections +import array byteorder = sys.byteorder @@ -731,7 +732,7 @@ def __init__(self, auto=None, length=None, offset=None, **kwargs): """Either specify an 'auto' initialiser: auto -- a string of comma separated tokens, an integer, a file object, - a bytearray, a boolean iterable or another bitstring. + a bytearray, a boolean iterable, an array or another bitstring. Or initialise via **kwargs with one (and only one) of: bytes -- raw data as a string, for example read from a binary file. @@ -1242,7 +1243,7 @@ self._datastore = ByteStore(bytearray(0)) def _setauto(self, s, length, offset): - """Set bitstring from a bitstring, file, bool, integer, iterable or string.""" + """Set bitstring from a bitstring, file, bool, integer, array, iterable or string.""" # As s can be so many different things it's important to do the checks # in the correct order, as some types are also other allowed types. # So basestring must be checked before Iterable @@ -1277,6 +1278,10 @@ if isinstance(s, (bytes, bytearray)): self._setbytes_unsafe(bytearray(s), len(s) * 8, 0) return + if isinstance(s, array.array): + b = s.tostring() + self._setbytes_unsafe(bytearray(b), len(b) * 8, 0) + return if isinstance(s, numbers.Integral): # Initialise with s zero bits. if s < 0: @@ -1916,9 +1921,13 @@ "not multiple of 4 bits.") if not length: return '' - # This monstrosity is the only thing I could get to work for both 2.6 and 3.1. - # TODO: Is utf-8 really what we mean here? - s = str(binascii.hexlify(self._slice(start, start + length).tobytes()).decode('utf-8')) + s = self._slice(start, start + length).tobytes() + try: + s = s.hex() # Available in Python 3.5 + except AttributeError: + # This monstrosity is the only thing I could get to work for both 2.6 and 3.1. + # TODO: Is utf-8 really what we mean here? + s = str(binascii.hexlify(s).decode('utf-8')) # If there's one nibble too many then cut it off return s[:-1] if (length // 4) % 2 else s diff -Nru python-bitstring-3.1.4/debian/changelog python-bitstring-3.1.5/debian/changelog --- python-bitstring-3.1.4/debian/changelog 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/changelog 2016-05-26 07:12:01.000000000 +0000 @@ -1,3 +1,15 @@ +python-bitstring (3.1.5-1) unstable; urgency=medium + + * New upstream release. + * Refresh patch queue. + * Update copyright information. + * d/rules: better formatting. + * Bump standards version to 3.9.8, no changes required. + * Add upstream metadata. + * d/gbp.conf: use DEP-14 repository layout. + + -- Ghislain Antony Vaillant Thu, 26 May 2016 08:11:34 +0100 + python-bitstring (3.1.4-1) unstable; urgency=medium * Update patch queue: diff -Nru python-bitstring-3.1.4/debian/control python-bitstring-3.1.5/debian/control --- python-bitstring-3.1.4/debian/control 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/control 2016-05-26 07:12:01.000000000 +0000 @@ -11,7 +11,7 @@ python3-all, python3-setuptools, python-sphinx -Standards-Version: 3.9.7 +Standards-Version: 3.9.8 Vcs-Browser: https://anonscm.debian.org/cgit/debian-science/packages/python-bitstring.git Vcs-Git: https://anonscm.debian.org/git/debian-science/packages/python-bitstring.git Homepage: http://scott-griffiths.github.io/bitstring/ diff -Nru python-bitstring-3.1.4/debian/copyright python-bitstring-3.1.5/debian/copyright --- python-bitstring-3.1.4/debian/copyright 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/copyright 2016-05-26 07:12:01.000000000 +0000 @@ -1,10 +1,10 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Scott Griffiths -Upstream-Contact: scott@griffiths.name +Upstream-Contact: dr.scottgriffiths@gmail.com Source: https://github.com/scott-griffiths/bitstring Files: * -Copyright: 2006-2016 Scott Griffiths +Copyright: 2006-2016 Scott Griffiths License: Expat Files: debian/* @@ -12,8 +12,6 @@ License: Expat License: Expat - The MIT License - . 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 diff -Nru python-bitstring-3.1.4/debian/gbp.conf python-bitstring-3.1.5/debian/gbp.conf --- python-bitstring-3.1.4/debian/gbp.conf 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/gbp.conf 2016-05-26 07:12:01.000000000 +0000 @@ -1,6 +1,6 @@ [DEFAULT] -upstream-branch = upstream -debian-branch = master +upstream-branch = upstream/latest +debian-branch = debian/master upstream-tag = upstream/%(version)s debian-tag = debian/%(version)s pristine-tar = True diff -Nru python-bitstring-3.1.4/debian/patches/fix-testsuite-discovery.patch python-bitstring-3.1.5/debian/patches/fix-testsuite-discovery.patch --- python-bitstring-3.1.4/debian/patches/fix-testsuite-discovery.patch 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/patches/fix-testsuite-discovery.patch 2016-05-26 07:12:01.000000000 +0000 @@ -6,7 +6,7 @@ This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ --- a/test/test_bits.py +++ b/test/test_bits.py -@@ -214,10 +214,10 @@ +@@ -215,10 +215,10 @@ class FileBased(unittest.TestCase): def setUp(self): @@ -21,7 +21,7 @@ def testCreationWithOffset(self): self.assertEqual(self.a, '0x0123456789abcdef') -@@ -243,7 +243,7 @@ +@@ -244,7 +244,7 @@ class Mmap(unittest.TestCase): def setUp(self): diff -Nru python-bitstring-3.1.4/debian/rules python-bitstring-3.1.5/debian/rules --- python-bitstring-3.1.4/debian/rules 2016-03-23 11:54:30.000000000 +0000 +++ python-bitstring-3.1.5/debian/rules 2016-05-26 07:12:01.000000000 +0000 @@ -13,7 +13,8 @@ override_dh_auto_build: dh_auto_build - PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bhtml doc/ build/html + PYTHONPATH=. http_proxy='127.0.0.1:9' \ + sphinx-build -N -b html doc build/html override_dh_installchangelogs: dh_installchangelogs release_notes.txt diff -Nru python-bitstring-3.1.4/debian/upstream/metadata python-bitstring-3.1.5/debian/upstream/metadata --- python-bitstring-3.1.4/debian/upstream/metadata 1970-01-01 00:00:00.000000000 +0000 +++ python-bitstring-3.1.5/debian/upstream/metadata 2016-05-26 07:12:01.000000000 +0000 @@ -0,0 +1,6 @@ +Bug-Database: https://github.com/scott-griffiths/bitstring/issues +Bug-Submit: https://github.com/scott-griffiths/bitstring/issues/new +Changelog: https://github.com/scott-griffiths/bitstring/blob/master/release_notes.txt +Name: bitstring +Repository: git@github.com:scott-griffiths/bitstring.git +Repository-Browse: https://github.com/scott-griffiths/bitstring diff -Nru python-bitstring-3.1.4/doc/bitstring_classes.rst python-bitstring-3.1.5/doc/bitstring_classes.rst --- python-bitstring-3.1.4/doc/bitstring_classes.rst 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/doc/bitstring_classes.rst 2016-05-17 17:43:58.000000000 +0000 @@ -44,6 +44,7 @@ * A positive integer, used to create a bitstring of that many zero bits. * A file object, presumably opened in read-binary mode, from which the bitstring will be formed. * A ``bytearray`` object. +* An ``array`` object. This is used after being converted to it's constituent byte data via its ``tostring`` method. * In Python 3 only, a ``bytes`` object. Note this won't work for Python 2.7 as ``bytes`` is just a synonym for ``str``. diff -Nru python-bitstring-3.1.4/doc/creation.rst python-bitstring-3.1.5/doc/creation.rst --- python-bitstring-3.1.4/doc/creation.rst 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/doc/creation.rst 2016-05-17 17:43:58.000000000 +0000 @@ -37,7 +37,7 @@ --------------------- When initialising a bitstring you need to specify at most one initialiser. These will be explained in full below, but briefly they are: -* ``auto`` : Either a specially formatted string, a list or tuple, a file object, integer, bytearray, bytes or another bitstring. +* ``auto`` : Either a specially formatted string, a list or tuple, a file object, integer, bytearray, array, bytes or another bitstring. * ``bytes`` : A ``bytes`` object (a ``str`` in Python 2), for example read from a binary file. * ``hex``, ``oct``, ``bin``: Hexadecimal, octal or binary strings. * ``int``, ``uint``: Signed or unsigned bit-wise big-endian binary integers. @@ -207,7 +207,7 @@ -------------------- The ``auto`` parameter is the first parameter in the :class:`__init__` function and so the ``auto=`` can be omitted when using it. It accepts either a string, an iterable, another bitstring, an integer, a bytearray or a file object. -Strings starting with ``0x`` or ``hex:`` are interpreted as hexadecimal, ``0o`` or ``oct:`` implies octal, and strings starting with ``0b`` or ``bin:`` are interpreted as binary. You can also initialise with the various integer initialisers as described above. If given another bitstring it will create a copy of it, (non string) iterables are interpreted as boolean arrays and file objects acts a source of binary data. Finally you can use an integer to create a zeroed bitstring of that number of bits. :: +Strings starting with ``0x`` or ``hex:`` are interpreted as hexadecimal, ``0o`` or ``oct:`` implies octal, and strings starting with ``0b`` or ``bin:`` are interpreted as binary. You can also initialise with the various integer initialisers as described above. If given another bitstring it will create a copy of it, (non string) iterables are interpreted as boolean arrays and file objects acts a source of binary data. An ``array`` object will be converted into its constituent bytes. Finally you can use an integer to create a zeroed bitstring of that number of bits. :: >>> fromhex = BitArray('0x01ffc9') >>> frombin = BitArray('0b01') @@ -220,6 +220,7 @@ >>> fromfile = BitArray(f) >>> zeroed = BitArray(1000) >>> frombytes = BitArray(bytearray(b'xyz')) + >>> fromarray = BitArray(array.array('h', [3, 17, 10])) It can also be used to convert between the :class:`BitArray` and :class:`Bits` classes:: diff -Nru python-bitstring-3.1.4/LICENSE python-bitstring-3.1.5/LICENSE --- python-bitstring-3.1.4/LICENSE 1970-01-01 00:00:00.000000000 +0000 +++ python-bitstring-3.1.5/LICENSE 2016-05-17 17:43:58.000000000 +0000 @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2006-2016 Scott Griffiths (dr.scottgriffiths@gmail.com) + +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 -Nru python-bitstring-3.1.4/MANIFEST.in python-bitstring-3.1.5/MANIFEST.in --- python-bitstring-3.1.4/MANIFEST.in 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/MANIFEST.in 2016-05-17 17:43:58.000000000 +0000 @@ -4,4 +4,4 @@ include README.rst prune doc include doc/bitstring_manual.pdf - +include LICENSE diff -Nru python-bitstring-3.1.4/release_notes.txt python-bitstring-3.1.5/release_notes.txt --- python-bitstring-3.1.4/release_notes.txt 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/release_notes.txt 2016-05-17 17:43:58.000000000 +0000 @@ -3,6 +3,13 @@ -------------------------------- --------------------------------------- +May 17th 2016: version 3.1.5 released +--------------------------------------- + +* Support initialisation from an array. +* Added a separate LICENSE file. + +--------------------------------------- March 19th 2016: version 3.1.4 released --------------------------------------- This is another bug fix release. diff -Nru python-bitstring-3.1.4/setup.py python-bitstring-3.1.5/setup.py --- python-bitstring-3.1.4/setup.py 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/setup.py 2016-05-17 17:43:58.000000000 +0000 @@ -11,7 +11,7 @@ 'For Python 2.4 / 2.5 please use bitstring version 1.0 instead.') setup(name='bitstring', - version='3.1.4', + version='3.1.5', description='Simple construction, analysis and modification of binary data.', author='Scott Griffiths', author_email='dr.scottgriffiths@gmail.com', diff -Nru python-bitstring-3.1.4/test/test_bits.py python-bitstring-3.1.5/test/test_bits.py --- python-bitstring-3.1.4/test/test_bits.py 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/test/test_bits.py 2016-05-17 17:43:58.000000000 +0000 @@ -5,6 +5,7 @@ sys.path.insert(0, '..') import bitstring +import array from bitstring import MmapByteArray from bitstring import Bits, BitArray, ConstByteStore, ByteStore @@ -390,4 +391,33 @@ a.append('0b1') self.assertEqual(type(a), Bits) b = bitstring.ConstBitStream(bitstring.BitStream()) - self.assertEqual(type(b), bitstring.ConstBitStream) \ No newline at end of file + self.assertEqual(type(b), bitstring.ConstBitStream) + + +class InitFromArray(unittest.TestCase): + + def testEmptyArray(self): + a = array.array('B') + b = Bits(a) + self.assertEqual(b.length, 0) + + def testSingleByte(self): + a = array.array('B', b'\xff') + b = Bits(a) + self.assertEqual(b.length, 8) + self.assertEqual(b.hex, 'ff') + + def testSignedShort(self): + a = array.array('h') + a.append(10) + a.append(-1) + b = Bits(a) + self.assertEqual(b.length, 32) + self.assertEqual(b.bytes, a.tostring()) + + def testDouble(self): + a = array.array('d', [0.0, 1.0, 2.5]) + b = Bits(a) + self.assertEqual(b.length, 192) + c, d, e = b.unpack('3*floatne:64') + self.assertEqual((c, d, e), (0.0, 1.0, 2.5)) \ No newline at end of file diff -Nru python-bitstring-3.1.4/test/test_bitstring.py python-bitstring-3.1.5/test/test_bitstring.py --- python-bitstring-3.1.4/test/test_bitstring.py 2016-03-21 18:40:35.000000000 +0000 +++ python-bitstring-3.1.5/test/test_bitstring.py 2016-05-17 17:43:58.000000000 +0000 @@ -12,7 +12,7 @@ class ModuleData(unittest.TestCase): def testVersion(self): - self.assertEqual(bitstring.__version__, '3.1.4') + self.assertEqual(bitstring.__version__, '3.1.5') def testAll(self): exported = ['ConstBitArray', 'ConstBitStream', 'BitStream', 'BitArray',