def root_dict_to_etree(d):
 assert (len(d) == 1), ('Incoming dict len must be exactly 1. Data: %r' % d)
 (key,) = d.keys()
 retval = etree.Element(key)
 for val in d.values():
  break
 if (val is None):
  return retval
 if (isinstance(val, dict) or isinstance(val, odict)):
  dict_to_etree(val, retval)
 elif ((not isinstance(val, collections.Sized)) or isinstance(val, six.string_types)):
  retval.text = str(val)
 else:
  for a in val:
   dict_to_etree(a, retval)
 return retval

def root_dict_to_etree ( d ) : assert ( len ( d ) == 1 ) , ( 'Incoming dict len must be exactly 1. Data: %r' % d ) ( key , ) = d . keys ( ) retval = etree . Element ( key ) for val in d . values ( ) : break if ( val is None ) : return retval if ( isinstance ( val , dict ) or isinstance ( val , odict ) ) : dict_to_etree ( val , retval ) elif ( ( not isinstance ( val , collections . Sized ) ) or isinstance ( val , six . string_types ) ) : retval . text = str ( val ) else : for a in val : dict_to_etree ( a , retval ) return retval
converts a dictionary to an xml hiearchy .