+
     h  c                   s   R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
HtHtHtHt ^ RIHtHtHtHtHt  ! R R4      t ! R R]P,                  P.                  4      t ! R	 R
]P,                  P.                  4      t ! R R4      t ! R R]P,                  P6                  ]P,                  P8                  4      tR# )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                   s   a  ] tR t^6t o Rt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R 4       t]R	 4       t]R
 4       tRtV tR# )DeviceszL
Class for constructing :class:`Device` objects from various kinds of data.
c                s    VP                  VP                  4      '       gH   \        P                  P	                  VP                  VP                  \        P                  4      4      pV P                  W4      # )aj  
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
)Z
startswithsys_pathospathZjoinZlstripZsepfrom_sys_path)clscontextr      &&&:/usr/lib/python3.14/site-packages/pyudev/device/_device.py	from_pathZDevices.from_path;   sQ    * w//0077<< 0 0$++bff2EFD  //    c                s    VP                   P                  V\        V4      4      pV'       g   \        V4      h\	        W4      # )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
)_libudevZudev_device_new_from_syspathr   r   Device)r   r   r   device   &&& r   r   ZDevices.from_sys_pathT   s@    ( !!>>'1
 +H55g&&r   c                s    VP                  RR4      pVP                  P                  V\        V4      \        V4      4      pV'       g   \	        W#4      h\        W4      # )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
Z/Z!)Zreplacer   Z&udev_device_new_from_subsystem_sysnamer   r   r   )r   r   	subsystemsys_namer      &&&& r   	from_nameZDevices.from_nameo   sZ    . ##C-!!HH'	24Fx4P
 +I@@g&&r   c                s    VP                   P                  V\        V^ ,          4      V4      pV'       g   \        W#4      h\	        W4      # )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   Zudev_device_new_from_devnumr   r   r   )r   r   typnumberr   r   r   from_device_numberZDevices.from_device_number   sG    J !!=='A/
 -c::g&&r   c                s     \        V4      p\        P                  ! V4      P                  pT P                  YT4      #   \        \
        3 d   p\        T4      hRp?ii ; i)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   ZstatZst_rdevZEnvironmentErrorZ
ValueErrorr   r"   )r   r   filenamedevice_typedevice_numberZerrs   &&&   r   from_device_fileZDevices.from_device_file   s]    D	1)(3KGGH-55M %%gMJJ !*- 	1+C00	1s   +? A AA c                sv   a VP                  RR7      p\        V3R lV 4       R4      pVe   V# \        S4      h)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.
Znet)r   c              3   sj   <"   T F(  qP                   P                  R 4      S8X  g   K$  Vx  K*  	  R# 5i)ifindexN)
attributesget).0Zdr'      & r   	<genexpr>Z/Devices.from_interface_index.<locals>.<genexpr>   s'     R1<<+;+;I+F'+QQQs   !3
3N)list_devicesZnextr   )r   r   r'   Znetwork_devicesZdevs   &&f  r   from_interface_indexZDevices.from_interface_index   sD     "...?RRTX
 ?J5g>>r   c                s0   V^ ,          pVR,          pVR9   d   \         P                  ! R4      pVP                  V4      pV'       dZ   \        P                  ! \        VP                  R4      4      \        VP                  R4      4      4      pV P                  WV4      # \        V4      hVR8X  d   V P                  W4      # VR8X  dB   VP                  R4      w  rp
V
'       d   V'       d   V P                  WV
4      # \        V4      h\        V4      h)	z
Locate a device based on the kernel device.

:param `Context` context: the libudev context
:param str kernel_device: the kernel device
:returns: the device corresponding to ``kernel_device``
:rtype: `Device`
:   NNz^(?P<major>\d+):(?P<minor>\d+)$ZmajorZminorZnZ+Z:)ZbZc)reZcompilematchr   ZmakedevintZgroupr"   r   r.   Z	partitionr   )r   r   Zkernel_deviceZswitch_charZrestZ	number_rer1   r!   r   _Zkernel_device_names   &&&        r   from_kernel_deviceZDevices.from_kernel_device   s     $A&R *$

