o
    Uh%                     @   s  d dl Z d dlmZ d dlmZ ddlT g dZe dZdd	 Z	e d
Z
dd Ze dZdd ZG dd dZG dd deZdd Zd,ddZd,ddZd,ddZd,ddZG dd  d ZG d!d" d"ZG d#d$ d$ZG d%d& d&eZG d'd( d(eZd)efd*d+ZdS )-    N)Union)warn   )*)	DBusAddressnew_method_callnew_method_return	new_error
new_signalMessageGenerator
PropertiesIntrospectableDBusErrorResponsezZ([A-Za-z_-][A-Za-z0-9_-]*(\.[A-Za-z_-][A-Za-z0-9_-]*)+|:[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+))$c                 C   J   t | dkr| d d d }td|dt| s#td| dd S )N      ...z
Bus name ( ) is too long (> 255 characters)) is not valid)len
ValueErrorbus_name_patmatchnameabbr r   d/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/jeepney/wrappers.pycheck_bus_name      
r   z2[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)+$c                 C   r   )Nr   r   r   zInterface name (r   r   )r   r   interface_patr   r   r   r   r   check_interface!   r   r!   z[A-Za-z_][A-Za-z0-9_]*$c                 C   r   )Nr   r   r   zMember name (r   z is not valid)r   r   member_name_patr   r   r   r   r   check_member_name*   r   r#   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
r   aA  This identifies the object and interface a message is for.

    e.g. messages to display desktop notifications would have this address::

        DBusAddress('/org/freedesktop/Notifications',
                    bus_name='org.freedesktop.Notifications',
                    interface='org.freedesktop.Notifications')
    Nc                 C   sB   t  | || _|d urt| || _|d urt| || _d S N)ObjectPathType
check_dataobject_pathr   bus_namer!   	interfaceselfr'   r(   r)   r   r   r   __init__;   s   
zDBusAddress.__init__c                 C   s   d t| j| j| j| jS )Nz'{}({!r}, bus_name={!r}, interface={!r}))formattype__name__r'   r(   r)   r+   r   r   r   __repr__G   s   zDBusAddress.__repr__c                 C   s   t | t| | j| j|S r$   )r!   r.   r'   r(   )r+   r)   r   r   r   with_interfaceK   s   zDBusAddress.with_interfaceNN)r/   
__module____qualname____doc__r,   r1   r2   r   r   r   r   r   2   s
    
r   c                       s   e Zd Zd fdd	Z  ZS )
DBusObjectNc                    s    t  ||| tddd d S )Nz)Deprecated alias, use DBusAddress instead   )
stacklevel)superr,   r   r*   	__class__r   r   r,   P   s   zDBusObject.__init__r3   )r/   r4   r5   r,   __classcell__r   r   r;   r   r7   O   s    r7   c              	   C   s   t tj| ddddi dS )Nr   r   )flagsprotocol_versionbody_lengthserialfields)Header
Endiannesslittle)msg_typer   r   r   
new_headerT   s   rH   r   c                 C   s   t | ttj}| j|jtj< | jdu rt	d| j|jtj
< | jdur,| j|jtj< ||jtj< |dur<||jtj< t||S )a  Construct a new method call message

    This is a relatively low-level method. In many cases, this will be called
    from a :class:`MessageGenerator` subclass which provides a more convenient
    API.

    :param DBusAddress remote_obj: The object to call a method on
    :param str method: The name of the method to call
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data (i.e. method parameters)
    Nz3remote_obj.bus_name cannot be None for method calls)r#   rH   MessageTypemethod_callr'   rC   HeaderFieldspathr(   r   destinationr)   member	signatureMessage)
remote_objmethodrO   bodyheaderr   r   r   r   X   s   



r   c                 C   s^   t tj}| jj|jtj< | jjtj	d}|dur ||jtj
< |dur*||jtj< t||S )zConstruct a new response message

    :param Message parent_msg: The method call this is a reply to
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    N)rH   rI   method_returnrT   rB   rC   rK   reply_serialgetsenderrM   rO   rP   )
parent_msgrO   rS   rT   rX   r   r   r   r   r   s   

