%PDF- %PDF-
Mini Shell

Mini Shell

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

�

9*�bO,����dZddlZddlZddlZddlZddlmZddlmZd�Z	Gd�de
�ZGd�d	e�ZGd
�de�Z
Gd�d
e�ZGd�de�ZGd�de
�Zy)z�
    pyudev.discover
    ===============

    Tools to discover a device given limited information.

    .. moduleauthor::  mulhern <amulhern@redhat.com>
�N��DeviceNotFoundError)�Devicesc�B��tj���fd��}|S)z\
    Allow Device discovery methods to return None instead of raising an
    exception.
    c�4��	�|i|��S#t$rYywxYw)z�
        Returns result of calling ``func`` on ``args``, ``kwargs``.
        Returns None if ``func`` raises :exc:`DeviceNotFoundError`.
        Nr)�args�kwargs�funcs  ��1/usr/lib/python3/dist-packages/pyudev/discover.py�the_funcz wrap_exception.<locals>.the_func+s*���	���(��(�(��"�	��	�s��	�)�	functools�wraps)r
rs` r�wrap_exceptionr%s'����_�_�T������O�c��eZdZdZej
Zeejd���Z	eejd���Z
ed��Zed��Zy)�
HypothesiszM
    Represents a hypothesis about the meaning of the device identifier.
    c��t��)a�
        Match the given string according to the hypothesis.

        The purpose of this method is to obtain a value corresponding to
        ``value`` if that is possible. It may use a regular expression, but
        in general it should just return ``value`` and let the lookup method
        sort out the rest.

        :param str value: the string to inspect
        :returns: the matched thing or None if unmatched
        :rtype: the type of lookup's key parameter or NoneType
        ��NotImplementedError��cls�values  r�matchzHypothesis.match@s
��"�#�#rc��t��)aN
        Lookup the given string according to the hypothesis.

        :param Context context: the pyudev context
        :param key: a key with which to lookup the device
        :type key: the type of match's return value if not None
        :returns: a list of Devices obtained
        :rtype: frozenset of :class:`Device`
        r)r�context�keys   r�lookupzHypothesis.lookupQs
��"�#�#rc��y)z�
        A potentially expensive method that may allow an :class:`Hypothesis`
        to find devices more rapidly or to find a device that it would
        otherwise miss.

        :param Context context: the pyudev context
        N��rrs  r�setupzHypothesis.setup_s��	
rc�`�|j|�}|�|j||�St�S)a
        Get any devices that may correspond to the given string.

        :param Context context: the pyudev context
        :param str value: the value to look for
        :returns: a list of devices obtained
        :rtype: set of :class:`Device`
        )rr�	frozenset)rrrrs    r�get_deviceszHypothesis.get_devicesjs.���i�i����+.�?�s�z�z�'�3�'�K�	��KrN)
