From 5e3f1d3f468a5e981e0544e273d361e9f6fce517 Mon Sep 17 00:00:00 2001 From: "pmoody@google.com" Date: Tue, 29 Nov 2011 01:21:23 +0000 Subject: fix git-svn-id: https://ipaddr-py.googlecode.com/svn@237 09200d28-7f98-11dd-ad27-0f66e57d2035 --- trunk/ipaddr.py | 16 ++++++++-------- trunk/ipaddr_test.py | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py index ef60011..5943635 100644 --- a/trunk/ipaddr.py +++ b/trunk/ipaddr.py @@ -1022,10 +1022,8 @@ class _BaseV4(object): self._version = 4 self._max_prefixlen = IPV4LENGTH - def _explode_shorthand_ip_string(self, ip_str=None): - if not ip_str: - ip_str = str(self) - return ip_str + def _explode_shorthand_ip_string(self): + return str(self) def _ip_int_from_string(self, ip_str): """Turn the given IP string into an integer for comparison. @@ -1571,7 +1569,7 @@ class _BaseV6(object): hextets = self._compress_hextets(hextets) return ':'.join(hextets) - def _explode_shorthand_ip_string(self, ip_str=None): + def _explode_shorthand_ip_string(self): """Expand a shortened IPv6 address. Args: @@ -1581,10 +1579,10 @@ class _BaseV6(object): A string, the expanded IPv6 address. """ - if not ip_str: + if isinstance(self, _BaseNet): + ip_str = str(self.ip) + else: ip_str = str(self) - if isinstance(self, _BaseNet): - ip_str = str(self.ip) ip_int = self._ip_int_from_string(ip_str) parts = [] @@ -1592,6 +1590,8 @@ class _BaseV6(object): parts.append('%04x' % (ip_int & 0xFFFF)) ip_int >>= 16 parts.reverse() + if isinstance(self, _BaseNet): + return '%s/%d' % (':'.join(parts), self.prefixlen) return ':'.join(parts) @property diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py index 47345db..9446889 100755 --- a/trunk/ipaddr_test.py +++ b/trunk/ipaddr_test.py @@ -967,9 +967,9 @@ class IpaddrUnitTest(unittest.TestCase): def testExplodeShortHandIpStr(self): addr1 = ipaddr.IPv6Network('2001::1') addr2 = ipaddr.IPv6Address('2001:0:5ef5:79fd:0:59d:a0e5:ba1') - self.assertEqual('2001:0000:0000:0000:0000:0000:0000:0001', - addr1._explode_shorthand_ip_string(str(addr1.ip))) - self.assertEqual('0000:0000:0000:0000:0000:0000:0000:0001', + self.assertEqual('2001:0000:0000:0000:0000:0000:0000:0001/128', + addr1.exploded) + self.assertEqual('0000:0000:0000:0000:0000:0000:0000:0001/128', ipaddr.IPv6Network('::1/128').exploded) # issue 77 self.assertEqual('2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1', -- cgit v1.2.1