diff options
author | mkaay <mkaay@mkaay.de> | 2011-02-13 15:06:03 +0100 |
---|---|---|
committer | mkaay <mkaay@mkaay.de> | 2011-02-13 15:06:03 +0100 |
commit | 908c28bab89525250172a4013667319942846065 (patch) | |
tree | 73b85517ae12f8be4bc2071409136f181907795d /module/gui/connector.py | |
parent | cleanup (diff) | |
download | pyload-908c28bab89525250172a4013667319942846065.tar.xz |
fixes + improvements
Diffstat (limited to 'module/gui/connector.py')
-rw-r--r-- | module/gui/connector.py | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/module/gui/connector.py b/module/gui/connector.py index a9cb0610c..5acfdfc8b 100644 --- a/module/gui/connector.py +++ b/module/gui/connector.py @@ -26,13 +26,8 @@ from PyQt4.QtGui import * import socket -from module.remote.thriftbackend.thriftgen.pyload import Pyload -from module.remote.thriftbackend.thriftgen.pyload.ttypes import * -from module.remote.thriftbackend.Socket import Socket -from module.remote.thriftbackend.Protocol import Protocol - -from thrift import Thrift -from thrift.transport import TTransport +from module.remote.thriftbackend.ThriftClient import ThriftClient, WrongLogin, NoSSL, NoConnection +from thrift.Thrift import TException class Connector(QObject): def __init__(self): @@ -55,16 +50,17 @@ class Connector(QObject): self.ssl = ssl def connectProxy(self): - transport = Socket(self.host, self.port, self.ssl) - transport = TTransport.TBufferedTransport(transport) - protocol = Protocol(transport) - client = Pyload.Client(protocol) - - transport.open() - - if not client.login(self.user, self.password): + try: + client = ThriftClient(self.host, self.port, self.user, self.password) + except WrongLogin: self.emit(SIGNAL("error_box"), "bad login credentials") return False + except NoSSL: + self.emit(SIGNAL("error_box"), "no ssl support") + return False + except NoConnection: + self.emit(SIGNAL("connectionLost")) + return False self.proxy = DispatchRPC(self.mutex, client) self.connect(self.proxy, SIGNAL("proxy_error"), self._proxyError) @@ -113,15 +109,21 @@ class DispatchRPC(QObject): self.f = f self.mutex = mutex self.dispatcher = dispatcher - self.error = True def __call__(self, *args, **kwargs): + lost = False + error = False try: return self.f(*args, **kwargs) except socket.error: - self.dispatcher.emit(SIGNAL("connectionLost")) + lost = True + except TException: + lost = True except Exception, e: - if self.error: - self.dispatcher.emit(SIGNAL("proxy_error"), self.dispatcher.fname, e) + err = e finally: self.mutex.unlock() + if lost: + self.dispatcher.emit(SIGNAL("connectionLost")) + if error: + self.dispatcher.emit(SIGNAL("proxy_error"), self.dispatcher.fname, error) |