[maemo-commits] [maemo-commits] r8870 - projects/haf/trunk/python-dbus/dbus
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Dec 26 20:54:41 EET 2006
- Previous message: [maemo-commits] r8869 - projects/haf/trunk/python/debian
- Next message: [maemo-commits] r8871 - projects/haf/trunk/python-dbus/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: luciano Date: 2006-12-26 20:54:38 +0200 (Tue, 26 Dec 2006) New Revision: 8870 Modified: projects/haf/trunk/python-dbus/dbus/introspect_parser.py Log: Removing libxml2 dependency Modified: projects/haf/trunk/python-dbus/dbus/introspect_parser.py =================================================================== --- projects/haf/trunk/python-dbus/dbus/introspect_parser.py 2006-12-26 16:44:14 UTC (rev 8869) +++ projects/haf/trunk/python-dbus/dbus/introspect_parser.py 2006-12-26 18:54:38 UTC (rev 8870) @@ -1,51 +1,33 @@ -import libxml2 +from xml.sax import make_parser, handler import cStringIO -import exceptions -def process_introspection_data(data): - method_map = {} +class IntrospectionHandler(handler.ContentHandler): + def __init__(self, method_map): + self._map = method_map + self._name = [] - XMLREADER_START_ELEMENT_NODE_TYPE = 1 - XMLREADER_END_ELEMENT_NODE_TYPE = 15 + def startElement(self, name, attrs): + if name in ['interface', 'method']: + self._name.append(str(attrs['name'])) + elif name == 'arg': + direction = attrs.get('direction', 'in') + if direction == 'in': + try: + self._map['.'.join(self._name)] += str(attrs['type']) + except KeyError, e: + self._map['.'.join(self._name)] = str(attrs['type']) + def endElement(self, name): + if name == 'method': + if not self._map.has_key('.'.join(self._name)): + self._map['.'.join(self._name)] = '' # no args + if name in ['interface', 'method']: + self._name.pop() + +def process_introspection_data(data): + method_map = {} + parser = make_parser() + parser.setContentHandler(IntrospectionHandler(method_map)) 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) - + parser.parse(stream) return method_map
- Previous message: [maemo-commits] r8869 - projects/haf/trunk/python/debian
- Next message: [maemo-commits] r8871 - projects/haf/trunk/python-dbus/debian
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]