mirror of
https://github.com/python/cpython.git
synced 2025-07-29 22:24:49 +00:00
make py3k compat code explicitly on
This commit is contained in:
parent
6bf1900e18
commit
b83819f291
2 changed files with 36 additions and 58 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue