Skip to content

Travis CI: Detect Python syntax errors and undefined names #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
dist: xenial
os: linux
dist: focal
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.7-dev"
- "3.8-dev"
- "3.8"
- "3.9-dev"
- "nightly"
install: pip install pytest
install: pip install flake8 pytest
before_script: flake8 . --count --select=E9,F63,F72,F82 --show-source --statistics
script: pytest -k "not fuzz"
10 changes: 5 additions & 5 deletions IPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
__version__ = '1.00'

import bisect
import sys
import types
try:
import collections.abc as collections_abc
Expand Down Expand Up @@ -124,13 +123,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):
Expand Down
71 changes: 35 additions & 36 deletions example/confbuilder.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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')

Expand All @@ -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 = {}
Expand All @@ -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:
Expand All @@ -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')

Expand All @@ -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 += '||||'
Expand All @@ -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))))