3 u1‘WÃã@sÎdZddlmZddlmZddlmZddlmZddlZddlZddlm Z ddl m Z dd l m Z dd l m Z dd lmZeed d ƒZdd„Zdd„Zdd„ZeƒZdd„Zdd„ZGdd„deƒZdS)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)zè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)``. ré)rÚpipe2)ÚlibcÚflagsÚfds©rú/usr/lib/python3.6/pipe.pyÚ _pipe2_ctypes4s  rcCsXtjƒ}|tj@dkr0x|D]}t|tjƒqW|t@dkrTx|D]}t|tƒqBW|S)zæ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)``. r)ÚosÚpipeÚ O_NONBLOCKÚset_fd_status_flagr Ú set_fd_flag)rrÚfdrrrÚ_pipe2_by_pipeBs    rc CsNttdƒrtjSy$tdttƒ}t|dƒr2tt|ƒ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||BƒdS)zwSet a flag on a file descriptor. ``fd`` is the file descriptor or file object, ``flag`` the flag as integer. rN)ÚfcntlZF_GETFDZF_SETFD)rÚflagrrrrrksrcCs(tj|tjdƒ}tj|tj||BƒdS)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,eZdZdZedd„ƒZdd„Zdd„ZdS) ÚPipezï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()`. cCsttjtBƒ\}}|||ƒS)zLOpen and return a new :class:`Pipe`. The pipe uses non-blocking IO.)Ú_PIPE2rrr )ÚclsÚsourceÚsinkrrrÚopenŠsz Pipe.opencCs$tj|ddƒ|_tj|ddƒ|_dS)zÉ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.ÚrbrÚwbN)rÚfdopenr#r$)ÚselfZ source_fdZsink_fdrrrÚ__init__’sz Pipe.__init__c Cs z|jjƒWd|jjƒXdS)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!rrÚobjectr rrrrÚ s&