Commit a735ecde authored by John (J5) Palmieri's avatar John (J5) Palmieri

make complex types output work - all types are now covered

* dfeet/dbus_utils.py(convert_complex_type): handle arrays, structs and arrays
  of dict entries while also handling complex type recursion
  (convert_simple_type): fix converting 'b' to Boolean and 'y' to Byte
  (sig_to_type_list): handle lists which are the intermediate representation
  of children of complex types
  (sig_to_markup): treat complex types as one big markup though we need to
  change how markup works in the future to be even more detailed
parent 10303af3
def convert_complex_type(subsig):
result = None
len_consumed = 0
c = subsig[0]
#if c == 'a':
# result = ['Array of ', sig_to_type_list(subsig[1:])]
c_lookahead = ''
try:
c_lookahead = subsig[1]
except:
c_lookahead = ''
return result
if c == 'a' and c_lookahead == '{': # handle dicts as a special case array
ss = subsig[2:]
# account for the trailing '}'
len_consumed = 3
c = ss[0]
key = convert_simple_type(c)
ss = ss[1:]
(r, lc) = convert_complex_type(ss)
if r:
subtypelist = [key]
for item in r:
subtypelist.append(item)
len_consumed += lc + 1
else:
value = convert_simple_type(ss[0])
subtypelist = [key, value]
len_consumed += 1
result = ['Dict of {', subtypelist,'}']
elif c == 'a': # handle an array
ss = subsig[1:]
(r, lc) = convert_complex_type(ss)
if r:
subtypelist = r
len_consumed = lc + 1
else:
subtypelist = sig_to_type_list(ss[0])
len_consumed = 1
result = ['Array of [', subtypelist, ']']
elif c == '(': # handle structs
# iterate over sig until paren_count == 0
paren_count = 1
i = 0
ss = subsig[1:]
len_ss = len(ss)
while i < len_ss and paren_count != 0:
if ss[i] == '(':
paren_count+=1
elif ss[i] == ')':
paren_count-=1
i+=1
len_consumed = i
ss = ss[0:i-1]
result = ['Struct of (', sig_to_type_list(ss), ')']
return (result, len_consumed)
def convert_simple_type(c):
result = None
......@@ -18,6 +74,8 @@ def convert_simple_type(c):
elif c == 's':
result = 'String'
elif c == 'b':
result = 'Boolean'
elif c == 'y':
result = 'Byte'
elif c == 'o':
result = 'Object Path'
......@@ -31,34 +89,58 @@ def convert_simple_type(c):
def sig_to_type_list(sig):
i = 0
result = []
for c in sig:
sig_len = len(sig)
while i < sig_len:
c = sig[i]
type = convert_simple_type(c)
if not type:
type = convert_complex_type(sig[i:])
(type, len_consumed) = convert_complex_type(sig[i:])
if not type:
type = 'Error(' + c + ')'
result.append(type)
i += len_consumed
if isinstance(type, list):
for item in type:
result.append(item)
else:
result.append(type)
i+=1
return result
def type_list_to_string(type_list):
result = ''
add_cap = False
result = ', '.join(type_list)
for dbus_type in type_list:
if isinstance(dbus_type, list):
result += type_list_to_string(dbus_type)
add_cap = True
else:
# we get rid of the leading comma later
if not add_cap:
result += ', '
else:
add_cap = False
return result
try:
result += dbus_type
except:
print type_list
return result[2:]
def sig_to_markup(sig, span_attr_str):
list = sig_to_type_list(sig)
markedup_list = []
for dbus_type in list:
m = '<span ' + span_attr_str + '>'
m += dbus_type + '</span>'
markedup_list.append(m)
m = '<span ' + span_attr_str + '>'
m += type_list_to_string(list)
m += '</span>'
return type_list_to_string(markedup_list)
return m
def sig_to_string(sig):
return type_list_to_string(sig_to_type_list(sig))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment