dbus/python/introspect_parser.py
Robert McQueen e598c5edc5 2005-11-07 Robert McQueen <robot101@debian.org>
* python/decorators.py: Change emit_signal function to use the
	signature annotation of the signal when marhsalling the arguments from
	the service. Fix a bug where the code checking signature length
	against argument length referenced the wrong variable.

	* python/introspect_parser.py: Avoid adding the type signature of
	signal arguments to any methods which occur after them in the
	introspection data (!) by making the parser a little more careful
	about its current state.

	* python/service.py: Remove debug prints from last commit (again :D).

	* test/python/test-client.py, test/python/test-service.py: Add test
	signals with signature decorators to test the strict marshalling code
	gives errors at the right time. Could do with checking the signals
	actually get emitted too, given that the test does nothing with
	signals at the moment...
2005-11-07 15:31:30 +00:00

51 lines
1.8 KiB
Python

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
stream = cStringIO.StringIO(data.encode('utf-8'))
input_source = libxml2.inputBuffer(stream)
reader = input_source.newTextReader("urn:introspect")
ret = reader.Read()
current_iface = None
current_method = None
current_sigstr = ''
while ret == 1:
name = reader.LocalName()
if reader.NodeType() == XMLREADER_START_ELEMENT_NODE_TYPE:
if (not current_iface and not current_method and name == 'interface'):
current_iface = reader.GetAttribute('name')
elif (current_iface and not current_method and name == 'method'):
current_method = reader.GetAttribute('name')
if reader.IsEmptyElement():
method_map[current_iface + '.' + current_method] = ''
current_method = None
current_sigstr = ''
elif (current_iface and current_method and name == 'arg'):
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:
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
current_sigstr = ''
ret = reader.Read()
if ret != 0:
raise exceptions.IntrospectionParserException(data)
return method_map