%PDF- %PDF-
Direktori : /lib/python3/dist-packages/pyudev/device/__pycache__/ |
Current File : //lib/python3/dist-packages/pyudev/device/__pycache__/_device.cpython-312.pyc |
� 9*�b � � � � d Z ddlZddlZddlZddlZddlmZ ddlmZm Z m Z mZmZm Z mZ ddlmZmZmZmZmZ G d� de� Z G d� d ej. j0 � Z G d � dej. j0 � Z G d� d e� Z G d� dej. j8 ej. j: � Zy)z� pyudev.device._device ===================== Device class implementation of :mod:`pyudev`. .. moduleauthor:: Sebastian Wiesner <lunaryorn@gmail.com> � N)� timedelta)�DeviceNotFoundAtPathError�DeviceNotFoundByFileError�#DeviceNotFoundByInterfaceIndexError�!DeviceNotFoundByKernelDeviceError�DeviceNotFoundByNameError�DeviceNotFoundByNumberError� DeviceNotFoundInEnvironmentError)�ensure_byte_string�ensure_unicode_string�get_device_type�string_to_bool�udev_list_iteratec � � e Zd ZdZed� � Zed� � Zed� � Zed� � Zed� � Z ed� � Z ed� � Zed � � Zed � � Z y)�DeviceszT Class for constructing :class:`Device` objects from various kinds of data. c �� � |j |j � sGt j j |j |j t j � � }| j ||� S )a� Create a device from a device ``path``. The ``path`` may or may not start with the ``sysfs`` mount point: >>> from pyudev import Context, Device >>> context = Context() >>> Devices.from_path(context, '/devices/platform') Device(u'/sys/devices/platform') >>> Devices.from_path(context, '/sys/devices/platform') Device(u'/sys/devices/platform') ``context`` is the :class:`Context` in which to search the device. ``path`` is a device path as unicode or byte string. Return a :class:`Device` object for the device. Raise :exc:`DeviceNotFoundAtPathError`, if no device was found for ``path``. .. versionadded:: 0.18 )� startswith�sys_path�os�path�join�lstrip�sep� from_sys_path)�cls�contextr s �7/usr/lib/python3/dist-packages/pyudev/device/_device.py� from_pathzDevices.from_path; sP � �* ���w�/�/�0��7�7�<�<�� 0� 0�$�+�+�b�f�f�2E�F�D�� � ��$�/�/� c �~ � |j j |t |� � }|st |� �t ||� S )a� Create a new device from a given ``sys_path``: >>> from pyudev import Context, Device >>> context = Context() >>> Devices.from_sys_path(context, '/sys/devices/platform') Device(u'/sys/devices/platform') ``context`` is the :class:`Context` in which to search the device. ``sys_path`` is a unicode or byte string containing the path of the device inside ``sysfs`` with the mount point included. Return a :class:`Device` object for the device. Raise :exc:`DeviceNotFoundAtPathError`, if no device was found for ``sys_path``. .. versionadded:: 0.18 )�_libudev�udev_device_new_from_syspathr r �Device)r r r �devices r r zDevices.from_sys_pathT sB � �( �!�!�>�>��'��1� �� �+�H�5�5��g�v�&�&r c � � |j dd� }|j j |t |� t |� � }|st ||� �t ||� S )a. Create a new device from a given ``subsystem`` and a given ``sys_name``: >>> from pyudev import Context, Device >>> context = Context() >>> sda = Devices.from_name(context, 'block', 'sda') >>> sda Device(u'/sys/devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda') >>> sda == Devices.from_path(context, '/block/sda') ``context`` is the :class:`Context` in which to search the device. ``subsystem`` and ``sys_name`` are byte or unicode strings, which denote the subsystem and the name of the device to create. Return a :class:`Device` object for the device. Raise :exc:`DeviceNotFoundByNameError`, if no device was found with the given name. .. versionadded:: 0.18 �/�!)�replacer! �&udev_device_new_from_subsystem_sysnamer r r# )r r � subsystem�sys_namer$ s r � from_namezDevices.from_nameo s^ � �. �#�#�C��-���!�!�H�H��'� �2�4F�x�4P� �� �+�I�x�@�@��g�v�&�&r c � � |j j |t |d � |� }|st ||� �t ||� S )a� Create a new device from a device ``number`` with the given device ``type``: >>> import os >>> from pyudev import Context, Device >>> ctx = Context() >>> major, minor = 8, 0 >>> device = Devices.from_device_number(context, 'block', ... os.makedev(major, minor)) >>> device Device(u'/sys/devices/pci0000:00/0000:00:11.0/host0/target0:0:0/0:0:0:0/block/sda') >>> os.major(device.device_number), os.minor(device.device_number) (8, 0) Use :func:`os.makedev` to construct a device number from a major and a minor device number, as shown in the example above. .. warning:: Device numbers are not unique across different device types. Passing a correct number with a wrong type may silently yield a wrong device object, so make sure to pass the correct device type. ``context`` is the :class:`Context`, in which to search the device. ``type`` is either ``'char'`` or ``'block'``, according to whether the device is a character or block device. ``number`` is the device number as integer. Return a :class:`Device` object for the device with the given device ``number``. Raise :exc:`DeviceNotFoundByNumberError`, if no device was found with the given device type and number. .. versionadded:: 0.18 r )r! �udev_device_new_from_devnumr r r# )r r �typ�numberr$ s r �from_device_numberzDevices.from_device_number� sK � �J �!�!�=�=��'��A��/�� �� �-�c�6�:�:��g�v�&�&r c �� � t |� }t j |� j }| j |||� S # t t f$ r}t |� �d}~ww xY w)a� Create a new device from the given device file: >>> from pyudev import Context, Device >>> context = Context() >>> device = Devices.from_device_file(context, '/dev/sda') >>> device Device(u'/sys/devices/pci0000:00/0000:00:0d.0/host2/target2:0:0/2:0:0:0/block/sda') >>> device.device_node u'/dev/sda' .. warning:: Though the example seems to suggest that ``device.device_node == filename`` holds with ``device = Devices.from_device_file(context, filename)``, this is only true in a majority of cases. There *can* be devices, for which this relation is actually false! Thus, do *not* expect :attr:`~Device.device_node` to be equal to the given ``filename`` for the returned :class:`Device`. Especially, use :attr:`~Device.device_node` if you need the device file of a :class:`Device` created with this method afterwards. ``context`` is the :class:`Context` in which to search the device. ``filename`` is a string containing the path of a device file. Return a :class:`Device` representing the given device file. Raise :exc:`DeviceNotFoundByFileError` if ``filename`` is no device file at all or if ``filename`` does not exist or if its metadata was inaccessible. .. versionadded:: 0.18 N)r r �stat�st_rdev�EnvironmentError� ValueErrorr r1 )r r �filename�device_type� device_number�errs r �from_device_filezDevices.from_device_file� s_ � �D 1�)�(�3�K��G�G�H�-�5�5�M� �%�%�g�{�M�J�J�� !�*�-� 1�+�C�0�0�� 1�s �*? �A�A�Ac �p �� |j d�� }t �fd�|D � d� }|�|S t �� �)a? Locate a device based on the interface index. :param `Context` context: the libudev context :param int ifindex: the interface index :returns: the device corresponding to the interface index :rtype: `Device` This method is only appropriate for network devices. �net)r* c 3 �` �K � | ]% }|j j d � �k( s�"|�� �' y�w)�ifindexN)� attributes�get)�.0�dr? s �r � <genexpr>z/Devices.from_interface_index.<locals>.<genexpr>� s'