Merge remote-tracking branch 'theboegl/master' into 2478

This commit is contained in:
Joona Hoikkala
2016-03-20 11:30:56 +02:00
6 changed files with 55 additions and 2 deletions
+11 -2
View File
@@ -110,8 +110,17 @@ class Addr(object):
@classmethod
def fromstring(cls, str_addr):
"""Initialize Addr from string."""
tup = str_addr.partition(':')
return cls((tup[0], tup[2]))
if str_addr.startswith('['):
# ipv6 addresses starts with [
endIndex = str_addr.rfind(']')
host = str_addr[:endIndex + 1]
port = ''
if len(str_addr) > endIndex + 2 and str_addr[endIndex + 1] == ':':
port = str_addr[endIndex + 2:]
return cls((host, port))
else:
tup = str_addr.partition(':')
return cls((tup[0], tup[2]))
def __str__(self):
if self.tup[1]: