%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core22/current/usr/lib/python3/dist-packages/pyudev/__pycache__/
Upload File :
Create Path :
Current File : //snap/core22/current/usr/lib/python3/dist-packages/pyudev/__pycache__/discover.cpython-310.pyc

o

8g+^w,�@s�dZddlmZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZd	d
�Ze
�ej�Gdd�de��ZGd
d�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z�
    pyudev.discover
    ===============

    Tools to discover a device given limited information.

    .. moduleauthor::  mulhern <amulhern@redhat.com>
�)�absolute_import)�division)�print_function)�unicode_literalsN��DeviceNotFoundError)�Devicescst����fdd��}|S)z\
    Allow Device discovery methods to return None instead of raising an
    exception.
    cs&z�|i|��WStyYdSw)z�
        Returns result of calling ``func`` on ``args``, ``kwargs``.
        Returns None if ``func`` raises :exc:`DeviceNotFoundError`.
        Nr)�args�kwargs��func��1/usr/lib/python3/dist-packages/pyudev/discover.py�the_func0s
�z wrap_exception.<locals>.the_func)�	functools�wraps)rrr
rr�wrap_exception*s
rc@sLeZdZdZeejdd���Zeejdd���Zedd��Z	edd	��Z
d
S)�
HypothesiszM
    Represents a hypothesis about the meaning of the device identifier.
    cC�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�valuer
r
r�matchDszHypothesis.matchcCr)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�keyr
r
r�lookupUszHypothesis.lookupcCsdS)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
        Nr
�rrr
r
r�setupcs	zHypothesis.setupcCs$|�|�}|dur|�||�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`
        N)rr�	frozenset)rrrrr
r
r�get_devicesns

zHypothesis.get_devicesN)�__name__�
__module__�__qualname__�__doc__�classmethod�abc�abstractmethodrrrr!r
r
r
rr>s

rc@sLeZdZdZedd��Zedd��Zedd��Zedd	��Zed
d��Z	dS)
�DeviceNumberHypothesisz�
    Represents the hypothesis that the device is a device number.

    The device may be separated into major/minor number or a composite number.
    cCs8t�d�}|�|�}|ot�t|�d��t|�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_rerr
r
r�_match_major_minor�s

	
�z)DeviceNumberHypothesis._match_major_minorcCs&t�d�}|�|�}|ot|�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)r,r-rr0r1)rr�	number_rerr
r
r�
_match_number�s
	
z$DeviceNumberHypothesis._match_numbercCs|�|�p	|�|�S)z�
        Match the number under the assumption that it is a device number.

        :returns: the device number or None
        :rtype: int or NoneType
        )r3r6rr
r
rr�szDeviceNumberHypothesis.matchcCs|j}t�tj�|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_pathr.�listdir�path�join)rrr8r
r
r�find_subsystems�s	z&DeviceNumberHypothesis.find_subsystemsc�8ttj�����fdd�|���D�}tdd�|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��|]	}��|��VqdS�Nr
��.0�s�rrrr
r�	<genexpr>���z0DeviceNumberHypothesis.lookup.<locals>.<genexpr>cs��|]	}|dur|VqdSr?r
�rA�rr
r
rrD�rE)rr�from_device_numberr<r �rrr�resr
rCrr��

zDeviceNumberHypothesis.lookupN)
r"r#r$r%r&r3r6rr<rr
r
r
rr)|s


	
r)c@s(eZdZdZedd��Zedd��ZdS)�DevicePathHypothesiszG
    Discover the device assuming the identifier is a device path.
    cC�|S)z�
        Match ``value`` under the assumption that it is a device path.

        :returns: the device path or None
        :rtype: str or NoneType
        r
rr
r
rr��zDevicePathHypothesis.matchcCs(ttj�||�}|durt|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`
        N)rr�	from_pathr rJr
