changeset 2502:d9aef892fda8

Fix xmlrpc commands. How come I've never noticed how b0rked it was?!
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 05:11:19 +0200
parents de573a7f49ce
children 09afb8020b20 c27ee67397f0
files jabberbot/xmlrpcbot.py
diffstat 1 files changed, 28 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/xmlrpcbot.py	Sun Jul 22 05:10:32 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Sun Jul 22 05:11:19 2007 +0200
@@ -82,7 +82,13 @@
         self.commands_out.put_nowait(report)
 
     def get_auth_token(self, jid):
-        token = self.connection.getAuthToken(jid, self.config.secret)
+        """Get an auth token using user's Jabber ID
+
+        @type jid: unicode
+        """
+        # We have to use a bare JID
+        jid = jid.split('/')[0]
+        token = self.connection.getJabberAuthToken(jid, self.config.secret)
         if token:
             self.token = token
 
@@ -139,12 +145,13 @@
 
         if not self.token:
             self.warn_no_credentials(command.jid)
-            getpage_result = self.multicall()
+            getpage_result = self.multicall()[0]
         else:
-            getpage_result, token_result = self.multicall()
+            token_result, getpage_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpage_result[0]
+        command.data = getpage_result
 
     get_page = _xmlrpc_decorator(get_page)
 
@@ -156,12 +163,13 @@
 
         if not self.token:
             self.warn_no_credentials(command.jid)
-            getpagehtml_result = self.multicall()
+            getpagehtml_result = self.multicall()[0]
         else:
             token_result, getpagehtml_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpagehtml_result[0]
+        command.data = getpagehtml_result
 
     get_page_html = _xmlrpc_decorator(get_page_html)
 
@@ -177,12 +185,13 @@
 
         if not self.token:
             # FIXME: notify the user that he may not have full rights on the wiki
-            getpagelist_result = self.multicall()
+            getpagelist_result = self.multicall()[0]
         else:
             token_result, getpagelist_result = self.multicall()
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(command.jid)
 
-        # FIXME: warn if token turned out being wrong
-        command.data = getpagelist_result[0]
+        command.data = getpagelist_result
 
     get_page_list = _xmlrpc_decorator(get_page_list)
 
@@ -193,18 +202,18 @@
         self.multicall.getPageInfo(command.pagename)
 
         if not self.token:
-            # FIXME: notify the user that he may not have full rights on the wiki
-            getpageinfo_result = self.multicall()
+            self.warn_no_credentials(command.jid)
+            getpageinfo_result = self.multicall()[0]
         else:
             token_result, getpageinfo_result = self.multicall()
-
-        # FIXME: warn if token turned out being wrong
+            if token_result != u"SUCCESS":
+                self.warn_no_credentials(jid)
 
-        author = getpageinfo_result[0]['author']
+        author = getpageinfo_result['author']
         if author.startswith("Self:"):
-            author = getpageinfo_result[0]['author'][5:]
+            author = getpageinfo_result['author'][5:]
 
-        datestr = str(getpageinfo_result[0]['lastModified'])
+        datestr = str(getpageinfo_result['lastModified'])
         date = u"%(year)s-%(month)s-%(day)s at %(time)s" % {
                     'year': datestr[:4],
                     'month': datestr[4:6],
@@ -217,7 +226,7 @@
 Current version: %(version)s""") % {
              'author': author,
              'modification': date,
-             'version': getpageinfo_result[0]['version'],
+             'version': getpageinfo_result['version'],
          }
 
         command.data = msg