changeset 2504:c27ee67397f0

Make pylint happy where it made sense, fix a few minor bugs.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 22 Jul 2007 05:33:02 +0200
parents d9aef892fda8
children 0a90c1bad60f
files jabberbot/i18n.py jabberbot/xmlrpcbot.py jabberbot/xmppbot.py
diffstat 3 files changed, 28 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/i18n.py	Sun Jul 22 05:11:19 2007 +0200
+++ b/jabberbot/i18n.py	Sun Jul 22 05:33:02 2007 +0200
@@ -7,10 +7,10 @@
 """
 import logging, xmlrpclib
 
-translations = None
+TRANSLATIONS = None
 
 
-def getText(original, lang="en"):
+def get_text(original, lang="en"):
     """ Return a translation of text in the user's language.
 
         @type original: unicode
@@ -18,12 +18,12 @@
     if original == u"":
         return u""
 
-    global translations
-    if not translations:
+    global TRANSLATIONS
+    if not TRANSLATIONS:
         init_i18n()
 
     try:
-        return translations[lang][original]
+        return TRANSLATIONS[lang][original]
     except KeyError:
         return original
 
@@ -34,8 +34,8 @@
     @type config: jabberbot.config.BotConfig
 
     """
-    global translations
-    translations = request_translations(config) or {'en': {}}
+    global TRANSLATIONS
+    TRANSLATIONS = request_translations(config) or {'en': {}}
 
 
 def request_translations(config):
--- a/jabberbot/xmlrpcbot.py	Sun Jul 22 05:11:19 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Sun Jul 22 05:33:02 2007 +0200
@@ -6,18 +6,19 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import datetime, logging, time, xmlrpclib, Queue
+import logging, xmlrpclib, Queue
 from SimpleXMLRPCServer import SimpleXMLRPCServer
 from threading import Thread
 
 import jabberbot.commands as cmd
 from jabberbot.multicall import MultiCall
-from jabberbot.i18n import getText
+from jabberbot.i18n import get_text
 
-_ = getText
+_ = get_text
 
 class ConfigurationError(Exception):
     def __init__(self, message):
+        Exception.__init__()
         self.message = message
 
 class XMLRPCClient(Thread):
@@ -207,7 +208,7 @@
         else:
             token_result, getpageinfo_result = self.multicall()
             if token_result != u"SUCCESS":
-                self.warn_no_credentials(jid)
+                self.warn_no_credentials(command.jid)
 
         author = getpageinfo_result['author']
         if author.startswith("Self:"):
--- a/jabberbot/xmppbot.py	Sun Jul 22 05:11:19 2007 +0200
+++ b/jabberbot/xmppbot.py	Sun Jul 22 05:33:02 2007 +0200
@@ -68,10 +68,12 @@
         self.last_online = None
 
     def set_supports_forms(self, resource):
+        """Flag the given resource as supporting Data Forms"""
         if resource in self.resources:
             self.resources[resource]["forms"] = True
 
     def supports_forms(self, resource):
+        """Check if the given resource supports Data Forms"""
         if resource in self.resources:
             return self.resources[resource]["forms"]
         else:
@@ -212,8 +214,8 @@
             if not contact.is_valid(current_time):
                 del self.contacts[jid]
 
-    def getText(self, jid):
-        """Returns a getText function (_) for the given JID
+    def get_text(self, jid):
+        """Returns a gettext function (_) for the given JID
 
         @param jid: bare Jabber ID of the user we're going to communicate with
         @type jid: str or pyxmpp.jid.JID
@@ -228,7 +230,7 @@
         if jid in self.contacts:
             language = self.contacts[jid].language
 
-        return lambda text: i18n.getText(text, lang=language)
+        return lambda text: i18n.get_text(text, lang=language)
 
     def poll_commands(self):
         """Checks for new commands in the input queue and executes them
@@ -272,7 +274,7 @@
 
             return
 
-        _ = self.getText(command.jid)
+        _ = self.get_text(command.jid)
 
         # Handle subscribtion management commands
         if isinstance(command, cmd.AddJIDToRosterCommand):
@@ -333,7 +335,7 @@
         stanza = Presence(to_jid=jid, stanza_type="unsubscribed")
         self.get_stream().send(stanza)
 
-    def send_message(self, jid, text, subject="", msg_type=u"chat", form=None):
+    def send_message(self, jid, text, subject="", msg_type=u"chat"):
         """Sends a message
 
         @param jid: JID to send the message to
@@ -349,7 +351,7 @@
         pass
 
     def send_search_form(self, jid):
-        _ = self.getText(jid)
+        _ = self.get_text(jid)
 
         # These encode()s may look weird, but due to some pyxmpp oddness we have
         # to provide an utf-8 string instead of unicode. Bug reported, patches submitted...
@@ -378,8 +380,8 @@
         @type command: unicode
 
         """
-        for cmd in self.internal_commands:
-            if cmd.lower() == command:
+        for internal_cmd in self.internal_commands:
+            if internal_cmd.lower() == command:
                 return True
 
         return False
@@ -390,8 +392,8 @@
         @type command: unicode
 
         """
-        for cmd in self.xmlrpc_commands:
-            if cmd.lower() == command:
+        for xmlrpc_cmd in self.xmlrpc_commands:
+            if xmlrpc_cmd.lower() == command:
                 return True
 
         return False
@@ -433,7 +435,7 @@
         @type sender: pyxmpp.jid.JID
 
         """
-        _ = self.getText(sender)
+        _ = self.get_text(sender)
 
         if command[0] == "ping":
             return "pong"
@@ -476,7 +478,7 @@
         @return: a help message
 
         """
-        _ = self.getText(jid)
+        _ = self.get_text(jid)
 
         if command == "help":
             return _("""The "help" command prints a short, helpful message \
@@ -508,7 +510,7 @@
         @type command: list representing a command, name and parameters
 
         """
-        _ = self.getText(sender)
+        _ = self.get_text(sender)
         command_class = self.xmlrpc_commands[command[0]]
 
         # Add sender's JID to the argument list
@@ -681,7 +683,7 @@
         It's sent in response to an uknown message or the "help" command.
 
         """
-        _ = self.getText(jid)
+        _ = self.get_text(jid)
 
         msg = _("Hello there! I'm a MoinMoin Notification Bot. Available commands:\
 \n\n%(internal)s\n%(xmlrpc)s")