[Python-checkins] r72207 - python/branches/py3k/Lib/ipaddr.py
gregory.p.smith
python-checkins at python.org
Sat May 2 20:35:58 CEST 2009
Author: gregory.p.smith
Date: Sat May 2 20:35:58 2009
New Revision: 72207
Log:
ipaddr cleanup for python 3.x:
* Get rid of __hex__.
* Support bytearray as well as bytes.
* Don't double test for integer input.
Modified:
python/branches/py3k/Lib/ipaddr.py
Modified: python/branches/py3k/Lib/ipaddr.py
==============================================================================
--- python/branches/py3k/Lib/ipaddr.py (original)
+++ python/branches/py3k/Lib/ipaddr.py Sat May 2 20:35:58 2009
@@ -263,9 +263,6 @@
def __int__(self):
return self.ip
- def __hex__(self):
- return hex(int(self))
-
def address_exclude(self, other):
"""Remove an address from a larger block.
@@ -572,7 +569,7 @@
self._version = 4
# Efficient constructor from integer.
- if isinstance(ipaddr, int) or isinstance(ipaddr, int):
+ if isinstance(ipaddr, int):
self.ip = ipaddr
self._prefixlen = 32
self.netmask = self._ALL_ONES
@@ -580,7 +577,8 @@
raise IPv4IpValidationError(ipaddr)
return
- if isinstance(ipaddr, bytes) and len(ipaddr) == 4:
+ # Constructing from a packed address
+ if isinstance(ipaddr, (bytes, bytearray)) and len(ipaddr) == 4:
self.ip = struct.unpack('!I', ipaddr)[0]
self._prefixlen = 32
self.netmask = self._ALL_ONES
@@ -909,7 +907,7 @@
self._version = 6
# Efficient constructor from integer.
- if isinstance(ipaddr, int) or isinstance(ipaddr, int):
+ if isinstance(ipaddr, int):
self.ip = ipaddr
self._prefixlen = 128
self.netmask = self._ALL_ONES
@@ -917,7 +915,8 @@
raise IPv6IpValidationError(ipaddr)
return
- if isinstance(ipaddr, bytes) and len(ipaddr) == 16:
+ # Constructing from a packed address
+ if isinstance(ipaddr, (bytes, bytearray)) and len(ipaddr) == 16:
tmp = struct.unpack('!QQ', ipaddr)
self.ip = (tmp[0] << 64) | tmp[1]
self._prefixlen = 128
More information about the Python-checkins
mailing list