#EFIOOD)EG,-s5;;w3G/H --gFKK7FFC++G::C151D.Y-!i}}W9KLL7FF3MBBr   c                sr    VP                   P                  V4      pV'       g   \        4       h\        W4      # )a2  
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.18
)r   Z udev_device_new_from_environmentr   r   )r   r   r      && r   from_environmentZDevices.from_environment  s1    * !!BB7K244g&&r   c                st    V P                   V P                  V P                  V P                  V P                  .# )z
Return methods that obtain a :class:`Device` from a variety of
different data.

:return: a list of from_* methods.
:rtype: list of class methods

.. versionadded:: 0.18
)r&   r"   r   r   r   )r      &r   METHODSZDevices.METHODS4  s7       ""MMMM
 	
r    N)__name__
__module____qualname____firstlineno____doc__classmethodr   r   r   r"   r&   r.   r4   r6   r8   __static_attributes____classdictcell__Z__classdict__   @r   r   r   6   s      0 00 ' '4 ' '< )' )'V 'K 'KR ? ?( C C@ ' '2 
 
r   r   c                   s.  a  ] tR tRt o Rt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tR	 tR
 tR t]R 4       t]R 4       t]R 4       tR0R ltR t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t ]R 4       t!]R 4       t"]R  4       t#]R! 4       t$]R" 4       t%R# t&R$ t'R% t(R& t)R' t*R( t+R) t,R* t-R+ t.R, t/R- t0R. t1R/t2V t3R# )1r   iH  aw  
A single device with attached attributes and 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::

   Currently, Device extends Mapping. The mapping that it stores is that
   of udev property names to udev property values. This use is deprecated
   and Device will no longer extend Mapping in 1.0. To look up udev
   properties, use the Device.properties property.

.. warning::

   **Never** use object identity (``is`` operator) to compare
   :class:`Device` objects.  :mod:`pyudev` may create multiple
   :class:`Device` objects for the same device.  Instead 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`.
c                d    ^ RI pVP                  R\        ^R7       \        P	                  W4      # )zW
.. versionadded:: 0.4
.. deprecated:: 0.18
   Use :class:`Devices.from_path` instead.
N>Will be removed in 1.0. Use equivalent Devices method instead.Z
stacklevel)warningswarnDeprecationWarningr   r   )r   r   r   rG   r   r   r   ZDevice.from_pathj  s4     	L 	 	

   //r   c                rD   )a4  
.. 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`.
.. deprecated:: 0.18
   Use :class:`Devices.from_sys_path` instead.
NrE   rF   )rG   rH   rI   r   r   )r   r   r   rG   r   r   r   ZDevice.from_sys_path{  s4     	L 	 	

 $$W77r   c                f    ^ RI pVP                  R\        ^R7       \        P	                  WV4      # )zW
.. versionadded:: 0.5
.. deprecated:: 0.18
   Use :class:`Devices.from_name` instead.
NrE   rF   )rG   rH   rI   r   r   )r   r   r   r   rG   r   r   r   ZDevice.from_name  s6     	L 	 	

   X>>r   c                rJ   )za
.. versionadded:: 0.11
.. deprecated:: 0.18
   Use :class:`Devices.from_device_number` instead.
NrE   rF   )rG   rH   rI   r   r"   )r   r   r    r!   rG   r   r   r"   ZDevice.from_device_number  s6     	L 	 	

 ))'??r   c                rD   )z_
.. versionadded:: 0.15
.. deprecated:: 0.18
   Use :class:`Devices.from_device_file` instead.
NrE   rF   )rG   rH   rI   r   r&   )r   r   r#   rG   r   r   r&   ZDevice.from_device_file  s4     	L 	 	

 ''::r   c                sd    ^ RI pVP                  R\        ^R7       \        P	                  V4      # )z^
.. versionadded:: 0.6
.. deprecated:: 0.18
   Use :class:`Devices.from_environment` instead.
NrE   rF   )rG   rH   rI   r   r6   )r   r   rG   r5   r   r6   ZDevice.from_environment  s4     	L 	 	

 ''00r   c                s    \         P                  P                  P                  V 4       Wn        W n        VP                  V n        R # N)collectionsabcMapping__init__r   _as_parameter_r   )selfr   Z_devicer   r   rO   ZDevice.__init__  s2    ((.%((r   c                s<    V P                   P                  V 4       R # rK   )r   Zudev_device_unrefrQ   r7   r   __del__ZDevice.__del__  s    ''-r   c                s$    R P                  V 4      # )zDevice({0.sys_path!r}))ZformatrR   r7   r   __repr__ZDevice.__repr__  s    '..t44r   c                s    V P                   P                  V 4      pV'       g   R# \        V P                  V P                   P	                  V4      4      # )zG
