Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def function_out(*args, **kwargs):
try:
return function_in(*args, **kwargs)
except dbus.exceptions.DBusException as e:
if e.get_dbus_name() == DBUS_UNKNOWN_METHOD:
raise ItemNotFoundException('Item does not exist!')
if e.get_dbus_name() == DBUS_NO_SUCH_OBJECT:
raise ItemNotFoundException(e.get_dbus_message())
if e.get_dbus_name() in (DBUS_NO_REPLY, DBUS_NOT_SUPPORTED):
raise SecretServiceNotAvailableException(
e.get_dbus_message())
raise
return function_out
def bus_get_object(bus, object_path, service_name=None):
"""A wrapper around :meth:`SessionBus.get_object` that raises
:exc:`~secretstorage.exceptions.SecretServiceNotAvailableException`
when appropriate."""
name = service_name or BUS_NAME
try:
return bus.get_object(name, object_path, introspect=False)
except dbus.exceptions.DBusException as e:
if e.get_dbus_name() in (DBUS_SERVICE_UNKNOWN, DBUS_EXEC_FAILED,
DBUS_NO_REPLY):
raise SecretServiceNotAvailableException(e.get_dbus_message())
raise
def send_and_get_reply(self, msg: Message) -> Any:
try:
return self._connection.send_and_get_reply(msg)
except DBusErrorResponse as resp:
if resp.name in (DBUS_UNKNOWN_METHOD, DBUS_NO_SUCH_OBJECT):
raise ItemNotFoundException('Item does not exist!') from resp
elif resp.name in (DBUS_SERVICE_UNKNOWN, DBUS_EXEC_FAILED,
DBUS_NO_REPLY):
data = resp.data
if isinstance(data, tuple):
data = data[0]
raise SecretServiceNotAvailableException(data) from resp
raise
.. versionchanged:: 3.0
Before the port to Jeepney, this function returned an
instance of :class:`dbus.SessionBus` class.
.. versionchanged:: 3.1
This function no longer accepts any arguments.
"""
try:
connection = connect_and_authenticate()
add_match_rules(connection)
return connection
except KeyError as ex:
# os.environ['DBUS_SESSION_BUS_ADDRESS'] may raise it
reason = "Environment variable {} is unset".format(ex.args[0])
raise SecretServiceNotAvailableException(reason) from ex
except (ConnectionError, ValueError) as ex:
raise SecretServiceNotAvailableException(str(ex)) from ex
Qt uses GLib main loops on UNIX-like systems by default, so one
will rarely need to set `use_qt_loop` to :const:`True`.
"""
if main_loop and not dbus.get_default_main_loop():
if use_qt_loop:
from dbus.mainloop.pyqt5 import DBusQtMainLoop
DBusQtMainLoop(set_as_default=True)
else:
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
try:
return dbus.SessionBus()
except dbus.exceptions.DBusException as e:
if e.get_dbus_name() in (DBUS_NOT_SUPPORTED,
DBUS_EXEC_FAILED, DBUS_NO_REPLY, DBUS_ACCESS_DENIED):
raise SecretServiceNotAvailableException(
e.get_dbus_message())
raise