%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core20/2379/lib/python3/dist-packages/pyudev/__pycache__/
Upload File :
Create Path :
Current File : //snap/core20/2379/lib/python3/dist-packages/pyudev/__pycache__/discover.cpython-38.pyc

U

u1�W�,�@s�dZddlmZddlmZddlmZddlmZddlZddlZddlZddl	Z	ddl
Z
ddlmZddlm
Z
d	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)�Devices��DeviceNotFoundErrorcst����fdd��}|S)z\
    Allow Device discovery methods to return None instead of raising an
    exception.
    cs(z�||�WStk
r"YdSXdS)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_func1s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.
    cCs
t��dS)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
        N��NotImplementedError��cls�valuer
r
r�matchDszHypothesis.matchcCs
t��dS)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`
        Nr)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$|�|�}|dk	r|�||�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�}|�|�}|o6t�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)rrZmajor_minor_rerr
r
r�_match_major_minor�s	�
�z)DeviceNumberHypothesis._match_major_minorcCs&t�d�}|�|�}|o$t|�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+)$Znumber)r+r,rr/r0)rrZ	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
        )r1r2rr
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
        Zdev)�sys_pathr-�listdir�path�join)rrr3r
r
r�find_subsystems�s	z&DeviceNumberHypothesis.find_subsystemscs8ttj�����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`
        c3s|]}��|��VqdS�Nr
��.0�s�rrrr
r�	<genexpr>�sz0DeviceNumberHypothesis.lookup.<locals>.<genexpr>css|]}|dk	r|VqdSr8r
�r:�rr
r
rr=�s)rrZfrom_device_numberr7r�rrr�resr
r<rr�s

zDeviceNumberHypothesis.lookupN)
r!r"r#r$r%r1r2rr7rr
r
r
rr(|s


	
r(c@s(eZdZdZedd��Zedd��ZdS)�DevicePathHypothesiszG
    Discover the device assuming the identifier is a device path.
    cCs|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�szDevicePathHypothesis.matchcCs(ttj�||�}|dk	r"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`
        N)rrZ	from_pathrr@r
r
rr�s
zDevicePathHypothesis.lookupN)r!r"r#r$r%rrr
r
r
rrB�s

	rBc@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
        )Zbus�classZ	subsystemc3s|]}tj��|�VqdSr8�r-r5r6)r:�name�r3r
rr=�sz7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>css|]}tj�|�r|VqdSr8)r-r5�isdir�r:�dr
r
rr=�scss"|]}t�|�D]
}|VqqdSr8)r-r4)r:rK�nr
r
rr=�s)r3r)rrZdirnamesZabsnamesZ	realnamesr
rHrr7�s
	z$DeviceNameHypothesis.find_subsystemscCs|S)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�szDeviceNameHypothesis.matchcs8ttj�����fdd�|���D�}tdd�|D��S)rCc3s|]}��|��VqdSr8r
r9r<r
rr=sz.DeviceNameHypothesis.lookup.<locals>.<genexpr>css|]}|dk	r|VqdSr8r
r>r
r
rr=s)rr�	from_namer7rr@r
r<rrs

zDeviceNameHypothesis.lookupN)r!r"r#r$r%r7rrr
r
r
rrD�s

	rDc@sZeZdZdZdddddddd	d
ddgZed
d��Zedd��Zedd��Zedd��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|VqdSr8)�list�device_linksrJr
r
rr=5s
z5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>css|]}|jD]
}|VqqdSr8)rP)r:rK�lr
r
rr=6scss|]}tj�|�VqdSr8)r-r5�dirname)r:rQr
r
rr=7s)Zlist_devices�sorted�set)rr�devicesZdevices_with_linksZlinksr
r
r�
get_link_dirs(s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)rV�
_LINK_DIRSrr
r
rr9s	zDeviceFileHypothesis.setupcCs|Sr8r
rr
r
rrDszDeviceFileHypothesis.matchcsrttj��d�kr4����}|dk	r.t|f�St�S�fdd�|jD�}��fdd�|D�}tdd�|D��SdS)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�|��VqdSr8rF)r:Zld)rr
rr=[sz.DeviceFileHypothesis.lookup.<locals>.<genexpr>c3s|]}��|�VqdSr8r
)r:�f)rrr
rr=\scss|]}|dk	r|VqdSr8r
rJr
r
rr=]s)rrZfrom_device_filerrW)rrrZdevice�filesrUr
r<rrHs

zDeviceFileHypothesis.lookupN)
r!r"r#r$rWr%rVrrrr
r
r
rrNs*�



rNc@s4eZdZdZeeeegZdd�Z	dd�Z
dd�ZdS)	�	Discoveryz1
    Provides discovery methods for devices.
    cCs|j|_dSr8)�_HYPOTHESES�_hypotheses)�selfr
r
r�__init__mszDiscovery.__init__cCs|jD]}|�|�qdS)z
        Set up individual hypotheses.

        May be an expensive call.

        :param Context context: the context
        N)r]r)r^rZhypr
r
rrps
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]
}|VqqdSr8)r )r:�hrK�rrr
rr=�sz(Discovery.get_devices.<locals>.<genexpr>)rr])r^rrr
rarr {s	�zDiscovery.get_devicesN)r!r"r#r$rNrDr(rBr\r_rr r
r
r
rr[`s�r[)r$Z
__future__rrrrr&rr-r+ZsixZ
pyudev.devicerrrZ
add_metaclass�ABCMeta�objectrr(rBrDrNr[r
r
r
r�<module>s&	
=K/M

Zerion Mini Shell 1.0