U
    K^"                     @   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rd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 kr| j | S |tkr&t}n(|tkr4t}n|tkrBt}ntd| tj	|||d}||_
|sr|| 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|| k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 )zReturn 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_connectionzself._connection == self, for backwards
                           compatibility with earlier dbus-python versions
                           where Bus was not a subclass of Connection.c                 C   s
   t | dS )zStatic 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   s    zBus.get_sessionc                 C   s
   t | dS )zStatic 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   s    zBus.get_systemc                 C   s
   t | dS )zStatic 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   s    zBus.get_starterc                 C   sP   | j tkrd}n$| j tkr d}n| j tkr0d}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)F)F)r0   r/   __qualname____doc__r   r   TYPE_SESSIONr   r%   r)   propertyZ_connectionr+   staticmethodr,   r-   r3   __str____classcell__r    r    r(   r!   r   1   s$   
3
	
	
	r   c                   @   s   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      s    zSystemBus.__new__)FNr0   r/   r4   r5   r   r    r    r    r!   r      s   r   c                   @   s   e Zd ZdZdddZdS )r   z(The session (current login) message bus.FNc                 C   s   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   r6   r;   r    r    r!   r      s    zSessionBus.__new__)FNr<   r    r    r    r!   r      s   r   c                   @   s   e Zd ZdZdddZdS )r   zjThe bus that activated this process (only valid if
    this process was launched by DBus activation).
    FNc                 C   s   t j| t j||dS )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.
        r=   )r   r   ZTYPE_STARTERr;   r    r    r!   r      s    zStarterBus.__new__)FNr<   r    r    r    r!   r      s   r   N)r5   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 