+
     hL  c                   s    R t ^ RIt^ RIt^ RIHt ^ RIHtHtHt ^ RI	H
t
 ]! ]RR4      tR tR tR	 t]! 4       tR
 tR t ! R R4      tR# )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  <lunaryorn@gmail.com>
N)partial)ERROR_CHECKERSFD_PAIR
SIGNATURES)load_ctypes_library	O_CLOEXECi   c                s\    \        4       pV P                  W!4       V^ ,          V^,          3# )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   pipe2)libcflagsfds   && 4/usr/lib/python3.14/site-packages/pyudev/_os/pipe.py_pipe2_ctypesr   -   s)     )CJJsq63q6>    c                s   \         P                  ! 4       pV \         P                  ,          ^ 8w  d$   V F  p\        V\         P                  4       K  	  V \        ,          ^ 8w  d   V F  p\        V\        4       K  	  V# )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)``.

)osZpipe
O_NONBLOCKset_fd_status_flagr   set_fd_flag)r   r	   Zfile_descriptor   &  r   _pipe2_by_piper   ;   s^     '')Cr}}!"O>  #yA"O3  #Jr   c                 s    \        \        R4      '       d   \        P                  #  \        R\        \
        4      p \        V R4      '       d   \        \        V 4      # \        #   \         d
    \        u # i ; i)z^
Find the appropriate implementation for ``pipe2``.

Return a function implementing ``pipe2``.r   r   )
Zhasattrr   r   r   r   r   r    r   r   ZImportError)r   s    r   _get_pipe2_implementationr   Q   sg    
 r7xx"6:~F,3D',B,BGM4(	
HV	
  s   6A% A% %A98A9c                    \         P                   ! V \         P                  ^ 4      p\         P                   ! V \         P                  W!,          4       R# )zoSet a flag on a file descriptor.

``fd`` is the file descriptor or file object, ``flag`` the flag as integer.

N)fcntlZF_GETFDZF_SETFDZfdZflagr   r
   r   r   r   d   0     KKEMM1-E	KKEMM5<0r   c                r   )zvSet a status flag on a file descriptor.

``fd`` is the file descriptor or file object, ``flag`` the flag as integer.

N)r   ZF_GETFLZF_SETFLr   r
   r   r   r   n   r   r   c                   s@   a  ] tR t^xt o Rt]R 4       tR tR tRt	V t
R# )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()`.

c                s^    \        \        P                  \        ,          4      w  rV ! W4      # )zDOpen and return a new :class:`Pipe`.

The pipe uses non-blocking IO.)_PIPE2r   r   r   )Zclssourcesinkr   r   openZ	Pipe.open   s$    
 bmmi786  r   c                sz    \         P                  ! VR^ 4      V n        \         P                  ! VR^ 4      V n        R# )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.ZrbZwbN)r   Zfdopenr   r   )selfZ	source_fdZsink_fds   &&&r   __init__ZPipe.__init__   s,    
 ii	43IIgtQ/	r   c                s     V P                   P                  4        V P                  P                  4        R#   T P                  P                  4        i ; i)zCloses both sides of the pipe.N)r   closer   )r   s   &r   r    Z
Pipe.close   s4    	KKIIOODIIOOs	   8 A)r   r   N)Z__name__Z
__module__Z__qualname__Z__firstlineno____doc__Zclassmethodr   r   r    Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r   r   r   x   s-      ! !0 r   r   )r!   r   r   Z	functoolsr    Zpyudev._ctypeslib.libcr   r   r   Zpyudev._ctypeslib.utilsr   Zgetattrr   r   r   r   r   r   r   r   ) r   r   <module>r"      s^   "   	  G F 7 BY/	,  
#	$11   r   