r
rr�s
zDevicePathHypothesis.lookupN)r"r#r$r%r&rrr
r
r
rrM�s
	rMc@s4eZdZdZedd��Zedd��Zedd��ZdS)	�DeviceNameHypothesiszf
    Discover the device assuming the input is a device name.

    Try every available subsystem.
    cs<|j�d}�fdd�|D�}dd�|D�}tdd�|D��S)z�
        Find all subsystems in sysfs.

        :param Context context: the context
        :rtype: frozenset
        :returns: subsystems in sysfs
        )�bus�class�	subsystemc3s�|]
}tj��|�VqdSr?�r.r:r;)rA�name�r8r
rrD���z7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>css �|]}tj�|�r|VqdSr?)r.r:�isdir�rA�dr
r
rrD���css$�|]
}t�|�D]}|Vq	qdSr?)r.r9)rAr\�nr
r
rrD�s�")r8r )rr�dirnames�absnames�	realnamesr
rXrr<�s
	z$DeviceNameHypothesis.find_subsystemscCrN)z�
        Match ``value`` under the assumption that it is a device name.

        :returns: the device path or None
        :rtype: str or NoneType
        r
rr
r
rr�rOzDeviceNameHypothesis.matchcr=)rPc3r>r?r
r@rCr
rrDrEz.DeviceNameHypothesis.lookup.<locals>.<genexpr>csrFr?r
rGr
r
rrDrE)rr�	from_namer<r rJr
rCrrrLzDeviceNameHypothesis.lookupN)r"r#r$r%r&r<rrr
r
r
rrR�s

	rRc@sHeZdZdZgd�Zedd��Zedd��Zedd��Zed	d
��Z	dS)�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/vgcCs:|��}dd�|D�}dd�|D�}ttdd�|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
        css�|]
}t|j�r|VqdSr?)�list�device_linksr[r
r
rrD*rYz5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>css �|]}|jD]}|VqqdSr?)re)rAr\�lr
r
rrD+r]css�|]	}tj�|�VqdSr?)r.r:�dirname)rArfr
r
rrD,rE)�list_devices�sorted�set)rr�devices�devices_with_links�linksr
r
r�
get_link_dirssz"DeviceFileHypothesis.get_link_dirscCs|�|�|_dS)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)rn�
_LINK_DIRSrr
r
rr.s	zDeviceFileHypothesis.setupcCrNr?r
rr
r
rr9szDeviceFileHypothesis.matchcsnttj��d�vr����}|durt|f�St�S�fdd�|jD�}��fdd�|D�}tdd�|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.
        �/Nc3s�|]
}tj�|��VqdSr?rV)rA�ld)rr
rrDPrYz.DeviceFileHypothesis.lookup.<locals>.<genexpr>c3s�|]}��|�VqdSr?r
)rA�f)rrr
rrDQs�csrFr?r
r[r
r
rrDRrE)rr�from_device_filer ro)rrr�device�filesrkr
rCrr=s

zDeviceFileHypothesis.lookupN)
r"r#r$r%ror&rnrrrr
r
r
rrcs



rcc@s4eZdZdZeeeegZdd�Z	dd�Z
dd�ZdS)	�	Discoveryz1
    Provides discovery methods for devices.
    cCs|j|_dSr?)�_HYPOTHESES�_hypotheses)�selfr
r
r�__init__`szDiscovery.__init__cCs|jD]}|�|�qdS)z
        Set up individual hypotheses.

        May be an expensive call.

        :param Context context: the context
        N)rxr)ryr�hypr
r
rrcs
�zDiscovery.setupcst��fdd�|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`
        c3s&�|]}|����D]}|Vq
qdSr?)r!)rA�hr\�rrr
rrDws���z(Discovery.get_devices.<locals>.<genexpr>)r rx)ryrrr
r}rr!ns	�zDiscovery.get_devicesN)r"r#r$r%rcrRr)rMrwrzrr!r
r
r
rrvUs�rv)r%�
__future__rrrrr'rr.r,�six�pyudev._errorsr�
pyudev.devicerr�
add_metaclass�ABCMeta�objectrr)rMrRrcrvr
r
r
r�<module>s(	
=G/F

Zerion Mini Shell 1.0