Ë
    9*ªbL  ã                   ó˜   — d Z ddlZddlZddlmZ ddlmZmZmZ ddl	m
Z
  eedd«      Zd„ Zd	„ Zd
„ Z e«       Zd„ Zd„ Z G d„ d«      Zy)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                 óN   — t        «       }| j                  ||«       |d   |d   fS )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Úfdss      ú1/usr/lib/python3/dist-packages/pyudev/_os/pipe.pyÚ_pipe2_ctypesr   -   s+   € ô ‹)€CØ‡J�Jˆs�EÔØˆq‰6�3�q‘6ˆ>Ðó    c                 óâ   — t        j                  «       }| t         j                  z  dk7  r!|D ]  }t        |t         j                  «       Œ | t        z  dk7  r|D ]  }t        |t        «       Œ |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)r   r   Úfile_descriptors      r   Ú_pipe2_by_piper   ;   sh   € ô �'‰'‹)€CØŒr�}‰}Ñ Ò!Ø"ò 	?ˆOÜ˜´·±Õ>ð	?àŒyÑ˜AÒØ"ò 	4ˆOÜ˜¬Õ3ð	4à€Jr   c                  óÜ   — t        t        d«      rt        j                  S 	 t        dt        t
        «      } t        | d«      rt        t        | «      S t        S # t        $ r	 t        cY S w xY w)zf
    Find the appropriate implementation for ``pipe2``.

    Return a function implementing ``pipe2``.r   r   )
Úhasattrr   r   r   r   r   r   r   r   ÚImportError)r   s    r   Ú_get_pipe2_implementationr   Q   sa   € ô
 Œr�7ÔÜ�x‰xˆðÜ" 6¬:´~ÓFˆä,3°D¸'Ô,BŒG”M 4Ó(ð	
ÜHVð	
øô ò ÜÒðús   ¢0A ÁA ÁA+Á*A+c                 óž   — t        j                   | t         j                  d«      }t        j                   | t         j                  ||z  «       y)zwSet a flag on a file descriptor.

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

    r   N)ÚfcntlÚF_GETFDÚF_SETFD©ÚfdÚflagr   s      r   r   r   d   ó2   € ô �K‰K˜œEŸM™M¨1Ó-€EÜ	‡K�K�”E—M‘M 5¨4¡<Õ0r   c                 óž   — t        j                   | t         j                  d«      }t        j                   | t         j                  ||z  «       y)z~Set a status flag on a file descriptor.

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

    r   N)r   ÚF_GETFLÚF_SETFLr"   s      r   r   r   n   r%   r   c                   ó,   — e Zd ZdZed„ «       Zd„ Zd„ Zy)Ú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()`.

    c                 óZ   — t        t        j                  t        z  «      \  }} | ||«      S )zLOpen and return a new :class:`Pipe`.

        The pipe uses non-blocking IO.)Ú_PIPE2r   r   r   )ÚclsÚsourceÚsinks      r   Úopenz	Pipe.openƒ   s(   € ô
 œbŸm™m¬iÑ7Ó8‰ˆ�Ù�6˜4Ó Ð r   c                 ót   — t        j                  |dd«      | _        t        j                  |dd«      | _        y)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/   )ÚselfÚ	source_fdÚsink_fds      r   Ú__init__zPipe.__init__‹   s,   € ô
 —i‘i 	¨4°Ó3ˆŒÜ—I‘I˜g t¨QÓ/ˆ�	r   c                 ó¬   — 	 | j                   j                  «        | j                  j                  «        y# | j                  j                  «        w xY w)zCloses both sides of the pipe.N)r.   Úcloser/   )r5   s    r   r:   z
Pipe.close“   s4   € ð	Ø�K‰K×ÑÔà�I‰I�O‰OÕøˆD�I‰I�O‰OÕús	   ‚7 ·AN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úclassmethodr0   r8   r:   © r   r   r*   r*   x   s%   „ ñð ñ!ó ð!ò0ór   r*   )r>   r   r   Ú	functoolsr   Úpyudev._ctypeslib.libcr   r   r   Úpyudev._ctypeslib.utilsr   Úgetattrr   r   r   r   r,   r   r   r*   r@   r   r   ú<module>rE      s^   ðñ"ó  Û 	Ý ÷ GÑ FÝ 7ñ �B˜ YÓ/€	òòò,ñ  
#Ó	$€ò1ò1÷ ò  r   