HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/cockpit/channels/__pycache__/dbus.cpython-39.opt-1.pyc
a

�/�h�V�@s�ddlZddlZddlZddlZddlZddlmmZddl	m
Z
ddlmZm
Z
mZddlmZmZe�e�ZGdd�d�Zdd	�ZGd
d�de�ZdS)�N)�systemd_ctypes)�Bus�BusError�
introspection�)�Channel�ChannelErrorc@s@eZdZdd�Zdd�Zdd�Zddd	�Zd
d�Zddd
�ZdS)�InterfaceCachecCsi|_t�|_dS�N)�cache�set�old��self�r�9/usr/lib/python3.9/site-packages/cockpit/channels/dbus.py�__init__tszInterfaceCache.__init__cCs|j�|�dSr
)r�update)r�
interfacesrrr�injectxszInterfaceCache.injectc�sD|�||dd�IdH\}t�|�}dd�|�d�D�}|�|�|S)Nz#org.freedesktop.DBus.IntrospectableZ
IntrospectcSsi|]}|jdt�|��qS)�name)ZattribrZparse_interface)�.0�tagrrr�
<dictcomp>��z2InterfaceCache.introspect_path.<locals>.<dictcomp>�	interface)�call_method_async�ETZ
fromstring�findallr)r�bus�destination�object_pathZxml�etrrrr�introspect_path{s�

zInterfaceCache.introspect_pathNc�s`z|j|WStyYn0|rT|rTz|�|||�IdHWntyRYn0|j�|�Sr
)r�KeyErrorr#r�get�r�interface_namerr r!rrr�
get_interface�szInterfaceCache.get_interfacec�s0||jvrdS|j�|�|�||||�IdHSr
)r
�addr(r&rrr�get_interface_if_new�s
z#InterfaceCache.get_interface_if_newc�sD|�||||�IdH}|dur.td|�d���d�|d|d�S)Nz
Interface z
 is not found��methods�in)r(r$�join)rr'�methodrr r!rrrr�
get_signature�szInterfaceCache.get_signature)NNN)NNN)	�__name__�
__module__�__qualname__rrr#r(r*r0rrrrr	ss
r	cCs"dd�|��D�|�|i�|<dS)NcSsi|]\}}||j�qSr)�value)r�k�vrrrr�rz!notify_update.<locals>.<dictcomp>)�items�
setdefault)�notify�pathr'�propsrrr�
notify_update�sr<c@s�eZdZejdd�ZdZdZdZdZ	dZ
dd�Zdd�Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�DBusChannelr)�indentz
dbus-json3Nc
�s�fdd���fdd�}�j|dddd�jd�z$�j�dddd	d
�j�IdH\}Wn�ty�}z�|jdkr�z$�j�ddddd
�jd�IdHWq�ty�}z*t�d�j|j��jdd�WYd}~q�d}~00nt�d�j|j�WYd}~nd}~00�|�dS)Ncs �j|kr|�_�j|d�dS)N��owner)r@�	send_jsonr?rrr�
send_owner�s
z9DBusChannel.setup_name_owner_tracking.<locals>.send_ownercs(|��\}}}�|dkr|ndd�dS)Nr+r?)�get_body)�message�_nameZ_old�new)rBrr�handler�sz6DBusChannel.setup_name_owner_tracking.<locals>.handlerzorg.freedesktop.DBusz/org/freedesktop/DBusZNameOwnerChanged)�senderr:r�memberZarg0ZGetNameOwner�sz)org.freedesktop.DBus.Error.NameHasNoOwnerZStartServiceByNameZsurz Failed to start service '%s': %sr?z'Failed to get owner of service '%s': %s)	�add_signal_handlerrrrr�logger�debugrDrA)rrG�unique_name�errorZstart_errorr)rrBr�setup_name_owner_tracking�s8��

�$(z%DBusChannel.setup_name_owner_trackingc
s�t��_|�d��_g�_|�d�}|�d�}z�|dur||durT|dkrTtddd��t�d|�j�tj	|�jdud	��_
n�|d
kr�t�d�j��jjj
�_
n`|dkr�t�d
�j�t���_
n>|dks�|dur�t�d�j�t���_
ntdd|�d�d��Wn@t�yB}z&tdd|�d|��d�|�WYd}~n
d}~00z�j
�dd�Wn6t�y�}z|jtjk�rx�WYd}~n
d}~00t���_�jdu�r��fdd�}��|��n���dS)Nrr�addressZnonezprotocol-errorz0only one of "bus" and "address" can be specified�rDzget bus with address %s for %s)rQZ
bus_clientZinternalzget internal bus for %sZsessionzget session bus for %s�systemzget system bus for %sz
invalid bus "�"zfailed to connect to z bus: rc	�sp�j4IdH�H���IdH�jr4�j�jd�n��ddi�Wd�IdHql1IdHsb0YdS)N)rNZproblemz	not-found)�watch_processing_lockrPr@�ready�closerrrr�	get_readys
z&DBusChannel.do_open.<locals>.get_ready)r	rr%r�matchesrrLrMrrFrZrouterZinternal_busZclientZdefault_userZdefault_system�OSErrorZattach_event�errnoZEBUSY�asyncio�LockrU�create_taskrV)r�optionsrrQ�exc�errrXrrr�do_open�sB