r   c                 C   sj   t tj}| jj|jtj< ||jtj< | jj	tj
d}|dur&||jtj< |dur0||jtj< t||S )zConstruct a new error response message

    :param Message parent_msg: The method call this is a reply to
    :param str error_name: The name of the error
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    N)rH   rI   errorrT   rB   rC   rK   rV   
error_namerW   rX   rM   rO   rP   )rY   r[   rO   rS   rT   rX   r   r   r   r	      s   

r	   c                 C   sj   t | ttj}| j|jtj< | jdu rt	d| j|jtj< ||jtj
< |dur0||jtj< t||S )zConstruct a new signal message

    :param DBusAddress emitter: The object sending the signal
    :param str signal: The name of the signal
    :param str signature: The DBus signature of the body data
    :param tuple body: Body data
    Nz,emitter.interface cannot be None for signals)r#   rH   rI   signalr'   rC   rK   rL   r)   r   rN   rO   rP   )emitterr\   rO   rS   rT   r   r   r   r
      s   


r
   c                   @   s2   e Zd ZU dZdZee ed< dd Zdd Z	dS )r   zSubclass this to define the methods available on a DBus interface.
    
    jeepney.bindgen can automatically create subclasses using introspection.
    Nr)   c                 C   s8   t  | t| | jd urt| j || _|| _d S r$   )r%   r&   r   r)   r!   r'   r(   )r+   r'   r(   r   r   r   r,      s   


zMessageGenerator.__init__c                 C   s   d t| j| j| jS )Nz{}({!r}, bus_name={!r}))r-   r.   r/   r'   r(   r0   r   r   r   r1      s   zMessageGenerator.__repr__)
r/   r4   r5   r6   r)   Optionalstr__annotations__r,   r1   r   r   r   r   r      s
   
 	r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )		ProxyBasezA proxy is an IO-aware wrapper around a MessageGenerator
    
    Calling methods on a proxy object will send a message and wait for the
    reply. This is a base class for proxy implementations in jeepney.io.
    c                 C   s
   || _ d S r$   )_msggen)r+   msggenr   r   r   r,      s   
zProxyBase.__init__c                 C   s:   | dr	t|t| j|d }t|r| |S t|)N__)
startswithAttributeErrorgetattrrb   callable_method_call)r+   itemmake_msgr   r   r   __getattr__   s   

zProxyBase.__getattr__c                 C   s   t d)Nz#Needs to be implemented in subclass)NotImplementedError)r+   rk   r   r   r   ri      s   zProxyBase._method_callN)r/   r4   r5   r6   r,   rl   ri   r   r   r   r   ra      s
    
ra   c                   @   s>   e Zd ZdZdeeef fddZdd Zdd Z	d	d
 Z
dS )r   zBuild messages for accessing object properties

    If a D-Bus object has multiple interfaces, each interface has its own
    set of properties.

    This uses the standard DBus interface ``org.freedesktop.DBus.Properties``
    objc                 C   s   || _ t|j|jdd| _d S )Nzorg.freedesktop.DBus.Properties)r(   r)   )rn   r   r'   r(   props_if)r+   rn   r   r   r   r,      s   
zProperties.__init__c                 C   s   t | jdd| jj|fS )z$Get the value of the property *name*Getssr   ro   rn   r)   )r+   r   r   r   r   rW      s   

zProperties.getc                 C   s   t | jdd| jjfS )z*Get all property values for this interfaceGetAllsrr   r0   r   r   r   get_all   s   
zProperties.get_allc                 C   s   t | jdd| jj|||ffS )z?Set the property *name* to *value* (with appropriate signature)Setssvrr   )r+   r   rO   valuer   r   r   set   s   
zProperties.setN)r/   r4   r5   r6   r   r   r   r,   rW   ru   ry   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )r   z#org.freedesktop.DBus.Introspectablec                 C   s
   t | dS )z3Request D-Bus introspection XML for a remote object
Introspect)r   r0   r   r   r   rz      s   
zIntrospectable.IntrospectN)r/   r4   r5   r)   rz   r   r   r   r   r      s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )r   z?Raised by proxy method calls when the reply is an error messagec                 C   s   |j jtj| _|j| _d S r$   )rT   rC   rW   rK   r[   r   rS   data)r+   msgr   r   r   r,      s   zDBusErrorResponse.__init__c                 C   s   d | j| jS )Nz[{}] {})r-   r   r{   r0   r   r   r   __str__   s   zDBusErrorResponse.__str__N)r/   r4   r5   r6   r,   r}   r   r   r   r   r      s    r   r|   c                 C   s   | j jtjkrt| | jS )zGet the body of a message, raising DBusErrorResponse for error messages

    This is to be used with replies to method_call messages, which may be
    method_return or error.
    )rT   message_typerI   rZ   r   rS   )r|   r   r   r   
unwrap_msg   s   r   )Nr   )retypingr   warningsr   	low_level__all__compiler   r   r    r!   r"   r#   r   r7   rH   r   r   r	   r
   r   ra   r   r   	Exceptionr   rP   r   r   r   r   r   <module>   s4    






