Skip to content

Commit

Permalink
requirements_common.txt: Upgrade iptools==0.6.1 for Python 3 and ipv4…
Browse files Browse the repository at this point in the history
…/ipv6 (#1680)

* https://pypi.org/project/iptools/

https://pypi.org/project/iptools is currently [failing our build process](https://travis-ci.org/internetarchive/openlibrary/jobs/464164657#L894) on Python 3 because of a syntax error.  This PR upgrades to a Python 3 compatible release.

* iptools.validate_ip() —> iptools.ip4.validate_ip(

To track with changes to the iptools API.

* iptools.ipv4.validate_cidr()

* Update iprange.py
  • Loading branch information
cclauss authored and mekarpeles committed Dec 10, 2018
1 parent 1f677a3 commit 63db9c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions openlibrary/core/iprange.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,21 @@ def add_ip_range(self, ip_range, value):
# Convert ranges in CIDR format into (start, end) tuple
if isinstance(ip_range, six.string_types) and "/" in ip_range:
# ignore bad value
if not iptools.validate_cidr(ip_range):
if not iptools.ipv4.validate_cidr(ip_range):
return
ip_range = iptools.cidr2block(ip_range)
ip_range = iptools.ipv4.cidr2block(ip_range)

# Find the integer representation of first 2 parts of the start and end IPs
if isinstance(ip_range, tuple):
# ignore bad ips
if not iptools.validate_ip(ip_range[0]) or not iptools.validate_ip(ip_range[1]):
if not iptools.ipv4.validate_ip(ip_range[0]) or not iptools.ipv4.validate_ip(ip_range[1]):
return

# Take the first 2 parts of the begin and end ip as integer
start = iptools.ip2long(ip_range[0]) >> 16
end = iptools.ip2long(ip_range[1]) >> 16
start = iptools.ipv4.ip2long(ip_range[0]) >> 16
end = iptools.ipv4.ip2long(ip_range[1]) >> 16
else:
start = iptools.ip2long(ip_range) >> 16
start = iptools.ipv4.ip2long(ip_range) >> 16
end = start

# for each integer in the range add an entry.
Expand All @@ -169,7 +169,7 @@ def add_ip_range_text(self, ip_range_text, value):

def __getitem__(self, ip):
# integer representation of first 2 parts
base = iptools.ip2long(ip) >> 16
base = iptools.ipv4.ip2long(ip) >> 16
for ip_range, value in self.ip_ranges.get(base, {}).items():
if ip in ip_range:
return value
Expand Down
2 changes: 1 addition & 1 deletion requirements_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ DBUtils==1.3
flake8==3.6.0
Genshi==0.6
gunicorn==19.9.0
iptools==0.4.0
iptools==0.6.1
internetarchive==1.8.1
lxml==4.2.5
pyflakes==2.0.0
Expand Down

0 comments on commit 63db9c4

Please sign in to comment.