From 6e46652242932561f6ef1e5baca3ea08ef35a6d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Thu, 16 Jul 2020 18:44:18 +0100 Subject: [PATCH 1/9] Remove the last usage of six. This removes the dependency from the package, since now we're requiring Python 3.5 anyway. --- pyproject.toml | 2 +- setup.py | 1 - tests/test_parse_enhanced_packet.py | 83 ++++++++++++++--------------- tests/test_structs.py | 9 ++-- tests/test_utils.py | 36 ++++++------- 5 files changed, 62 insertions(+), 69 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 509fe66..3cbeb45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,4 +17,4 @@ multi_line_output = 3 include_trailing_comma = true known_first_party = ['pcapng'] -known_third_party = ['pytest', 'scapy', 'six'] +known_third_party = ['pytest', 'scapy'] diff --git a/setup.py b/setup.py index cbe96bb..3be3c67 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,6 @@ setup( packages=find_packages(), - install_requires=["six"], extras_require={ "dev": [ "isort", diff --git a/tests/test_parse_enhanced_packet.py b/tests/test_parse_enhanced_packet.py index 0deb821..7cabb62 100644 --- a/tests/test_parse_enhanced_packet.py +++ b/tests/test_parse_enhanced_packet.py @@ -2,7 +2,6 @@ import struct import pytest -import six from pcapng.blocks import EnhancedPacket, InterfaceDescription, SectionHeader from pcapng.scanner import FileScanner @@ -12,48 +11,46 @@ def test_read_block_enhanced_packet_bigendian(): scanner = FileScanner( io.BytesIO( - six.b( - # ---------- Section header - "\x0a\x0d\x0d\x0a" # Magic number - "\x00\x00\x00\x20" # Block size (32 bytes) - "\x1a\x2b\x3c\x4d" # Magic number - "\x00\x01\x00\x00" # Version - "\xff\xff\xff\xff\xff\xff\xff\xff" # Undefined section length - "\x00\x00\x00\x00" # Empty options - "\x00\x00\x00\x20" # Block size (32 bytes) - # ---------- Interface description - "\x00\x00\x00\x01" # block magic - "\x00\x00\x00\x40" # block syze (64 bytes) - "\x00\x01" # link type - "\x00\x00" # reserved block - "\x00\x00\xff\xff" # size limit - "\x00\x02\x00\x04" - "eth0" # if_name - "\x00\x09\x00\x01" - "\x06\x00\x00\x00" # if_tsresol (+padding) - "\x00\x0c\x00\x13" - "Linux 3.2.0-4-amd64\x00" # if_os - "\x00\x00\x00\x00" # end of options - "\x00\x00\x00\x40" # block syze (64 bytes) - # ---------- Enhanced packet - "\x00\x00\x00\x06" # block magic - "\x00\x00\x00\x78" # block syze (120 bytes) - "\x00\x00\x00\x00" # interface id (first one, eth0) - "\x00\x04\xf8\x1e" - "\x3c\x3e\xd5\xa9" # timestamp (microseconds) - "\x00\x00\x00\x51" # Captured length - "\x00\x00\x00\x51" # Original length - # Packet data (81 bytes) - "\x00\x02\x157\xa2D\x00\xae\xf3R\xaa\xd1\x08\x00" # Ethernet - "E\x00\x00C\x00\x01\x00\x00@\x06x<\xc0\xa8\x05\x15B#\xfa\x97" # IP - "\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 " # TCP - "\x00\xbb9\x00\x00" # TCP(cont) - "GET /index.html HTTP/1.0 \n\n" # HTTP - "\x00\x00\x00" # Padding - # todo: add options? - "\x00\x00\x00\x00" # Empty options - "\x00\x00\x00\x78" # block syze (120 bytes) - ) + # ---------- Section header + b"\x0a\x0d\x0d\x0a" # Magic number + b"\x00\x00\x00\x20" # Block size (32 bytes) + b"\x1a\x2b\x3c\x4d" # Magic number + b"\x00\x01\x00\x00" # Version + b"\xff\xff\xff\xff\xff\xff\xff\xff" # Undefined section length + b"\x00\x00\x00\x00" # Empty options + b"\x00\x00\x00\x20" # Block size (32 bytes) + # ---------- Interface description + b"\x00\x00\x00\x01" # block magic + b"\x00\x00\x00\x40" # block syze (64 bytes) + b"\x00\x01" # link type + b"\x00\x00" # reserved block + b"\x00\x00\xff\xff" # size limit + b"\x00\x02\x00\x04" + b"eth0" # if_name + b"\x00\x09\x00\x01" + b"\x06\x00\x00\x00" # if_tsresol (+padding) + b"\x00\x0c\x00\x13" + b"Linux 3.2.0-4-amd64\x00" # if_os + b"\x00\x00\x00\x00" # end of options + b"\x00\x00\x00\x40" # block syze (64 bytes) + # ---------- Enhanced packet + b"\x00\x00\x00\x06" # block magic + b"\x00\x00\x00\x78" # block syze (120 bytes) + b"\x00\x00\x00\x00" # interface id (first one, eth0) + b"\x00\x04\xf8\x1e" + b"\x3c\x3e\xd5\xa9" # timestamp (microseconds) + b"\x00\x00\x00\x51" # Captured length + b"\x00\x00\x00\x51" # Original length + # Packet data (81 bytes) + b"\x00\x02\x157\xa2D\x00\xae\xf3R\xaa\xd1\x08\x00" # Ethernet + b"E\x00\x00C\x00\x01\x00\x00@\x06x<\xc0\xa8\x05\x15B#\xfa\x97" # IP + b"\x00\x14\x00P\x00\x00\x00\x00\x00\x00\x00\x00P\x02 " # TCP + b"\x00\xbb9\x00\x00" # TCP(cont) + b"GET /index.html HTTP/1.0 \n\n" # HTTP + b"\x00\x00\x00" # Padding + # todo: add options? + b"\x00\x00\x00\x00" # Empty options + b"\x00\x00\x00\x78" # block syze (120 bytes) ) ) diff --git a/tests/test_structs.py b/tests/test_structs.py index 8080c82..1ec71de 100644 --- a/tests/test_structs.py +++ b/tests/test_structs.py @@ -6,7 +6,6 @@ import struct import pytest -import six from pcapng.exceptions import BadMagic, CorruptedFile, StreamEmpty, TruncatedFile from pcapng.structs import ( @@ -296,16 +295,16 @@ def test_options_object(): assert options["opt_comment"] == "Comment #1" assert options[1] == "Comment #1" assert options.get_all("opt_comment") == ["Comment #1", "Comment #2"] - assert isinstance(options["opt_comment"], six.text_type) + assert isinstance(options["opt_comment"], str) assert options["spam"] == b"I love spam spam spam!" - assert isinstance(options["spam"], six.binary_type) + assert isinstance(options["spam"], bytes) assert options["eggs"] == 0x100 - assert isinstance(options["eggs"], six.integer_types) + assert isinstance(options["eggs"], int) assert options["bacon"] == "Bacon is delicious!" - assert isinstance(options["bacon"], six.text_type) + assert isinstance(options["bacon"], str) with pytest.raises(KeyError): options["missing"] diff --git a/tests/test_utils.py b/tests/test_utils.py index 64ec63d..eb848c0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,5 +1,3 @@ -from six import int2byte - from pcapng.utils import ( pack_timestamp_resolution, unpack_euiaddr, @@ -34,24 +32,24 @@ def test_unpack_euiaddr(): def test_unpack_tsresol(): - assert unpack_timestamp_resolution(int2byte(0)) == 1 - assert unpack_timestamp_resolution(int2byte(1)) == 1e-1 - assert unpack_timestamp_resolution(int2byte(6)) == 1e-6 - assert unpack_timestamp_resolution(int2byte(100)) == 1e-100 + assert unpack_timestamp_resolution(bytes((0,))) == 1 + assert unpack_timestamp_resolution(bytes((1,))) == 1e-1 + assert unpack_timestamp_resolution(bytes((6,))) == 1e-6 + assert unpack_timestamp_resolution(bytes((100,))) == 1e-100 - assert unpack_timestamp_resolution(int2byte(0 | 0b10000000)) == 1 - assert unpack_timestamp_resolution(int2byte(1 | 0b10000000)) == 2 ** -1 - assert unpack_timestamp_resolution(int2byte(6 | 0b10000000)) == 2 ** -6 - assert unpack_timestamp_resolution(int2byte(100 | 0b10000000)) == 2 ** -100 + assert unpack_timestamp_resolution(bytes((0 | 0b10000000,))) == 1 + assert unpack_timestamp_resolution(bytes((1 | 0b10000000,))) == 2 ** -1 + assert unpack_timestamp_resolution(bytes((6 | 0b10000000,))) == 2 ** -6 + assert unpack_timestamp_resolution(bytes((100 | 0b10000000,))) == 2 ** -100 def test_pack_tsresol(): - assert pack_timestamp_resolution(10, 0b00000000) == int2byte(0b00000000) - assert pack_timestamp_resolution(10, 0b00000011) == int2byte(0b00000011) - assert pack_timestamp_resolution(10, 0b00000100) == int2byte(0b00000100) - assert pack_timestamp_resolution(10, 0b00111100) == int2byte(0b00111100) - - assert pack_timestamp_resolution(2, 0b00000000) == int2byte(0b10000000) - assert pack_timestamp_resolution(2, 0b00000011) == int2byte(0b10000011) - assert pack_timestamp_resolution(2, 0b00000100) == int2byte(0b10000100) - assert pack_timestamp_resolution(2, 0b00111100) == int2byte(0b10111100) + assert pack_timestamp_resolution(10, 0b00000000) == bytes((0b00000000,)) + assert pack_timestamp_resolution(10, 0b00000011) == bytes((0b00000011,)) + assert pack_timestamp_resolution(10, 0b00000100) == bytes((0b00000100,)) + assert pack_timestamp_resolution(10, 0b00111100) == bytes((0b00111100,)) + + assert pack_timestamp_resolution(2, 0b00000000) == bytes((0b10000000,)) + assert pack_timestamp_resolution(2, 0b00000011) == bytes((0b10000011,)) + assert pack_timestamp_resolution(2, 0b00000100) == bytes((0b10000100,)) + assert pack_timestamp_resolution(2, 0b00111100) == bytes((0b10111100,)) From 9f6a1f70059628f29144102ab451b7b90569cb7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Thu, 16 Jul 2020 18:51:53 +0100 Subject: [PATCH 2/9] Move all the remaining packaging configuration to setup.cfg. Note that the package_data entries were not actually in use: those files are top-level rather than part of a package, so the resulting distribution is identical. --- setup.cfg | 16 ++++++++++++++++ setup.py | 21 ++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/setup.cfg b/setup.cfg index b05cfc1..c271947 100644 --- a/setup.cfg +++ b/setup.cfg @@ -18,6 +18,22 @@ classifiers = Programming Language :: Python :: 3.8 Programming Language :: Python :: Implementation :: CPython +[options] +packages = find: +zip_safe = False + +[options.extras_require] +dev = + flake8 + isort + pre-commit + pytest-cov + pytest-pycodestyle + pytest>=5.4 + setuptools_scm[toml] + sphinx + sphinx-rtd-theme + [flake8] max-line-length = 88 diff --git a/setup.py b/setup.py index 3be3c67..a167290 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,5 @@ -from setuptools import find_packages, setup +from setuptools import setup import setuptools_scm # noqa: F401 -setup( - packages=find_packages(), - extras_require={ - "dev": [ - "isort", - "pytest>=5.4", - "pytest-cov", - "pytest-pycodestyle", - "flake8", - "pre-commit", - "setuptools_scm[toml]", - "sphinx", - "sphinx-rtd-theme", - ], - }, - package_data={"": ["README.rst", "CHANGELOG.rst", "LICENSE"]}, - zip_safe=False, -) +setup() From 55367a36b584cf2306cdd9ddce6805df1973ea9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Thu, 16 Jul 2020 18:53:11 +0100 Subject: [PATCH 3/9] Add missing python_requires setting now that 3.5 is the minimum version. --- setup.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.cfg b/setup.cfg index c271947..8e85013 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,6 +19,7 @@ classifiers = Programming Language :: Python :: Implementation :: CPython [options] +python_requires = ~= 3.5 packages = find: zip_safe = False From 13eda3eb0db6ee059aa751ef3535c3ee605a069d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 27 Jul 2020 18:53:35 +0100 Subject: [PATCH 4/9] Remove empty test file. --- tests/test_object_representations.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 tests/test_object_representations.py diff --git a/tests/test_object_representations.py b/tests/test_object_representations.py deleted file mode 100644 index e69de29..0000000 From 51f6e24106bf56532215ab57041297770fc2e549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 3 Aug 2020 17:21:04 +0100 Subject: [PATCH 5/9] Use setup-cfg-fmt to reformat the setup.cfg file. Revert the name change to underscore, but keep the rest. Note that this removes CHANGELOG.rst from the PyPI descriptor, which is probably correct. --- setup.cfg | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8e85013..58e695b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,17 +1,18 @@ [metadata] name = python-pcapng +description = Library to read/write the pcap-ng format used by various packet sniffers. +long_description = file: README.rst +long_description_content_type = text/x-rst url = pythhttps://github.com/rshk/python-pcapng author = Samuele Santi author_email = samuele@samuelesanti.com -description = Library to read/write the pcap-ng format used by various packet sniffers. -long_description = file: README.rst, CHANGELOG.rst -long_description_content_type = text/x-rst -license = Apache Software License 2.0 +license = Apache-2.0 +license_file = LICENSE license_files = LICENSE classifiers = - License :: OSI Approved :: Apache Software License Development Status :: 5 - Production/Stable + License :: OSI Approved :: Apache Software License Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 @@ -19,8 +20,8 @@ classifiers = Programming Language :: Python :: Implementation :: CPython [options] -python_requires = ~= 3.5 packages = find: +python_requires = ~= 3.5 zip_safe = False [options.extras_require] @@ -28,9 +29,9 @@ dev = flake8 isort pre-commit + pytest>=5.4 pytest-cov pytest-pycodestyle - pytest>=5.4 setuptools_scm[toml] sphinx sphinx-rtd-theme From 804682d8dfb28d5d314755b2e35861c99512b1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 7 Sep 2020 10:17:04 +0100 Subject: [PATCH 6/9] Update pre-commit configuration to use newest version of all tools. --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f3d8358..639d96b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,21 +1,21 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + rev: v3.2.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace -- repo: https://github.com/timothycrosley/isort - rev: 4.3.21 +- repo: https://github.com/PyCQA/isort + rev: 5.5.1 hooks: - id: isort additional_dependencies: - toml -- repo: https://github.com/python/black - rev: 19.10b0 +- repo: https://github.com/psf/black + rev: 20.8b1 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.9 + rev: 3.8.3 hooks: - id: flake8 From 1c31c58a78f2a70f7c6b5045749ddc91ab39852a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 7 Sep 2020 10:17:46 +0100 Subject: [PATCH 7/9] Correct TypeError string formatting syntax. This is reported by the newer versions of flake8. --- pcapng/flags.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pcapng/flags.py b/pcapng/flags.py index 309dd92..06b3bbf 100644 --- a/pcapng/flags.py +++ b/pcapng/flags.py @@ -87,7 +87,7 @@ def __init__(self, owner, offset, size, extra=None): if len(extra) > 2 ** size: raise TypeError( "{cls} iterable has too many values (got {got}, " - + "{size} bits only address {max})".format( + "{size} bits only address {max})".format( cls=self.__class__.__name__, got=len(extra), size=size, @@ -156,7 +156,7 @@ def __init__(self, schema, nbits=32, initial=0): if tot_bits > nbits: raise TypeError( "Too many fields for {nbits}-bit field " - + "(schema defines {tot} bits)".format(nbits=nbits, tot=tot_bits) + "(schema defines {tot} bits)".format(nbits=nbits, tot=tot_bits) ) bitn = 0 From adacf3245b4f0b96587199d3a554297b38d5744b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 7 Sep 2020 10:18:01 +0100 Subject: [PATCH 8/9] Update setuptools import with newer isort. --- setup.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.py b/setup.py index a167290..f684491 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ -from setuptools import setup - import setuptools_scm # noqa: F401 +from setuptools import setup setup() From a01745330723de3042b4a0d3ae69966cd31c0832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Mon, 7 Sep 2020 10:18:36 +0100 Subject: [PATCH 9/9] Remove pytest-pycodestyle dependency. The pytest-pycodestyle package is now a Python 3.6+ dependency, so it will fail on 3.5. But even so, we don't need it, as flake8 (already ran as part of pre-commit) already runs codestyle. --- .travis.yml | 2 +- setup.cfg | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13e26c4..a31842c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,4 +17,4 @@ install: - pip install .[dev] script: - - py.test -vvv --pycodestyle --cov=pcapng --cov-report=term-missing tests + - py.test -vvv --cov=pcapng --cov-report=term-missing tests diff --git a/setup.cfg b/setup.cfg index 58e695b..27eb6d4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,7 +31,6 @@ dev = pre-commit pytest>=5.4 pytest-cov - pytest-pycodestyle setuptools_scm[toml] sphinx sphinx-rtd-theme