Skip to content

Commit

Permalink
Python3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanasco committed May 1, 2019
1 parent 4bc80f1 commit acdc251
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

0.7.0 -
- Python3 support via six
- Python2.6 required

0.6.5 - 2015-08-11
==================

Expand Down
24 changes: 14 additions & 10 deletions cidrize.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

__author__ = 'Jathan McCollum'
__email__ = '[email protected]'
__version__ = '0.6.5'
__version__ = '0.7.0'

"""
Intelligently parse IPv4/IPv6 addresses, CIDRs, ranges, and wildcard matches to
Expand All @@ -14,15 +15,18 @@
interactively for debugging purposes.
"""

# stdlib
import itertools
import logging
from netaddr import (AddrFormatError, IPAddress, IPGlob, IPNetwork, IPRange,
IPSet, spanning_cidr)
import os
import re
import socket
import sys

# pypi
from netaddr import (AddrFormatError, IPAddress, IPGlob, IPNetwork, IPRange,
IPSet, spanning_cidr)

# Globals
EVERYTHING = ['internet at large', '*', 'all', 'any', 'internet', '0.0.0.0',
'0.0.0.0/0', '0.0.0.0-255.255.255.255']
Expand Down Expand Up @@ -377,15 +381,15 @@ def optimize_network_range(ipstr, threshold=0.9, verbose=DEBUG):
ratio = float(len(strict)) / float(len(loose))

if verbose:
print 'Subnet usage ratio: %s; Threshold: %s' % (ratio, threshold)
print('Subnet usage ratio: %s; Threshold: %s' % (ratio, threshold))

if ratio >= threshold:
if verbose:
print 'Over threshold, IP Parse Mode: LOOSE'
print('Over threshold, IP Parse Mode: LOOSE')
result = loose.iter_cidrs()
else:
if verbose:
print 'Under threshold, IP Parse Mode: STRICT'
print('Under threshold, IP Parse Mode: STRICT')
result = strict.iter_cidrs()

return result
Expand Down Expand Up @@ -464,7 +468,7 @@ def dump(cidr):
log.debug('dump(): Got? %r' % cidr)

ip_first = IPAddress(cidr.first)
ip_firsthost = ip_first if single else cidr.iter_hosts().next()
ip_firsthost = ip_first if single else next(cidr.iter_hosts())
ip_gateway = IPAddress(cidr.last - 1)
ip_bcast = cidr.broadcast
ip_netmask = cidr.netmask
Expand Down Expand Up @@ -529,7 +533,7 @@ def parse_args(argv):
def phelp():
"""I help."""
parser.print_help()
print notes
print(notes)

if opts.help or len(args) == 1:
phelp()
Expand Down Expand Up @@ -558,9 +562,9 @@ def main():
cidr = cidrize(ipstr, modular=False)
if cidr:
if opts.verbose:
print dump(cidr),
print(dump(cidr),)
else:
print output_str(cidr)
print(output_str(cidr))
except IndexError:
return -1

Expand Down
14 changes: 8 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

try:
from setuptools import setup, Command
Expand All @@ -10,10 +11,10 @@
import unittest

#from cidrize import __version__
__version__ = '0.6.4'
__version__ = '0.7.0'

if sys.version_info[:2] < (2, 4):
print "This package requires Python 2.4+. Sorry!"
if sys.version_info[:2] < (2, 6):
print("This package requires Python 2.6+. Sorry!")
sys.exit(-1)

class CleanCommand(Command):
Expand All @@ -25,7 +26,7 @@ def finalize_options(self):
self.files = './build ./dist ./MANIFEST ./*.pyc ./*.egg-info'
def run(self):
#files = './build ./dist ./MANIFEST ./*.pyc'
print 'Cleaning: %s' % self.files
print('Cleaning: %s' % self.files)
os.system('rm -rf ' + self.files)

class TestCommand(Command):
Expand Down Expand Up @@ -54,7 +55,8 @@ def run(self):
author_email = '[email protected]',
py_modules = ['cidrize'],
scripts = ['scripts/cidr'],
install_requires=['netaddr>=0.7.6'],
install_requires=['netaddr>=0.7.6',],
tests_require=['netaddr>=0.7.6', ],
keywords = [
'Networking', 'Systems Administration', 'IANA', 'IEEE', 'CIDR', 'IP',
'IPv4', 'IPv6', 'IP Address', 'Firewalls', 'Security',
Expand All @@ -73,9 +75,9 @@ def run(self):
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Topic :: Education :: Testing',
'Topic :: Internet',
'Topic :: Internet :: Name Service (DNS)',
Expand Down

0 comments on commit acdc251

Please sign in to comment.