%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /snap/core/17212/usr/lib/python3/dist-packages/pyudev/__pycache__/
Upload File :
Create Path :
Current File : //snap/core/17212/usr/lib/python3/dist-packages/pyudev/__pycache__/device.cpython-35.pyc



��P|��@sydZddlmZmZmZmZddlZddlmZm	Z	m
Z
ddlmZddl
mZddlmZmZmZmZmZdd	d
ddd
ddgZGdd�de�ZGdd�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd
�d
e
e	�Zdd�ZGdd	�d	e�ZdS)z�
    pyudev.device
    =============

    Device class implementation of :mod:`pyudev`.

    .. moduleauthor::  Sebastian Wiesner  <lunaryorn@gmail.com>
�)�print_function�division�unicode_literals�absolute_importN)�Mapping�	Container�Iterable)�	timedelta)�libudev)�ensure_byte_string�ensure_unicode_string�udev_list_iterate�string_to_bool�get_device_type�Device�
Attributes�Tags�DeviceNotFoundError�DeviceNotFoundAtPathError�DeviceNotFoundByNameError�DeviceNotFoundByNumberError� DeviceNotFoundInEnvironmentErrorc@seZdZdZdS)rz�
    An exception indicating that no :class:`Device` was found.

    .. versionchanged:: 0.5
       Rename from ``NoSuchDeviceError`` to its current name.
    N)�__name__�
__module__�__qualname__�__doc__�rr�//usr/lib/python3/dist-packages/pyudev/device.pyr/sc@s@eZdZdZdd�Zedd��Zdd�ZdS)	rzh
    A :exc:`DeviceNotFoundError` indicating that no :class:`Device` was
    found at a given path.
    cCstj||�dS)N)r�__init__)�self�sys_pathrrrr>sz"DeviceNotFoundAtPathError.__init__cCs|jdS)z<
        The path that caused this error as string.
        r)�args)rrrrr Asz"DeviceNotFoundAtPathError.sys_pathcCsdj|j�S)NzNo device at {0!r})�formatr )rrrr�__str__Hsz!DeviceNotFoundAtPathError.__str__N)rrrrr�propertyr r#rrrrr8sc@sReZdZdZdd�Zedd��Zedd��Zdd	�Zd
S)rzj
    A :exc:`DeviceNotFoundError` indicating that no :class:`Device` was
    found with a given name.
    cCstj|||�dS)N)rr)r�	subsystem�sys_namerrrrRsz"DeviceNotFoundByNameError.__init__cCs|jdS)zA
        The subsystem that caused this error as string.
        r)r!)rrrrr%Usz#DeviceNotFoundByNameError.subsystemcCs|jdS)z@
        The sys name that caused this error as string.
        �)r!)rrrrr&\sz"DeviceNotFoundByNameError.sys_namecCs
dj|�S)Nz+No device {0.sys_name!r} in {0.subsystem!r})r")rrrrr#csz!DeviceNotFoundByNameError.__str__N)	rrrrrr$r%r&r#rrrrrLs
c@sReZdZdZdd�Zedd��Zedd��Zdd	�Zd
S)rzs
    A :exc:`DeviceNotFoundError` indicating, that no :class:`Device` was found
    for a given device number.
    cCstj|||�dS)N)rr)r�type�numberrrrrmsz$DeviceNotFoundByNumberError.__init__cCs|jdS)zj
        The device type causing this error as string.  Either ``'char'`` or
        ``'block'``.
        r)r!)rrrr�device_typepsz'DeviceNotFoundByNumberError.device_typecCs|jdS)zB
        The device number causing this error as integer.
        r')r!)rrrr�
device_numberxsz)DeviceNotFoundByNumberError.device_numbercCs
dj|�S)Nz7No {0.device_type} device with number {0.device_number})r")rrrrr#sz#DeviceNotFoundByNumberError.__str__N)	rrrrrr$r*r+r#rrrrrgs
c@s"eZdZdZdd�ZdS)rz�
    A :exc:`DeviceNotFoundError` indicating, that no :class:`Device` could
    be constructed from the process environment.
    cCsdS)NzNo device found in environmentr)rrrrr#�sz(DeviceNotFoundInEnvironmentError.__str__N)rrrrr#rrrrr�sc@s�eZdZdZedd��Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
dd�Zdd�Zdd�Z
edd��Zedd��Zedd��Zddd�Zdd�Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��Zed1d2��Zed3d4��Zed5d6��Zed7d8��Z ed9d:��Z!ed;d<��Z"ed=d>��Z#d?d@�Z$dAdB�Z%dCdD�Z&dEdF�Z'dGdH�Z(dIdJ�Z)dKdL�Z*dMdN�Z+dOdP�Z,dQdR�Z-dSdT�Z.dUdV�Z/dS)Wra�
    A single device with attached attributes and properties.

    This class subclasses the ``Mapping`` ABC, providing a read-only
    dictionary mapping property names to the corresponding values.
    Therefore all well-known dicitionary methods and operators
    (e.g. ``.keys()``, ``.items()``, ``in``) are available to access device
    properties.

    Aside of the properties, a device also has a set of udev-specific
    attributes like the path inside ``sysfs``.

    :class:`Device` objects compare equal and unequal to other devices and
    to strings (based on :attr:`device_path`).  However, there is no
    ordering on :class:`Device` objects, and the corresponding operators
    ``>``, ``<``, ``<=`` and ``>=`` raise :exc:`~exceptions.TypeError`.

    .. warning::

       Do **never** use object identity (``is`` operator) to compare
       :class:`Device` objects.  :mod:`pyudev` may create multiple
       :class:`Device` objects for the same device.  Instead simply compare
       devices by value using ``==`` or ``!=``.

    :class:`Device` objects are hashable and can therefore be used as keys
    in dictionaries and sets.

    They can also be given directly as ``udev_device *`` to functions wrapped
    through :mod:`ctypes`.
    cCsF|j|j�s6tjj|j|jtj��}|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()
        >>> Device.from_path(context, '/devices/platform')
        Device(u'/sys/devices/platform')
        >>> Device.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.4
        )�
startswithr �os�path�join�lstrip�sep�
from_sys_path)�cls�contextr.rrr�	from_path�s$zDevice.from_pathcCs7tj|t|��}|s*t|��|||�S)a�
        Create a new device from a given ``sys_path``:

        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> Device.from_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``.

        .. versionchanged:: 0.4
           Raise :exc:`NoSuchDeviceError` instead of returning ``None``, if
           no device was found for ``sys_path``.
        .. versionchanged:: 0.5
           Raise :exc:`DeviceNotFoundAtPathError` instead of
           :exc:`NoSuchDeviceError`.
        )r
Zudev_device_new_from_syspathrr)r3r4r �devicerrrr2�s
zDevice.from_sys_pathcCsCtj|t|�t|��}|s6t||��|||�S)a+
        Create a new device from a given ``subsystem`` and a given
        ``sys_name``:

        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> sda = Device.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 == Device.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.5
        )r
Z&udev_device_new_from_subsystem_sysnamerr)r3r4r%r&r6rrr�	from_name�szDevice.from_namecCsb|dkr!tdj|���tj|t|d�|�}|sUt||��|||�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 = Device.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.  Raise
        :exc:`~exceptions.ValueError`, if ``type`` is any other string than
        ``'char'`` or ``'block'``.

        .. versionadded:: 0.11
        �char�blockz6Invalid type: {0!r}. Must be one of "char" or "block".r)zcharzblock)�
ValueErrorr"r
Zudev_device_new_from_devnumrr)r3r4r(r)r6rrr�from_device_numbers'	zDevice.from_device_numbercCs1t|�}tj|�j}|j|||�S)a�
        Create a new device from the given device file:

        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> device = Device.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 = Device.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:`~exceptions.ValueError` if ``filename`` is no device file at all.
        Raise :exc:`~exceptions.EnvironmentError` if ``filename`` does not
        exist or if its metadata was inaccessible.

        .. versionadded:: 0.15
        )rr-�stat�st_rdevr;)r3r4�filenamer*r+rrr�from_device_file4s"zDevice.from_device_filecCs+tj|�}|st��|||�S)a�
        Create a new device from the process environment (as in
        :data:`os.environ`).

        This only works reliable, if the current process is called from an
        udev rule, and is usually used for tools executed from ``IMPORT=``
        rules.  Use this method to create device objects in Python scripts
        called from udev rules.

        ``context`` is the library :class:`Context`.

        Return a :class:`Device` object constructed from the environment.
        Raise :exc:`DeviceNotFoundInEnvironmentError`, if no device could be
        created from the environment.

        .. udevversion:: 152

        .. versionadded:: 0.6
        )r
