ÿØÿà JFIF    ÿÛ „ ( %!1!%*+...983,7(-.- PKXg]ܷe  __pycache__/poll.cpython-36.pycnu[3 W@s\dZddlmZddlmZddlmZddlmZddlZddlmZGdd d e Z dS) z pyudev._os.poll =============== Operating system interface for pyudev. .. moduleauthor:: Sebastian Wiesner )absolute_import)division)print_function)unicode_literalsN)eintr_retry_callc@sPeZdZdZejejdZeddZ e ddZ ddZ dd d Z d d Zd S)PollzwA poll object. This object essentially provides a more convenient interface around :class:`select.poll`. )rwcCs ||@dkS)Nr)eventseventr r /usr/lib/python3.6/poll.py _has_event1szPoll._has_eventcGsNttj}x:|D]2\}}|jj|}|s6tdj||j||qW||S)aGListen 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})rselectpoll_EVENT_TO_MASKget ValueErrorformatregister)clsr notifierfdr maskr r r for_events5s  zPoll.for_eventscCs ||_dS)zCreate a poll object for the given ``notifier``. ``notifier`` is the :class:`select.poll` object wrapped by the new poll object. N) _notifier)selfrr r r __init__Gsz Poll.__init__NcCst|jt|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_eventsrrr)rZtimeoutr r r rPsz Poll.pollccsx|D]\}}|j|tjr,tdj|n|j|tjrHtdj||j|tjr`|dfV|j|tjrx|dfV|j|tjr|dfVqWdS)zParse ``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}rr hN) rrZPOLLNVALIOErrorrZPOLLERRPOLLINPOLLOUTZPOLLHUP)rr rZ event_maskr r r rcs   zPoll._parse_events)N)__name__ __module__ __qualname____doc__rr"r#r staticmethodr classmethodrrrrr r r r r&s    r) r'Z __future__rrrrrZ pyudev._utilrobjectrr r r r s     PKXg]ϣFPP#__pycache__/__init__.cpython-36.pycnu[3 HV@s dZddlmZddlmZdS)z pyudev._os ========== Extras to compensate for deficiencies in python os module. .. moduleauthor:: mulhern )pipe)pollN)__doc__rrrr/usr/lib/python3.6/__init__.pys PKXg]C__pycache__/pipe.cpython-36.pycnu[3 u1W@sdZddlmZddlmZddlmZddlmZddlZddlZddlm Z ddl m Z dd l m Z dd l m Z dd lmZeed d ZddZddZddZeZddZddZGdddeZdS)a# pyudev._os.pipe =============== Fallback implementations for pipe. 1. pipe2 from python os module 2. pipe2 from libc 3. pipe from python os module The Pipe class wraps the chosen implementation. .. moduleauthor:: Sebastian Wiesner )absolute_import)division)print_function)unicode_literalsN)partial)fd_pair)ERROR_CHECKERS) SIGNATURES)load_ctypes_library O_CLOEXECicCs"t}|j|||d|dfS)zA ``pipe2`` implementation using ``pipe2`` from ctypes. ``libc`` is a :class:`ctypes.CDLL` object for libc. ``flags`` is an integer providing the flags to ``pipe2``. Return a pair of file descriptors ``(r, w)``. r)rpipe2)libcflagsfdsr/usr/lib/python3.6/pipe.py _pipe2_ctypes4s  rcCsXtj}|tj@dkr0x|D]}t|tjqW|t@dkrTx|D]}t|tqBW|S)zA ``pipe2`` implementation using :func:`os.pipe`. ``flags`` is an integer providing the flags to ``pipe2``. .. warning:: This implementation is not atomic! Return a pair of file descriptors ``(r, w)``. r)ospipe O_NONBLOCKset_fd_status_flagr set_fd_flag)rrfdrrr_pipe2_by_pipeBs    rc CsNttdrtjSy$tdtt}t|dr2tt|StSt k rHtSXdS)z]Find the appropriate implementation for ``pipe2``. Return a function implementing ``pipe2``.r rN) hasattrrr r r rrrr ImportError)rrrr_get_pipe2_implementationXs  rcCs(tj|tjd}tj|tj||BdS)zwSet a flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. rN)fcntlZF_GETFDZF_SETFD)rflagrrrrrksrcCs(tj|tjd}tj|tj||BdS)z~Set a status flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. rN)rZF_GETFLZF_SETFL)rrrrrrrusrc@s,eZdZdZeddZddZddZdS) PipezA unix pipe. A pipe object provides two file objects: :attr:`source` is a readable file object, and :attr:`sink` a writeable. Bytes written to :attr:`sink` appear at :attr:`source`. Open a pipe with :meth:`open()`. cCsttjtB\}}|||S)zLOpen and return a new :class:`Pipe`. The pipe uses non-blocking IO.)_PIPE2rrr )clssourcesinkrrropensz Pipe.opencCs$tj|dd|_tj|dd|_dS)zCreate a new pipe object from the given file descriptors. ``source_fd`` is a file descriptor for the readable side of the pipe, ``sink_fd`` is a file descriptor for the writeable side.rbrwbN)rfdopenr#r$)selfZ source_fdZsink_fdrrr__init__sz Pipe.__init__c Cs z|jjWd|jjXdS)zCloses both sides of the pipe.N)r#closer$)r)rrrr+sz Pipe.closeN)__name__ __module__ __qualname____doc__ classmethodr%r*r+rrrrr s  r )r/Z __future__rrrrrr functoolsrZpyudev._ctypeslib.libcrrr Zpyudev._ctypeslib.utilsr getattrr rrrr!rrobjectr rrrr s&            PKXg]ϣFPP)__pycache__/__init__.cpython-36.opt-1.pycnu[3 HV@s dZddlmZddlmZdS)z pyudev._os ========== Extras to compensate for deficiencies in python os module. .. moduleauthor:: mulhern )pipe)pollN)__doc__rrrr/usr/lib/python3.6/__init__.pys PKXg]C%__pycache__/pipe.cpython-36.opt-1.pycnu[3 u1W@sdZddlmZddlmZddlmZddlmZddlZddlZddlm Z ddl m Z dd l m Z dd l m Z dd lmZeed d ZddZddZddZeZddZddZGdddeZdS)a# pyudev._os.pipe =============== Fallback implementations for pipe. 1. pipe2 from python os module 2. pipe2 from libc 3. pipe from python os module The Pipe class wraps the chosen implementation. .. moduleauthor:: Sebastian Wiesner )absolute_import)division)print_function)unicode_literalsN)partial)fd_pair)ERROR_CHECKERS) SIGNATURES)load_ctypes_library O_CLOEXECicCs"t}|j|||d|dfS)zA ``pipe2`` implementation using ``pipe2`` from ctypes. ``libc`` is a :class:`ctypes.CDLL` object for libc. ``flags`` is an integer providing the flags to ``pipe2``. Return a pair of file descriptors ``(r, w)``. r)rpipe2)libcflagsfdsr/usr/lib/python3.6/pipe.py _pipe2_ctypes4s  rcCsXtj}|tj@dkr0x|D]}t|tjqW|t@dkrTx|D]}t|tqBW|S)zA ``pipe2`` implementation using :func:`os.pipe`. ``flags`` is an integer providing the flags to ``pipe2``. .. warning:: This implementation is not atomic! Return a pair of file descriptors ``(r, w)``. r)ospipe O_NONBLOCKset_fd_status_flagr set_fd_flag)rrfdrrr_pipe2_by_pipeBs    rc CsNttdrtjSy$tdtt}t|dr2tt|StSt k rHtSXdS)z]Find the appropriate implementation for ``pipe2``. Return a function implementing ``pipe2``.r rN) hasattrrr r r rrrr ImportError)rrrr_get_pipe2_implementationXs  rcCs(tj|tjd}tj|tj||BdS)zwSet a flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. rN)fcntlZF_GETFDZF_SETFD)rflagrrrrrksrcCs(tj|tjd}tj|tj||BdS)z~Set a status flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. rN)rZF_GETFLZF_SETFL)rrrrrrrusrc@s,eZdZdZeddZddZddZdS) PipezA unix pipe. A pipe object provides two file objects: :attr:`source` is a readable file object, and :attr:`sink` a writeable. Bytes written to :attr:`sink` appear at :attr:`source`. Open a pipe with :meth:`open()`. cCsttjtB\}}|||S)zLOpen and return a new :class:`Pipe`. The pipe uses non-blocking IO.)_PIPE2rrr )clssourcesinkrrropensz Pipe.opencCs$tj|dd|_tj|dd|_dS)zCreate a new pipe object from the given file descriptors. ``source_fd`` is a file descriptor for the readable side of the pipe, ``sink_fd`` is a file descriptor for the writeable side.rbrwbN)rfdopenr#r$)selfZ source_fdZsink_fdrrr__init__sz Pipe.__init__c Cs z|jjWd|jjXdS)zCloses both sides of the pipe.N)r#closer$)r)rrrr+sz Pipe.closeN)__name__ __module__ __qualname____doc__ classmethodr%r*r+rrrrr s  r )r/Z __future__rrrrrr functoolsrZpyudev._ctypeslib.libcrrr Zpyudev._ctypeslib.utilsr getattrr rrrr!rrobjectr rrrr s&            PKXg]ܷe  %__pycache__/poll.cpython-36.opt-1.pycnu[3 W@s\dZddlmZddlmZddlmZddlmZddlZddlmZGdd d e Z dS) z pyudev._os.poll =============== Operating system interface for pyudev. .. moduleauthor:: Sebastian Wiesner )absolute_import)division)print_function)unicode_literalsN)eintr_retry_callc@sPeZdZdZejejdZeddZ e ddZ ddZ dd d Z d d Zd S)PollzwA poll object. This object essentially provides a more convenient interface around :class:`select.poll`. )rwcCs ||@dkS)Nr)eventseventr r /usr/lib/python3.6/poll.py _has_event1szPoll._has_eventcGsNttj}x:|D]2\}}|jj|}|s6tdj||j||qW||S)aGListen 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})rselectpoll_EVENT_TO_MASKget ValueErrorformatregister)clsr notifierfdr maskr r r for_events5s  zPoll.for_eventscCs ||_dS)zCreate a poll object for the given ``notifier``. ``notifier`` is the :class:`select.poll` object wrapped by the new poll object. N) _notifier)selfrr r r __init__Gsz Poll.__init__NcCst|jt|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_eventsrrr)rZtimeoutr r r rPsz Poll.pollccsx|D]\}}|j|tjr,tdj|n|j|tjrHtdj||j|tjr`|dfV|j|tjrx|dfV|j|tjr|dfVqWdS)zParse ``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}rr hN) rrZPOLLNVALIOErrorrZPOLLERRPOLLINPOLLOUTZPOLLHUP)rr rZ event_maskr r r rcs   zPoll._parse_events)N)__name__ __module__ __qualname____doc__rr"r#r staticmethodr classmethodrrrrr r r r r&s    r) r'Z __future__rrrrrZ pyudev._utilrobjectrr r r r s     PKXg]jpipe.pynu[# -*- coding: utf-8 -*- # Copyright (C) 2013 Sebastian Wiesner # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by the # Free Software Foundation; either version 2.1 of the License, or (at your # option) any later version. # This library is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # You should have received a copy of the GNU Lesser General Public License # along with this library; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ pyudev._os.pipe =============== Fallback implementations for pipe. 1. pipe2 from python os module 2. pipe2 from libc 3. pipe from python os module The Pipe class wraps the chosen implementation. .. moduleauthor:: Sebastian Wiesner """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import os import fcntl from functools import partial from pyudev._ctypeslib.libc import fd_pair from pyudev._ctypeslib.libc import ERROR_CHECKERS from pyudev._ctypeslib.libc import SIGNATURES from pyudev._ctypeslib.utils import load_ctypes_library # Define O_CLOEXEC, if not present in os already O_CLOEXEC = getattr(os, 'O_CLOEXEC', 0o2000000) def _pipe2_ctypes(libc, flags): """A ``pipe2`` implementation using ``pipe2`` from ctypes. ``libc`` is a :class:`ctypes.CDLL` object for libc. ``flags`` is an integer providing the flags to ``pipe2``. Return a pair of file descriptors ``(r, w)``. """ fds = fd_pair() libc.pipe2(fds, flags) return fds[0], fds[1] def _pipe2_by_pipe(flags): """A ``pipe2`` implementation using :func:`os.pipe`. ``flags`` is an integer providing the flags to ``pipe2``. .. warning:: This implementation is not atomic! Return a pair of file descriptors ``(r, w)``. """ fds = os.pipe() if flags & os.O_NONBLOCK != 0: for fd in fds: set_fd_status_flag(fd, os.O_NONBLOCK) if flags & O_CLOEXEC != 0: for fd in fds: set_fd_flag(fd, O_CLOEXEC) return fds def _get_pipe2_implementation(): """Find the appropriate implementation for ``pipe2``. Return a function implementing ``pipe2``.""" if hasattr(os, 'pipe2'): return os.pipe2 # pylint: disable=no-member else: try: libc = load_ctypes_library("libc", SIGNATURES, ERROR_CHECKERS) return (partial(_pipe2_ctypes, libc) if hasattr(libc, 'pipe2') else _pipe2_by_pipe) except ImportError: return _pipe2_by_pipe _PIPE2 = _get_pipe2_implementation() def set_fd_flag(fd, flag): """Set a flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. """ flags = fcntl.fcntl(fd, fcntl.F_GETFD, 0) fcntl.fcntl(fd, fcntl.F_SETFD, flags | flag) def set_fd_status_flag(fd, flag): """Set a status flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. """ flags = fcntl.fcntl(fd, fcntl.F_GETFL, 0) fcntl.fcntl(fd, fcntl.F_SETFL, flags | flag) class Pipe(object): """A unix pipe. A pipe object provides two file objects: :attr:`source` is a readable file object, and :attr:`sink` a writeable. Bytes written to :attr:`sink` appear at :attr:`source`. Open a pipe with :meth:`open()`. """ @classmethod def open(cls): """Open and return a new :class:`Pipe`. The pipe uses non-blocking IO.""" source, sink = _PIPE2(os.O_NONBLOCK | O_CLOEXEC) return cls(source, sink) def __init__(self, source_fd, sink_fd): """Create a new pipe object from the given file descriptors. ``source_fd`` is a file descriptor for the readable side of the pipe, ``sink_fd`` is a file descriptor for the writeable side.""" self.source = os.fdopen(source_fd, 'rb', 0) self.sink = os.fdopen(sink_fd, 'wb', 0) def close(self): """Closes both sides of the pipe.""" try: self.source.close() finally: self.sink.close() PKXg]ˆpoll.pynu[# -*- coding: utf-8 -*- # Copyright (C) 2013 Sebastian Wiesner # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by the # Free Software Foundation; either version 2.1 of the License, or (at your # option) any later version. # This library is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # You should have received a copy of the GNU Lesser General Public License # along with this library; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ pyudev._os.poll =============== Operating system interface for pyudev. .. moduleauthor:: Sebastian Wiesner """ from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import select from pyudev._util import eintr_retry_call class Poll(object): """A poll object. This object essentially provides a more convenient interface around :class:`select.poll`. """ _EVENT_TO_MASK = {'r': select.POLLIN, 'w': select.POLLOUT} @staticmethod def _has_event(events, event): return events & event != 0 @classmethod def for_events(cls, *events): """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. """ notifier = eintr_retry_call(select.poll) for fd, event in events: mask = cls._EVENT_TO_MASK.get(event) if not mask: raise ValueError('Unknown event type: {0!r}'.format(event)) notifier.register(fd, mask) return cls(notifier) def __init__(self, notifier): """Create a poll object for the given ``notifier``. ``notifier`` is the :class:`select.poll` object wrapped by the new poll object. """ self._notifier = notifier def poll(self, timeout=None): """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). """ # Return a list to allow clients to determine whether there are any # events at all with a simple truthiness test. return list(self._parse_events(eintr_retry_call(self._notifier.poll, timeout))) def _parse_events(self, events): """Parse ``events``. ``events`` is a list of events as returned by :meth:`select.poll.poll()`. Yield all parsed events. """ for fd, event_mask in events: if self._has_event(event_mask, select.POLLNVAL): raise IOError('File descriptor not open: {0!r}'.format(fd)) elif self._has_event(event_mask, select.POLLERR): raise IOError('Error while polling fd: {0!r}'.format(fd)) if self._has_event(event_mask, select.POLLIN): yield fd, 'r' if self._has_event(event_mask, select.POLLOUT): yield fd, 'w' if self._has_event(event_mask, select.POLLHUP): yield fd, 'h' PKXg]qJ __init__.pynu[# -*- coding: utf-8 -*- # Copyright (C) 2015 mulhern # This library is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by the # Free Software Foundation; either version 2.1 of the License, or (at your # option) any later version. # This library is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License # for more details. # You should have received a copy of the GNU Lesser General Public License # along with this library; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA """ pyudev._os ========== Extras to compensate for deficiencies in python os module. .. moduleauthor:: mulhern """ from . import pipe from . import poll PKXg]ܷe  __pycache__/poll.cpython-36.pycnu[PKXg]ϣFPP#k __pycache__/__init__.cpython-36.pycnu[PKXg]C__pycache__/pipe.cpython-36.pycnu[PKXg]ϣFPP) __pycache__/__init__.cpython-36.opt-1.pycnu[PKXg]C% __pycache__/pipe.cpython-36.opt-1.pycnu[PKXg]ܷe  %0__pycache__/poll.cpython-36.opt-1.pycnu[PKXg]j*>pipe.pynu[PKXg]ˆ$Ppoll.pynu[PKXg]qJ v`__init__.pynu[PK -d