The parent :class:`Device` or ``None``, if there is no parent
device.
N)r   Zudev_device_get_parentr   r   udev_device_refrQ   parent   & r   rW   ZDevice.parent  s@     55d; dllDMM$A$A&$IJJr   c              #  s   "   V P                   P                  4       P                  V 4       F  pW8w  g   K  Vx  K  	  R# 5i)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)r   r-   Zmatch_parentrQ   r   rX   r   childrenZDevice.children  s4     8 ll//1>>tDF~ Es
   0A
Ac              #  sR   "   V P                   pVe   Vx  VP                   pK  R# 5i)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)rW   rV   rX   r   	ancestorsZDevice.ancestors  s)       L]]F !s   %'Nc                s    \        V4      pVe   \        V4      pV P                  P                  WV4      pV'       g   R# \        V P                  V P                  P                  V4      4      # )aa  
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)r   r   Z-udev_device_get_parent_with_subsystem_devtyper   r   rU   )rQ   r   r$   rW   r   r   find_parentZDevice.find_parent  s_    $ 'y1	",[9KLL[
 dllDMM$A$A&$IJJr   c                sR    ^ RI pVP                  R\        ^R7       V P                  # )aF  
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.
Nz5Will be removed in 1.0. Use Device.ancestors instead.rF   )rG   rH   rI   r[   rQ   rG   rX   r   traverseZDevice.traverse:  s-     	C 	 	

 ~~r   c                J    \        V P                  P                  V 4      4      # )zb
Absolute path of this device in ``sysfs`` including the ``sysfs``
mount point as unicode string.
)r	   r   Zudev_device_get_syspathrR   r7   r   r   ZDevice.sys_pathO  s     %T]]%J%J4%PQQr   c                r_   )z
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   Zudev_device_get_devpathrR   r7   r   device_pathZDevice.device_pathW  s     %T]]%J%J4%PQQr   c                Z    V P                   P                  V 4      pVf   R# \        V4      # )z
Name of the subsystem this device is part of as unicode string.

:returns: name of subsystem if found, else None
:rtype: unicode string or NoneType
N)r   Zudev_device_get_subsystemr	   )rQ   ZsubsysrX   r   r   ZDevice.subsystemc  s-     88>~tH+@+HHr   c                r_   )z6
Device file name inside ``sysfs`` as unicode string.
)r	   r   Zudev_device_get_sysnamerR   r7   r   r   ZDevice.sys_namen  s    
 %T]]%J%J4%PQQr   c                Z    V P                   P                  V 4      pVe   \        V4      # R# )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 = Devices.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   Zudev_device_get_sysnumr	   )rQ   r!   rX   r   
sys_numberZDevice.sys_numberu  s.    0 55d;060B$V,LLr   c                ra   )ar  
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   Zudev_device_get_devtyper	   )rQ   r$   rX   r   r$   ZDevice.device_type  s,    $ mm;;DA$[11r   c                rb   )zo
The driver name as unicode string, or ``None``, if there is no
driver for this device.

.. versionadded:: 0.5
N)r   Zudev_device_get_driverr	   )rQ   driverrX   r   rd   ZDevice.driver  s.     55d;060B$V,LLr   c                rb   )aQ  
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   Zudev_device_get_devnoder	   )rQ   ZnoderX   r   device_nodeZDevice.device_node  s.    $ }}44T:.2.>$T*HDHr   c                8    V P                   P                  V 4      # )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 = Devices.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   Zudev_device_get_devnumrR   r7   r   r%   ZDevice.device_number  s    4 }}33D99r   c                r_   )a	  
``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   Zudev_device_get_is_initializedrR   r7   r   is_initializedZDevice.is_initialized  s    * DMM@@FGGr   c                sP    V P                   P                  V 4      p\        VR7      # )aO  
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    )rQ   ri   rX   r   time_since_initializedZDevice.time_since_initialized  s#     }}KKDQl33r   c              #  s   "   V P                   P                  V 4      p\        V P                   V4       F  w  r#\        V4      x  K  	  R# 5i)at  
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:`Devices.from_device_file()`. Hence do *not* rely on
   ``Devices.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	   )rQ   Zdevlinksnamer3      &   r   device_linksZDevice.device_links  s>     . ==DDTJ(AGD'-- Bs   A
Ac                rb   )ak  
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   Zudev_device_get_actionr	   )rQ   actionrX   r   rn   ZDevice.action'  s.    6 55d;060B$V,LLr   c                rf   )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   Zudev_device_get_seqnumrR   r7   r   sequence_numberZDevice.sequence_numberE  s     }}33D99r   c                    \        V 4      # )aJ  
The system attributes of this device as read-only
:class:`Attributes` mapping.