Z udev_device_new_from_environmentr)r3r4r6rrr�from_environmentZs	zDevice.from_environmentcCs||_||_dS)N)r4Z_as_parameter_)rr4Z_devicerrrrts	zDevice.__init__cCstj|�dS)N)r
Zudev_device_unref)rrrr�__del__xszDevice.__del__cCs
dj|�S)NzDevice({0.sys_path!r}))r")rrrr�__repr__{szDevice.__repr__cCs2tj|�}|sdSt|jtj|��S)z_
        The parent :class:`Device` or ``None``, if there is no parent
        device.
        N)r
Zudev_device_get_parentrr4�udev_device_ref)r�parentrrrrD~sz
Device.parentccs8x1|jj�j|�D]}||kr|VqWdS)a�
        Yield all direct children of this device.

        .. note::

           In udev, parent-child relationships are generally ambiguous, i.e.
           a parent can have multiple children, *and* a child can have multiple
           parents. Hence, `child.parent == parent` does generally *not* hold
           for all `child` objects in `parent.children`. In other words,
           the :attr:`parent` of a device in this property can be different
           from this device!

        .. note::

           As the underlying library does not provide any means to directly
           query the children of a device, this property performs a linear
           search through all devices.

        Return an iterable yielding a :class:`Device` object for each direct
        child of this device.

        .. udevversion:: 172

        .. versionchanged:: 0.13
           Requires udev version 172 now.
        N)r4Zlist_devicesZmatch_parent)rr6rrr�children�szDevice.childrenccs(|j}x|r#|V|j}qWdS)z�
        Yield all ancestors of this device from bottom to top.

        Return an iterator yielding a :class:`Device` object for each
        ancestor of this device from bottom to top.

        .. versionadded:: 0.16
        N)rD)rrDrrr�	ancestors�s
		zDevice.ancestorsNcCs\t|�}|dk	r$t|�}tj|||�}|sCdSt|jtj|��S)u�
        Find the parent device with the given ``subsystem`` and
        ``device_type``.

        ``subsystem`` is a byte or unicode string containing the name of the
        subsystem, in which to search for the parent.  ``device_type`` is a
        byte or unicode string holding the expected device type of the parent.
        It can be ``None`` (the default), which means, that no specific device
        type is expected.

        Return a parent :class:`Device` within the given ``subsystem`` and – if
        ``device_type`` is not ``None`` – with the given ``device_type``, or
        ``None``, if this device has no parent device matching these
        constraints.

        .. versionadded:: 0.9
        N)rr
Z-udev_device_get_parent_with_subsystem_devtyperr4rC)rr%r*rDrrr�find_parent�szDevice.find_parentcCs#ddl}|jdt�|jS)a~
        Traverse all parent devices of this device from bottom to top.

        Return an iterable yielding all parent devices as :class:`Device`
        objects, *not* including the current device.  The last yielded
        :class:`Device` is the top of the device hierarchy.

        .. deprecated:: 0.16
           Will be removed in 1.0. Use :attr:`ancestors` instead.
        rNz5Will be removed in 1.0. Use Device.ancestors instead.)�warnings�warn�DeprecationWarningrF)rrHrrr�traverse�s	zDevice.traversecCsttj|��S)zz
        Absolute path of this device in ``sysfs`` including the ``sysfs``
        mount point as unicode string.
        )rr
Zudev_device_get_syspath)rrrrr �szDevice.sys_pathcCsttj|��S)a
        Kernel device path as unicode string.  This path uniquely identifies
        a single device.

        Unlike :attr:`sys_path`, this path does not contain the ``sysfs``
        mount point.  However, the path is absolute and starts with a slash
        ``'/'``.
        )rr
Zudev_device_get_devpath)rrrr�device_path�s
zDevice.device_pathcCsttj|��S)zQ
        Name of the subsystem this device is part of as unicode string.
        )rr
