[X2Go-Commits] [python-x2go] 01/02: Allow catching "connection refused" errors while talking to an X2Go Session Broker (X2GoBrokerConnectionException).
git-admin at x2go.org
git-admin at x2go.org
Fri Mar 28 23:58:10 CET 2014
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository python-x2go.
commit 2cc0568307db4c231eb3566b4d06a8d60f8c7cb9
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Mon Mar 24 13:49:55 2014 +0100
Allow catching "connection refused" errors while talking to an X2Go Session Broker (X2GoBrokerConnectionException).
---
debian/changelog | 2 ++
x2go/backends/profiles/httpbroker.py | 21 +++++++++++++++++----
x2go/x2go_exceptions.py | 2 ++
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/debian/changelog b/debian/changelog
index 1907a4b..b41a366 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -15,6 +15,8 @@ python-x2go (0.5.0.0-0x2go1) UNRELEASED; urgency=low
- Speed-optimize session profile ID <-> name mapping.
- Handle injection of PKey (Paramiko SSH key) objects for authentication
from the broker session profiles backend.
+ - Allow catching "connection refused" errors while talking to an X2Go
+ Session Broker (X2GoBrokerConnectionException).
* debian/control:
+ Add dependencies: python-requests, python-simplejson.
* python-x2go.spec:
diff --git a/x2go/backends/profiles/httpbroker.py b/x2go/backends/profiles/httpbroker.py
index 30e9b54..e8a2684 100644
--- a/x2go/backends/profiles/httpbroker.py
+++ b/x2go/backends/profiles/httpbroker.py
@@ -40,6 +40,7 @@ from x2go.defaults import CURRENT_LOCAL_USER as _CURRENT_LOCAL_USER
import x2go.backends.profiles.base as base
import x2go.log as log
from x2go.utils import genkeypair
+import x2go.x2go_exceptions
from x2go.x2go_exceptions import X2GoNotImplementedYetException
@@ -136,7 +137,10 @@ class X2GoSessionProfiles(base.X2GoSessionProfiles):
'user': broker_username or '',
'password': broker_password or '',
}
- r = requests.post(self.broker_url, data=request_data)
+ try:
+ r = requests.post(self.broker_url, data=request_data)
+ except requests.exceptions.ConnectionError:
+ raise x2go.x2go_exceptions.X2GoBrokerConnectionException('Failed to connect to URL %s' % self.broker_url)
if r.status_code == 200:
self.broker_username = broker_username or ''
self.broker_password = broker_password or ''
@@ -167,7 +171,10 @@ class X2GoSessionProfiles(base.X2GoSessionProfiles):
def is_broker_authenticated(self):
if self._broker_auth_successful is None:
# do a test auth against the given broker URL
- self.broker_simpleauth(self.broker_username, self.broker_password)
+ try:
+ self.broker_simpleauth(self.broker_username, self.broker_password)
+ except x2go.x2go_exceptions.X2GoBrokerConnectionException:
+ self._broker_auth_successful = False
return self._broker_auth_successful
def broker_listprofiles(self):
@@ -177,7 +184,10 @@ class X2GoSessionProfiles(base.X2GoSessionProfiles):
'user': self.broker_username,
'password': self.broker_password,
}
- r = requests.post(self.broker_url, data=request_data)
+ try:
+ r = requests.post(self.broker_url, data=request_data)
+ except requests.exceptions.ConnectionError:
+ raise x2go.x2go_exceptions.X2GoBrokerConnectionException('Failed to connect to URL %s' % self.broker_url)
if r.status_code == 200 and r.headers['content-type'].startswith("text/json"):
payload = json.loads(r.text)
if payload.has_key('mutable_profile_ids'):
@@ -197,7 +207,10 @@ class X2GoSessionProfiles(base.X2GoSessionProfiles):
'password': self.broker_password,
'pubkey': self.broker_my_pubkey,
}
- r = requests.post(self.broker_url, data=request_data)
+ try:
+ r = requests.post(self.broker_url, data=request_data)
+ except requests.exceptions.ConnectionError:
+ raise x2go.x2go_exceptions.X2GoBrokerConnectionException('Failed to connect to URL %s' % self.broker_url)
if r.status_code == 200 and r.headers['content-type'].startswith("text/json"):
payload = json.loads(r.text)
self._broker_profile_cache[profile_id] = payload['selected_session'] if payload['task'] == 'selectsession' else {}
diff --git a/x2go/x2go_exceptions.py b/x2go/x2go_exceptions.py
index 0ee1f57..2cda50c 100644
--- a/x2go/x2go_exceptions.py
+++ b/x2go/x2go_exceptions.py
@@ -69,6 +69,7 @@ class X2GoNotImplementedYetException(_X2GoException): pass
class X2GoDesktopSharingDenied(_X2GoException): pass
class X2GoDesktopSharingDenied(_X2GoException): pass
class X2GoTimeOutException(_X2GoException): pass
+class X2GoBrokerConnectionException(_X2GoException): pass
if _X2GOCLIENT_OS != 'Windows':
# faking Windows errors on non-Windows systems...
class WindowsError(_X2GoException): pass
@@ -100,3 +101,4 @@ class X2goSSHProxyAuthenticationException(_X2GoException): pass
class X2goNotImplementedYetException(_X2GoException): pass
class X2goDesktopSharingException(_X2GoException): pass
class X2goTimeOutException(_X2GoException): pass
+
--
Alioth's /srv/git/_hooks_/post-receive-email on /srv/git/code.x2go.org/python-x2go.git
More information about the x2go-commits
mailing list