dbus/python/introspect_parser.py
Robert McQueen ef47e01f75 2005-10-24 Robert McQueen <robot101@debian.org>
* python/dbus_bindings.pyx (String, MessageIter): make D-Bus strings
    derive from unicode instead of str, and encode/decode UTF-8 when
    marshalling/unmarshalling bus messages

    * python/introspect_parser.py: encode introspection data as UTF-8
    before passing the buffer into libxml2

    * test/python/test-client.py: add unicode test strings

    * test/data/valid-service-files/.cvsignore, test/python/.cvsignore:
    ignore generated python test files
2005-10-24 18:29:50 +00:00

50 lines
1.6 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=''
current_method=''
current_sigstr = ''
while ret == 1:
name = reader.LocalName()
if reader.NodeType() == XMLREADER_START_ELEMENT_NODE_TYPE:
if name == 'interface':
current_iface = reader.GetAttribute('name')
elif name == 'method':
current_method = reader.GetAttribute('name')
if reader.IsEmptyElement():
method_map[current_iface + '.' + current_method] = ''
current_method = ''
current_sigstr = ''
elif 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 name == 'method':
method_map[current_iface + '.' + current_method] = current_sigstr
current_method = ''
current_sigstr = ''
ret = reader.Read()
if ret != 0:
raise exceptions.IntrospectionParserException(data)
return method_map