Zudev_device_get_subsystem)rrrrr%�szDevice.subsystemcCsttj|��S)zF
        Device file name inside ``sysfs`` as unicode string.
        )rr
Zudev_device_get_sysname)rrrrr&szDevice.sys_namecCs)tj|�}|dk	r%t|�SdS)a�
        The trailing number of the :attr:`sys_name` as unicode string, or
        ``None``, if the device has no trailing number in its name.

        .. note::

           The number is returned as unicode string to preserve the exact
           format of the number, especially any leading zeros:

           >>> from pyudev import Context, Device
           >>> context = Context()
           >>> device = Device.from_path(context, '/sys/devices/LNXSYSTM:00')
           >>> device.sys_number
           u'00'

           To work with numbers, explicitly convert them to ints:

           >>> int(device.sys_number)
           0

        .. versionadded:: 0.11
        N)r
Zudev_device_get_sysnumr)rr)rrr�
sys_numberszDevice.sys_numbercCs)tj|�}|dk	r%t|�SdS)a�
        Device type as unicode string, or ``None``, if the device type is
        unknown.

        >>> from pyudev import Context
        >>> context = Context()
        >>> for device in context.list_devices(subsystem='net'):
        ...     '{0} - {1}'.format(device.sys_name, device.device_type or 'ethernet')
        ...
        u'eth0 - ethernet'
        u'wlan0 - wlan'
        u'lo - ethernet'
        u'vboxnet0 - ethernet'

        .. versionadded:: 0.10
        N)r
Zudev_device_get_devtyper)rr*rrrr*$szDevice.device_typecCs#tj|�}|rt|�SdS)z�
        The driver name as unicode string, or ``None``, if there is no
        driver for this device.

        .. versionadded:: 0.5
        N)r
Zudev_device_get_driverr)r�driverrrrrN:sz
Device.drivercCs#tj|�}|rt|�SdS)a�
        Absolute path to the device node of this device as unicode string or
        ``None``, if this device doesn't have a device node.  The path
        includes the device directory (see :attr:`Context.device_path`).

        This path always points to the actual device node associated with
        this device, and never to any symbolic links to this device node.
        See :attr:`device_links` to get a list of symbolic links to this
        device node.

        .. warning::

           For devices created with :meth:`from_device_file()`, the value of
           this property is not necessary equal to the ``filename`` given to
           :meth:`from_device_file()`.
        N)r
Zudev_device_get_devnoder)rZnoderrr�device_nodeFszDevice.device_nodecCs
tj|�S)a
        The device number of the associated device as integer, or ``0``, if no
        device number is associated.

        Use :func:`os.major` and :func:`os.minor` to decompose the device
        number into its major and minor number:

        >>> import os
        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> sda = Device.from_name(context, 'block', 'sda')
        >>> sda.device_number
        2048L
        >>> (os.major(sda.device_number), os.minor(sda.device_number))
        (8, 0)

        For devices with an associated :attr:`device_node`, this is the same as
        the ``st_rdev`` field of the stat result of the :attr:`device_node`:

        >>> os.stat(sda.device_node).st_rdev
        2048

        .. versionadded:: 0.11
        )r
Zudev_device_get_devnum)rrrrr+\szDevice.device_numbercCsttj|��S)ai
        ``True``, if the device is initialized, ``False`` otherwise.

        A device is initialized, if udev has already handled this device and
        has set up device node permissions and context, or renamed a network
        device.

        Consequently, this property is only implemented for devices with a
        device node or for network devices.  On all other devices this property
        is always ``True``.

        It is *not* recommended, that you use uninitialized devices.

        .. seealso:: :attr:`time_since_initialized`

        .. udevversion:: 165

        .. versionadded:: 0.8
        )�boolr
Zudev_device_get_is_initialized)rrrr�is_initializedxszDevice.is_initializedcCstj|�}td|�S)a�
        The time elapsed since initialization as :class:`~datetime.timedelta`.

        This property is only implemented on devices, which need to store
        properties in the udev database.  On all other devices this property is
        simply zero :class:`~datetime.timedelta`.

        .. seealso:: :attr:`is_initialized`

        .. udevversion:: 165

        .. versionadded:: 0.8
        �microseconds)r
