From 6c298032c4643ab2e9ad5a73e0c3b1fa8dad8e59 Mon Sep 17 00:00:00 2001 From: speyrefitte Date: Mon, 23 Jun 2014 15:51:18 +0200 Subject: [PATCH] Code refactoring --- rdpy/display/qt.py | 7 --- rdpy/examples/vncclient.py | 2 +- rdpy/network/error.py | 88 +++++++++++++------------------------- rdpy/protocol/rfb/rfb.py | 9 +--- 4 files changed, 33 insertions(+), 73 deletions(-) diff --git a/rdpy/display/qt.py b/rdpy/display/qt.py index 5e0f525..632a600 100644 --- a/rdpy/display/qt.py +++ b/rdpy/display/qt.py @@ -26,7 +26,6 @@ QRemoteDesktop is a widget use for render in rdpy from PyQt4 import QtGui, QtCore from rdpy.protocol.rfb.rfb import RFBClientObserver from rdpy.protocol.rdp.rdp import RDPClientObserver -from rdpy.network.error import UnRegistredObject class QAdaptor(object): ''' @@ -230,9 +229,6 @@ class QRemoteDesktop(QtGui.QWidget): call when button mouse is pressed @param event: qMouseEvent ''' - if self._adaptor is None: - raise UnRegistredObject("No adaptor to send mouse press event") - self._adaptor.sendMouseEvent(event) def keyPressEvent(self, event): @@ -240,8 +236,5 @@ class QRemoteDesktop(QtGui.QWidget): call when button key is pressed @param event: qKeyEvent ''' - if self._adaptor is None: - raise UnRegistredObject("No adaptor to send key press event") - self._adaptor.sendKeyEvent(event) \ No newline at end of file diff --git a/rdpy/examples/vncclient.py b/rdpy/examples/vncclient.py index 544dd11..ca44504 100644 --- a/rdpy/examples/vncclient.py +++ b/rdpy/examples/vncclient.py @@ -31,7 +31,7 @@ from PyQt4 import QtGui from rdpy.display.qt import RFBClientQt from rdpy.protocol.rfb import rfb -class RFBClientQtFactory(rfb.Factory): +class RFBClientQtFactory(rfb.ClientFactory): """ Factory create a VNC GUI client """ diff --git a/rdpy/network/error.py b/rdpy/network/error.py index d55ce34..69eacea 100644 --- a/rdpy/network/error.py +++ b/rdpy/network/error.py @@ -22,89 +22,61 @@ All exceptions error use in RDPY """ class InvalidValue(Exception): - ''' - raise when invalid value type occured - ''' + """ + Raise when invalid value type occurred + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) class InvalidExpectedDataException(Exception): - ''' - raise when expected data on network is invalid - ''' + """ + Raise when expected data on network is invalid + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) class NegotiationFailure(Exception): - ''' - raise when negotiation failure in different protocols - ''' + """ + Raise when negotiation failure in different protocols + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) class InvalidType(Exception): - ''' - raise when invalid value type occured - ''' + """ + Raise when invalid value type occured + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) class InvalidSize(Exception): - ''' - raise when invalid size is present in packet type occured - ''' + """ + Raise when invalid size is present in packet type occured + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) class ErrorReportedFromPeer(Exception): - ''' - raise when peer send an error - ''' + """ + Raise when peer send an error + """ def __init__(self, message = ""): - ''' - constructor with message + """ @param message: message show when exception is raised - ''' - Exception.__init__(self, message) - -class DisconnectLayer(Exception): - ''' - raise when try to send on unconnect layer - ''' - def __init__(self, message = ""): - ''' - constructor with message - @param message: message show when exception is raised - ''' - Exception.__init__(self, message) - -class UnRegistredObject(Exception): - ''' - raise when an object is not registred in other objet - ''' - def __init__(self, message = ""): - ''' - constructor with message - @param message: message show when exception is raised - ''' + """ Exception.__init__(self, message) diff --git a/rdpy/protocol/rfb/rfb.py b/rdpy/protocol/rfb/rfb.py index c87ac7f..f85c477 100644 --- a/rdpy/protocol/rfb/rfb.py +++ b/rdpy/protocol/rfb/rfb.py @@ -30,7 +30,7 @@ from twisted.internet import protocol from rdpy.network.layer import RawLayer, LayerMode from rdpy.network.type import UInt8, UInt16Be, UInt32Be, SInt32Be, String, CompositeType from rdpy.network.const import ConstAttributes, TypeAttributes -from rdpy.network.error import UnRegistredObject, InvalidValue +from rdpy.network.error import InvalidValue @ConstAttributes @TypeAttributes(String) @@ -520,7 +520,7 @@ class RFBController(object): print "Try to send an invalid pointer event" -class Factory(protocol.Factory): +class ClientFactory(protocol.Factory): """ Twisted Factory of RFB protocol """ @@ -560,9 +560,6 @@ class RFBClientObserver(object): @param isPressed: state of key @param key: ascii code of key """ - if self._controller is None: - raise UnRegistredObject("RFBClientObserver need to be registred to a RFBController object") - self._controller.sendKeyEvent(isPressed, key) def mouseEvent(self, button, x, y): @@ -572,8 +569,6 @@ class RFBClientObserver(object): @param x: x coordinate of mouse pointer @param y: y coordinate of mouse pointer """ - if self._controller is None: - raise UnRegistredObject("RFBClientObserver need to be registred to a RFBController object") mask = 0 if button == 1: mask = 1