2005-10-06 04:43:52 +00:00
|
|
|
import libxml2
|
|
|
|
|
import cStringIO
|
|
|
|
|
import exceptions
|
|
|
|
|
|
|
|
|
|
def process_introspection_data(data):
|
|
|
|
|
method_map = {}
|
|
|
|
|
|
|
|
|
|
XMLREADER_START_ELEMENT_NODE_TYPE = 1
|
|
|
|
|
XMLREADER_END_ELEMENT_NODE_TYPE = 15
|
|
|
|
|
|
2005-10-24 18:29:50 +00:00
|
|
|
stream = cStringIO.StringIO(data.encode('utf-8'))
|
2005-10-06 04:43:52 +00:00
|
|
|
input_source = libxml2.inputBuffer(stream)
|
|
|
|
|
reader = input_source.newTextReader("urn:introspect")
|
|
|
|
|
|
|
|
|
|
ret = reader.Read()
|
2005-11-07 15:31:30 +00:00
|
|
|
current_iface = None
|
|
|
|
|
current_method = None
|
2005-10-06 04:43:52 +00:00
|
|
|
current_sigstr = ''
|
2005-11-07 15:31:30 +00:00
|
|
|
|
2005-10-06 04:43:52 +00:00
|
|
|
while ret == 1:
|
|
|
|
|
name = reader.LocalName()
|
|
|
|
|
if reader.NodeType() == XMLREADER_START_ELEMENT_NODE_TYPE:
|
2005-11-07 15:31:30 +00:00
|
|
|
if (not current_iface and not current_method and name == 'interface'):
|
2005-10-06 04:43:52 +00:00
|
|
|
current_iface = reader.GetAttribute('name')
|
2005-11-07 15:31:30 +00:00
|
|
|
elif (current_iface and not current_method and name == 'method'):
|
2005-10-06 04:43:52 +00:00
|
|
|
current_method = reader.GetAttribute('name')
|
|
|
|
|
if reader.IsEmptyElement():
|
2005-11-07 15:31:30 +00:00
|
|
|
method_map[current_iface + '.' + current_method] = ''
|
|
|
|
|
current_method = None
|
2005-10-06 04:43:52 +00:00
|
|
|
current_sigstr = ''
|
2005-11-07 15:31:30 +00:00
|
|
|
|
|
|
|
|
elif (current_iface and current_method and name == 'arg'):
|
2005-10-06 04:43:52 +00:00
|
|
|
direction = reader.GetAttribute('direction')
|
|
|
|
|
|
|
|
|
|
if not direction or direction == 'in':
|
|
|
|
|
current_sigstr = current_sigstr + reader.GetAttribute('type')
|
|
|
|
|
|
|
|
|
|
elif reader.NodeType() == XMLREADER_END_ELEMENT_NODE_TYPE:
|
2005-11-07 15:31:30 +00:00
|
|
|
if (current_iface and not current_method and name == 'interface'):
|
|
|
|
|
current_iface = None
|
|
|
|
|
if (current_iface and current_method and name == 'method'):
|
|
|
|
|
method_map[current_iface + '.' + current_method] = current_sigstr
|
|
|
|
|
current_method = None
|
2005-10-06 04:43:52 +00:00
|
|
|
current_sigstr = ''
|
|
|
|
|
|
|
|
|
|
ret = reader.Read()
|
|
|
|
|
|
|
|
|
|
if ret != 0:
|
|
|
|
|
raise exceptions.IntrospectionParserException(data)
|
|
|
|
|
|
|
|
|
|
return method_map
|