Z&udev_device_get_usec_since_initializedr	)rrRrrr�time_since_initialized�szDevice.time_since_initializedccs;tj|�}x%t|�D]\}}t|�VqWdS)a�
        An iterator, which yields the absolute paths (including the device
        directory, see :attr:`Context.device_path`) of all symbolic links
        pointing to the :attr:`device_node` of this device.  The paths are
        unicode strings.

        UDev can create symlinks to the original device node (see
        :attr:`device_node`) inside the device directory.  This is often
        used to assign a constant, fixed device node to devices like
        removeable media, which technically do not have a constant device
        node, or to map a single device into multiple device hierarchies.
        The property provides access to all such symbolic links, which were
        created by UDev for this device.

        .. warning::

           Links are not necessarily resolved by
           :meth:`Device.from_device_file()`. Hence do *not* rely on
           ``Device.from_device_file(context, link).device_path ==
           device.device_path`` from any ``link`` in ``device.device_links``.
        N)r
Z#udev_device_get_devlinks_list_entryr
r)rZdevlinks�name�_rrr�device_links�szDevice.device_linkscCs#tj|�}|rt|�SdS)a
        The device event action as string, or ``None``, if this device was not
        received from a :class:`Monitor`.

        Usual actions are:

        ``'add'``
          A device has been added (e.g. a USB device was plugged in)
        ``'remove'``
          A device has been removed (e.g. a USB device was unplugged)
        ``'change'``
          Something about the device changed (e.g. a device property)
        ``'online'``
          The device is online now
        ``'offline'``
          The device is offline now

        .. warning::

           Though the actions listed above are the most common, this property
           *may* return other values, too, so be prepared to handle unknown
           actions!

        .. versionadded:: 0.16
        N)r
Zudev_device_get_actionr)r�actionrrrrW�sz
Device.actioncCs
tj|�S)z�
        The device event sequence number as integer, or ``0`` if this device
        has no sequence number, i.e. was not received from a :class:`Monitor`.

        .. versionadded:: 0.16
        )r
Zudev_device_get_seqnum)rrrr�sequence_number�szDevice.sequence_numbercCs
t|�S)aT
        The system attributes of this device as read-only
        :class:`Attributes` mapping.

        System attributes are basically normal files inside the the device
        directory.  These files contain all sorts of information about the
        device, which may not be reflected by properties.  These attributes
        are commonly used for matching in udev rules, and can be printed
        using ``udevadm info --attribute-walk``.

        The values of these attributes are not always proper strings, and
        can contain arbitrary bytes.

        .. versionadded:: 0.5
        )r)rrrr�
attributes�szDevice.attributescCs
t|�S)a�
        A :class:`Tags` object representing the tags attached to this device.

        The :class:`Tags` object supports a test for a single tag as well as
        iteration over all tags:

        >>> from pyudev import Context, Device
        >>> context = Context()
        >>> device = next(iter(context.list_devices(tag='systemd')))
        >>> 'systemd' in device.tags
        True
        >>> list(device.tags)
        [u'seat', u'systemd', u'uaccess']

        Tags are arbitrary classifiers that can be attached to devices by udev
        scripts and daemons.  For instance, systemd_ uses tags for multi-seat_
        support.

        .. _systemd: http://freedesktop.org/wiki/Software/systemd
        .. _multi-seat: http://www.freedesktop.org/wiki/Software/systemd/multiseat

        .. udevversion:: 154

        .. versionadded:: 0.6

        .. versionchanged:: 0.13
           Return a :class:`Tags` object now.
        )r)rrrr�tags�szDevice.tagsccs;tj|�}x%t|�D]\}}t|�VqWdS)z�
        Iterate over the names of all properties defined for this device.

        Return a generator yielding the names of all properties of this
        device as unicode strings.
        N)r
�%udev_device_get_properties_list_entryr
r)r�
propertiesrTrUrrr�__iter__szDevice.__iter__cCsBtj|�}d}x&tt|�dd�D]\}}q.W|S)zU
        Return the amount of properties defined for this device as integer.
        r�startr')r
