changeset 2332:456545b5acfe

Handle errors in get_auth_token() gracefully, fix a comment.
author Karol Nowak <grzywacz@sul.uni.lodz.pl>
date Wed, 27 Jun 2007 13:14:05 +0200
parents 493565b060ff
children 88c539512520
files jabberbot/xmlrpcbot.py
diffstat 1 files changed, 14 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/xmlrpcbot.py	Tue Jun 26 16:39:06 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Wed Jun 27 13:14:05 2007 +0200
@@ -75,7 +75,7 @@
         token = self.connection.getAuthToken(jid, self.config.secret)
         if token:
             self.token = token
-    
+                
     def _xmlrpc_decorator(function):
         """A decorator function, which adds some maintenance code
         
@@ -86,19 +86,25 @@
         def wrapped_func(self, command):
             self.token = None
             self.multicall = MultiCall(self.connection)
-            self.get_auth_token(command.jid)
+            jid = command.jid
             
-            if self.token:
-                self.multicall.applyAuthToken(self.token)
-   
             try:
                 try:
+                    self.get_auth_token(command.jid)
+                    if self.token:
+                        self.multicall.applyAuthToken(self.token)
+                        
                     function(self, command)
                     self.commands_out.put_nowait(command)
                 except xmlrpclib.Fault, fault:
                     msg = u"""Your request has failed. The reason is:\n%s"""
-                    notification = cmd.NotificationCommand(command.jid, msg % (fault.faultString, ))
+                    notification = cmd.NotificationCommand([jid], msg % (fault.faultString, ))
                     self.commands_out.put_nowait(notification)
+                except xmlrpclib.Error, err:
+                    msg = u"""A serious error occured while processing your request:\n%s"""
+                    notification = cmd.NotificationCommand([jid], msg % (str(err), ))
+                    self.commands_out.put_nowait(notification)
+                    
             finally:
                 del self.token
                 del self.multicall
@@ -255,8 +261,8 @@
     def send_notification(self, jids, text):
         """Instructs the XMPP component to send a notification
         
-        @param jid: a jid to send a message to (bare jid)
-        @type jid: str or unicode
+        @param jids: a list of JIDs to send a message to (bare JIDs)
+        @type jids: a list of str or unicode
         @param text: a message body
         @type text: unicode