0
zDBusChannel.do_opencs�tfi|��}d|d<d|vr2�jdur2�j|d<|�d�dkrF|d=��fdd�}�jdurzd|vrz|d�jkrz|}n�}d�d	d
�|��D��}���s�z�j�||�}Wq�Wq�ty�Yq�0q��j	�
|�dS)N�signal�typerH�path_namespace�/cs$�jdur �j|��kr �|�dSr
)r@Z
get_senderrR�rGrrr�filter_ownersz4DBusChannel.add_signal_handler.<locals>.filter_owner�,css"|]\}}|�d|�d�VqdS)z='�'Nr)r�keyr4rrr�	<genexpr>rz1DBusChannel.add_signal_handler.<locals>.<genexpr>)�dictrr%r.r7Z
is_closingr�	add_match�InterruptedErrorrY�append)rrG�kwargs�rrh�funcZr_string�matchrrgrrK
s$
 zDBusChannel.add_signal_handlercs$��fdd�}�j|fi|��dS)Ncs���|��dSr
)r^rRrgrr�sync_handler,sz:DBusChannel.add_async_signal_handler.<locals>.sync_handler)rK)rrGrqrurrgr�add_async_signal_handler+sz$DBusChannel.add_async_signal_handlerc
�sx|d\}}}}|�d�}|�d�}|�d�}|dur@|d9}nd}|�d�}	|	durft|�dkrfd	}	|	du�r\z0t�d
||�|j�|||j|j|�IdH}	Wn�ty�}
z,|j	|
jd|
j
��gg|d�WYd}
~
dSd}
~
0t�y|j	d
d|�d|�d�gg|d�YdSt�yZ}z(|j	dd|��gg|d�WYd}~dSd}~00z�|jj
|j||||	g|�R�}|jj||d�IdH}
|j4IdH�D|j	|
��g||du�r�dnd|
�d�d�Wd�IdH�q�1IdH�s�0YWntt�y<}
z$|j	|
j|
j
gg|d�WYd}
~
n@d}
~
0t�yrt�d|�|j	dt��gg|d�Yn0dS)N�call�id�flags�timeouti�l����rdrr+z%Doing introspection request for %s %szIntrospection: �rOrxz(org.freedesktop.DBus.Error.UnknownMethodzIntrospection data for method � z not availablezpython.error)rz�<T)�replyrxryrdzdo_call(%s): generic exception)r%�lenrLrMrr0rrrrArDr$�	ExceptionZmessage_new_method_callZ
call_asyncrUrC�	exception�	traceback�
format_exc)rrDr:�ifacer/�args�cookieryrzZ	signaturerOr`Zmethod_callr~rrr�do_call0sT





"��
�8,zDBusChannel.do_callc�s6|d}t�d|��fdd�}�j|fi|��dS)N�	add-matchzadding match %sc	�spt�d��j4IdH�>�j|��|��|��t|���gd�Wd�IdHql1IdHsb0YdS)Nz	got match)rc)	rLrMrUrA�get_pathr(�
get_member�listrCrRrrr�	match_hitms

�z+DBusChannel.do_add_match.<locals>.match_hit)rLrMrv)rrDrnr�rrr�do_add_matchis
zDBusChannel.do_add_matchc�s���fdd�}�j||dd��j��j|dd�IdH\}|��D]f\}}|��D]T\}	}
�dusj|	�krR�j�|	�j�j|�IdH}|r�|�|	|i�t|||	|
�qRqBdS)Nc
	�sd|��}|dkr�|��\}}t�d||�i}i}�j4IdH��|��D]T\}}�dusb|�krJ�j�|�j�j	|�IdH}|r�|�
||i�t||||�qJ�j|d��j|d�Wd�IdHq�1IdHs�0Yn||dk�r`|��\}}	t�d||	��j4IdH�2|t
�|	�i}�j|d�Wd�IdH�q`1IdH�sV0YdS)NZInterfacesAddedzinterfaces added %s %s��meta�r9ZInterfacesRemovedzinterfaces removed %s %s)r�rCrLrMrUr7rr*rrrr<rArm�fromkeys)
rDrIr:Zinterface_propsr�r9rr;�mmr�r'rrrrG~s*8
z6DBusChannel.setup_objectmanager_watch.<locals>.handlerz"org.freedesktop.DBus.ObjectManager)r:rZGetManagedObjects)	rvrrrr7rr*rr<)rr:r'r�r9rGZobjects�pZifacesr�r;r�rr�r�setup_objectmanager_watchys ��z%DBusChannel.setup_objectmanager_watchc	�s��fdd�}�j��j�j|�IdH}|dur@|�|�}||i}|�|�|r`�j|d|d�n�j|d|d�|D]V}	|	�d�r�qtz2�j��j|ddd|	�IdH\}
t	|||	|
�Wqtt
y�Yqt0qtdS)	Nc	�s
�j4IdH��|��}|��\}}}t�d||||�|D]~}z&�j��j|ddd||�IdH\}WnJty�}z2t�d||�j|t	|��WYd}~q<WYd}~n
d}~00|||<q<i}t
||||��j|d�Wd�IdH�q1IdHs�0YdS)NzNOTIFY: %s %s %s %s�org.freedesktop.DBus.PropertiesZGet�ssz+failed to fetch property %s.%s on %s %s: %sr�)rUr�rCrLrMrrrr�strr<rA)	rDr:rr;Zinvalids�invr~r`r9rrrrG�s&��"
z-DBusChannel.setup_path_watch.<locals>.handlerr�)rre)rr:zorg.freedesktop.DBus.ZGetAllrJ)rr#rrr%rrv�
startswithrr<r)rr:r'Zrecursive_propsr�r9rGZ	this_metarrr;rrr�setup_path_watch�s4

��
�zDBusChannel.setup_path_watchc
�s||d}|�d�}|�d�}|�d�}|�d�}|p6|}||k}|dusP|dur�t�d|�|jddgg|d	�|jg|d
�dSz�|j4IdH�|i}i}	|�|||||	�IdH|r�|�||||	�IdH|j|d�|j|	d�|jg|dd
�Wd�IdH�q&1IdH�s0YWnNt�yv}
z4t�d
||
j�|j|
j	|
jgg|d	�WYd}
~
n
d}
~
00dS)N�watchr:rerrxz#ignored incomplete watch request %szx.y.zzNot Implementedr{)r~rxr�r�z#do_watch(%s) caught D-Bus error: %s)
r%rLrMrArUr�r�rrDr)rrDr�r:rer'r��	recursiver�r9rOrrr�do_watch�s2



DzDBusChannel.do_watchc�s|j�|d�dS)Nr�)rr)rrDrrr�do_meta�szDBusChannel.do_metacCs�t�|�}t�d|j|�d|vr4|�|�|��n^d|vrN|�|�|��nDd|vrh|�|�|��n*d|vr�|�|�	|��nt�d|�dSdS)Nzreceive dbus request %s %srwr�r�r�zignored dbus request %s)
�json�loadsrLrMrr^r�r�r�r�)r�datarDrrr�do_data�s
zDBusChannel.do_datacCs&|jD]}|��qg|_|��dSr
)rY�cancelrW)rZslotrrr�do_closes

zDBusChannel.do_close)r1r2r3rZJSONEncoderZjson_encoderZpayloadrYrrr@rPrbrKrvr�r�r�r�r�r�r�r�rrrrr=�s$(39*0r=)r\r[r�Zloggingr�Zxml.etree.ElementTreeZetreeZElementTreerZcockpit._vendorrZcockpit._vendor.systemd_ctypesrrrZchannelrrZ	getLoggerr1rLr	r<r=rrrr�<module>%s
B2