r[�	enumerater
)rr\�irUrrr�__len__'s
%zDevice.__len__cCs:tj|t|��}|dkr0t|��t|�S)aA
        Get the given ``property`` from this device.

        ``property`` is a unicode or byte string containing the name of the
        property.

        Return the property value as unicode string, or raise a
        :exc:`~exceptions.KeyError`, if the given property is not defined
        for this device.
        N)r
Zudev_device_get_property_valuer�KeyErrorr)rr$�valuerrr�__getitem__1s
zDevice.__getitem__cCst||�S)a�
        Get the given ``property`` from this device as integer.

        ``property`` is a unicode or byte string containing the name of the
        property.

        Return the property value as integer. Raise a
        :exc:`~exceptions.KeyError`, if the given property is not defined
        for this device, or a :exc:`~exceptions.ValueError`, if the property
        value cannot be converted to an integer.
        )�int)rr$rrr�asintBszDevice.asintcCst||�S)a�
        Get the given ``property`` from this device as boolean.

        A boolean property has either a value of ``'1'`` or of ``'0'``,
        where ``'1'`` stands for ``True``, and ``'0'`` for ``False``.  Any
        other value causes a :exc:`~exceptions.ValueError` to be raised.

        ``property`` is a unicode or byte string containing the name of the
        property.

        Return ``True``, if the property value is ``'1'`` and ``False``, if
        the property value is ``'0'``.  Any other value raises a
        :exc:`~exceptions.ValueError`.  Raise a :exc:`~exceptions.KeyError`,
        if the given property is not defined for this device.
        )r)rr$rrr�asboolPsz
Device.asboolcCs
t|j�S)N)�hashrL)rrrr�__hash__bszDevice.__hash__cCs0t|t�r|j|jkS|j|kSdS)N)�
isinstancerrL)r�otherrrr�__eq__esz
Device.__eq__cCs0t|t�r|j|jkS|j|kSdS)N)rjrrL)rrkrrr�__ne__ksz
Device.__ne__cCstd��dS)NzDevice not orderable)�	TypeError)rrkrrr�__gt__qsz
Device.__gt__cCstd��dS)NzDevice not orderable)rn)rrkrrr�__lt__tsz
Device.__lt__cCstd��dS)NzDevice not orderable)rn)rrkrrr�__le__wsz
Device.__le__cCstd��dS)NzDevice not orderable)rn)rrkrrr�__ge__zsz
Device.__ge__)0rrrr�classmethodr5r2r7r;r?r@rrArBr$rDrErFrGrKr rLr%r&rMr*rNrOr+rQrSrVrWrXrYrZr]rardrfrgrirlrmrorprqrrrrrrr�sV0&
 
 
c@sdeZdZdZdd�Zeed�r<dd�Zndd�Zdd	�Zd
d�Z	dS)
rzk
    A iterable over :class:`Device` tags.

    Subclasses the ``Container`` and the ``Iterable`` ABC.
    cCs
||_dS)N)r6)rr6rrrr�sz
Tags.__init__�udev_device_has_tagcCsttj|jt|���S)N)rPr
rtr6r)r�tagrrr�_has_tag�s	z
Tags._has_tagcst�fdd�|D��S)Nc3s|]}|�kVqdS)Nr)�.0�t)rurr�	<genexpr>�sz Tags._has_tag.<locals>.<genexpr>)�any)rrur)rurrv�scCs
|j|�S)z�
        Check for existence of ``tag``.

        ``tag`` is a tag as unicode string.

        Return ``True``, if ``tag`` is attached to the device, ``False``
        otherwise.
        )rv)rrurrr�__contains__�s	zTags.__contains__ccs>tj|j�}x%t|�D]\}}t|�VqWdS)zS
        Iterate over all tags.

        Yield each tag as unicode string.
        N)r
Zudev_device_get_tags_list_entryr6r
r)rrZrurUrrrr]�sz
Tags.__iter__N)
rrrrr�hasattrr
rvr{r]rrrrr~scCs>tjj|�}|jd�p<|dkp<tjj|�S)ay
    Check, if ``filepath`` points to a valid udev attribute filename.

    Implementation is stolen from udev source code, ``print_all_attributes``
    in ``udev/udevadm-info.c``.  It excludes hidden files (starting with a
    dot), the special files ``dev`` and ``uevent`` and links.

    Return ``True``, if ``filepath`` refers to an attribute, ``False``
    otherwise.
    �.�dev�uevent)r~r)r-r.�basenamer,�islink)�filepathr>rrr�_is_attribute_file�sr�c@s�eZdZdZdd�Zeed�rBedd��Znedd��Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�ZdS)ra�
    A mapping which holds udev attributes for :class:`Device` objects.

    This class subclasses the ``Mapping`` ABC, providing a read-only
    dictionary mapping attribute names to the corresponding values.
    Therefore all well-known dicitionary methods and operators
    (e.g. ``.keys()``, ``.items()``, ``in``) are available to access device
    attributes.

    .. versionadded:: 0.5
    cCs
