%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/aptdaemon/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/aptdaemon/__pycache__/networking.cpython-312.pyc

�

��kd�&���ddlmZmZmZddlmZddlmZddlmZddlmZ	ddl
Z
ddlmZed�	�ddl
Z
ddlZe
jd
�ZGd�dej
�ZGd
�de�ZGd�de�Zdd�Zedk(rved��Ze
j.�Zej3e�ej5e
j6�ed�Ze�ej:�Zej?�yy)�)�Deferred�inline_callbacks�return_value)�GObject)�Gio)�GLib)�PackageKitGlibN)�
DBusGMainLoopT)�set_as_defaultzAptDaemon.NetMonitorc��eZdZdZdej
jdejffiZd�Z	d�Z
d�Zeee
�Z
ed��Zy)�NetworkMonitorBasezCheck the network state.�network-state-changedNc��tjd�tjj|�tj
j|_y)NzInitializing network monitor)�log�debugr�__init__�pk�NetworkEnum�ONLINE�_state��selfs �6/usr/lib/python3/dist-packages/aptdaemon/networking.pyrzNetworkMonitorBase.__init__2s2���	�	�0�1���� � ��&��n�n�+�+���c��|j|k7r0tjd|�||_|jd|�yy)NzNetwork state changed: %sr)rrr�emit)r�enums  r�
_set_statezNetworkMonitorBase._set_state7s8���;�;�$���I�I�1�4�8��D�K��I�I�-�t�4�rc��|jS�N)rrs r�
_get_statezNetworkMonitorBase._get_state=s���{�{�rc�.�t|j�y�zUpdate the network state.N)rrrs r�get_network_statez$NetworkMonitorBase.get_network_stateBs��	�T�[�[�!r)�__name__�
__module__�__qualname__�__doc__r�SignalFlags�	RUN_FIRST�
TYPE_PYOBJECT�__gsignals__rrr!�property�staterr$�rrr
r
*sb��"�+�g�.A�.A�.K�.K�.2�/6�/D�/D�.F�.H�I�L�,�
5��
�Z��,�E��"��"rr
c�2�eZdZdZd�Zd�Zd�Zed��Zy)�ProcNetworkMonitorzVUse the route information of the proc filesystem to detect
    the network state.
    c��tjd�tj|�tj
j|_tjjd�|_tjj|jtjjd�|_|jj!d|j"�y)Nz'Initializing proc based network monitor�/proc/net/route�changed)rrr
rrr�OFFLINErr�File�new_for_path�_file�monitor�FileMonitorFlags�NONE�_monitor�connect�_on_route_file_changedrs rrzProcNetworkMonitor.__init__Ns����	�	�;�<��#�#�D�)��n�n�,�,����X�X�*�*�+<�=��
����(�(����),�)=�)=�)B�)B�)-�/��
�	
�
�
���i�"�9�9�	;rc�$�|j�yr �r$)r�argss  rr>z)ProcNetworkMonitor._on_route_file_changedYs����� rc��td�5}|j�D]H}|jd�}|ddk(r�|ddk(r�&t|�dk7r�5|ddk(rn/|d	dk7s�Hn$tj
jcd
d
d
�Sd
d
d
�tj
jS#1swYtj
jSxYw)z,Parse the route file - taken from PackageKitr3�	r�Iface�lo���00000000�N)�open�	readlines�split�lenrrr5r)r�
route_file�line�rowss    r�_parse_route_filez$ProcNetworkMonitor._parse_route_file\s���
�#�
$�	.�
�"�,�,�.�
.���z�z�$�'����7�g�%���!�W��_����Y�"�_���!�W�
�*���!�W�
�*��!
.�$�~�~�-�-�'	.�	.�	.�(�~�~�$�$�$�)	.�(�~�~�$�$�$�s�AB-�%B-�-Cc�X�|j�|_t|j�yr#)rQr.rrs rr$z$ProcNetworkMonitor.get_network_statets ���+�+�-��
��T�Z�Z� rN)	r%r&r'r(rr>rQrr$r/rrr1r1Hs*���	;�!�%�0�!��!rr1c��eZdZdZdZedzZedzZdZdZdZ	dZ
d	Zd
�Ze
d��Zed��Zed
��Zed��Zed��Zy)�NetworkManagerMonitorz,Use NetworkManager to monitor network state.�org.freedesktop.NetworkManagerz.Connection.Activez.DevicerrGrI��c��tjd�tj|�t	j
�|_|jjdd�|_|jjd|j|j��|jj|jd|j��y)Nz#Initializing NetworkManager monitorrUz/org/freedesktop/NetworkManager�PropertiesChanged)�dbus_interface)�signal_namerZ)rrr
r�dbus�	SystemBus�bus�
get_object�proxy�connect_to_signal�_on_nm_properties_changed�
NM_DBUS_IFACE�add_signal_receiver� _on_nm_active_conn_props_changed�NM_ACTIVE_CONN_DBUS_IFACErs rrzNetworkManagerMonitor.__init__�s����	�	�7�8��#�#�D�)��>�>�#����X�X�(�(�)I�)J�L��
��
�
�$�$�%8�%)�%C�%C�48�4F�4F�	%�	H�	
���$�$��1�1�+��9�9�	%�	;rc��tj|d�}t�}|j|||j|j
��|S)z8Small helper to get the property value of a dbus object.zorg.freedesktop.DBus.Properties)�
reply_handler�
error_handler)r\�	Interfacer�Get�callback�errback)r`�	interfacer-�props�deferreds     r�get_dbus_propertyz'NetworkManagerMonitor.get_dbus_property�sJ�����u�&G�H���:��
�	�	�)�X� (� 1� 1� (� 0� 0�	�	2��rc#�K�d|vrM|ds5tjd�tjj|_y|j
���yy�w)z.Callback if NetworkManager properties changed.�ActiveConnectionsz#There aren't any active connectionsN)rrrrr5r.r$�rros  rrbz/NetworkManagerMonitor._on_nm_properties_changed�sK�����%�'��,�-��	�	�?�@��^�^�3�3��
��,�,�.�.�(�s�AAc#�:K�d|vry|j���y�w)z8Callback if properties of the active connection changed.�DefaultNr@rts  rrez6NetworkManagerMonitor._on_nm_active_conn_props_changed�s"�����E�!���$�$�&�&�s�c#�PK�tjj}	|j|j|j
d���}D�]�}|jj|j
|�}	|j||jd���}|s�M|j||jd���}d}|D�]}	|jj|j
|�}	|j|	|jd���}

|kr�P|
}|
|j |j"fvrtjj$}��|
|j&k(rtjj(}��|
|j*k(rtjj,}��|
|j.k(rtjj}��tjj0}��"���t|�y#tj$r$tjd�t|�Y���wxYw#tj$rtjd�Y�qwxYw#tj$r<tjd�ttjj�Y���wxYw�w)z-Query NetworkManager about the network state.rsz#Failed to determinate network staterv�Devices����
DeviceTypeN)rrr5rqr`rcr\�
DBusExceptionr�warningrr^r_rf�NM_DEVICE_DBUS_IFACE�UNKNOWN�NM_DEVICE_TYPE_GSM�NM_DEVICE_TYPE_CDMA�MOBILE�NM_DEVICE_TYPE_ETHERNET�WIRED�NM_DEVICE_TYPE_WIFI�WIFI�NM_DEVICE_TYPE_UNKNOWNr)rr.�active_conns�conn�conn_obj�
is_default�devs�priority_device_type�dev�dev_obj�dev_types           r�_query_network_managerz,NetworkManagerMonitor._query_network_manager�sZ�������&�&��	 �!%�!7�!7��
�
�8<�8J�8J�8K�"M�M�L�!�&	2�D��x�x�*�*�4�+=�+=�t�D�H�	
�#'�#9�#9��d�<�<�i�$I�I�
�!��!�3�3��d�<�<�i�I�I��
$&� ��
2��9�"�h�h�1�1�$�2D�2D�c�J�G�%)�%;�%;���!:�!:�L�&J� J�H��3�3��'/�$��� 7� 7� $� 8� 8� :�:��N�N�1�1�E���!=�!=�=��N�N�0�0�E���!9�!9�9��N�N�/�/�E���!<�!<�<��N�N�2�2�E��N�N�1�1�E�3
2�&	2�N	�U���W�!�!�	 ��K�K�=�>����	 ���%�%�
����A�B��
���)�)�9��K�K� E�F� ����!7�!7�8�9�s�J&�)G+�,J&�4!H%�J&�H%�5J&�>AI�C(J&�+3H"�J&�!H"�"J&�%(I�
J&�I�J&�AJ#�J&�"J#�#J&c#�dK�|j���|_t|j�y�wr#)r�r.rrs rr$z'NetworkManagerMonitor.get_network_state�s'���� �6�6�8�8��
��T�Z�Z� �s�.0N)r%r&r'r(rcrfr}r�r�r�rr�r�staticmethodrqrrbrer�r$r/rrrTrT{s���6�4�M� -�0D� D��(�9�4������������;������/��/��'��'��2��2�h�!��!rrTc���|r
t�S	t�S#tj$rYnwxYwtj
j
d�r
t�St�S)zReturn a network monitor.r3)r1rTr\r{�os�path�existsr
)�fallbacks r�get_network_monitorr��sW���!�#�#�
�$�&�&�����
��
��	�w�w�~�~�'�(�!�#�#���s�	�.�.�__main__c#�TK�tj���}td|z�y�w)NzInitial network state: %s)r9r$�print)r.s r�
_call_monitorr�s%�����/�/�1�1��
�*�U�2�4�s�&()F) �deferrrr�
gi.repositoryrrrr	rr\�dbus.mainloop.glibr
�loggingr��	getLoggerrr
r1rTr�r%r��
StreamHandler�log_handler�
addHandler�setLevel�DEBUGr9�MainLoop�loop�runr/rr�<module>r�s���6;�:�!���.��,�
�T�"��	��g���.�/��"����"�<0!�+�0!�fu!�.�u!�p
 ��z���5��5�(�'�'�'�)�K��N�N�;���L�L�����!�$�'�G��O��4�=�=�?�D��H�H�J�r

Zerion Mini Shell 1.0