U
    ÇZj(F  ã                   @   sì   d Z dZddlZddl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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! ddl"m#Z# d	eeef Z$d
Z%e &d¡Z'G dd„ de(ƒZ)G dd„ deƒZ*dS ))ÚBusConnectionÚreStructuredTexté    N)ÚBUS_DAEMON_IFACEÚBUS_DAEMON_NAMEÚBUS_DAEMON_PATHÚBUS_SESSIONÚBUS_STARTERÚ
BUS_SYSTEMÚ DBUS_START_REPLY_ALREADY_RUNNINGÚDBUS_START_REPLY_SUCCESSÚNAME_FLAG_ALLOW_REPLACEMENTÚNAME_FLAG_DO_NOT_QUEUEÚNAME_FLAG_REPLACE_EXISTINGÚRELEASE_NAME_REPLY_NON_EXISTENTÚRELEASE_NAME_REPLY_NOT_OWNERÚRELEASE_NAME_REPLY_RELEASEDÚ REQUEST_NAME_REPLY_ALREADY_OWNERÚREQUEST_NAME_REPLY_EXISTSÚREQUEST_NAME_REPLY_IN_QUEUEÚ REQUEST_NAME_REPLY_PRIMARY_OWNERÚvalidate_bus_nameÚvalidate_error_nameÚvalidate_interface_nameÚvalidate_member_nameÚvalidate_object_path)Ú
Connection)ÚDBusException)ÚHANDLER_RESULT_NOT_YET_HANDLED)Úis_py2zWtype='signal',sender='%s',interface='%s',member='NameOwnerChanged',path='%s',arg0='%%s'z)org.freedesktop.DBus.Error.NameHasNoOwnerzdbus.busc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚNameOwnerWatch)Ú_matchÚ_pending_callc              	      sn   t ˆ ƒ ‡fdd„}‡ ‡fdd„}|j|dtttˆ d�| _i }trJd|d< |jtttd	d
ˆ fˆ|f|Ž| _d S )Nc                    s   ˆ |ƒ d S ©N© )ZownedZ	old_ownerÚ	new_owner)Úcallbackr#   úK/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/dbus/bus.pyÚ	signal_cbB   s    z*NameOwnerWatch.__init__.<locals>.signal_cbc                    s:   |   ¡ tkrˆdƒ n t ¡  tjdˆ | j| d fd� d S )NÚ zGetNameOwner(%s) failed:)Úexc_info)Úget_dbus_nameÚ_NAME_HAS_NO_OWNERÚloggingÚbasicConfigÚ_loggerÚdebugÚ	__class__)Úe©Úbus_namer%   r#   r&   Úerror_cbE   s    

ÿz)NameOwnerWatch.__init__.<locals>.error_cbZNameOwnerChanged)Zarg0TÚutf8_stringsÚGetNameOwnerÚs)	r   Úadd_signal_receiverr   r   r   r    r   Ú
call_asyncr!   )ÚselfZbus_connr3   r%   r'   r4   Úkeywordsr#   r2   r&   Ú__init__?   s0    û  ûúzNameOwnerWatch.__init__c                 C   s8   | j d k	r| j  ¡  | jd k	r(| j ¡  d | _ d | _d S r"   )r    Úremover!   Úcancel)r:   r#   r#   r&   r>   ^   s    



zNameOwnerWatch.cancelN)Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r<   r>   r#   r#   r#   r&   r   <   s   r   c                       sÊ   e Zd ZdZeZeZeZ	e
ZeZedfdd„Zd*‡ fdd„	Zdd„ Zd	d
„ Zd+dd„Zdd„ Zd,dd„Zd-dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Z‡  Z S ).r   zxA connection to a D-Bus daemon that implements the
    ``org.freedesktop.DBus`` pseudo-service.

    :Since: 0.81.0
    Nc                 C   s"   | j ||d�}t ¡ |_i |_|S )N)Úmainloop)Z_new_for_busÚweakrefÚWeakValueDictionaryZ
_bus_namesÚ_signal_sender_matches)ÚclsZaddress_or_typerC   Úbusr#   r#   r&   Ú__new__{   s    
zBusConnection.__new__c                    sº   |  dd ¡}|d k	rB|d k	r$tdƒ‚|}ddlm} |dtdd� tt| ƒj|||||f|Ž‰ |d k	r¨|tkr¨|d d… d	krŒ‡ fd
d„}	nˆ j	}	|  
||	¡}
|
| jˆ < |  tˆ ƒ¡ ˆ S )NÚnamed_serviceú3bus_name and named_service cannot both be specifiedr   ©ÚwarnzrPassing the named_service parameter to add_signal_receiver by name is deprecated: please use positional parametersé   ©Ú
stacklevelé   ú:c                    s   | dkrˆ   ¡  d S )Nr(   )r=   )r$   ©Úmatchr#   r&   r%   š   s    z3BusConnection.add_signal_receiver.<locals>.callback)ÚpopÚ	TypeErrorÚwarningsrM   ÚDeprecationWarningÚsuperr   r8   r   Zset_sender_name_ownerÚwatch_name_ownerrF   Úadd_match_stringÚstr)r:   Zhandler_functionZsignal_nameZdbus_interfacer3   Úpathr;   rJ   rM   r%   Úwatch©r0   rS   r&   r8   †   s6     þ
   þþ
