From a596899efbe589600dc704a50986c3775f76be2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 14 Jun 2011 11:20:21 +0200 Subject: [PATCH 1/2] Allow to enter IPv6 address as hostname in DBLogin review39004 --- tryton/gui/window/dblogin.py | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/tryton/gui/window/dblogin.py b/tryton/gui/window/dblogin.py index 59339a82a8..79edccb0ed 100644 --- a/tryton/gui/window/dblogin.py +++ b/tryton/gui/window/dblogin.py @@ -505,6 +505,8 @@ class DBLogin(object): except ConfigParser.NoOptionError: username = '' host = self.profiles.get(profile, 'host') + if ':' in host: + host = '[%s]' % host port = self.profiles.get(profile, 'port') self.entry_host.set_text('%s:%s' % (host, port)) self.entry_database.set_text(self.profiles.get(profile, 'database')) @@ -522,8 +524,13 @@ class DBLogin(object): self.move_active = True def clear_profile_combo(self, entry, event): - host_entry = self.entry_host.get_text() - host, port = host_entry.split(':', 1) if ':' in host_entry else ('', '') + netloc = self.entry_host.get_text() + host = self.get_hostname(netloc) + try: + port = str(self.get_port(netloc)) + except ValueError: + host = '' + port = '' database = self.entry_database.get_text().strip() for idx, profile_info in enumerate(self.profile_store): if not profile_info[1]: @@ -544,6 +551,21 @@ class DBLogin(object): self.entry_database.props.visible = visibility self.label_database.props.visible = visibility + def get_hostname(self, netloc): + if '[' in netloc and ']' in netloc: + return netloc.split(']')[0][1:] + elif ':' in netloc: + return netloc.split(':')[0] + else: + return netloc + + def get_port(self, netloc): + netloc = netloc.split(']')[-1] + if ':' in netloc: + return int(netloc.split(':')[1]) + else: + return 8070 + def run(self, parent): profile_name = CONFIG['login.profile'] can_use_profile = self.profiles.has_section(profile_name) @@ -562,7 +584,11 @@ class DBLogin(object): break else: self.combo_profile.set_active(-1) - self.entry_host.set_text('%s:%s' % (CONFIG['login.server'], + if ':' in CONFIG['login.server']: + host = '[%s]' % CONFIG['login.server'] + else: + host = CONFIG['login.server'] + self.entry_host.set_text('%s:%s' % (host, CONFIG['login.port'])) db = CONFIG['login.db'] if CONFIG['login.db'] else '' self.entry_database.set_text(db) @@ -588,12 +614,16 @@ class DBLogin(object): if active_profile != -1: profile = self.profile_store[active_profile][0] CONFIG['login.profile'] = profile - host, port = (self.entry_host.get_text().split(':', 1) - + ['8070'])[:2] + netloc = self.entry_host.get_text() + host = self.get_hostname(netloc) try: - port = int(port) + port = self.get_port(netloc) except ValueError: continue + if ':' in host: + hostname = '[%s]' % host + else: + hostname = host if not common.test_server_version(host, port): continue database = self.entry_database.get_text() From 1b4a04761ef8ab27eb473acb0defce634faebba6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 14 Jun 2011 12:31:09 +0200 Subject: [PATCH 2/2] Enforce test_server_version if not version is returned --- tryton/common/common.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tryton/common/common.py b/tryton/common/common.py index c48a6a2e55..aad7cca3a7 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -130,6 +130,8 @@ def find_in_path(name): def test_server_version(host, port): version = rpc.server_version(host, port) + if not version: + return False return version.split('.')[:2] == VERSION.split('.')[:2] def refresh_dblist(host, port):