1 # Copyright (C) 2003, 2004, 2005, 2006 Red Hat Inc. <http://www.redhat.com/>
2 # Copyright (C) 2003 David Zeuthen
3 # Copyright (C) 2004 Rob Taylor
4 # Copyright (C) 2005, 2006 Collabora Ltd. <http://www.collabora.co.uk/>
6 # Licensed under the Academic Free License version 2.1
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 from xml
.parsers
.expat
import ExpatError
, ParserCreate
23 from dbus
.exceptions
import IntrospectionParserException
25 class _Parser(object):
26 __slots__
= ('map', 'in_iface', 'in_method', 'sig')
33 def parse(self
, data
):
34 parser
= ParserCreate('UTF-8', ' ')
35 parser
.buffer_text
= True
36 parser
.StartElementHandler
= self
.StartElementHandler
37 parser
.EndElementHandler
= self
.EndElementHandler
41 def StartElementHandler(self
, name
, attributes
):
43 if (not self
.in_method
and name
== 'interface'):
44 self
.in_iface
= attributes
['name']
46 if (not self
.in_method
and name
== 'method'):
47 self
.in_method
= attributes
['name']
48 elif (self
.in_method
and name
== 'arg'):
49 if attributes
.get('direction', 'in') == 'in':
50 self
.sig
+= attributes
['type']
52 def EndElementHandler(self
, name
):
54 if (not self
.in_method
and name
== 'interface'):
56 elif (self
.in_method
and name
== 'method'):
57 self
.map[self
.in_iface
+ '.' + self
.in_method
] = self
.sig
61 def process_introspection_data(data
):
62 """Return a dict mapping ``interface.method`` strings to the
63 concatenation of all their 'in' parameters, and mapping
64 ``interface.signal`` strings to the concatenation of all their
70 'com.example.SignalEmitter.OneString': 's',
71 'com.example.MethodImplementor.OneInt32Argument': 'i',
76 The introspection XML. Must be an 8-bit string of UTF-8.
79 return _Parser().parse(data
)
81 raise IntrospectionParserException('%s: %s' % (e
.__class
__, e
))