[d-feet/wjt/handle-unix-fd-type: 2/3] dbus_utils: simplify converting simple types



commit 70e7aa87ae4e8e028425090afca2a0c9cd513328
Author: Will Thompson <will willthompson co uk>
Date:   Thu Oct 18 15:25:57 2018 +0100

    dbus_utils: simplify converting simple types

 src/dfeet/dbus_utils.py | 54 +++++++++++++++++++------------------------------
 1 file changed, 21 insertions(+), 33 deletions(-)
---
diff --git a/src/dfeet/dbus_utils.py b/src/dfeet/dbus_utils.py
index 18df0fe..51c9069 100644
--- a/src/dfeet/dbus_utils.py
+++ b/src/dfeet/dbus_utils.py
@@ -2,6 +2,27 @@
 from __future__ import print_function
 
 
+SIMPLE_TYPE_NAMES = {
+    'n': 'Int16',
+    'q': 'UInt16',
+    'i': 'Int32',
+    'u': 'UInt32',
+    'x': 'Int64',
+    't': 'UInt64',
+    's': 'String',
+    'b': 'Boolean',
+    'y': 'Byte',
+    'o': 'Object Path',
+    'g': 'Signature',
+    'd': 'Double',
+    'v': 'Variant',
+}
+
+
+def convert_simple_type(c):
+    return SIMPLE_TYPE_NAMES.get(c)
+
+
 def convert_complex_type(subsig):
     result = None
     len_consumed = 0
@@ -64,39 +85,6 @@ def convert_complex_type(subsig):
     return (result, len_consumed)
 
 
-def convert_simple_type(c):
-    result = None
-
-    if c == 'n':
-        result = 'Int16'
-    elif c == 'q':
-        result = 'UInt16'
-    elif c == 'i':
-        result = 'Int32'
-    elif c == 'u':
-        result = 'UInt32'
-    elif c == 'x':
-        result = 'Int64'
-    elif c == 't':
-        result = 'UInt64'
-    elif c == 's':
-        result = 'String'
-    elif c == 'b':
-        result = 'Boolean'
-    elif c == 'y':
-        result = 'Byte'
-    elif c == 'o':
-        result = 'Object Path'
-    elif c == 'g':
-        result = 'Signature'
-    elif c == 'd':
-        result = 'Double'
-    elif c == 'v':
-        result = 'Variant'
-
-    return result
-
-
 def sig_to_type_list(sig):
     i = 0
     result = []


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]