<commit_before>import dbus
import dbus.mainloop.glib
import re

from gi.repository import GObject


class DeviceManager:
    def __init__(self, adapter_name):
        self.listener = None
        self.adapter_name = adapter_name

        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.mainloop = GObject.MainLoop()
        self.bus = dbus.SystemBus()
        adapter_object = self.bus.get_object('org.bluez', '/org/bluez/' + adapter_name)
        self.adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter1')
        self.device_path_regex = re.compile('^/org/bluez/' + adapter_name + '/dev((_[A-Z0-9]{2}){6})$')
<commit_msg>Catch dbus exceptions when initializing adapter<commit_after>import dbus
import dbus.mainloop.glib
import re

from gi.repository import GObject


class DeviceManager:
    def __init__(self, adapter_name):
        self.listener = None
        self.adapter_name = adapter_name

        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.mainloop = GObject.MainLoop()
        self.bus = dbus.SystemBus()

        try:
            adapter_object = self.bus.get_object('org.bluez', '/org/bluez/' + adapter_name)
        except dbus.exceptions.DBusException as e:
            # TODO: Use custom exception type
            raise Exception(
                "Cannot initialize Bluetooth adapter: " +
                e.get_dbus_name() + ": " +
                e.get_dbus_message()) from e

        self.adapter = dbus.Interface(adapter_object, 'org.bluez.Adapter1')
        self.device_path_regex = re.compile('^/org/bluez/' + adapter_name + '/dev((_[A-Z0-9]{2}){6})$')

{'fraction_non_alphanumeric': 0.11862323294406883, 'fraction_numerical': 0.006146281499692686, 'mean_word_length': 2.8305882352941176, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2900197', 'n_tokens_mistral': 524, 'n_tokens_neox': 511, 'n_words': 96}