diff --git a/HISTORY.md b/HISTORY.md index 11a2425..799412e 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,10 @@ # History +## 1.1.0 (2019-xx-xx) + +* Drop support for Python 2. +* Add support for Python 3.7. + ## 1.0.1 (2019-xx-xx) * Add manifest file. diff --git a/rabl/rabl.py b/rabl/rabl.py index 87c4124..9a5be6e 100644 --- a/rabl/rabl.py +++ b/rabl/rabl.py @@ -20,17 +20,10 @@ a small number of reports from many different sources. """ -from __future__ import absolute_import - import os import logging - -try: - import configparser -except ImportError: - import ConfigParser as configparser - -import ipaddr +import ipaddress +import configparser try: import MySQLdb @@ -88,7 +81,7 @@ def _handle(self): """Handle a single incoming connection.""" logger = logging.getLogger("rabl") logger.debug("Handling report from %s", self.client_address[0]) - packet = self.rfile.read(320000).strip() + packet = self.rfile.read(320000).decode("utf8").strip() # claimed_reporter is an IP address when from the trusted IP, or "" # otherwise. @@ -96,15 +89,15 @@ def _handle(self): is_spam = is_spam.lower() == "true" # We change reported IPv6 addresses to the /64 network. - address = ipaddr.IPAddress(address) - if isinstance(address, ipaddr.IPv6Address): - address = ipaddr.IPNetwork(str(address) + "/64").network - reporter = ipaddr.IPAddress(self.client_address[0]) + address = ipaddress.ip_address(address) + if isinstance(address, ipaddress.IPv6Address): + address = ipaddress.ip_network(str(address) + "/64").network + reporter = ipaddress.ip_address(self.client_address[0]) if reporter == CONF.get("rabl", "trusted_ip"): table_name = CONF.get("rabl", "trusted_table") # This IP is permitted to claim the report is from other IPs. - reporter = ipaddr.IPAddress(claimed_reporter) + reporter = ipaddress.ip_address(claimed_reporter) # If the report has a claimed reporter, then this has been # reported by a human, so may be able to be trusted more. elif claimed_reporter: diff --git a/rabl/write_to_rbldnsd.py b/rabl/write_to_rbldnsd.py index 117d1fa..b07dd6a 100644 --- a/rabl/write_to_rbldnsd.py +++ b/rabl/write_to_rbldnsd.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Reactive Autonomous Blackhole List Server @@ -6,19 +6,13 @@ data collected by the RABL server. """ -from __future__ import absolute_import - import os import shutil import hashlib import logging import datetime import tempfile - -try: - import configparser -except ImportError: - import ConfigParser as configparser +import configparser import MySQLdb @@ -50,7 +44,7 @@ def load_configuration(): def get_temporary_location(filename): """Return an appropriate temporary location to store the file. - + We use a temp folder within the final destination so that the copy should be atomic and so that we're using the same disk (e.g. taking advantage of the same speed, etc). @@ -126,7 +120,7 @@ def write_zone(filename, table_name, life, minspread): def generate_checksum(filename): """Generate a SHA256 hash checksum for the file.""" - with open(filename + ".sha256", "wb") as sha_sig: + with open(filename + ".sha256", "w") as sha_sig: with open(filename, "rb") as file_content: sha256_hash = hashlib.sha256() while True: diff --git a/requirements.txt b/requirements.txt index 6507685..e2d9bb7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ dnspython==1.16.0 idna==2.8 -ipaddr==2.2.0 mysqlclient==1.4.2.post1 sentry-sdk==0.10.2 spoon==1.0.6 diff --git a/salt/states/rabl.sls b/salt/states/rabl.sls index 6a2e875..5d44561 100644 --- a/salt/states/rabl.sls +++ b/salt/states/rabl.sls @@ -15,31 +15,11 @@ basic-install: - binutils - libc6 - gcc - - python-dev + - python3-dev + - python3-pip + - python3-whl - wget -broken_python_modules: - pkg.purged: - - pkgs: - - python-pip - - python-pip-whl - -download get-pip: - cmd.run: - - name: wget -nv -N https://bootstrap.pypa.io/get-pip.py - - cwd: /var/cache/ - - creates: /var/cache/get-pip.py - -#install pip: -# cmd.run: -# - name: /usr/bin/python /var/cache/get-pip.py -# - unless: 'test -f /usr/bin/pip && fgrep -q /usr/bin/python /usr/bin/pip && /usr/bin/python -m pip' -# - require: -# - cmd: download get-pip -# pip.installed: -# - name: setuptools -# - upgrade: True - mariadb-server: pkg: - latest diff --git a/setup.py b/setup.py index 5fa6473..638ebe8 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ "MySQL-python==1.2.5", "dnspython==1.16.0", "idna==2.8", - "ipaddr==2.2.0", "psutil==5.6.3", "sentry-sdk==0.10.2", "spoon==1.0.6", @@ -22,11 +21,11 @@ setup( name="se-rabl", - version="1.0.1", + version="1.1.0", description="SpamExperts RABL", long_description=readme, - author="SpamExperts B.V.", - author_email="support@spamexperts.com", + author="SolarWinds", + author_email="mail-plg-engineering@solarwinds.com", url="https://github.com/spamexperts/se-rabl", packages=["rabl"], scripts=["rabl/write_to_rbldnsd.py"], @@ -36,15 +35,11 @@ zip_safe=False, keywords="rabl,spam,spamexperts", classifiers=[ - "Development Status :: 2 - Pre-Alpha", + "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Natural Language :: English", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", + "Programming Language :: Python :: 3.7", ], test_suite="tests", tests_require=test_requirements, diff --git a/tests/unit/test_rabl.py b/tests/unit/test_rabl.py index d7493b0..923ce5c 100644 --- a/tests/unit/test_rabl.py +++ b/tests/unit/test_rabl.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """RABL unit tests."""