/pidgin/main: c3bab3be9695: Remove some "clever" Python code.

Elliott Sales de Andrade <[email protected]> Tue, 06 Sep 2016 11:30:53 -0400
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: c3bab3be96954983c164ab115cbe440d410b3ee5
Author:	 Elliott Sales de Andrade <[email protected]>
Date:	 2016-09-02 00:45 -0400
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/c3bab3be9695

Description:

Remove some "clever" Python code.

diffstat:

 finch/plugins/pietray.py            |  14 ++++++++------
 libpurple/dbus-analyze-functions.py |  19 ++++++++-----------
 libpurple/dbus-analyze-types.py     |   2 +-
 libpurple/purple-url-handler        |   4 +---
 4 files changed, 18 insertions(+), 21 deletions(-)

diffs (140 lines):

diff --git a/finch/plugins/pietray.py b/finch/plugins/pietray.py
--- a/finch/plugins/pietray.py
+++ b/finch/plugins/pietray.py
@@ -140,18 +140,20 @@ def popup_menu(icon, button, tm, none):
 
 
 def get_status_message():
+    status_names = {
+        1: 'Offline',
+        2: 'Available',
+        4: 'Invisible',
+        5: 'Away',
+    }
+
     status = purple.PurpleSavedstatusGetCurrent()
     msg = purple.PurpleSavedstatusGetMessage(status)
     if msg and len(msg) > 0:
         text = msg + " "
     else:
         text = ""
-    text = text + "(" + {
-        2: "Available",
-        5: "Away",
-        4: "Invisible",
-        1: "Offline"
-    }[purple.PurpleSavedstatusGetType(status)] + ")"
+    text += "(" + status_names[purple.PurpleSavedstatusGetType(status)] + ")"
     return text
 
 
diff --git a/libpurple/dbus-analyze-functions.py b/libpurple/dbus-analyze-functions.py
--- a/libpurple/dbus-analyze-functions.py
+++ b/libpurple/dbus-analyze-functions.py
@@ -105,9 +105,6 @@ class MyException(Exception):
     pass
 
 
-myexception = MyException()
-
-
 def ctopascal(name):
     newname = ""
     for word in name.split("_"):
@@ -122,12 +119,12 @@ class Parameter(object):
 
     def fromtokens(tokens, parameternumber=-1):
         if len(tokens) == 0:
-            raise myexception
+            raise MyException()
         if len(tokens) == 1 or tokens[-1] == pointer:
             if parameternumber >= 0:
                 return Parameter(tokens, "param%i" % (parameternumber, ))
             else:
-                raise myexception
+                raise MyException()
         else:
             return Parameter(tokens[:-1], tokens[-1])
 
@@ -139,7 +136,7 @@ class Binding(object):
         self.function = Parameter.fromtokens(functiontext.split())
 
         if self.function.name in excluded:
-            raise myexception
+            raise MyException()
 
         self.params = []
         for i in range(len(paramtexts)):
@@ -182,7 +179,7 @@ class Binding(object):
                 if const:
                     return self.inputstring(type, name, unsigned)
                 else:
-                    raise myexception
+                    raise MyException()
 
             elif type[0] == "GHashTable":
                 return self.inputhash(type, name)
@@ -199,7 +196,7 @@ class Binding(object):
             else:
                 return self.inputpointer(type, name)
 
-        raise myexception
+        raise MyException()
 
     def processoutput(self, type, name):
         const = False
@@ -238,7 +235,7 @@ class Binding(object):
         if type[0] == "gconstpointer":
             return self.outputgetdata(type, name)
 
-        raise myexception
+        raise MyException()
 
 
 class ClientBinding(Binding):
@@ -367,10 +364,10 @@ class ClientBinding(Binding):
     # Special case for *_get_data functions, don't need client bindings,
     #  but do need the name so it doesn't crash
     def inputgetdata(self, type, name):
-        raise myexception
+        raise MyException()
 
     def outputgetdata(self, type, name):
-        raise myexception
+        raise MyException()
 
 
 class ServerBinding(Binding):
diff --git a/libpurple/dbus-analyze-types.py b/libpurple/dbus-analyze-types.py
--- a/libpurple/dbus-analyze-types.py
+++ b/libpurple/dbus-analyze-types.py
@@ -68,7 +68,7 @@ for line in myinput:
             if match is not None:
                 print(toprint(match.group(1), line), file=args.output)
                 break
-            if line[0] not in [" ", "\t", "{", "\n"]:
+            if line[0] not in " \t{\n":
                 if args.verbatim:
                     print(line, file=args.output)
                 break
diff --git a/libpurple/purple-url-handler b/libpurple/purple-url-handler
--- a/libpurple/purple-url-handler
+++ b/libpurple/purple-url-handler
@@ -223,8 +223,6 @@ def irc(uri):
         for modifier in target.split(",")[1:]:
             modifiers[modifier] = True
 
-    isnick = True if "isnick" in modifiers else False
-
     paramstring = match.group(5)
     params = {}
     if paramstring:
@@ -240,7 +238,7 @@ def irc(uri):
     account = findaccount(protocol, matcher=correct_server)
 
     if target != "":
-        if isnick:
+        if "isnick" in modifiers:
             goim(account, unquote_plus(target.split(",")[0]),
                  params.get("msg"))
         else:

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits