From 0d406e7bafa8064edba92841235bfee79e191df4 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 23 May 2017 03:09:57 +0200 Subject: [PATCH] use _host to store host/ipv4/ipv6 for ipv6, it includes the outer square brackets. the host property strips any outer square brackets. --- src/borg/helpers.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/borg/helpers.py b/src/borg/helpers.py index 2f4a33790..3fc22e7cf 100644 --- a/src/borg/helpers.py +++ b/src/borg/helpers.py @@ -769,7 +769,7 @@ def bin_to_hex(binary): class Location: """Object representing a repository / archive location """ - proto = user = host = port = path = archive = None + proto = user = _host = port = path = archive = None # user must not contain "@", ":" or "/". # Quoting adduser error message: @@ -871,9 +871,7 @@ class Location: if m: self.proto = m.group('proto') self.user = m.group('user') - self.host = m.group('host') - if self.host is not None: - self.host = self.host.lstrip('[').rstrip(']') + self._host = m.group('host') self.port = m.group('port') and int(m.group('port')) or None self.path = normpath_special(m.group('path')) self.archive = m.group('archive') @@ -887,12 +885,10 @@ class Location: m = self.scp_re.match(text) if m: self.user = m.group('user') - self.host = m.group('host') - if isinstance(self.host, str): - self.host = self.host.lstrip('[').rstrip(']') + self._host = m.group('host') self.path = normpath_special(m.group('path')) self.archive = m.group('archive') - self.proto = self.host and 'ssh' or 'file' + self.proto = self._host and 'ssh' or 'file' return True return False @@ -916,6 +912,12 @@ class Location: def __repr__(self): return "Location(%s)" % self + @property + def host(self): + # strip square brackets used for IPv6 addrs + if self._host is not None: + return self._host.lstrip('[').rstrip(']') + def canonical_path(self): if self.proto == 'file': return self.path @@ -927,7 +929,7 @@ class Location: else: path = self.path return 'ssh://{}{}{}{}'.format('{}@'.format(self.user) if self.user else '', - self.host, + self._host, # needed for ipv6 addrs ':{}'.format(self.port) if self.port else '', path)