£Á°èZ¨Ä…–K§‚«“ô4“ÒÙ´dîfUÙÃÅ WKbyÊ¦•êŽ…È®FÒ¿ÊÎóCozá¬S@6{Í:›œêZÌ:Š•_%:¢¾¾~;‘Ã~èŠ©ÊÇí`ÔÑ©úë™µ'5I¿fš×WO%ø9¾«¾DK|€ùÍD”Ýs]nHÕ¶ê×Ó¼ãžªéUWŸÈË%DÒÕ¬ï‘]/Åcx  ‰ï2ß]ä6G[]S£ÔÏ¯rs{úëóµmÒï#UQxo·õÞCe]"±/aÙ&Eã4ú9Jé_ÞåëdãöKë)AÞ                  ¯¹ægƒÛowÐø^d™ý½ßB7áyMä9ÜÖUã
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<html>
3
u1W                 @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlm	Z	 ddl
mZ dd	l
mZ dd
l
mZ ddlmZ eeddZdd Zdd Zdd Ze Zdd Zdd ZG dd deZdS )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>
    )absolute_import)division)print_function)unicode_literalsN)partial)fd_pair)ERROR_CHECKERS)
SIGNATURES)load_ctypes_library	O_CLOEXECi   c             C   s"   t  }| j|| |d |d fS )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      )r   pipe2)libcflagsfds r   /usr/lib/python3.6/pipe.py_pipe2_ctypes4   s    	r   c             C   sX   t j }| t j@ dkr0x|D ]}t|t j qW | t@ dkrTx|D ]}t|t qBW |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   )ospipe
O_NONBLOCKset_fd_status_flagr   set_fd_flag)r   r   fdr   r   r   _pipe2_by_pipeB   s    

r   c              C   sN   t tdrtjS y$tdtt} t | dr2tt| S tS  t	k
rH   tS X dS )z]Find the appropriate implementation for ``pipe2``.

Return a function implementing ``pipe2``.r   r   N)
hasattrr   r   r
   r	   r   r   r   r   ImportError)r   r   r   r   _get_pipe2_implementationX   s    
r   c             C   s(   t j | t jd}t j | t j||B  dS )zwSet a flag on a file descriptor.

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

    r   N)fcntlZF_GETFDZF_SETFD)r   flagr   r   r   r   r   k   s    r   c             C   s(   t j | t jd}t j | t j||B  dS )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   ZF_GETFLZF_SETFL)r   r   r   r   r   r   r   u   s    r   c               @   s,   e Zd ZdZedd Zdd Zdd ZdS )	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             C   s   t tjtB \}}| ||S )zLOpen and return a new :class:`Pipe`.

        The pipe uses non-blocking IO.)_PIPE2r   r   r   )clssourcesinkr   r   r   open   s    z	Pipe.openc             C   s$   t j|dd| _t j|dd| _dS )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.rbr   wbN)r   fdopenr#   r$   )selfZ	source_fdZsink_fdr   r   r   __init__   s    zPipe.__init__c          
   C   s    z| j j  W d| jj  X dS )zCloses both sides of the pipe.N)r#   closer$   )r)   r   r   r   r+      s    z
Pipe.closeN)__name__
__module____qualname____doc__classmethodr%   r*   r+   r   r   r   r   r       s   	r    )r/   Z
__future__r   r   r   r   r   r   	functoolsr   Zpyudev._ctypeslib.libcr   r   r	   Zpyudev._ctypeslib.utilsr
   getattrr   r   r   r   r!   r   r   objectr    r   r   r   r   <module>    s&   

