_dbus_bindings: Expose name-validation functions to Python code.
[dbus-python-phuang.git] / dbus / introspect_parser.py
blob47c9806e8688eb040cf8b4e84916663ac87a9673
1 import libxml2
2 import cStringIO
3 import exceptions
5 def process_introspection_data(data):
6 method_map = {}
8 XMLREADER_START_ELEMENT_NODE_TYPE = 1
9 XMLREADER_END_ELEMENT_NODE_TYPE = 15
11 stream = cStringIO.StringIO(data.encode('utf-8'))
12 input_source = libxml2.inputBuffer(stream)
13 reader = input_source.newTextReader("urn:introspect")
15 ret = reader.Read()
16 current_iface = None
17 current_method = None
18 current_sigstr = ''
20 while ret == 1:
21 name = reader.LocalName()
22 if reader.NodeType() == XMLREADER_START_ELEMENT_NODE_TYPE:
23 if (not current_iface and not current_method and name == 'interface'):
24 current_iface = reader.GetAttribute('name')
25 elif (current_iface and not current_method and name == 'method'):
26 current_method = reader.GetAttribute('name')
27 if reader.IsEmptyElement():
28 method_map[current_iface + '.' + current_method] = ''
29 current_method = None
30 current_sigstr = ''
32 elif (current_iface and current_method and name == 'arg'):
33 direction = reader.GetAttribute('direction')
35 if not direction or direction == 'in':
36 current_sigstr = current_sigstr + reader.GetAttribute('type')
38 elif reader.NodeType() == XMLREADER_END_ELEMENT_NODE_TYPE:
39 if (current_iface and not current_method and name == 'interface'):
40 current_iface = None
41 if (current_iface and current_method and name == 'method'):
42 method_map[current_iface + '.' + current_method] = current_sigstr
43 current_method = None
44 current_sigstr = ''
46 ret = reader.Read()
48 if ret != 0:
49 raise exceptions.IntrospectionParserException(data)
51 return method_map