
    9*b                     0    d Z ddlZddlmZ  G d d      Zy)z
    pyudev._os.poll
    ===============

    Operating system interface for pyudev.

    .. moduleauthor:: Sebastian Wiesner  <lunaryorn@gmail.com>
    N)eintr_retry_callc                   v    e Zd ZdZej
                  ej                  dZed        Z	e
d        Zd Zd	dZd Zy)
PollzwA poll object.

    This object essentially provides a more convenient interface around
    :class:`select.poll`.

    )rwc                     | |z  dk7  S )Nr    )eventsevents     1/usr/lib/python3/dist-packages/pyudev/_os/poll.py
_has_eventzPoll._has_event+   s    ~""    c                     t        t        j                        }|D ]K  \  }}| j                  j	                  |      }|st        dt        |             |j                  ||       M  | |      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.

        zUnknown event type: )r   selectpoll_EVENT_TO_MASKget
ValueErrorreprregister)clsr
   notifierfdr   masks         r   
for_eventszPoll.for_events/   sq     $FKK0 	(IB%%))%0D #7U}!EFFb$'		(
 8}r   c                     || _         y)zCreate a poll object for the given ``notifier``.

        ``notifier`` is the :class:`select.poll` object wrapped by the new poll
        object.

        N)	_notifier)selfr   s     r   __init__zPoll.__init__A   s     "r   Nc                 r    t        | j                  t        | j                  j                  |                  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   timeouts     r   r   z	Poll.pollJ   s,    " D&&'78K8KW'UVWWr   c              #     K   |D ]  \  }}| j                  |t        j                        rt        dt	        |             | j                  |t        j
                        rt        dt	        |             | j                  |t        j                        r|df | j                  |t        j                        r|df | j                  |t        j                        s|df  yw)zParse ``events``.

        ``events`` is a list of events as returned by
        :meth:`select.poll.poll()`.

        Yield all parsed events.

        zFile descriptor not open: zError while polling fd: r   r   hN)	r   r   POLLNVALIOErrorr   POLLERRPOLLINPOLLOUTPOLLHUP)r   r
   r   
event_masks       r   r"   zPoll._parse_events]   s      % 	NB
z6??; :48*EFFz6>>: 8b
CDDz6==9#gz6>>:#gz6>>:#g	s   C#C/&	C/)N)__name__
__module____qualname____doc__r   r)   r*   r   staticmethodr   classmethodr   r   r   r"   r	   r   r   r   r   !   sQ     "==v~~>N# #  ""X&r   r   )r0   r   pyudev._utilr   r   r	   r   r   <module>r4      s    "  *P Pr   