z!BusConnection.add_signal_receiverc                 C   s0   |   t|ƒ¡ | j |d ¡}|d k	r,| ¡  d S r"   )Ú remove_match_string_non_blockingr\   rF   rU   r>   )r:   rT   r^   r#   r#   r&   Ú_clean_up_signal_match¦   s    z$BusConnection._clean_up_signal_matchc              
   C   s€   |d k	rx|d d… dkrx|t krxz|  |¡W S  tk
rt } z*| ¡ tkrL‚ |  |¡ |  |¡ W Y ¢S d }~X Y q|X n|S d S )NrQ   rR   )r   Úget_name_ownerr   r*   r+   Ústart_service_by_name)r:   r3   r1   r#   r#   r&   Úactivate_name_owner­   s    ÿ
"z!BusConnection.activate_name_ownerTFc                 K   s|   |r|   ¡  | dd¡}|dk	rN|dk	r0tdƒ‚ddlm} |dtdd� |}|rhtd	d
 | ¡ ¡ ƒ‚| j| ||||d�S )aJ  Return a local proxy for the given remote object.

        Method calls on the proxy are translated into method calls on the
        remote object.

        :Parameters:
            `bus_name` : str
                A bus name (either the unique name or a well-known name)
                of the application owning the object. The keyword argument
                named_service is a deprecated alias for this.
            `object_path` : str
                The object path of the desired object
            `introspect` : bool
                If true (default), attempt to introspect the remote
                object to find out supported methods and their signatures
            `follow_name_owner_changes` : bool
                If the object path is a well-known name and this parameter
                is false (default), resolve the well-known name to the unique
                name of its current owner and bind to that instead; if the
                ownership of the well-known name changes in future,
                keep communicating with the original owner.
                This is necessary if the D-Bus API used is stateful.

                If the object path is a well-known name and this parameter
                is true, whenever the well-known name changes ownership in
                future, bind to the new owner, if any.

                If the given object path is a unique name, this parameter
                has no effect.

        :Returns: a `dbus.proxies.ProxyObject`
        :Raises `DBusException`: if resolving the well-known name to a
            unique name fails
        rJ   NrK   r   rL   ziPassing the named_service parameter to get_object by name is deprecated: please use positional parametersrN   rO   z4get_object does not take these keyword arguments: %sz, )Ú
introspectÚfollow_name_owner_changes)	Z_require_main_looprU   rV   rW   rM   rX   ÚjoinÚkeysZProxyObjectClass)r:   r3   Zobject_pathre   rf   ÚkwargsrJ   rM   r#   r#   r&   Ú
get_object¼   s(    $ þÿ
þzBusConnection.get_objectc                 C   s   t |ƒ |  tttdd|f¡S )zêGet the numeric uid of the process owning the given bus name.

        :Parameters:
            `bus_name` : str
                A bus name, either unique or well-known
        :Returns: a `dbus.UInt32`
        :Since: 0.80.0
        ZGetConnectionUnixUserr7   ©r   Úcall_blockingr   r   r   ©r:   r3   r#   r#   r&   Úget_unix_userõ   s    	  þzBusConnection.get_unix_userr   c              
   C   s$   t |ƒ d|  tttdd||f¡fS )a?  Start a service which will implement the given bus name on this Bus.

        :Parameters:
            `bus_name` : str
                The well-known bus name to be activated.
            `flags` : dbus.UInt32
                Flags to pass to StartServiceByName (currently none are
                defined)

        :Returns: A tuple of 2 elements. The first is always True, the
            second is either START_REPLY_SUCCESS or
            START_REPLY_ALREADY_RUNNING.

        :Raises `DBusException`: if the service could not be started.
        :Since: 0.80.0
        TZStartServiceByNameÚsurk   )r:   r3   Úflagsr#   r#   r&   rc     s    
 ýz#BusConnection.start_service_by_namec              	   C   s$   t |dd� |  tttdd||f¡S )a„  Request a bus name.

        :Parameters:
            `name` : str
                The well-known name to be requested
            `flags` : dbus.UInt32
                A bitwise-OR of 0 or more of the flags
                `NAME_FLAG_ALLOW_REPLACEMENT`,
                `NAME_FLAG_REPLACE_EXISTING`
                and `NAME_FLAG_DO_NOT_QUEUE`
        :Returns: `REQUEST_NAME_REPLY_PRIMARY_OWNER`,
            `REQUEST_NAME_REPLY_IN_QUEUE`,
            `REQUEST_NAME_REPLY_EXISTS` or
            `REQUEST_NAME_REPLY_ALREADY_OWNER`
        :Raises `DBusException`: if the bus daemon cannot be contacted or
            returns an error.
        F©Zallow_uniqueZRequestNamero   rk   )r:   Únamerp   r#   r#   r&   Úrequest_name  s      þzBusConnection.request_namec                 C   s"   t |dd� |  tttdd|f¡S )as  Release a bus name.

        :Parameters:
            `name` : str
                The well-known name to be released
        :Returns: `RELEASE_NAME_REPLY_RELEASED`,
            `RELEASE_NAME_REPLY_NON_EXISTENT`
            or `RELEASE_NAME_REPLY_NOT_OWNER`
        :Raises `DBusException`: if the bus daemon cannot be contacted or
            returns an error.
        Frq   ZReleaseNamer7   rk   )r:   rr   r#   r#   r&   Úrelease_name3  s      þzBusConnection.release_namec                 C   s(   i }t rd|d< | jtttdddf|ŽS )z‰Return a list of all currently-owned names on the bus.

        :Returns: a dbus.Array of dbus.UTF8String
        :Since: 0.81.0
        Tr5   Z	ListNamesr(   r#   ©r   rl   r   r   r   ©r:   r;   r#   r#   r&   Ú
list_namesD  s      þþzBusConnection.list_namesc                 C   s(   i }t rd|d< | jtttdddf|ŽS )z�Return a list of all names that can be activated on the bus.

        :Returns: a dbus.Array of dbus.UTF8String
        :Since: 0.81.0
        Tr5   ZListActivatableNamesr(   r#   ru   rv   r#   r#   r&   Úlist_activatable_namesQ  s      þþz$BusConnection.list_activatable_namesc                 C   s6   i }t rd|d< t|dd� | jtttdd|ff|ŽS )z²Return the unique connection name of the primary owner of the
        given name.

        :Raises `DBusException`: if the `bus_name` has no owner
        :Since: 0.81.0
        Tr5   Frq   r6   r7   )r   r   rl   r   r   r   )r:   r3   r;   r#   r#   r&   rb   ^  s      þþzBusConnection.get_name_ownerc                 C   s   t | ||ƒS )a  Watch the unique connection name of the primary owner of the
        given name.

        `callback` will be called with one argument, which is either the
        unique connection name, or the empty string (meaning the name is
        not owned).

        :Since: 0.81.0
        )r   )r:   r3   r%   r#   r#   r&   rZ   m  s    
