summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Moody <pmoody@google.com>2011-11-29 01:21:23 +0000
committerPeter Moody <pmoody@google.com>2011-11-29 01:21:23 +0000
commita054c3823522f2cb77fffa0e31f8f29c50060601 (patch)
tree1557355e05ecdee2c5d00a6d1e3c6483f8316378
parentdfa1b947b65a28f96b179742de26b301d04b5210 (diff)
downloadipaddr-py-a054c3823522f2cb77fffa0e31f8f29c50060601.tar.gz
fix
git-svn-id: https://ipaddr-py.googlecode.com/svn/trunk@237 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--ipaddr.py16
-rwxr-xr-xipaddr_test.py6
2 files changed, 11 insertions, 11 deletions
diff --git a/ipaddr.py b/ipaddr.py
index ef60011..5943635 100644
--- a/ipaddr.py
+++ b/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/ipaddr_test.py b/ipaddr_test.py
index 47345db..9446889 100755
--- a/ipaddr_test.py
+++ b/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',