1 """D-Bus exceptions."""
3 # Copyright (C) 2007 Collabora Ltd. <http://www.collabora.co.uk/>
5 # Permission is hereby granted, free of charge, to any person
6 # obtaining a copy of this software and associated documentation
7 # files (the "Software"), to deal in the Software without
8 # restriction, including without limitation the rights to use, copy,
9 # modify, merge, publish, distribute, sublicense, and/or sell copies
10 # of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
25 __all__
= ('DBusException', 'MissingErrorHandlerException',
26 'MissingReplyHandlerException', 'ValidationException',
27 'IntrospectionParserException', 'UnknownMethodException',
28 'NameExistsException')
30 class DBusException(Exception):
31 def __init__(self
, *args
, **kwargs
):
32 name
= kwargs
.pop('name', None)
33 if name
is not None or getattr(self
, '_dbus_error_name', None) is None:
34 self
._dbus
_error
_name
= name
36 raise TypeError('DBusException does not take keyword arguments: %s'
37 % ', '.join(kwargs
.keys()))
38 Exception.__init
__(self
, *args
)
41 s
= Exception.__str
__(self
)
42 if self
._dbus
_error
_name
is not None:
43 return '%s: %s' % (self
._dbus
_error
_name
, s
)
47 def get_dbus_name(self
):
48 return self
._dbus
_error
_name
50 class MissingErrorHandlerException(DBusException
):
52 DBusException
.__init
__(self
, "error_handler not defined: if you define a reply_handler you must also define an error_handler")
54 class MissingReplyHandlerException(DBusException
):
56 DBusException
.__init
__(self
, "reply_handler not defined: if you define an error_handler you must also define a reply_handler")
58 class ValidationException(DBusException
):
59 def __init__(self
, msg
=''):
60 DBusException
.__init
__(self
, "Error validating string: %s"%msg
)
62 class IntrospectionParserException(DBusException
):
63 def __init__(self
, msg
=''):
64 DBusException
.__init
__(self
, "Error parsing introspect data: %s"%msg
)
66 class UnknownMethodException(DBusException
):
67 _dbus_error_name
= 'org.freedesktop.DBus.Error.UnknownMethod'
68 def __init__(self
, method
):
69 DBusException
.__init
__(self
, "Unknown method: %s"%method
)
71 class NameExistsException(DBusException
):
72 def __init__(self
, name
):
73 DBusException
.__init
__(self
, "Bus name already exists: %s"%name
)