||_dS)N)r6)rr6rrrr�szAttributes.__init__�"udev_device_get_sysattr_list_entryccs>tj|j�}x%t|�D]\}}t|�VqWdS)N)r
r�r6r
r)rZattrs�	attributerUrrr�_attributes�szAttributes._attributescs/�jj���fdd�tj��D�S)Nc3s<|]2}ttjj�|��r|�kr|VqdS)N)r�r-r.r/)rw�fn)rr rrry�sz)Attributes._attributes.<locals>.<genexpr>)r6r r-�listdir)rr)rr rr��scCs0d}x#t|jdd�D]\}}qW|S)z:
        Return the amount of attributes defined.
        rr^r')r_r�)rr`rUrrrra�s"zAttributes.__len__cCs|jS)zl
        Iterate over all attributes defined.

        Yield each attribute name as unicode string.
        )r�)rrrrr]�szAttributes.__iter__cCs%tj|jt|��}|dk	S)N)r
�udev_device_get_sysattr_valuer6r)rr�rcrrrr{�szAttributes.__contains__cCs7tj|jt|��}|dkr3t|��|S)aO
        Get the given system ``attribute`` for the device.

        ``attribute`` is a unicode or byte string containing the name of the
        system attribute.

        Return the attribute value as byte string, or raise a
        :exc:`~exceptions.KeyError`, if the given attribute is not defined
        for this device.
        N)r
r�r6rrb)rr�rcrrrrd�s
zAttributes.__getitem__cCst||�S)a]
        Get the given ``atribute`` for the device as unicode string.

        Depending on the content of the attribute, this may or may not work.
        Be prepared to catch :exc:`~exceptions.UnicodeDecodeError`.

        ``attribute`` is a unicode or byte string containing the name of the
        attribute.

        Return the attribute value as byte string.  Raise a
        :exc:`~exceptions.KeyError`, if the given attribute is not defined
        for this device, or :exc:`~exceptions.UnicodeDecodeError`, if the
        content of the attribute cannot be decoded into a unicode string.
        )r)rr�rrr�asstring�szAttributes.asstringcCst|j|��S)a�
        Get the given ``attribute`` as integer.

        ``attribute`` is a unicode or byte string containing the name of the
        attribute.

        Return the attribute value as integer. Raise a
        :exc:`~exceptions.KeyError`, if the given attribute is not defined
        for this device, or a :exc:`~exceptions.ValueError`, if the
        attribute value cannot be converted to an integer.
        )rer�)rr�rrrrf
szAttributes.asintcCst|j|��S)a�
        Get the given ``attribute`` from this device as boolean.

        A boolean attribute has either a value of ``'1'`` or of ``'0'``,
        where ``'1'`` stands for ``True``, and ``'0'`` for ``False``.  Any
        other value causes a :exc:`~exceptions.ValueError` to be raised.

        ``attribute`` is a unicode or byte string containing the name of the
        attribute.

        Return ``True``, if the attribute value is ``'1'`` and ``False``, if
        the attribute value is ``'0'``.  Any other value raises a
        :exc:`~exceptions.ValueError`.  Raise a :exc:`~exceptions.KeyError`,
        if the given attribute is not defined for this device.
        )rr�)rr�rrrrgszAttributes.asboolN)rrrrrr|r
r$r�rar]r{rdr�rfrgrrrrr�s	) rZ
__future__rrrrr-�collectionsrrrZdatetimer	Zpyudev._libudevr
Zpyudev._utilrrr
rr�__all__�LookupErrorrrrrrrrr�rrrrr�<module>s*"(			
���(

Zerion Mini Shell 1.0