~ubuntu-branches/ubuntu/vivid/blueman/vivid-proposed

« back to all changes in this revision

Viewing changes to blueman/bluez/errors.py

  • Committer: Package Import Robot
  • Author(s): Artur Rona
  • Date: 2014-12-24 18:33:36 UTC
  • mfrom: (2.3.8 sid)
  • Revision ID: package-import@ubuntu.com-20141224183336-cyb82ot0y8tz8flq
Tags: 1.99~alpha1-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/patches/01_dont_autostart_lxde.patch:
    + Don't autostart the applet in LXDE.
  - debian/patches/03_filemanager_fix.patch:
    + Add support for more filemanagers.
* debian/patches/02_dont_crash_on_non-bluetooth_card.patch:
  - Dropped, no longer applicable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# errors.py - custom dbus bluez errors
2
 
#
3
 
# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com>
4
 
# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com>
5
 
#
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.
10
 
#
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.
15
 
#
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
 
1
import dbus
 
2
 
19
3
 
20
4
class BluezDBusException(Exception):
21
 
    """
22
 
    Custom Bluez Dbus Exception class.
23
 
    """
24
5
    def __init__(self, reason):
25
 
        """ """
26
6
        self.reason = reason
27
7
 
28
 
    # __init__
29
8
    def __str__(self):
30
 
        """ """
31
9
        return self.reason
32
 
    # repr
 
10
 
33
11
 
34
12
class DBusFailedError(BluezDBusException):
35
13
    pass
36
14
 
 
15
 
37
16
class DBusInvalidArgumentsError(BluezDBusException):
38
17
    pass
39
18
 
 
19
 
40
20
class DBusNotAuthorizedError(BluezDBusException):
41
21
    pass
42
22
 
 
23
 
43
24
class DBusOutOfMemoryError(BluezDBusException):
44
25
    pass
45
26
 
 
27
 
46
28
class DBusNoSuchAdapterError(BluezDBusException):
47
29
    pass
48
30
 
 
31
 
49
32
class DBusNotReadyError(BluezDBusException):
50
33
    pass
51
34
 
 
35
 
52
36
class DBusNotAvailableError(BluezDBusException):
53
37
    pass
54
38
 
 
39
 
55
40
class DBusNotConnectedError(BluezDBusException):
56
41
    pass
57
42
 
 
43
 
58
44
class DBusConnectionAttemptFailedError(BluezDBusException):
59
45
    pass
60
46
 
 
47
 
61
48
class DBusAlreadyExistsError(BluezDBusException):
62
49
    pass
63
50
 
 
51
 
64
52
class DBusDoesNotExistError(BluezDBusException):
65
53
    pass
66
54
 
 
55
 
67
56
class DBusNoReplyError(BluezDBusException):
68
57
    pass
69
58
 
 
59
 
70
60
class DBusInProgressError(BluezDBusException):
71
61
    pass
72
62
 
 
63
 
73
64
class DBusNotSupportedError(BluezDBusException):
74
65
    pass
75
66
 
 
67
 
76
68
class DBusAuthenticationFailedError(BluezDBusException):
77
69
    pass
78
70
 
 
71
 
79
72
class DBusAuthenticationTimeoutError(BluezDBusException):
80
73
    pass
81
74
 
 
75
 
82
76
class DBusAuthenticationRejectedError(BluezDBusException):
83
77
    pass
84
78
 
 
79
 
85
80
class DBusAuthenticationCanceledError(BluezDBusException):
86
81
    pass
87
82
 
 
83
 
88
84
class DBusUnsupportedMajorClassError(BluezDBusException):
89
85
    pass
90
86
 
91
 
class DBusNotSupportedError(BluezDBusException):
92
 
    pass
93
87
 
94
88
class DBusServiceUnknownError(BluezDBusException):
95
89
    pass
96
90
 
 
91
 
97
92
class DBusMainLoopNotSupportedError(BluezDBusException):
98
93
    pass
99
94
 
 
95
 
100
96
class DBusMainLoopModuleNotFoundError(BluezDBusException):
101
97
    pass
102
98
 
 
99
 
103
100
class BluezUnavailableAgentMethodError(BluezDBusException):
104
101
    pass
105
102
 
106
103
 
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}
 
125
 
128
126
 
129
127
def parse_dbus_error(exception):
130
 
    """
131
 
    Return a custom exception based in the dbus exception that was raised.
132
 
    """
133
128
    global __DICT_ERROR__
134
129
 
135
130
    aux = "%s" % exception
136
 
    aux_splt = aux.split(None,1)
 
131
    aux_splt = aux.split(None, 1)
137
132
    try:
138
133
        return __DICT_ERROR__[aux_splt[0]](aux_splt[1])
139
134
    except KeyError:
140
135
        return exception
141
 
    # parse_dbus_error
 
136
 
 
137
 
 
138
def raise_dbus_error(func):
 
139
    def warp(*args, **kwargs):
 
140
        try:
 
141
            return func(*args, **kwargs)
 
142
        except dbus.DBusException as exception:
 
143
            raise parse_dbus_error(exception)
 
144
    return warp
 
145
 
 
146
 
 
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'