a 8g+^®ã@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)ÚERROR_CHECKERS)ÚFD_PAIR)Ú SIGNATURES)Úload_ctypes_libraryÚ O_CLOEXECicCs"tƒ}| ||¡|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ú3/usr/lib/python3.9/site-packages/pyudev/_os/pipe.pyÚ _pipe2_ctypes2s  rcCsPt ¡}|tj@dkr,|D]}t|tjƒq|t@dkrL|D]}t|tƒq<|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_pipe@s   rcCsRttdƒrtjSz&tdttƒ}t|dƒr2tt|ƒntWSt yLtYS0dS)z]Find the appropriate implementation for ``pipe2``. Return a function implementing ``pipe2``.r rN) Úhasattrrr r r rrrrÚ ImportError)rrrrÚ_get_pipe2_implementationVs  ÿ ÿ rcCs(t |tjd¡}t |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ÚflagrrrrrhsrcCs(t |tjd¡}t |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_SETFLrrrrrrsrc@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$t |dd¡|_t |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__cCs*z|j ¡W|j ¡n |j ¡0dS)zCloses both sides of the pipe.N)r$Úcloser%)r*rrrr,—s z Pipe.closeN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú classmethodr&r+r,rrrrr!|s   r!)r0Z __future__rrrrrrÚ functoolsrZpyudev._ctypeslib.libcrrr Zpyudev._ctypeslib.utilsr Úgetattrr rrrr"rrÚobjectr!rrrrÚs&