o
    ñt3b…"  ã                   @   sÔ   d Z ddlmZ dZdZddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ erHdd
lmZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z9Implementation for dbus.Bus. Not to be imported directly.é    )Ú
generators)ÚBusÚ	SystemBusÚ
SessionBusÚ
StarterBusZreStructuredText)ÚDBusException)ÚBUS_DAEMON_IFACEÚBUS_DAEMON_NAMEÚBUS_DAEMON_PATHÚBUS_SESSIONÚBUS_STARTERÚ
BUS_SYSTEMÚ DBUS_START_REPLY_ALREADY_RUNNINGÚDBUS_START_REPLY_SUCCESSÚvalidate_bus_nameÚvalidate_interface_nameÚvalidate_member_nameÚvalidate_object_path)ÚBusConnection)ÚSignalMessage)Úis_py2)Ú
UTF8Stringc                       sŽ   e Zd ZdZi Zejddfdd„Z‡ fdd„Zdd	„ Z	e
e	ddd
ƒZddd„ZeeƒZddd„ZeeƒZddd„ZeeƒZdd„ ZeZ‡  ZS )r   a   A connection to one of three possible standard buses, the SESSION,
    SYSTEM, or STARTER bus. This class manages shared connections to those
    buses.

    If you're trying to subclass `Bus`, you may be better off subclassing
    `BusConnection`, which doesn't have all this magic.
    FNc                 C   sv   |s|| j v r| j | S |tkrt}n|tkrt}n|tkr!t}ntd| ƒ‚tj	|||d�}||_
|s9|| j |< |S )aË  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.
        zinvalid bus_type %s)Úmainloop)Ú_shared_instancesr   r   r   r   r   r   Ú
ValueErrorr   Ú__new__Ú	_bus_type)ÚclsZbus_typeÚprivater   ÚsubclassZbus© r    ú,/usr/lib/python3/dist-packages/dbus/_dbus.pyr   <   s   

zBus.__new__c                    s4   | j }| jj |¡| u r| jj|= tt| ƒ ¡  d S )N)r   Ú	__class__r   ÚgetÚsuperr   Úclose)ÚselfÚt©r"   r    r!   r%   o   s   
z	Bus.closec                 C   s   | S )zªReturn self, for backwards compatibility with earlier dbus-python
        versions where Bus was not a subclass of Connection.

        :Deprecated: since 0.80.0
        r    )r&   r    r    r!   Úget_connectionu   s   zBus.get_connectionz¹self._connection == self, for backwards
                           compatibility with earlier dbus-python versions
                           where Bus was not a subclass of Connection.c                 C   ó
   t | d�S )z³Static method that returns a connection to the session bus.

        :Parameters:
            `private` : bool
                If true, do not return a shared connection.
        ©r   )r   r+   r    r    r!   Úget_session�   ó   
zBus.get_sessionc                 C   r*   )z²Static method that returns a connection to the system bus.

        :Parameters:
            `private` : bool
                If true, do not return a shared connection.
        r+   )r   r+   r    r    r!   Ú
get_systemŒ   r-   zBus.get_systemc                 C   r*   )z³Static method that returns a connection to the starter bus.

        :Parameters:
            `private` : bool
                If true, do not return a shared connection.
        r+   )r   r+   r    r    r!   Úget_starter˜   r-   zBus.get_starterc                 C   sP   | j tkrd}n| j tkrd}n
| j tkrd}nd}d| jj| jj|t| ƒf S )NZsessionÚsystemZstarterzunknown bus typez<%s.%s (%s) at %#x>)r   r   r   r   r"   Ú
__module__Ú__name__Úid)r&   Únamer    r    r!   Ú__repr__£   s   


þzBus.__repr__)F)r2   r1   Ú__qualname__Ú__doc__r   r   ÚTYPE_SESSIONr   r%   r)   ÚpropertyZ_connectionr,   Ústaticmethodr.   r/   r5   Ú__str__Ú__classcell__r    r    r(   r!   r   1   s&    
ÿ3ÿ
	
	
	r   c                   @   ó   e Zd ZdZddd„ZdS )r   zThe system-wide message bus.FNc                 C   s   t j| t j||d�S )aÆ  Return a connection to the system bus.

        :Parameters:
            `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.
        )r   r   )r   r   ZTYPE_SYSTEM©r   r   r   r    r    r!   r   ·   ó   ÿzSystemBus.__new__©FN©r2   r1   r6   r7   r   r    r    r    r!   r   µ   ó    r   c                   @   r=   )r   z(The session (current login) message bus.FNc                 C   ó   t j| t j||d�S )aÇ  Return a connection to the session bus.

        :Parameters:
            `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.
        ©r   r   )r   r   r8   r>   r    r    r!   r   È   r?   zSessionBus.__new__r@   rA   r    r    r    r!   r   Æ   rB   r   c                   @   r=   )r   zjThe bus that activated this process (only valid if
    this process was launched by DBus activation).
    FNc                 C   rC   )aÛ  Return a connection to the bus that activated this process.

        :Parameters:
            `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.
        rD   )r   r   ZTYPE_STARTERr>   r    r    r!   r   Û   r?   zStarterBus.__new__r@   rA   r    r    r    r!   r   ×   s    r   N)r7   Z
__future__r   Ú__all__Z__docformat__Zdbus.exceptionsr   Z_dbus_bindingsr   r	   r
   r   r   r   r   r   r   r   r   r   Zdbus.busr   Zdbus.lowlevelr   Zdbus._compatr   r   r   r   r   r   r    r    r    r!   Ú<module>   s     8 