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 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/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 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.cfg b/setup.cfg index b05cfc1..27eb6d4 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,23 +1,40 @@ [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 Programming Language :: Python :: 3.8 Programming Language :: Python :: Implementation :: CPython +[options] +packages = find: +python_requires = ~= 3.5 +zip_safe = False + +[options.extras_require] +dev = + flake8 + isort + pre-commit + pytest>=5.4 + pytest-cov + setuptools_scm[toml] + sphinx + sphinx-rtd-theme + [flake8] max-line-length = 88 diff --git a/setup.py b/setup.py index cbe96bb..f684491 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,4 @@ -from setuptools import find_packages, setup - import setuptools_scm # noqa: F401 +from setuptools import setup -setup( - packages=find_packages(), - install_requires=["six"], - 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() diff --git a/tests/test_object_representations.py b/tests/test_object_representations.py deleted file mode 100644 index e69de29..0000000 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,))