summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-02-17 23:42:38 +0000
committerpmoody@google.com <pmoody@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035>2011-02-17 23:42:38 +0000
commite4673a1b7152001261d30d02150a5ebc38c764b3 (patch)
treea1481063d7c61690dc1b24f1ae86e4894683f9e9
parent9a79b82f2b16f8e13f81963e833f6218c0851b4b (diff)
downloadipaddr-py-e4673a1b7152001261d30d02150a5ebc38c764b3.tar.gz
+ bug in _is_shorthand_ip not correctly identifying shortened ips.
git-svn-id: https://ipaddr-py.googlecode.com/svn@218 09200d28-7f98-11dd-ad27-0f66e57d2035
-rw-r--r--trunk/ipaddr.py16
-rwxr-xr-xtrunk/ipaddr_test.py4
2 files changed, 15 insertions, 5 deletions
diff --git a/trunk/ipaddr.py b/trunk/ipaddr.py
index 62d49f7..d7eb222 100644
--- a/trunk/ipaddr.py
+++ b/trunk/ipaddr.py
@@ -1540,13 +1540,17 @@ class _BaseV6(object):
if self._is_shorthand_ip(ip_str):
new_ip = []
hextet = ip_str.split('::')
- sep = len(hextet[0].split(':')) + len(hextet[1].split(':'))
- new_ip = hextet[0].split(':')
- for _ in xrange(8 - sep):
- new_ip.append('0000')
- new_ip += hextet[1].split(':')
+ if len(hextet) > 1:
+ sep = len(hextet[0].split(':')) + len(hextet[1].split(':'))
+ new_ip = hextet[0].split(':')
+ for _ in xrange(8 - sep):
+ new_ip.append('0000')
+ new_ip += hextet[1].split(':')
+
+ else:
+ new_ip = ip_str.split(':')
# Now need to make sure every hextet is 4 lower case characters.
# If a hextet is < 4 characters, we've got missing leading 0's.
ret_ip = []
@@ -1627,6 +1631,8 @@ class _BaseV6(object):
"""
if ip_str.count('::') == 1:
return True
+ if filter(lambda x: len(x) < 4, ip_str.split(':')):
+ return True
return False
@property
diff --git a/trunk/ipaddr_test.py b/trunk/ipaddr_test.py
index 5ad815c..79c341d 100755
--- a/trunk/ipaddr_test.py
+++ b/trunk/ipaddr_test.py
@@ -909,10 +909,14 @@ 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',
ipaddr.IPv6Network('::1/128').exploded)
+ # issue 77
+ self.assertEqual('2001:0000:5ef5:79fd:0000:059d:a0e5:0ba1',
+ addr2.exploded)
def testIntRepresentation(self):
self.assertEqual(16909060, int(self.ipv4))