System attributes are basically normal files inside 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.

:returns: an Attributes object, useful for reading attributes
:rtype: Attributes

.. versionadded:: 0.5
)
AttributesrR   r7   r   r(   ZDevice.attributesO  s    0 $r   c                rp   )z]
The udev properties of this object as read-only Properties mapping.

.. versionadded:: 0.21
)
PropertiesrR   r7   r   
propertiesZDevice.propertiesi  s     $r   c                rp   )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
>>> 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.
)TagsrR   r7   r   tagsZDevice.tagsr  s    < Dzr   c                n    ^ RI pVP                  R\        ^R7       V P                  P	                  4       # )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.

.. deprecated:: 0.21
   Will be removed in 1.0. Access properties with Device.properties.
NAWill be removed in 1.0. Access properties with Device.properties.rF   )rG   rH   rI   rs   __iter__r]   rX   r   rx   ZDevice.__iter__  s6     	O 	 	

 ''))r   c                rv   )z
Return the amount of properties defined for this device as integer.

.. deprecated:: 0.21
   Will be removed in 1.0. Access properties with Device.properties.
Nrw   rF   )rG   rH   rI   rs   __len__r]   rX   r   ry   ZDevice.__len__  s6     	O 	 	

 &&((r   c                p    ^ RI pVP                  R\        ^R7       V P                  P	                  V4      # )a\  
Get the given property from this device.

``prop`` 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.

.. deprecated:: 0.21
   Will be removed in 1.0. Access properties with Device.properties.
Nrw   rF   )rG   rH   rI   rs   __getitem__rQ   proprG   r5   r   r{   ZDevice.__getitem__  s8     	O 	 	

 **400r   c                rz   )a  
Get the given property from this device as integer.

``prop`` 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.

.. deprecated:: 0.21
   Will be removed in 1.0. Use Device.properties.asint() instead.
Nz<Will be removed in 1.0. Use Device.properties.asint instead.rF   )rG   rH   rI   rs   asintr|   r5   r   r~   ZDevice.asint  s8      	J 	 	

 $$T**r   c                rz   )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.

``prop`` 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.

.. deprecated:: 0.21
   Will be removed in 1.0. Use Device.properties.asbool() instead.
Nz=Will be removed in 1.0. Use Device.properties.asbool instead.rF   )rG   rH   rI   rs   asboolr|   r5   r   r   ZDevice.asbool  s8    ( 	K 	 	

 %%d++r   c                s,    \        V P                  4      # rK   )Zhashr`   rR   r7   r   __hash__ZDevice.__hash__  s    D$$%%r   c                s~    \        V\        4      '       d   V P                  VP                  8H  # V P                  V8H  # rK   Z
isinstancer   r`   rQ   Zother   &&r   __eq__ZDevice.__eq__  7    eV$$##u'8'8885((r   c                s~    \        V\        4      '       d   V P                  VP                  8g  # V P                  V8g  # rK   r   r   r   r   __ne__ZDevice.__ne__  r   r   c                    \        R 4      hzDevice not orderableZ	TypeErrorr   r   r   __gt__ZDevice.__gt__      .//r   c                r   r   r   r   r   r   __lt__ZDevice.__lt__  r   r   c                r   r   r   r   r   r   __le__ZDevice.__le__  r   r   c                r   r   r   r   r   r   __ge__ZDevice.__ge__  r   r   )rP   r   r   rK   )4r:   r;   r<   r=   r>   r?   r   r   r   r"   r&   r6   rO   rS   rT   propertyrW   rZ   r[   r\   r^   r   r`   r   r   rc   r$   rd   re   r%   rh   rj   rm   rn   ro   r(   rs   ru   rx   ry   r{   r~   r   r   r   r   r   r   r   r   r@   rA   rB   rC   r   r   r   H  s    @ 0 0  8 8* ? ?  @ @  ; ;  1 1 ).5 
K 
K  > # #K:* R R 	R 	R I I R R M M4 2 2, M M I I( : :6 H H, 4 4" . .4 M M: : :    2      >*()"10+2,:&)
)
0000 0r   r   c                   sH   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )rr   i  zB
udev properties :class:`Device` objects.

