1
# errors.py - custom dbus bluez errors
3
# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com>
4
# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
4
class BluezDBusException(Exception):
22
Custom Bluez Dbus Exception class.
24
5
def __init__(self, reason):
26
6
self.reason = reason
34
12
class DBusFailedError(BluezDBusException):
37
16
class DBusInvalidArgumentsError(BluezDBusException):
40
20
class DBusNotAuthorizedError(BluezDBusException):
43
24
class DBusOutOfMemoryError(BluezDBusException):
46
28
class DBusNoSuchAdapterError(BluezDBusException):
49
32
class DBusNotReadyError(BluezDBusException):
52
36
class DBusNotAvailableError(BluezDBusException):
55
40
class DBusNotConnectedError(BluezDBusException):
58
44
class DBusConnectionAttemptFailedError(BluezDBusException):
61
48
class DBusAlreadyExistsError(BluezDBusException):
64
52
class DBusDoesNotExistError(BluezDBusException):
67
56
class DBusNoReplyError(BluezDBusException):
70
60
class DBusInProgressError(BluezDBusException):
73
64
class DBusNotSupportedError(BluezDBusException):
76
68
class DBusAuthenticationFailedError(BluezDBusException):
79
72
class DBusAuthenticationTimeoutError(BluezDBusException):
82
76
class DBusAuthenticationRejectedError(BluezDBusException):
85
80
class DBusAuthenticationCanceledError(BluezDBusException):
88
84
class DBusUnsupportedMajorClassError(BluezDBusException):
91
class DBusNotSupportedError(BluezDBusException):
94
88
class DBusServiceUnknownError(BluezDBusException):
97
92
class DBusMainLoopNotSupportedError(BluezDBusException):
100
96
class DBusMainLoopModuleNotFoundError(BluezDBusException):
103
100
class BluezUnavailableAgentMethodError(BluezDBusException):
107
__DICT_ERROR__ = {'org.bluez.Error.Failed:':DBusFailedError,
108
'org.bluez.Error.InvalidArguments:':DBusInvalidArgumentsError,
109
'org.bluez.Error.NotAuthorized:':DBusNotAuthorizedError,
110
'org.bluez.Error.OutOfMemory:':DBusOutOfMemoryError,
111
'org.bluez.Error.NoSuchAdapter:':DBusNoSuchAdapterError,
112
'org.bluez.Error.NotReady:':DBusNotReadyError,
113
'org.bluez.Error.NotAvailable:':DBusNotAvailableError,
114
'org.bluez.Error.NotConnected:':DBusNotConnectedError,
115
'org.bluez.serial.Error.ConnectionAttemptFailed:':DBusConnectionAttemptFailedError,
116
'org.bluez.Error.AlreadyExists:':DBusAlreadyExistsError,
117
'org.bluez.Error.DoesNotExist:':DBusDoesNotExistError,
118
'org.bluez.Error.InProgress:':DBusInProgressError,
119
'org.bluez.Error.NoReply:':DBusNoReplyError,
120
'org.bluez.Error.NotSupported:':DBusNotSupportedError,
121
'org.bluez.Error.AuthenticationFailed:':DBusAuthenticationFailedError,
122
'org.bluez.Error.AuthenticationTimeout:':DBusAuthenticationTimeoutError,
123
'org.bluez.Error.AuthenticationRejected:':DBusAuthenticationRejectedError,
124
'org.bluez.Error.AuthenticationCanceled:':DBusAuthenticationCanceledError,
125
'org.bluez.serial.Error.NotSupported:':DBusNotSupportedError,
126
'org.bluez.Error.UnsupportedMajorClass:':DBusUnsupportedMajorClassError,
127
'org.freedesktop.DBus.Error.ServiceUnknown:':DBusServiceUnknownError}
104
__DICT_ERROR__ = {'org.bluez.Error.Failed:': DBusFailedError,
105
'org.bluez.Error.InvalidArguments:': DBusInvalidArgumentsError,
106
'org.bluez.Error.NotAuthorized:': DBusNotAuthorizedError,
107
'org.bluez.Error.OutOfMemory:': DBusOutOfMemoryError,
108
'org.bluez.Error.NoSuchAdapter:': DBusNoSuchAdapterError,
109
'org.bluez.Error.NotReady:': DBusNotReadyError,
110
'org.bluez.Error.NotAvailable:': DBusNotAvailableError,
111
'org.bluez.Error.NotConnected:': DBusNotConnectedError,
112
'org.bluez.serial.Error.ConnectionAttemptFailed:': DBusConnectionAttemptFailedError,
113
'org.bluez.Error.AlreadyExists:': DBusAlreadyExistsError,
114
'org.bluez.Error.DoesNotExist:': DBusDoesNotExistError,
115
'org.bluez.Error.InProgress:': DBusInProgressError,
116
'org.bluez.Error.NoReply:': DBusNoReplyError,
117
'org.bluez.Error.NotSupported:': DBusNotSupportedError,
118
'org.bluez.Error.AuthenticationFailed:': DBusAuthenticationFailedError,
119
'org.bluez.Error.AuthenticationTimeout:': DBusAuthenticationTimeoutError,
120
'org.bluez.Error.AuthenticationRejected:': DBusAuthenticationRejectedError,
121
'org.bluez.Error.AuthenticationCanceled:': DBusAuthenticationCanceledError,
122
'org.bluez.serial.Error.NotSupported:': DBusNotSupportedError,
123
'org.bluez.Error.UnsupportedMajorClass:': DBusUnsupportedMajorClassError,
124
'org.freedesktop.DBus.Error.ServiceUnknown:': DBusServiceUnknownError}
129
127
def parse_dbus_error(exception):
131
Return a custom exception based in the dbus exception that was raised.
133
128
global __DICT_ERROR__
135
130
aux = "%s" % exception
136
aux_splt = aux.split(None,1)
131
aux_splt = aux.split(None, 1)
138
133
return __DICT_ERROR__[aux_splt[0]](aux_splt[1])
138
def raise_dbus_error(func):
139
def warp(*args, **kwargs):
141
return func(*args, **kwargs)
142
except dbus.DBusException as exception:
143
raise parse_dbus_error(exception)
147
def raise_type_error(instance, cls):
148
if not isinstance(instance, cls):
149
raise TypeError('Expecting an instance of ' + cls.__name__ + ', not ' + type(instance).__name__)
b'\\ No newline at end of file'