%PDF- %PDF-
| Direktori : /snap/core/current/usr/lib/python3/dist-packages/pyudev/__pycache__/ |
| Current File : //snap/core/current/usr/lib/python3/dist-packages/pyudev/__pycache__/monitor.cpython-35.pyc |
��P�N � @ s� d Z d d l m Z m Z m Z m Z d d l Z d d l Z d d l m Z d d l
m Z d d l m
Z
d d l m Z d d l m Z d d
g Z Gd d � d e � Z Gd d
� d
e � Z d S)
z�
pyudev.monitor
==============
Monitor implementation.
.. moduleauthor:: Sebastian Wiesner <lunaryorn@gmail.com>
� )�print_function�division�unicode_literals�absolute_importN)�Thread)�closing)�libudev)�ensure_byte_string)�Device�Monitor�MonitorObserverc @ s� e Z d Z d Z d d � Z d d � Z e d d d � � Z e d d
� � Z d d � Z
d
d d � Z d d � Z d d � Z
d d � Z d d � Z d d � Z d d � Z d
d d � Z d d � Z d d! � Z d
S)"r at
A synchronous device event monitor.
A :class:`Monitor` objects connects to the udev daemon and listens for
changes to the device list. A monitor is created by connecting to the
kernel daemon through netlink (see :meth:`from_netlink`):
>>> from pyudev import Context, Monitor
>>> context = Context()
>>> monitor = Monitor.from_netlink(context)
Once the monitor is created, you can add a filter using :meth:`filter_by()`
or :meth:`filter_by_tag()` to drop incoming events in subsystems, which are
not of interest to the application:
>>> monitor.filter_by('input')
When the monitor is eventually set up, you can either poll for events
synchronously:
>>> device = monitor.poll(timeout=3)
>>> if device:
... print('{0.action}: {0}'.format(device))
...
Or you can monitor events asynchronously with :class:`MonitorObserver`.
To integrate into various event processing frameworks, the monitor provides
a :func:`selectable <select.select>` file description by :meth:`fileno()`.
However, do *not* read or write directly on this file descriptor.
Instances of this class can directly be given as ``udev_monitor *`` to
functions wrapped through :mod:`ctypes`.
.. versionchanged:: 0.16
Remove :meth:`from_socket()` which is deprecated, and even removed in
recent udev versions.
c C s | | _ | | _ d | _ d S)NF)�contextZ_as_parameter_�_started)�selfr
Z monitor_p� r �0/usr/lib/python3/dist-packages/pyudev/monitor.py�__init__V s zMonitor.__init__c C s t j | � d S)N)r Zudev_monitor_unref)r r r r �__del__[ s zMonitor.__del__�udevc C sX | d k r! t d j | � � � t j | t | � � } | sK t d � � | | | � S)a�
Create a monitor by connecting to the kernel daemon through netlink.
``context`` is the :class:`Context` to use. ``source`` is a string,
describing the event source. Two sources are available:
``'udev'`` (the default)
Events emitted after udev as registered and configured the device.
This is the absolutely recommended source for applications.
``'kernel'``
Events emitted directly after the kernel has seen the device. The
device has not yet been configured by udev and might not be usable
at all. **Never** use this, unless you know what you are doing.
Return a new :class:`Monitor` object, which is connected to the
given source. Raise :exc:`~exceptions.ValueError`, if an invalid
source has been specified. Raise
:exc:`~exceptions.EnvironmentError`, if the creation of the monitor
failed.
�kernelr z8Invalid source: {0!r}. Must be one of "udev" or "kernel"zCould not create udev monitor)r r )�
ValueError�formatr Zudev_monitor_new_from_netlinkr �EnvironmentError)�clsr
�source�monitorr r r �from_netlink^ s zMonitor.from_netlinkc C s | j S)z�
``True``, if this monitor was started, ``False`` otherwise. Readonly.
.. seealso:: :meth:`start()`
.. versionadded:: 0.16
)r )r r r r �started~ s zMonitor.startedc C s
t j | � S)z�
Return the file description associated with this monitor as integer.
This is really a real file descriptor ;), which can be watched and
:func:`select.select`\ ed.
)r Zudev_monitor_get_fd)r r r r �fileno� s zMonitor.filenoNc C sB t | � } | r t | � } t j | | | � t j | � d S)a
Filter incoming events.
``subsystem`` is a byte or unicode string with the name of a
subsystem (e.g. ``'input'``). Only events originating from the
given subsystem pass the filter and are handed to the caller.
If given, ``device_type`` is a byte or unicode string specifying the
device type. Only devices with the given device type are propagated
to the caller. If ``device_type`` is not given, no additional
filter for a specific device type is installed.
These filters are executed inside the kernel, and client processes
will usually not be woken up for device, that do not match these
filters.
.. versionchanged:: 0.15
This method can also be after :meth:`start()` now.
N)r r Z/udev_monitor_filter_add_match_subsystem_devtype�udev_monitor_filter_update)r Z subsystemZdevice_typer r r � filter_by� s
zMonitor.filter_byc C s'