.. versionadded:: 0.21
c                    \         P                  P                  P                  V 4       Wn        VP
                  V n        R # rK   )rL   rM   rN   rO   r   r   rY   r   r   rO   ZProperties.__init__&  s*    ((.r   c              #     "   V P                   P                  V P                  4      p\        V P                   V4       F  w  r#\	        V4      x  K  	  R# 5i)z
Iterate over the names of all properties defined for the 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	   )rQ   rs   rk   r3   rl   r   rx   ZProperties.__iter__+  sB      ]]HHU
(
CGD'-- D   AAc                s    V P                   P                  V P                  4      p\        R \	        V P                   V4       4       4      # )zE
Return the amount of properties defined for this device as integer.
c              3   s&   "   T F  p^x  K	  	  R# 5i)r/   Nr9   )r*   r3   rX   r   r,   Z%Properties.__len__.<locals>.<genexpr>;  s     KJ1Js   )r   r   r   Zsumr   )rQ   rs   rX   r   ry   ZProperties.__len__6  s9     ]]HHU
K/zJKKKr   c                s    V P                   P                  V P                  \        V4      4      pVf   \	        V4      h\        V4      # )a  
Get the given property from this device.

``prop`` 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.
)r   Zudev_device_get_property_valuer   r   KeyErrorr	   )rQ   r}   valuer5   r   r{   ZProperties.__getitem__=  sC     <<KK+D1
 =4. $U++r   c                $    \        W,          4      # )a_  
Get the given property from this device as integer.

``prop`` 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.
)r2   rQ   r}   r   r   r~   ZProperties.asintO  s     4:r   c                r   )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.

``prop`` 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   r   r   r   r   ZProperties.asbool]  s      dj))r   r   r   N)r:   r;   r<   r=   r>   rO   rx   ry   r{   r~   r   r@   rA   rB   rC   r   rr   rr     s.     (
	.L,$* *r   rr   c                   s\   a  ] tR tRt o RtR t]R 4       tR tRR lt	R t
R	 tR
 tRtV tR# )rq   ip  zE
udev attributes for :class:`Device` objects.

.. versionadded:: 0.5
c                s4    Wn         VP                  V n        R # rK   )r   r   rY   r   r   rO   ZAttributes.__init__w  s    r   c              #  s   "   \        V P                  R4      '       g   R# V P                  P                  V P                  4      p\	        V P                  V4       F  w  r#\        V4      x  K  	  R# 5i)a  
Yield the ``available`` attributes for the device.

It is not guaranteed that a key in this list will have a value.
It is not guaranteed that a key not in this list will not have a value.

It is guaranteed that the keys in this list are the keys that libudev
considers to be "available" attributes.

If libudev version does not define udev_device_get_sysattr_list_entry()
yields nothing.

See rhbz#1267584.
"udev_device_get_sysattr_list_entryN)hasattrr   r   r   r   r	   )rQ   Zattrs	attributer3   rl   r   available_attributesZAttributes.available_attributes{  sW       t}}&JKK@@M-dmmUCLI'	22 Ds   A2A4c                s    V P                   P                  V P                  \        V4      4      pVf   \	        V4      hV# )a  
Get the given system ``attribute`` for the device.

:param attribute: the key for an attribute value
:type attribute: unicode or byte string
:returns: the value corresponding to ``attribute``
:rtype: an arbitrary sequence of bytes
:raises KeyError: if no value found
)r   Zudev_device_get_sysattr_valuer   r   r   )rQ   r   r   r5   r   _getZAttributes._get  s>     ;;KK+I6
 =9%%r   Nc                sL     V P                  V4      #   \         d    Tu # i ; i)a<  
