def __new__(cls, bus_type=BusConnection.TYPE_SESSION, private=False, mainloop=None): """Constructor, returning an existing instance where appropriate. The returned instance is actually always an instance of `SessionBus`, `SystemBus` or `StarterBus`. :Parameters: `bus_type` : cls.TYPE_SESSION, cls.TYPE_SYSTEM or cls.TYPE_STARTER Connect to the appropriate bus `private` : bool If true, never return an existing shared instance, but instead return a private connection. :Deprecated: since 0.82.3. Use dbus.bus.BusConnection for private connections. `mainloop` : dbus.mainloop.NativeMainLoop The main loop to use. The default is to use the default main loop if one has been set up, or raise an exception if none has been. :Changed: in dbus-python 0.80: converted from a wrapper around a Connection to a Connection subclass. """ if (not private and bus_type in cls._shared_instances): return cls._shared_instances[bus_type] # this is a bit odd, but we create instances of the subtypes # so we can return the shared instances if someone tries to # construct one of them (otherwise we'd eg try and return an # instance of Bus from __new__ in SessionBus). why are there # three ways to construct this class? we just don't know. if bus_type == BUS_SESSION: subclass = SessionBus elif bus_type == BUS_SYSTEM: subclass = SystemBus elif bus_type == BUS_STARTER: subclass = StarterBus else: raise ValueError('invalid bus_type %s' % bus_type) bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop) bus._bus_type = bus_type if not private: cls._shared_instances[bus_type] = bus return bus
def __new__(cls, bus_type=BusConnection.TYPE_SESSION, private=False, mainloop=None): """Constructor, returning an existing instance where appropriate. The returned instance is actually always an instance of `SessionBus`, `SystemBus` or `StarterBus`. :Parameters: `bus_type` : cls.TYPE_SESSION, cls.TYPE_SYSTEM or cls.TYPE_STARTER Connect to the appropriate bus `private` : bool If true, never return an existing shared instance, but instead return a private connection `mainloop` : dbus.mainloop.NativeMainLoop The main loop to use. The default is to use the default main loop if one has been set up, or raise an exception if none has been. :ToDo: - There is currently no way to connect this class to a custom address. - Some of this functionality should be available on peer-to-peer D-Bus connections too. :Changed: in dbus-python 0.80: converted from a wrapper around a Connection to a Connection subclass. """ if (not private and bus_type in cls._shared_instances): return cls._shared_instances[bus_type] # this is a bit odd, but we create instances of the subtypes # so we can return the shared instances if someone tries to # construct one of them (otherwise we'd eg try and return an # instance of Bus from __new__ in SessionBus). why are there # three ways to construct this class? we just don't know. if bus_type == BUS_SESSION: subclass = SessionBus elif bus_type == BUS_SYSTEM: subclass = SystemBus elif bus_type == BUS_STARTER: subclass = StarterBus else: raise ValueError('invalid bus_type %s' % bus_type) bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop) bus._bus_type = bus_type if not private: cls._shared_instances[bus_type] = bus return bus
def __new__(cls, mainLoop=None): bus = BusConnection.__new__(cls, mbusConfig.DBUS_ADDRESS, mainloop=mainLoop) return bus