From bfa318c63141bc36b7fcf6cb7f8f6f443790b73b Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 1 May 2019 09:34:47 +0200 Subject: [PATCH 1/7] Travis CI: Detect Python syntax errors and undefined names http://flake8.pycqa.org --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4c96f64..8bd09fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,6 @@ python: - "3.7-dev" - "3.8-dev" - "nightly" +before_install: pip install flake8 +before_script: flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics script: nosetests -e fuzz From ce51690b7e1e0bc1986f1ebf7bd2e74e227d905b Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 1 May 2019 09:43:20 +0200 Subject: [PATCH 2/7] Use feature detection instead of version detection https://docs.python.org/3/howto/pyporting.html#use-feature-detection-instead-of-version-detection --- IPy.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IPy.py b/IPy.py index 3ccf989..b80e6a3 100644 --- a/IPy.py +++ b/IPy.py @@ -10,7 +10,6 @@ import bisect import collections -import sys import types # Definition of the Ranges for IPv4 IPs @@ -121,13 +120,14 @@ IPV6_TEST_MAP = 0xffffffffffffffffffffffff00000000 IPV6_MAP_MASK = 0x00000000000000000000ffff00000000 -if sys.version_info >= (3,): +try: + INT_TYPES = (int, long) + STR_TYPES = (str, unicode) + xrange +except NameError: INT_TYPES = (int,) STR_TYPES = (str,) xrange = range -else: - INT_TYPES = (int, long) - STR_TYPES = (str, unicode) class IPint(object): From eeb75d96fe3417d3ff176fcc0b106647d4e7b9dd Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 1 May 2019 09:50:43 +0200 Subject: [PATCH 3/7] Use print() function in both Python 2 and Python 3 Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3. There are 250 days until Python 2 end of life. --- example/confbuilder.py | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/example/confbuilder.py b/example/confbuilder.py index b799cf7..f448f5f 100644 --- a/example/confbuilder.py +++ b/example/confbuilder.py @@ -1,3 +1,4 @@ +from __future__ import print_function # This is a hack I use to generate my tinydns configuration # It serves as e test for converting from Perl Net::IP to # Python and IPy @@ -15,11 +16,11 @@ 'ns.dorsch.org': '195.143.234.25', 'ns.c0re.jp': '217.6.214.130'} -print "# *** nameservers ***" -for x in ns.keys(): - print "=%s:%s" % (x, ns[x]) +print("# *** nameservers ***") +for x in ns: + print("=%s:%s" % (x, ns[x])) -print "\n# *** domains ***" +print("\n# *** domains ***") fd = open('domains') @@ -28,13 +29,13 @@ if x[-1] == '\n': x = x[:-1] (domain, owner) = x.split(':') - print "'%s:Contact for this domain is %s" % (domain, owner) - for y in ns.keys(): - print ".%s::%s" % (domain, y) + print("'%s:Contact for this domain is %s" % (domain, owner)) + for y in ns: + print(".%s::%s" % (domain, y)) fd.close() -print "\n# *** Networks ***" +print("\n# *** Networks ***") fd = open('networks') ip6map = {} @@ -47,12 +48,12 @@ if len(x) > 0 and x[0] != '#': nets = x.split(',') name = nets.pop(0) - print "# Network: %s" % name + print("# Network: %s" % name) for y in nets: ip = IPy.IP(y) - print "# Address range: %s (%s), %d addresses" % (ip.strCompressed(), ip.iptype(), ip.len()) - print "=net.%s:%s" % (name, ip.net()) - print "=broadcast.%s:%s" % (name, ip.broadcast()) + print("# Address range: %s (%s), %d addresses" % (ip.strCompressed(), ip.iptype(), ip.len())) + print("=net.%s:%s" % (name, ip.net())) + print("=broadcast.%s:%s" % (name, ip.broadcast())) if ip.version() == 4: for z in ip: @@ -61,14 +62,14 @@ rmap[z.int()] = z.strBin() + "." + name else: # IPv6 - for z in ns.keys(): + for z in ns: for v in ip.reverseName(): - print ".%s::%s" % (v, z) + print(".%s::%s" % (v, z)) ip6map[ip.strFullsize(0)] = name fd.close() -print "\n# *** hosts ***" +print("\n# *** hosts ***") fd = open('hosts') @@ -77,12 +78,12 @@ x = x[:-1] if x != '' and x[0] != '#': if "@Z'.".find(x[0]) >= 0: - print x + print(x) else: if "=+'".find(x[0]) >= 0: i = x.split(':') rmap[IPy.IP(i[1]).int()] = '' - print x + print(x) else: x = x[1:] x += '||||' @@ -107,35 +108,33 @@ ip = IPy.IP(y) if ip.version() == 4: # IPv4 is easy - if not nmap.has_key(ip.int()): - print >>sys.stderr, "*** warning: no network for %s (%s) - ignoring" % (y, name) - print "# no network for %s (%s)" % (y, name) + if ip.int() not in nmap: + print("*** warning: no network for %s (%s) - ignoring" % (y, name), file=sys.stderr) + print("# no network for %s (%s)" % (y, name)) else: - print "=%s.%s:%s" % (name, nmap[ip.int()], y) - print "'%s.%s:Host contact is %s" % (name, nmap[ip.int()], admin) + print("=%s.%s:%s" % (name, nmap[ip.int()], y)) + print("'%s.%s:Host contact is %s" % (name, nmap[ip.int()], admin)) rmap[ip.int()] = '' for z in aliases: - print "+%s:%s" % (z, ip) - print "'%s:Host contact is %s" % (z, admin) + print("+%s:%s" % (z, ip)) + print("'%s:Host contact is %s" % (z, admin)) else: #IPv6 here net = ip.strFullsize(0) net = net[:19] + ':0000:0000:0000:0000' - if ip6map.has_key(net): - print >>sys.stderr, "*** warning: no network for %s (%s) - ignoring" % (ip, name) - print "# no network for %s (%s) - ignoring" % (ip, name) + if net in ip6map: + print("*** warning: no network for %s (%s) - ignoring" % (ip, name), file=sys.stderr) + print("# no network for %s (%s) - ignoring" % (ip, name)) else: - print "6%s.%s:%s"; (name, ip6map[net], ip.strHex()[2:]) + print("6%s.%s:%s"); (name, ip6map[net], ip.strHex()[2:]) for z in aliases: - print "3%s:%s" % (name, ip.strHex()[2:]) - print "'%s:Host contact is %s" % (name, admin) + print("3%s:%s" % (name, ip.strHex()[2:])) + print("'%s:Host contact is %s" % (name, admin)) fd.close() -print "\n# *** reverse lookup ***" -k = nmap.keys() -k.sort() -for x in k: - if rmap.has_key(x) and rmap[x] != '': - print "=%s:%s" % (rmap[x], str(IPy.IP(x))) +print("\n# *** reverse lookup ***") +for x in sorted(nmap): + if rmap.get(x): + print("=%s:%s" % (rmap[x], str(IPy.IP(x)))) From b2d6b23eb1ac299eab3f5901db45987748d3dc82 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 1 May 2019 10:00:20 +0200 Subject: [PATCH 4/7] Add missing % in formatting statement --- example/confbuilder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/confbuilder.py b/example/confbuilder.py index f448f5f..5e59d43 100644 --- a/example/confbuilder.py +++ b/example/confbuilder.py @@ -126,7 +126,7 @@ print("*** warning: no network for %s (%s) - ignoring" % (ip, name), file=sys.stderr) print("# no network for %s (%s) - ignoring" % (ip, name)) else: - print("6%s.%s:%s"); (name, ip6map[net], ip.strHex()[2:]) + print("6%s.%s:%s" % (name, ip6map[net], ip.strHex()[2:])) for z in aliases: print("3%s:%s" % (name, ip.strHex()[2:])) print("'%s:Host contact is %s" % (name, admin)) From 000d05166aa6ec3f1b7fe3ec59de54d08fbdd276 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 18 Jun 2020 07:43:53 +0200 Subject: [PATCH 5/7] pip will soon have a real dependency resolver So give pip all dependencies in a single command. --- .travis.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e87ea64..ff5bd31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +os: linux dist: xenial language: python python: @@ -6,10 +7,9 @@ python: - "3.5" - "3.6" - "3.7" - - "3.7-dev" - - "3.8-dev" + - "3.8" + - "3.9-dev" - "nightly" -before_install: pip install flake8 +install: pip install flake8 pytest before_script: flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics -install: pip install pytest script: pytest -k "not fuzz" From e66134756887c28385441d72399de560060bc0a2 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 18 Jun 2020 07:47:23 +0200 Subject: [PATCH 6/7] Python 3.4 is end of life https://devguide.python.org/devcycle/#end-of-life-branches https://devguide.python.org/#status-of-python-branches --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ff5bd31..4ca90e7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ dist: xenial language: python python: - "2.7" - - "3.4" - "3.5" - "3.6" - "3.7" From 0785b8d1a031cf86d69a1e59bfdbd0fd5dd21a5c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 18 Jun 2020 10:37:04 +0200 Subject: [PATCH 7/7] Upgrade to focal --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4ca90e7..6f7e4bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ os: linux -dist: xenial +dist: focal language: python python: - "2.7"