Get the given system ``attribute`` for the device.

:param attribute: the key for an attribute value
:type attribute: unicode or byte string
:param default: a default if no corresponding value found
:type default: a sequence of bytes
:returns: the value corresponding to ``attribute`` or ``default``
:rtype: object
)r   r   )rQ   r   Zdefaultr   r   r)   ZAttributes.get  s*    	99Y'' 	N	s    ##c                6    \        V P                  V4      4      # )aV  
Get the given ``attribute`` for the device as unicode string.

:param attribute: the key for an attribute value
:type attribute: unicode or byte string
:returns: the value corresponding to ``attribute``, as unicode
:rtype: unicode
:raises KeyError: if no value found for ``attribute``
:raises UnicodeDecodeError: if value is not convertible
)r	   r   rQ   r   r   r   asstringZAttributes.asstring  s     %TYYy%9::r   c                r   )a  
Get the given ``attribute`` as an int.

:param attribute: the key for an attribute value
:type attribute: unicode or byte string
:returns: the value corresponding to ``attribute``, as an int
:rtype: int
:raises KeyError: if no value found for ``attribute``
:raises UnicodeDecodeError: if value is not convertible to unicode
:raises ValueError: if unicode value can not be converted to an int
)r2   r   r   r   r   r~   ZAttributes.asint  s     4==+,,r   c                r   )a_  
Get the given ``attribute`` from this device as a bool.

:param attribute: the key for an attribute value
:type attribute: unicode or byte string
:returns: the value corresponding to ``attribute``, as bool
:rtype: bool
:raises KeyError: if no value found for ``attribute``
:raises UnicodeDecodeError: if value is not convertible to unicode
:raises ValueError: if unicode value can not be converted to a bool

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.
)r   r   r   r   r   r   ZAttributes.asbool  s      dmmI677r   r   rK   )r:   r;   r<   r=   r>   rO   r   r   r   r)   r   r~   r   r@   rA   rB   rC   r   rq   rq   p  sA     ( 3 3*" ;-8 8r   rq   c                   s<   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	rt   i  z_
A iterable over :class:`Device` tags.

Subclasses the ``Container`` and the ``Iterable`` ABC.
c                r   rK   )rL   rM   IterablerO   r   r   rY   r   r   rO   ZTags.__init__  s*      ))$/r   c                s   a \        V P                  R4      '       d9   \        V P                  P                  V P                  \        S4      4      4      # \        ;QJ d    V3R lV  4       F  '       g   K   R# 	  R# ! V3R lV  4       4      # )zS
Whether ``tag`` exists.

:param tag: unicode string with name of tag
:rtype: bool
udev_device_has_tagc              3   s,   <"   T F	  qS8H  x  K  	  R # 5irK   r9   )r*   Zttagr+   r   r,   Z Tags._has_tag.<locals>.<genexpr>  s     *T8Ts   TF)r   r   rg   r   r   r   ZanyrQ   r   s   &fr   _has_tagZTags._has_tag  sn     4=="78811$++?QRU?VW  s*T*ss*s*s*T***r   c                s$    V P                  V4      # )z
Check for existence of ``tag``.

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

Return ``True``, if ``tag`` is attached to the device, ``False``
otherwise.
)r   r   r   r   __contains__ZTags.__contains__  s     }}S!!r   c              #  r   )z;
Iterate over all tags.

Yield each tag as unicode string.
N)r   Zudev_device_get_tags_list_entryr   r   r	   )rQ   ru   r   r3   rl   r   rx   ZTags.__iter__  sA      }}<<T[[I't<FC',, =r   r   N)r:   r;   r<   r=   r>   rO   r   r   rx   r@   rA   rB   rC   r   rt   rt     s#     (+	"- -r   rt   )r>   rL   r   r0   ZsysZdatetimer    Zpyudev._errorsr   r   r   r   r   r   r   Zpyudev._utilr   r	   r
   r   r   r   rM   rN   r   rr   rq   r   Z	Containerrt   r9   r   r   <module>r      s   "  	 	 
    O
 O
dT0[__$$ T0nN*(( N*bm8 m8`/-;??##[__%>%> /-r   