Remove some "clever" Python code.

Fri, 02 Sep 2016 00:45:59 -0400

author
Elliott Sales de Andrade <qulogic@pidgin.im>
date
Fri, 02 Sep 2016 00:45:59 -0400
changeset 37985
c3bab3be9695
parent 37984
6a5ca046a90d
child 37986
77721c9f7a85

Remove some "clever" Python code.

finch/plugins/pietray.py file | annotate | diff | comparison | revisions
libpurple/dbus-analyze-functions.py file | annotate | diff | comparison | revisions
libpurple/dbus-analyze-types.py file | annotate | diff | comparison | revisions
libpurple/purple-url-handler file | annotate | diff | comparison | revisions
--- a/finch/plugins/pietray.py	Thu Sep 01 23:58:47 2016 -0400
+++ b/finch/plugins/pietray.py	Fri Sep 02 00:45:59 2016 -0400
@@ -140,18 +140,20 @@
 
 
 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
 
 
--- a/libpurple/dbus-analyze-functions.py	Thu Sep 01 23:58:47 2016 -0400
+++ b/libpurple/dbus-analyze-functions.py	Fri Sep 02 00:45:59 2016 -0400
@@ -105,9 +105,6 @@
     pass
 
 
-myexception = MyException()
-
-
 def ctopascal(name):
     newname = ""
     for word in name.split("_"):
@@ -122,12 +119,12 @@
 
     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 @@
         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 @@
                 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 @@
             else:
                 return self.inputpointer(type, name)
 
-        raise myexception
+        raise MyException()
 
     def processoutput(self, type, name):
         const = False
@@ -238,7 +235,7 @@
         if type[0] == "gconstpointer":
             return self.outputgetdata(type, name)
 
-        raise myexception
+        raise MyException()
 
 
 class ClientBinding(Binding):
@@ -367,10 +364,10 @@
     # 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):
--- a/libpurple/dbus-analyze-types.py	Thu Sep 01 23:58:47 2016 -0400
+++ b/libpurple/dbus-analyze-types.py	Fri Sep 02 00:45:59 2016 -0400
@@ -68,7 +68,7 @@
             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
--- a/libpurple/purple-url-handler	Thu Sep 01 23:58:47 2016 -0400
+++ b/libpurple/purple-url-handler	Fri Sep 02 00:45:59 2016 -0400
@@ -223,8 +223,6 @@
         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 @@
     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:

mercurial