Current Dir: /snap/core22/2955/usr/lib/python3/dist-packages/pyudev/_os/__pycache__/
[FILE] pipe.cpython-310.pyc [ edit | delete | rename ]
[FILE] poll.cpython-310.pyc [ edit | delete | rename ]
[FILE] __init__.cpython-310.pyc [ edit | delete | rename ]
Viewing: /snap/core22/2955/usr/lib/python3/dist-packages/pyudev/_os/__pycache__/poll.cpython-310.pyc
o
8g+^ � @ s\ d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ G dd � d e �Z
dS )
z�
pyudev._os.poll
===============
Operating system interface for pyudev.
.. moduleauthor:: Sebastian Wiesner <lunaryorn@gmail.com>
� )�absolute_import)�division)�print_function)�unicode_literalsN)�eintr_retry_callc @ sP e Zd ZdZejejd�Zedd� �Z e
dd� �Zdd� Zdd
d�Z
dd
� Zd S )�PollzwA poll object.
This object essentially provides a more convenient interface around
:class:`select.poll`.
)�r�wc C s | |@ dkS )Nr � )�events�eventr
r
�1/usr/lib/python3/dist-packages/pyudev/_os/poll.py�
_has_event. s zPoll._has_eventc G sJ t tj�}|D ]\}}| j�|�}|std�|���|�||� q| |�S )aG Listen for ``events``.
``events`` is a list of ``(fd, event)`` pairs, where ``fd`` is a file
descriptor or file object and ``event`` either ``'r'`` or ``'w'``. If
``r``, listen for whether that is ready to be read. If ``w``, listen
for whether the channel is ready to be written to.
zUnknown event type: {0!r})r �select�poll�_EVENT_TO_MASK�get�
ValueError�format�register)�clsr �notifier�fdr �maskr
r
r
�
for_events2 s
zPoll.for_eventsc C s
|| _ dS )z�Create a poll object for the given ``notifier``.
``notifier`` is the :class:`select.poll` object wrapped by the new poll
object.
N)� _notifier)�selfr r
r
r
�__init__D s
z
Poll.__init__Nc C s t | �t| jj|���S )a{ Poll for events.
``timeout`` is an integer specifying how long to wait for events (in
milliseconds). If omitted, ``None`` or negative, wait until an event
occurs.
Return a list of all events that occurred before ``timeout``, where
each event is a pair ``(fd, event)``. ``fd`` is the integral file
descriptor, and ``event`` a string indicating the event type. If
``'r'``, there is data to read from ``fd``. If ``'w'``, ``fd`` is
writable without blocking now. If ``'h'``, the file descriptor was
hung up (i.e. the remote side of a pipe was closed).
)�list�
_parse_eventsr r r )r �timeoutr
r
r
r M s �z Poll.pollc c s� � |D ]D\}}| � |tj�rtd�|���| � |tj�r#td�|���| � |tj�r/|dfV | � |tj�r;|dfV | � |tj�rG|dfV qdS )z�Parse ``events``.
``events`` is a list of events as returned by
:meth:`select.poll.poll()`.
Yield all parsed events.
zFile descriptor not open: {0!r}zError while polling fd: {0!r}r r �hN) r r �POLLNVAL�IOErrorr �POLLERR�POLLIN�POLLOUT�POLLHUP)r r r �
event_maskr
r
r
r a s �
��zPoll._parse_events)N)�__name__�
__module__�__qualname__�__doc__r r% r&