From c7bce44745a20cc9856d8594fa619a8a715d4e90 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Wed, 22 Jan 2020 23:15:20 +0530 Subject: [PATCH 1/2] Import ABC from collections.abc instead of collections for Python 3.9 compatibility. --- bitstring.py | 12 ++++++++---- test/test_bitstream.py | 9 +++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bitstring.py b/bitstring.py index e3ea1590..14c93881 100644 --- a/bitstring.py +++ b/bitstring.py @@ -72,9 +72,13 @@ import os import struct import operator -import collections import array +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable + byteorder = sys.byteorder bytealigned = False @@ -1311,7 +1315,7 @@ def _setauto(self, s, length, offset): data = bytearray((s + 7) // 8) self._datastore = ByteStore(data, s, 0) return - if isinstance(s, collections.Iterable): + if isinstance(s, Iterable): # Evaluate each item as True or False and set bits to 1 or 0. self._setbin_unsafe(''.join(str(int(bool(x))) for x in s)) return @@ -3501,7 +3505,7 @@ def invert(self, pos=None): if pos is None: self._invert_all() return - if not isinstance(pos, collections.Iterable): + if not isinstance(pos, Iterable): pos = (pos,) length = self.len @@ -3589,7 +3593,7 @@ def byteswap(self, fmt=None, start=None, end=None, repeat=True): bytesizes.append(PACK_CODE_SIZE[f]) else: bytesizes.extend([PACK_CODE_SIZE[f[-1]]] * int(f[:-1])) - elif isinstance(fmt, collections.Iterable): + elif isinstance(fmt, Iterable): bytesizes = fmt for bytesize in bytesizes: if not isinstance(bytesize, numbers.Integral) or bytesize < 0: diff --git a/test/test_bitstream.py b/test/test_bitstream.py index 1a91d37d..3c4f286b 100644 --- a/test/test_bitstream.py +++ b/test/test_bitstream.py @@ -6,7 +6,12 @@ import bitstring import copy import os -import collections + +try: + from collections.abc import Iterable +except ImportError: + from collections import Iterable + from bitstring import BitStream, ConstBitStream, pack from bitstring import offsetcopy @@ -3457,7 +3462,7 @@ def testPackingDefaultIntWithKeyword(self): self.assertEqual(s.len, 17) def testInitFromIterable(self): - self.assertTrue(isinstance(range(10), collections.Iterable)) + self.assertTrue(isinstance(range(10), Iterable)) s = ConstBitStream(range(12)) self.assertEqual(s, '0x7ff') From b2a27f33c1efda32175409ac5a0bc78cad10aa59 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Wed, 22 Jan 2020 23:15:57 +0530 Subject: [PATCH 2/2] Fix warnings regarding invalid escape sequences. --- bitstring.py | 2 +- doc/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bitstring.py b/bitstring.py index 14c93881..b7696b9f 100644 --- a/bitstring.py +++ b/bitstring.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -""" +r""" This package defines classes that simplify bit-wise creation, manipulation and interpretation of data. diff --git a/doc/conf.py b/doc/conf.py index 94a58d8c..3802f3f9 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -215,7 +215,7 @@ \\cleardoublepage """ % release -latex_elements = {'preamble': '\setcounter{tocdepth}{2}\definecolor{VerbatimBorderColor}{rgb}{1,1,1}', +latex_elements = {'preamble': r'\setcounter{tocdepth}{2}\definecolor{VerbatimBorderColor}{rgb}{1,1,1}', 'fncychap': '\\usepackage[Sonny]{fncychap}', 'maketitle': titlepage, 'papersize': 'a4paper',