[X2Go-Commits] [x2gobroker] 02/02: Consolidate x2gobroker.utils.split_host_address() with a test and rewrite completely.
git-admin at x2go.org
git-admin at x2go.org
Tue Oct 28 17:56:56 CET 2014
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository x2gobroker.
commit 41485378b9b790c894d69240b6e158cb2321b028
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Tue Oct 28 17:56:50 2014 +0100
Consolidate x2gobroker.utils.split_host_address() with a test and rewrite completely.
---
debian/changelog | 2 ++
x2gobroker/tests/test_utils.py | 32 ++++++++++++++++++++++++++++++++
x2gobroker/utils.py | 38 +++++++++++++++++++++++++++++---------
3 files changed, 63 insertions(+), 9 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 73161a5..0ecf46b 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -165,6 +165,8 @@ x2gobroker (0.0.3.0-0x2go1) UNRELEASED; urgency=low
- logrotate configs: Rotated logs via "su x2gobroker adm".
- Use hostname as hard-coded in server_list (from session profile configuration),
don't try to strip off the domain name.
+ - Consolidate x2gobroker.utils.split_host_address() with a test and rewrite
+ completely.
* debian/control:
+ Provide separate bin:package for SSH brokerage: x2gobroker-ssh.
+ Replace LDAP support with session brokerage support in LONG_DESCRIPTION.
diff --git a/x2gobroker/tests/test_utils.py b/x2gobroker/tests/test_utils.py
index f4f86ac..4de9b1b 100644
--- a/x2gobroker/tests/test_utils.py
+++ b/x2gobroker/tests/test_utils.py
@@ -131,6 +131,38 @@ class TestX2GoBrokerUtils(unittest.TestCase):
matching_hostnames = x2gobroker.utils.matching_hostnames(server_list_a, server_list_b)
self.assertEqual(matching_hostnames, ['server2'])
+ def test_split_host_address(self):
+
+ host = 8080
+ default_address = '127.0.0.1'
+ default_port = 22
+ bind_address, bind_port = x2gobroker.utils.split_host_address(host, default_address, default_port)
+ self.assertEqual((bind_address, bind_port), (default_address, host))
+
+ host = '8080'
+ default_address = None
+ default_port = None
+ bind_address, bind_port = x2gobroker.utils.split_host_address(host, default_address, default_port)
+ self.assertEqual((bind_address, bind_port), ('0.0.0.0', int(host)))
+
+ host = '0.0.0.0'
+ default_address = '127.0.0.1'
+ default_port = 8080
+ bind_address, bind_port = x2gobroker.utils.split_host_address(host, default_address, default_port)
+ self.assertEqual((bind_address, bind_port), (host, default_port))
+
+ host = '[::1]:8221'
+ default_address = '127.0.0.1'
+ default_port = 8080
+ bind_address, bind_port = x2gobroker.utils.split_host_address(host, default_address, default_port)
+ self.assertEqual((bind_address, bind_port), ('[::1]', 8221))
+
+ host = '[::1]'
+ default_address = '127.0.0.1'
+ default_port = 8080
+ bind_address, bind_port = x2gobroker.utils.split_host_address(host, default_address, default_port)
+ self.assertEqual((bind_address, bind_port), (host, default_port))
+
def test_suite():
from unittest import TestSuite, makeSuite
diff --git a/x2gobroker/utils.py b/x2gobroker/utils.py
index bcb9e2a..a7cb75a 100644
--- a/x2gobroker/utils.py
+++ b/x2gobroker/utils.py
@@ -193,29 +193,49 @@ def drop_privileges(uid, gid):
def split_host_address(host, default_address=None, default_port=22):
+ if type(host) is types.IntType:
+ host = unicode(host)
# do some stripping first...
host = host.strip()
host = host.lstrip('*')
host = host.lstrip(':')
+ bind_address = None
+ bind_port = None
+
+ is_ipv6 = None
+ if host[0] == '[':
+ is_ipv6 = True
+
if ':' in host:
bind_address, bind_port = host.rsplit(':', 1)
try:
bind_port = int(bind_port)
- except TypeError:
+ except ValueError:
# obviously we split an IPv6 address
bind_address = host
- bind_port = 22
+ bind_port = int(default_port)
else:
- if default_address is not None:
- bind_address = default_address
+ try:
+ # in host we find a port number only
bind_port = int(host)
- elif default_port is not None:
- bind_address = host
- bind_port = default_port
- else:
+ except ValueError:
bind_address = host
- bind_port = 0
+ if type(default_port) is types.IntType:
+ # use the given default, in host, there is an IP address or hostname
+ bind_port = default_port
+ else:
+ # setting a hard-coded port
+ bind_port = 22
+
+ if bind_address is None:
+ # in "host" we found the bind_port, now we assign the bind_address
+ bind_address = '0.0.0.0'
+ if default_address:
+ bind_address = default_address
+
bind_address = bind_address.lstrip('[').rstrip(']')
+ if is_ipv6:
+ bind_address = '[{address}]'.format(address=bind_address)
return bind_address, bind_port
--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git
More information about the x2go-commits
mailing list