diff options
Diffstat (limited to 'bluez/utils.py')
-rw-r--r-- | bluez/utils.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bluez/utils.py b/bluez/utils.py new file mode 100644 index 0000000..52ee4b5 --- /dev/null +++ b/bluez/utils.py @@ -0,0 +1,35 @@ +# utils.py +# +# Copyright (C) 2008 Vinicius Gomes <vcgomes [at] gmail [dot] com> +# Copyright (C) 2008 Li Dongyang <Jerry87905 [at] gmail [dot] com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import dbus +import errors + +def raise_dbus_error(method): + def warp(*args, **kwargs): + try: + return method(*args, **kwargs) + except dbus.DBusException, exception: + raise errors.parse_dbus_error(exception) + return warp +# raise_dbus_error + +def raise_type_error(instance, cls): + if not isinstance(instance, cls): + raise TypeError('Expecting an instance of ' + cls.__name__ + ', not ' + type(instance).__name__) +# raise_type_error |