X-Git-Url: https://code.delx.au/pymsnt/blobdiff_plain/c6c8cb0ddd254bc06480376371e582ada797f3e6..38edf008bd005c4fc3a8cecba0379640f8bea4f6:/src/tlib/msn/msnw.py diff --git a/src/tlib/msn/msnw.py b/src/tlib/msn/msnw.py index c4f7c34..1060293 100644 --- a/src/tlib/msn/msnw.py +++ b/src/tlib/msn/msnw.py @@ -50,8 +50,9 @@ class MSNConnection: def _getNotificationReferral(self): def timeout(): + self.timeout = None if not d.called: - d.errback() + d.errback(Exception("Timeout")) self.logOut() # Clean up everything self.timeout = reactor.callLater(30, timeout) dispatchFactory = msn.DispatchFactory() @@ -65,6 +66,7 @@ class MSNConnection: def _gotNotificationReferral(self, (host, port)): self.timeout.cancel() + self.timeout = None # Create the NotificationClient self.notificationFactory = msn.NotificationFactory() self.notificationFactory.userHandle = self.username @@ -76,7 +78,6 @@ class MSNConnection: def _sendSavedEvents(self): self.savedEvents.send(self) - self.savedEvents = None def _notificationClientReady(self, notificationClient): self.notificationClient = notificationClient @@ -175,8 +176,8 @@ class MSNConnection: if self.notificationClient: LogEvent(INFO, self.ident) self.notificationClient.changeAvatar(imageData, push=True) - else: - self.savedEvents.avatarImageData = imageData + # Save the avatar for reuse on disconnection + self.savedEvents.avatarImageData = imageData def changeStatus(self, statusCode, screenName, personal): """ @@ -201,10 +202,10 @@ class MSNConnection: self.notificationClient.changeStatus(statusCode.encode("utf-8")).addCallback(cb) self.notificationClient.changeScreenName(screenName.encode("utf-8")).addCallback(cb) self.notificationClient.changePersonalMessage(personal.encode("utf-8")).addCallback(cb) - else: - self.savedEvents.statusCode = statusCode - self.savedEvents.screenName = screenName - self.savedEvents.personal = personal + # Remember the saved status + self.savedEvents.statusCode = statusCode + self.savedEvents.screenName = screenName + self.savedEvents.personal = personal def addContact(self, listType, userHandle): """ See msn.NotificationClient.addContact """ @@ -359,6 +360,10 @@ class DispatchClient(msn.DispatchClient): class NotificationClient(msn.NotificationClient): + def doDisconnect(self, *args): + if hasattr(self, "transport") and self.transport: + self.transport.loseConnection() + def loginFailure(self, message): self.factory.msncon.loginFailed(message) @@ -372,13 +377,18 @@ class NotificationClient(msn.NotificationClient): def logOut(self): msn.NotificationClient.logOut(self) + # If we explicitly log out, then all of these events + # are now redundant + self.loginFailure = self.doDisconnect + self.loggedIn = self.doDisconnect + self.connectionLost = self.doDisconnect def connectionLost(self, reason): - if not self.factory.msncon: return # If we called logOut def wait(): LogEvent(INFO, self.factory.msncon.ident) msn.NotificationClient.connectionLost(self, reason) - self.factory.msncon.connectionLost(reason) + if self.factory.maxRetries >= self.factory.retries: + self.factory.msncon.connectionLost(reason) # Make sure this event is handled after any others reactor.callLater(0, wait) @@ -459,9 +469,16 @@ class SwitchboardSessionBase(msn.SwitchboardClient): self.ready = False def __del__(self): + self.ready = False LogEvent(INFO, self.ident) del self.msncon self.transport.disconnect() + + def connectionLost(self, reason): + self.ready = False + self.msncon = None + self.msnobj = None + self.ident = (self.ident[0], self.ident[1] + " Disconnected!") def loggedIn(self): LogEvent(INFO, self.ident) @@ -649,9 +666,7 @@ class OneSwitchboardSession(SwitchboardSessionBase): del self.remoteUser self.contactCount = 0 self.msncon.gotGroupchat(self, userHandle) - if not self.groupchat: - LogEvent(ERROR, self.ident) - raise Exception("YouNeedAGroupchat-WeHaveAProblemError") # FIXME + assert self.groupchat def failedMessage(self, text): self.msncon.failedMessage(self.remoteUser, text)