zBusConnection.watch_name_ownerc              	   C   s   t |  tttdd|f¡ƒS )z»Return True iff the given bus name has an owner on this bus.

        :Parameters:
            `bus_name` : str
                The bus name to look up
        :Returns: a `bool`
        ZNameHasOwnerr7   )Úboolrl   r   r   r   rm   r#   r#   r&   Úname_has_ownery  s    
  þzBusConnection.name_has_ownerc                 C   s   |   tttdd|f¡ dS )á  Arrange for this application to receive messages on the bus that
        match the given rule. This version will block.

        :Parameters:
            `rule` : str
                The match rule
        :Raises `DBusException`: on error.
        :Since: 0.80.0
        ÚAddMatchr7   N©rl   r   r   r   ©r:   Úruler#   r#   r&   r[   …  s    
   ÿzBusConnection.add_match_stringc              
   C   s   |   tttdd|fdd¡ dS )á=  Arrange for this application to receive messages on the bus that
        match the given rule. This version will not block, but any errors
        will be ignored.


        :Parameters:
            `rule` : str
                The match rule
        :Raises `DBusException`: on error.
        :Since: 0.80.0
        r|   r7   N©r9   r   r   r   r~   r#   r#   r&   Úadd_match_string_non_blocking”  s        þz+BusConnection.add_match_string_non_blockingc                 C   s   |   tttdd|f¡ dS )r{   ÚRemoveMatchr7   Nr}   r~   r#   r#   r&   Úremove_match_string¤  s    
   ÿz!BusConnection.remove_match_stringc              
   C   s   |   tttdd|fdd¡ dS )r€   rƒ   r7   Nr�   r~   r#   r#   r&   r`   ±  s        þz.BusConnection.remove_match_string_non_blocking)NNNN)TF)r   )r   )!r?   r@   rA   Ú__doc__r   ZTYPE_SESSIONr	   ZTYPE_SYSTEMr   ZTYPE_STARTERr   ZSTART_REPLY_SUCCESSr
   ZSTART_REPLY_ALREADY_RUNNINGrI   r8   ra   rd   rj   rn   rc   rs   rt   rw   rx   rb   rZ   rz   r[   r‚   r„   r`   Ú__classcell__r#   r#   r_   r&   r   g   s<        þ   ÿ
9

r   )+Ú__all__Ú__docformat__r,   rD   Z_dbus_bindingsr   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Zdbus.connectionr   Zdbus.exceptionsr   Zdbus.lowlevelr   Zdbus._compatr   Z_NAME_OWNER_CHANGE_MATCHr+   Ú	getLoggerr.   Úobjectr   r   r#   r#   r#   r&   Ú<module>   s"   d
ÿý
+