summaryrefslogtreecommitdiff
path: root/Lib/ipaddr.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-02 18:10:37 +0000
committerBenjamin Peterson <benjamin@python.org>2009-05-02 18:10:37 +0000
commitb83819f2912b7be618be35dc5c0bf911bd37220c (patch)
tree56171cb01153334e7b3afd0285dc1f72cefe8492 /Lib/ipaddr.py
parent6bf1900e18e57bc43824a229eadc95c98e016fa5 (diff)
downloadcpython-git-b83819f2912b7be618be35dc5c0bf911bd37220c.tar.gz
make py3k compat code explicitly on
Diffstat (limited to 'Lib/ipaddr.py')
-rw-r--r--Lib/ipaddr.py37
1 files changed, 11 insertions, 26 deletions
diff --git a/Lib/ipaddr.py b/Lib/ipaddr.py
index f40cd7bb58..77c21f58d5 100644
--- a/Lib/ipaddr.py
+++ b/Lib/ipaddr.py
@@ -193,17 +193,6 @@ def collapse_address_list(addresses):
sorted(addresses, key=BaseIP._get_networks_key))
-# Test whether this Python implementation supports byte objects that
-# are not identical to str ones.
-# We need to exclude platforms where bytes == str so that we can
-# distinguish between packed representations and strings, for example
-# b'12::' (the IPv4 address 49.50.58.58) and '12::' (an IPv6 address).
-try:
- _compat_has_real_bytes = bytes != str
-except NameError: # <Python2.6
- _compat_has_real_bytes = False
-
-
class BaseIP(object):
"""A generic IP object.
@@ -591,13 +580,11 @@ class IPv4(BaseIP):
raise IPv4IpValidationError(ipaddr)
return
- # Constructing from a packed address
- if _compat_has_real_bytes:
- if isinstance(ipaddr, bytes) and len(ipaddr) == 4:
- self.ip = struct.unpack('!I', ipaddr)[0]
- self._prefixlen = 32
- self.netmask = self._ALL_ONES
- return
+ if isinstance(ipaddr, bytes) and len(ipaddr) == 4:
+ self.ip = struct.unpack('!I', ipaddr)[0]
+ self._prefixlen = 32
+ self.netmask = self._ALL_ONES
+ return
# Assume input argument to be string or any object representation
# which converts into a formatted IP prefix string.
@@ -930,14 +917,12 @@ class IPv6(BaseIP):
raise IPv6IpValidationError(ipaddr)
return
- # Constructing from a packed address
- if _compat_has_real_bytes:
- if isinstance(ipaddr, bytes) and len(ipaddr) == 16:
- tmp = struct.unpack('!QQ', ipaddr)
- self.ip = (tmp[0] << 64) | tmp[1]
- self._prefixlen = 128
- self.netmask = self._ALL_ONES
- return
+ if isinstance(ipaddr, bytes) and len(ipaddr) == 16:
+ tmp = struct.unpack('!QQ', ipaddr)
+ self.ip = (tmp[0] << 64) | tmp[1]
+ self._prefixlen = 128
+ self.netmask = self._ALL_ONES
+ return
# Assume input argument to be string or any object representation
# which converts into a formatted IP prefix string.