Reviewers: ,


Please review this at http://codereview.tryton.org/39004/

Affected files:
  M tryton/gui/window/dblogin.py


Index: tryton/gui/window/dblogin.py
===================================================================
--- a/tryton/gui/window/dblogin.py
+++ b/tryton/gui/window/dblogin.py
@@ -505,6 +505,8 @@
         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 @@
         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):
             profile = profile_info[0]
@@ -542,6 +549,21 @@
         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)
@@ -560,7 +582,11 @@
                     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)
@@ -586,12 +612,17 @@
             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
+            netloc = netloc.split(']')[-1]
             database = self.entry_database.get_text()
             login = self.entry_login.get_text()
             CONFIG['login.server'] = host


--
[email protected] mailing list

Reply via email to