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 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 from xml
.parsers
.expat
import ExpatError
, ParserCreate
25 from dbus
.exceptions
import IntrospectionParserException
27 class _Parser(object):
28 __slots__
= ('map', 'in_iface', 'in_method', 'sig')
35 def parse(self
, data
):
36 parser
= ParserCreate('UTF-8', ' ')
37 parser
.buffer_text
= True
38 parser
.StartElementHandler
= self
.StartElementHandler
39 parser
.EndElementHandler
= self
.EndElementHandler
43 def StartElementHandler(self
, name
, attributes
):
45 if (not self
.in_method
and name
== 'interface'):
46 self
.in_iface
= attributes
['name']
48 if (not self
.in_method
and name
== 'method'):
49 self
.in_method
= attributes
['name']
50 elif (self
.in_method
and name
== 'arg'):
51 if attributes
.get('direction', 'in') == 'in':
52 self
.sig
+= attributes
['type']
54 def EndElementHandler(self
, name
):
56 if (not self
.in_method
and name
== 'interface'):
58 elif (self
.in_method
and name
== 'method'):
59 self
.map[self
.in_iface
+ '.' + self
.in_method
] = self
.sig
63 def process_introspection_data(data
):
64 """Return a dict mapping ``interface.method`` strings to the
65 concatenation of all their 'in' parameters, and mapping
66 ``interface.signal`` strings to the concatenation of all their
72 'com.example.SignalEmitter.OneString': 's',
73 'com.example.MethodImplementor.OneInt32Argument': 'i',
78 The introspection XML. Must be an 8-bit string of UTF-8.
81 return _Parser().parse(data
)
83 raise IntrospectionParserException('%s: %s' % (e
.__class
__, e
))