�__name__�
__module__�__qualname__�__doc__�abc�ABCMeta�
__metaclass__�classmethod�abstractmethodrrr!r$rrrrr9s~����K�K�M�����
$���
$�����
$���
$��
��
��
L��
Lrrc�`�eZdZdZed��Zed��Zed��Zed��Zed��Z	y)�DeviceNumberHypothesisz�
    Represents the hypothesis that the device is a device number.

    The device may be separated into major/minor number or a composite number.
    c���tjd�}|j|�}|xrFtjt|j
d��t|j
d���S)z�
        Match the number under the assumption that it is a major,minor pair.

        :param str value: value to match
        :returns: the device number or None
        :rtype: int or NoneType
        z#^(?P<major>\d+)(\D+)(?P<minor>\d+)$�major�minor)�re�compiler�os�makedev�int�group)rr�major_minor_rers    r�_match_major_minorz)DeviceNumberHypothesis._match_major_minors\�����$J�K���$�$�U�+���
��������G�$�%�s�5�;�;�w�+?�'@�
�	
rc��tjd�}|j|�}|xrt|j	d��S)z�
        Match the number under the assumption that it is a single number.

        :param str value: value to match
        :returns: the device number or None
        :rtype: int or NoneType
        z^(?P<number>\d+)$�number)r3r4rr7r8)rr�	number_rers    r�
_match_numberz$DeviceNumberHypothesis._match_number�s:���J�J�3�4�	�����&���3��U�[�[��2�3�3rc�J�|j|�xs|j|�S)z�
        Match the number under the assumption that it is a device number.

        :returns: the device number or None
        :rtype: int or NoneType
        )r:r>rs  rrzDeviceNumberHypothesis.match�s%���%�%�e�,�H��0A�0A�%�0H�Hrc��|j}tjtjj	|d��S)z�
        Find subsystems in /sys/dev.

        :param Context context: the context
        :returns: a lis of available subsystems
        :rtype: list of str
        �dev)�sys_pathr5�listdir�path�join)rrrBs   r�find_subsystemsz&DeviceNumberHypothesis.find_subsystems�s-���#�#���z�z�"�'�'�,�,�x��7�8�8rc�����ttj�����fd�|j��D�}t	d�|D��S)z�
        Lookup by the device number.

        :param Context context: the context
        :param int key: the device number
        :returns: a list of matching devices
        :rtype: frozenset of :class:`Device`
        c3�2�K�|]}��|�����y�w�Nr��.0�srr
rs  ���r�	<genexpr>z0DeviceNumberHypothesis.lookup.<locals>.<genexpr>�������K��t�G�Q��$�K���c3�&K�|]	}|��|���y�wrIr�rK�rs  rrMz0DeviceNumberHypothesis.lookup.<locals>.<genexpr>������9�q�1�=��9����)rr�from_device_numberrFr#�rrr�resr
s `` @rrzDeviceNumberHypothesis.lookup�s;����g�8�8�9��K�c�.A�.A�'�.J�K���9�C�9�9�9rN)
r%r&r'r(r,r:r>rrFrrrrr/r/xsm����
��
��
4��
4��I��I��	9��	9��:��:rr/c�0�eZdZdZed��Zed��Zy)�DevicePathHypothesiszG
    Discover the device assuming the identifier is a device path.
    c��|S)z�
        Match ``value`` under the assumption that it is a device path.

        :returns: the device path or None
        :rtype: str or NoneType
        rrs  rrzDevicePathHypothesis.match��	���rc�r�ttj�||�}|�t|f�St�S)��
        Lookup by the path.

        :param Context context: the context
        :param str key: the device path
        :returns: a list of matching devices
        :rtype: frozenset of :class:`Device`
        )rr�	from_pathr#)rrrrWs    rrzDevicePathHypothesis.lookup�s5��0�n�W�.�.�/���=��$'�O�y�#�� �D���DrN)r%r&r'r(r,rrrrrrYrY�s1��������
E��
ErrYc�@�eZdZdZed��Zed��Zed��Zy)�DeviceNameHypothesiszf
    Discover the device assuming the input is a device name.

    Try every available subsystem.
    c�l��|j�d}�fd�|D�}d�|D�}td�|D��S)z�
        Find all subsystems in sysfs.

        :param Context context: the context
        :rtype: frozenset
        :returns: subsystems in sysfs
        )�bus�class�	subsystemc3�^�K�|]$}tjj�|����&y�wrI�r5rDrE)rK�namerBs  �rrMz7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>�s �����F�T�B�G�G�L�L��4�0�F���*-c3�`K�|]&}tjj|�s�#|���(y�wrI)r5rD�isdir�rK�ds  rrMz7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>�s����=�1�B�G�G�M�M�!�,<�Q�=�s�$.�.c3�TK�|] }tj|�D]}|����"y�wrI)r5rC)rKrl�ns   rrMz7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>�s$����E�q�r�z�z�!�}�E�!��E��E�s�&()rBr#)rr�dirnames�absnames�	realnamesrBs     @rrFz$DeviceNameHypothesis.find_subsystems�s:����#�#��0��F�X�F��=��=�	��E�I�E�E�Erc��|S)z�
        Match ``value`` under the assumption that it is a device name.

        :returns: the device path or None
        :rtype: str or NoneType
        rrs  rrzDeviceNameHypothesis.match�r[rc�����ttj�����fd�|j��D�}t	d�|D��S)r]c3�2�K�|]}��|�����y�wrIrrJs  ���rrMz.DeviceNameHypothesis.lookup.<locals>.<genexpr>rNrOc3�&K�|]	}|��|���y�wrIrrQs  rrMz.DeviceNameHypothesis.lookup.<locals>.<genexpr>	rSrT)rr�	from_namerFr#rVs `` @rrzDeviceNameHypothesis.lookup�s;����g�/�/�0��K�c�.A�.A�'�.J�K���9�C�9�9�9rN)r%r&r'r(r,rFrrrrrr`r`�sE����F��F������:��:rr`c�X�eZdZdZgd�Zed��Zed��Zed��Zed��Z	y)�DeviceFileHypothesisz�
    Discover the device assuming the value is some portion of a device file.

    The device file may be a link to a device node.
    )z/devz/dev/disk/by-idz/dev/disk/by-labelz/dev/disk/by-partlabelz/dev/disk/by-partuuidz/dev/disk/by-pathz/dev/disk/by-uuidz/dev/input/by-pathz/dev/mapperz/dev/mdz/dev/vgc�|�|j�}d�|D�}d�|D�}ttd�|D���S)a7
        Get all directories that may contain links to device nodes.

        This method checks the device links of every device, so it is very
        expensive.

        :param Context context: the context
        :returns: a sorted list of directories that contain device links
        :rtype: list
        c3�LK�|]}t|j�s�|���y�wrI)�list�device_linksrks  rrMz5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>.s����I�A�D����4H�a�I�s�$�$c3�BK�|]}|jD]}|����y�wrI)r|)rKrl�ls   rrMz5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>/s ����G�q����G�1��G��G�s�c3�ZK�|]#}tjj|����%y�wrI)r5rD�dirname)rKr~s  rrMz5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>0s����<��"�'�'�/�/�!�,�<�s�)+)�list_devices�sorted�set)rr�devices�devices_with_links�linkss     r�
get_link_dirsz"DeviceFileHypothesis.get_link_dirs!s>���&�&�(��I��I��G�.�G���c�<�e�<�<�=�=rc�0�|j|�|_y)z�
        Set the link directories to be used when discovering by file.

        Uses `get_link_dirs`, so is as expensive as it is.

        :param Context context: the context
        N)r��
_LINK_DIRSr s  rr!zDeviceFileHypothesis.setup2s���*�*�7�3��rc��|SrIrrs  rrzDeviceFileHypothesis.match=s���rc������ttj��d�vr!����}|�t|f�St�S�fd�|jD�}��fd�|D�}td�|D��S)a�
        Lookup the device under the assumption that the key is part of
        the name of a device file.

        :param Context context: the context
        :param str key: a portion of the device file name

        It is assumed that either it is the whole name of the device file
        or it is the basename.

        A device file may be a device node or a device link.
        �/c3�^�K�|]$}tjj|�����&y�wrIrf)rK�ldrs  �rrMz.DeviceFileHypothesis.lookup.<locals>.<genexpr>Ts �����@�2������b�#�&�@�rhc3�0�K�|]
}��|����y�wrIr)rK�frr
s  ��rrMz.DeviceFileHypothesis.lookup.<locals>.<genexpr>Us�����3��4���#�3�s�c3�&K�|]	}|��|���y�wrIrrks  rrMz.DeviceFileHypothesis.lookup.<locals>.<genexpr>Vs����=�q�q�}��=�rT)rr�from_device_filer#r�)rrr�device�filesr�r
s ``   @rrzDeviceFileHypothesis.lookupAsj����g�6�6�7���#�:��'�3�'�F�+1�+=�9�f�Y�'�N�9�;�N�@����@��3�U�3���=�G�=�=�=rN)
r%r&r'r(r�r,r�r!rrrrrrxrxs^����J��>��>� �4��4������>��>rrxc�.�eZdZdZeeeegZd�Z	d�Z
d�Zy)�	Discoveryz1
    Provides discovery methods for devices.
    c�&�|j|_yrI)�_HYPOTHESES�_hypotheses)�selfs r�__init__zDiscovery.__init__fs���+�+��rc�H�|jD]}|j|��y)z
        Set up individual hypotheses.

        May be an expensive call.

        :param Context context: the context
        N)r�r!)r�r�hyps   rr!zDiscovery.setupis%���#�#�	�C��I�I�g��	rc�D���t��fd�|jD��S)z�
        Get the devices corresponding to value.

        :param Context context: the context
        :param str value: some identifier of the device
        :returns: a list of corresponding devices
        :rtype: frozenset of :class:`Device`
        c3�P�K�|]}|j���D]}|����y�wrI)r$)rK�hrlrrs   ��rrMz(Discovery.get_devices.<locals>.<genexpr>}s3�����
�����w��1N�
�,-�A�
�
�
�s�#&)r#r�)r�rrs ``rr$zDiscovery.get_devicests%����
��'�'�
�
�	
rN)r%r&r'r(rxr`r/rYr�r�r!r$rrrr�r�Ys+���
	����	�K�,�	�
rr�)r(r)r
r5r3�pyudev._errorsr�
pyudev.devicerr�objectrr/rYr`rxr�rrr�<module>r�sy��"���	�	�/�!��(<L��<L�~E:�Z�E:�PE�:�E�:,:�:�,:�^J>�:�J>�Z&
��&
r

Zerion Mini Shell 1.0