Hello community, here is the log from the commit of package python-bitstruct for openSUSE:Factory checked in at 2020-07-21 15:48:53 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-bitstruct (Old) and /work/SRC/openSUSE:Factory/.python-bitstruct.new.3592 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-bitstruct" Tue Jul 21 15:48:53 2020 rev:2 rq:821998 version:8.11.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-bitstruct/python-bitstruct.changes 2020-04-07 10:28:38.422317407 +0200 +++ /work/SRC/openSUSE:Factory/.python-bitstruct.new.3592/python-bitstruct.changes 2020-07-21 15:50:34.652309550 +0200 @@ -1,0 +2,7 @@ +Tue Jul 21 05:57:35 UTC 2020 - Steve Kowalik <steven.kowa...@suse.com> + +- Update to 8.11.0: + * Add support for copy and deepcopy inC extension. + * Only build C extension for CPython 3. + +------------------------------------------------------------------- Old: ---- bitstruct-8.9.0.tar.gz New: ---- bitstruct-8.11.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-bitstruct.spec ++++++ --- /var/tmp/diff_new_pack.GfLN5H/_old 2020-07-21 15:50:35.892311083 +0200 +++ /var/tmp/diff_new_pack.GfLN5H/_new 2020-07-21 15:50:35.896311088 +0200 @@ -1,6 +1,7 @@ # # spec file for package python-bitstruct # +# Copyright (c) 2020 SUSE LLC # Copyright (c) 2020, Martin Hauke <mar...@gmx.de> # # All modifications and additions to the file contributed by third parties @@ -12,23 +13,23 @@ # license that conforms to the Open Source Definition (Version 1.9) # published by the Open Source Initiative. -# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# %{?!python_module:%define python_module() python-%{**} python3-%{**}} %define skip_python2 1 Name: python-bitstruct -Version: 8.9.0 +Version: 8.11.0 Release: 0 -License: MIT Summary: Interpret strings as packed binary data -Url: https://github.com/eerimoq/bitstruct -Group: Development/Languages/Python +License: MIT +URL: https://github.com/eerimoq/bitstruct Source: https://files.pythonhosted.org/packages/source/b/bitstruct/bitstruct-%{version}.tar.gz -BuildRequires: python-rpm-macros BuildRequires: %{python_module devel} BuildRequires: %{python_module setuptools} BuildRequires: fdupes +BuildRequires: python-rpm-macros %python_subpackages %description ++++++ bitstruct-8.9.0.tar.gz -> bitstruct-8.11.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/Makefile new/bitstruct-8.11.0/Makefile --- old/bitstruct-8.9.0/Makefile 2019-09-29 10:13:12.000000000 +0200 +++ new/bitstruct-8.11.0/Makefile 2020-04-15 09:47:58.000000000 +0200 @@ -1,6 +1,7 @@ test: python2 setup.py test python3 setup.py test + pypy3 setup.py test $(MAKE) test-sdist codespell -d $$(git ls-files) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/PKG-INFO new/bitstruct-8.11.0/PKG-INFO --- old/bitstruct-8.9.0/PKG-INFO 2020-01-20 23:16:45.000000000 +0100 +++ new/bitstruct-8.11.0/PKG-INFO 2020-06-10 18:31:21.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: bitstruct -Version: 8.9.0 +Version: 8.11.0 Summary: This module performs conversions between Python values and C bit field structs represented as Python byte strings. Home-page: https://github.com/eerimoq/bitstruct Author: Erik Moqvist, Ilya Petukhov @@ -36,7 +36,7 @@ unpack operations. There are two independent C implementations; `bitstruct.c`, which is part of this package, and the standalone package `cbitstruct`_. These implementations are only available in - Python 3, and must be explicitly imported. By default the pure Python + CPython 3, and must be explicitly imported. By default the pure Python implementation is used. To use `bitstruct.c`, do ``import bitstruct.c as bitstruct``. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/README.rst new/bitstruct-8.11.0/README.rst --- old/bitstruct-8.9.0/README.rst 2020-01-20 23:13:55.000000000 +0100 +++ new/bitstruct-8.11.0/README.rst 2020-04-15 09:55:22.000000000 +0200 @@ -28,7 +28,7 @@ unpack operations. There are two independent C implementations; `bitstruct.c`, which is part of this package, and the standalone package `cbitstruct`_. These implementations are only available in -Python 3, and must be explicitly imported. By default the pure Python +CPython 3, and must be explicitly imported. By default the pure Python implementation is used. To use `bitstruct.c`, do ``import bitstruct.c as bitstruct``. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/bitstruct/c.c new/bitstruct-8.11.0/bitstruct/c.c --- old/bitstruct-8.9.0/bitstruct/c.c 2019-10-09 22:43:01.000000000 +0200 +++ new/bitstruct-8.11.0/bitstruct/c.c 2020-06-10 18:19:11.000000000 +0200 @@ -49,8 +49,195 @@ PyObject *names_p; }; +static void compiled_format_dealloc(struct compiled_format_t *self_p); + +static PyObject *m_compiled_format_pack(struct compiled_format_t *self_p, + PyObject *args_p); + +static PyObject *m_compiled_format_unpack(struct compiled_format_t *self_p, + PyObject *args_p); + +static PyObject *m_compiled_format_pack_into(struct compiled_format_t *self_p, + PyObject *args_p, + PyObject *kwargs_p); + +static PyObject *m_compiled_format_unpack_from(struct compiled_format_t *self_p, + PyObject *args_p, + PyObject *kwargs_p); + +static PyObject *m_compiled_format_calcsize(struct compiled_format_t *self_p); + +static PyObject *m_compiled_format_copy(struct compiled_format_t *self_p); + +static PyObject *m_compiled_format_deepcopy(struct compiled_format_t *self_p, + PyObject *args_p); + +static void compiled_format_dict_dealloc(struct compiled_format_dict_t *self_p); + +static PyObject *m_compiled_format_dict_pack(struct compiled_format_dict_t *self_p, + PyObject *data_p); + +static PyObject *m_compiled_format_dict_unpack( + struct compiled_format_dict_t *self_p, + PyObject *data_p); + +static PyObject *m_compiled_format_dict_pack_into( + struct compiled_format_dict_t *self_p, + PyObject *args_p, + PyObject *kwargs_p); + +static PyObject *m_compiled_format_dict_unpack_from( + struct compiled_format_dict_t *self_p, + PyObject *args_p, + PyObject *kwargs_p); + +static PyObject *m_compiled_format_dict_calcsize( + struct compiled_format_dict_t *self_p); + +static PyObject *m_compiled_format_dict_copy( + struct compiled_format_dict_t *self_p); + +static PyObject *m_compiled_format_dict_deepcopy( + struct compiled_format_dict_t *self_p, + PyObject *args_p); + +PyDoc_STRVAR(pack___doc__, + "pack(fmt, *args)\n" + "--\n" + "\n"); + +PyDoc_STRVAR(unpack___doc__, + "unpack(fmt, data)\n" + "--\n" + "\n"); + +PyDoc_STRVAR(pack_into___doc__, + "pack_into(fmt, buf, offset, *args, **kwargs)\n" + "--\n" + "\n"); + +PyDoc_STRVAR(unpack_from___doc__, + "unpack_from(fmt, data, offset=0)\n" + "--\n" + "\n"); + +PyDoc_STRVAR(calcsize___doc__, + "calcsize(fmt)\n" + "--\n" + "\n"); + static PyObject *py_zero_p = NULL; +static struct PyMethodDef compiled_format_methods[] = { + { + "pack", + (PyCFunction)m_compiled_format_pack, + METH_VARARGS, + pack___doc__ + }, + { + "unpack", + (PyCFunction)m_compiled_format_unpack, + METH_VARARGS, + unpack___doc__ + }, + { + "pack_into", + (PyCFunction)m_compiled_format_pack_into, + METH_VARARGS | METH_KEYWORDS, + pack_into___doc__ + }, + { + "unpack_from", + (PyCFunction)m_compiled_format_unpack_from, + METH_VARARGS | METH_KEYWORDS, + unpack_from___doc__ + }, + { + "calcsize", + (PyCFunction)m_compiled_format_calcsize, + METH_NOARGS, + calcsize___doc__ + }, + { + "__copy__", + (PyCFunction)m_compiled_format_copy, + METH_NOARGS + }, + { + "__deepcopy__", + (PyCFunction)m_compiled_format_deepcopy, + METH_VARARGS + }, + { NULL } +}; + +static PyTypeObject compiled_format_type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "bitstruct.c.CompiledFormat", + .tp_doc = NULL, + .tp_basicsize = sizeof(struct compiled_format_t), + .tp_itemsize = 0, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_dealloc = (destructor)compiled_format_dealloc, + .tp_methods = compiled_format_methods, +}; + +static struct PyMethodDef compiled_format_dict_methods[] = { + { + "pack", + (PyCFunction)m_compiled_format_dict_pack, + METH_O, + pack___doc__ + }, + { + "unpack", + (PyCFunction)m_compiled_format_dict_unpack, + METH_O, + unpack___doc__ + }, + { + "pack_into", + (PyCFunction)m_compiled_format_dict_pack_into, + METH_VARARGS | METH_KEYWORDS, + pack_into___doc__ + }, + { + "unpack_from", + (PyCFunction)m_compiled_format_dict_unpack_from, + METH_VARARGS | METH_KEYWORDS, + unpack_from___doc__ + }, + { + "calcsize", + (PyCFunction)m_compiled_format_dict_calcsize, + METH_NOARGS, + calcsize___doc__ + }, + { + "__copy__", + (PyCFunction)m_compiled_format_dict_copy, + METH_NOARGS + }, + { + "__deepcopy__", + (PyCFunction)m_compiled_format_dict_deepcopy, + METH_VARARGS + }, + { NULL } +}; + +static PyTypeObject compiled_format_dict_type = { + PyVarObject_HEAD_INIT(NULL, 0) + .tp_name = "bitstruct.c.CompiledFormatDict", + .tp_doc = NULL, + .tp_basicsize = sizeof(struct compiled_format_dict_t), + .tp_itemsize = 0, + .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + .tp_dealloc = (destructor)compiled_format_dict_dealloc, + .tp_methods = compiled_format_dict_methods, +}; + static bool is_names_list(PyObject *names_p) { if (!PyList_Check(names_p)) { @@ -720,11 +907,6 @@ return (pack_finalize(packed_p)); } -PyDoc_STRVAR(pack___doc__, - "pack(fmt, *args)\n" - "--\n" - "\n"); - static PyObject *m_pack(PyObject *module_p, PyObject *args_p) { Py_ssize_t number_of_args; @@ -802,11 +984,6 @@ return (unpacked_p); } -PyDoc_STRVAR(unpack___doc__, - "unpack(fmt, data)\n" - "--\n" - "\n"); - static PyObject *m_unpack(PyObject *module_p, PyObject *args_p) { PyObject *format_p; @@ -943,11 +1120,6 @@ return (pack_into_finalize(&bounds)); } -PyDoc_STRVAR(pack_into___doc__, - "pack_into(fmt, buf, offset, *args, **kwargs)\n" - "--\n" - "\n"); - static PyObject *m_pack_into(PyObject *module_p, PyObject *args_p, PyObject *kwargs_p) @@ -1002,11 +1174,6 @@ return (unpack(info_p, data_p, offset)); } -PyDoc_STRVAR(unpack_from___doc__, - "unpack_from(fmt, data, offset=0)\n" - "--\n" - "\n"); - static PyObject *m_unpack_from(PyObject *module_p, PyObject *args_p, PyObject *kwargs_p) @@ -1392,11 +1559,6 @@ return (PyLong_FromLong(info_p->number_of_bits)); } -PyDoc_STRVAR(calcsize___doc__, - "calcsize(fmt)\n" - "--\n" - "\n"); - static PyObject *m_calcsize(PyObject *module_p, PyObject *format_p) { PyObject *size_p; @@ -1633,50 +1795,40 @@ return (calcsize(self_p->info_p)); } -static struct PyMethodDef compiled_format_methods[] = { - { - "pack", - (PyCFunction)m_compiled_format_pack, - METH_VARARGS, - pack___doc__ - }, - { - "unpack", - (PyCFunction)m_compiled_format_unpack, - METH_VARARGS, - unpack___doc__ - }, - { - "pack_into", - (PyCFunction)m_compiled_format_pack_into, - METH_VARARGS | METH_KEYWORDS, - pack_into___doc__ - }, - { - "unpack_from", - (PyCFunction)m_compiled_format_unpack_from, - METH_VARARGS | METH_KEYWORDS, - unpack_from___doc__ - }, - { - "calcsize", - (PyCFunction)m_compiled_format_calcsize, - METH_NOARGS, - calcsize___doc__ - }, - { NULL } -}; +static PyObject *m_compiled_format_copy(struct compiled_format_t *self_p) +{ + struct compiled_format_t *new_p; + size_t info_size; -static PyTypeObject compiled_format_type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "bitstruct.c.CompiledFormat", - .tp_doc = NULL, - .tp_basicsize = sizeof(struct compiled_format_t), - .tp_itemsize = 0, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_dealloc = (destructor)compiled_format_dealloc, - .tp_methods = compiled_format_methods, -}; + new_p = (struct compiled_format_t *)compiled_format_type.tp_alloc( + &compiled_format_type, + 0); + + if (new_p == NULL) { + return (NULL); + } + + info_size = sizeof(*self_p->info_p); + info_size += (sizeof(self_p->info_p->fields[0]) + * (self_p->info_p->number_of_fields - 1)); + + new_p->info_p = PyMem_RawMalloc(info_size); + + if (new_p->info_p == NULL) { + /* ToDo: Free new_p. */ + return (NULL); + } + + memcpy(new_p->info_p, self_p->info_p, info_size); + + return ((PyObject *)new_p); +} + +static PyObject *m_compiled_format_deepcopy(struct compiled_format_t *self_p, + PyObject *args_p) +{ + return (m_compiled_format_copy(self_p)); +} static PyObject *compiled_format_dict_new(PyTypeObject *subtype_p, PyObject *format_p, @@ -1794,50 +1946,42 @@ return (calcsize(self_p->info_p)); } -static struct PyMethodDef compiled_format_dict_methods[] = { - { - "pack", - (PyCFunction)m_compiled_format_dict_pack, - METH_O, - pack___doc__ - }, - { - "unpack", - (PyCFunction)m_compiled_format_dict_unpack, - METH_O, - unpack___doc__ - }, - { - "pack_into", - (PyCFunction)m_compiled_format_dict_pack_into, - METH_VARARGS | METH_KEYWORDS, - pack_into___doc__ - }, - { - "unpack_from", - (PyCFunction)m_compiled_format_dict_unpack_from, - METH_VARARGS | METH_KEYWORDS, - unpack_from___doc__ - }, - { - "calcsize", - (PyCFunction)m_compiled_format_dict_calcsize, - METH_NOARGS, - calcsize___doc__ - }, - { NULL } -}; +static PyObject *m_compiled_format_dict_copy(struct compiled_format_dict_t *self_p) +{ + struct compiled_format_dict_t *new_p; + size_t info_size; -static PyTypeObject compiled_format_dict_type = { - PyVarObject_HEAD_INIT(NULL, 0) - .tp_name = "bitstruct.c.CompiledFormatDict", - .tp_doc = NULL, - .tp_basicsize = sizeof(struct compiled_format_dict_t), - .tp_itemsize = 0, - .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - .tp_dealloc = (destructor)compiled_format_dict_dealloc, - .tp_methods = compiled_format_dict_methods, -}; + new_p = (struct compiled_format_dict_t *)compiled_format_dict_type.tp_alloc( + &compiled_format_dict_type, + 0); + + if (new_p == NULL) { + return (NULL); + } + + info_size = sizeof(*self_p->info_p); + info_size += (sizeof(self_p->info_p->fields[0]) + * (self_p->info_p->number_of_fields - 1)); + + new_p->info_p = PyMem_RawMalloc(info_size); + + if (new_p->info_p == NULL) { + /* ToDo: Free new_p. */ + return (NULL); + } + + memcpy(new_p->info_p, self_p->info_p, info_size); + Py_INCREF(self_p->names_p); + new_p->names_p = self_p->names_p; + + return ((PyObject *)new_p); +} + +static PyObject *m_compiled_format_dict_deepcopy(struct compiled_format_dict_t *self_p, + PyObject *args_p) +{ + return (m_compiled_format_dict_copy(self_p)); +} PyDoc_STRVAR(compile___doc__, "compile(fmt, names=None)\n" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/bitstruct/version.py new/bitstruct-8.11.0/bitstruct/version.py --- old/bitstruct-8.9.0/bitstruct/version.py 2020-01-20 23:14:07.000000000 +0100 +++ new/bitstruct-8.11.0/bitstruct/version.py 2020-06-10 18:23:01.000000000 +0200 @@ -1 +1 @@ -__version__ = '8.9.0' +__version__ = '8.11.0' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/bitstruct.egg-info/PKG-INFO new/bitstruct-8.11.0/bitstruct.egg-info/PKG-INFO --- old/bitstruct-8.9.0/bitstruct.egg-info/PKG-INFO 2020-01-20 23:16:45.000000000 +0100 +++ new/bitstruct-8.11.0/bitstruct.egg-info/PKG-INFO 2020-06-10 18:31:21.000000000 +0200 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: bitstruct -Version: 8.9.0 +Version: 8.11.0 Summary: This module performs conversions between Python values and C bit field structs represented as Python byte strings. Home-page: https://github.com/eerimoq/bitstruct Author: Erik Moqvist, Ilya Petukhov @@ -36,7 +36,7 @@ unpack operations. There are two independent C implementations; `bitstruct.c`, which is part of this package, and the standalone package `cbitstruct`_. These implementations are only available in - Python 3, and must be explicitly imported. By default the pure Python + CPython 3, and must be explicitly imported. By default the pure Python implementation is used. To use `bitstruct.c`, do ``import bitstruct.c as bitstruct``. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/setup.py new/bitstruct-8.11.0/setup.py --- old/bitstruct-8.9.0/setup.py 2019-09-29 10:13:12.000000000 +0200 +++ new/bitstruct-8.11.0/setup.py 2020-04-15 09:47:58.000000000 +0200 @@ -3,6 +3,7 @@ import sys import re import setuptools +import platform from setuptools import find_packages @@ -12,6 +13,16 @@ re.MULTILINE).group(1) +def is_cpython_3(): + if platform.python_implementation() != 'CPython': + return False + + if sys.version_info[0] < 3: + return False + + return True + + def setup(ext_modules): setuptools.setup( name='bitstruct', @@ -35,7 +46,7 @@ test_suite="tests") -if sys.version_info[0] > 2: +if is_cpython_3(): try: setup([setuptools.Extension('bitstruct.c', sources=[ @@ -46,5 +57,5 @@ print('WARNING: Failed to build the C extension.') setup([]) else: - print('INFO: C extension not implemented in Python 2.') + print('INFO: C extension only implemented in CPython 3.') setup([]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/tests/test_bitstruct.py new/bitstruct-8.11.0/tests/test_bitstruct.py --- old/bitstruct-8.9.0/tests/test_bitstruct.py 2019-10-02 17:01:05.000000000 +0200 +++ new/bitstruct-8.11.0/tests/test_bitstruct.py 2020-04-15 09:47:58.000000000 +0200 @@ -105,8 +105,7 @@ with self.assertRaises(TypeError) as cm: pack('r5', 1.0) - self.assertEqual(str(cm.exception), - "object of type 'float' has no len()") + self.assertIn("'float' has no", str(cm.exception)) # Cannot encode argument as utf-8. with self.assertRaises(AttributeError) as cm: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/bitstruct-8.9.0/tests/test_c.py new/bitstruct-8.11.0/tests/test_c.py --- old/bitstruct-8.9.0/tests/test_c.py 2019-10-09 15:24:06.000000000 +0200 +++ new/bitstruct-8.11.0/tests/test_c.py 2020-06-10 18:21:44.000000000 +0200 @@ -2,12 +2,25 @@ import sys import timeit import unittest +import platform +import copy -if sys.version_info[0] < 3: - print('Skipping C extension tests in Python 2.') -else: + +def is_cpython_3(): + if platform.python_implementation() != 'CPython': + return False + + if sys.version_info[0] < 3: + return False + + return True + + +if is_cpython_3(): import bitstruct.c from bitstruct.c import * +else: + print('Skipping C extension tests for non-CPython 3.') class CTest(unittest.TestCase): @@ -17,7 +30,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return packed = pack('u1u1s6u7u9', 0, 0, -2, 65, 22) @@ -93,7 +106,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return unpacked = unpack('u1u1s6u7u9', b'\x3e\x82\x16') @@ -183,7 +196,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return packed = pack('u1u1s6u7u9', 0, 0, -2, 65, 22) @@ -204,7 +217,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return size = calcsize('u1u1s6u7u9') @@ -227,7 +240,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return cf = bitstruct.c.compile('u1u1s6u7u9') @@ -241,10 +254,9 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return - res = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a' ref = b'\x01\x03\x02\x04\x08\x07\x06\x05\x0a\x09' self.assertEqual(byteswap('12142', ref), res) @@ -262,7 +274,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return packed = bytearray(3) @@ -326,7 +338,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return unpacked = unpack_from('u1u1s6u7u9', b'\x1f\x41\x0b\x00', 1) @@ -349,7 +361,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return cf = bitstruct.c.compile('u2') @@ -362,7 +374,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return cf = bitstruct.c.compile('u1') @@ -377,7 +389,7 @@ """ - if sys.version_info[0] < 3: + if not is_cpython_3(): return with self.assertRaises(NotImplementedError): @@ -403,7 +415,7 @@ self.assertEqual(unpacked, b'123') def test_pack_unpack_dict(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return unpacked = { @@ -421,7 +433,7 @@ self.assertEqual(unpack_dict(fmt, names, packed), unpacked) def test_pack_into_unpack_from_dict(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return unpacked = { @@ -442,7 +454,7 @@ self.assertEqual(unpack_from_dict(fmt, names, packed), unpacked) def test_compiled_pack_into_unpack_from_dict(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return unpacked = { @@ -464,7 +476,7 @@ self.assertEqual(cf.unpack_from(packed), unpacked) def test_compile(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return cf = bitstruct.c.compile('u1u1s6u7u9') @@ -476,7 +488,7 @@ self.assertEqual(unpacked, (0, 0, -2, 65, 22)) def test_compile_pack_unpack_formats(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return fmts = [ @@ -509,7 +521,7 @@ self.assertEqual(unpacked_2, decoded) def test_compile_formats(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return bitstruct.c.compile('p1u1') @@ -519,7 +531,7 @@ bitstruct.c.compile() def test_pack_unpack_signed(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return datas = [ @@ -534,7 +546,7 @@ self.assertEqual(unpack(fmt, packed), (value, )) def test_pack_unpack_unsigned(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return datas = [ @@ -549,7 +561,7 @@ self.assertEqual(unpack(fmt, packed), (value, )) def test_various(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return with self.assertRaises(ValueError): @@ -746,7 +758,7 @@ self.assertEqual(str(cm.exception), 'Names is not a list.') def test_whitespaces(self): - if sys.version_info[0] < 3: + if not is_cpython_3(): return fmts = [ @@ -757,6 +769,44 @@ for fmt in fmts: bitstruct.c.compile(fmt) + def test_copy(self): + if not is_cpython_3(): + return + + cf = bitstruct.c.compile('u1u1s6u7u9') + + cf = copy.copy(cf) + packed = cf.pack(0, 0, -2, 65, 22) + self.assertEqual(packed, b'\x3e\x82\x16') + + cf = copy.deepcopy(cf) + packed = cf.pack(0, 0, -2, 65, 22) + self.assertEqual(packed, b'\x3e\x82\x16') + + def test_copy_dict(self): + if not is_cpython_3(): + return + + unpacked = { + 'foo': 0, + 'bar': 0, + 'fie': -2, + 'fum': 65, + 'fam': 22 + } + names = ['foo', 'bar', 'fie', 'fum', 'fam'] + cf = bitstruct.c.compile('u1u1s6u7u9', names) + + cf = copy.copy(cf) + packed = cf.pack(unpacked) + self.assertEqual(packed, b'\x3e\x82\x16') + self.assertEqual(cf.unpack(packed), unpacked) + + cf = copy.deepcopy(cf) + packed = cf.pack(unpacked) + self.assertEqual(packed, b'\x3e\x82\x16') + self.assertEqual(cf.unpack(packed), unpacked) + if __name__ == '__main__': unittest.main()