<s> '''<STR_LIT>''' <EOL> import os <EOL> import operator <EOL> import six <EOL> import ctypes <EOL> import ctypes . util <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> c_loff_t = ctypes . c_long <EOL> c_ssize_t = getattr ( ctypes , '<STR_LIT>' , ctypes . c_long ) <EOL> class Tee ( object ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = '<STR_LIT>' , <EOL> def __init__ ( self ) : <EOL> libc = ctypes . CDLL ( ctypes . util . find_library ( '<STR_LIT:c>' ) , use_errno = True ) <EOL> try : <EOL> c_tee = libc . tee <EOL> except AttributeError : <EOL> self . _c_tee = None <EOL> return <EOL> c_tee . argtypes = [ <EOL> ctypes . c_int , <EOL> ctypes . c_int , <EOL> ctypes . c_size_t , <EOL> ctypes . c_uint <EOL> ] <EOL> c_tee . restype = c_ssize_t <EOL> def errcheck ( result , func , arguments ) : <EOL> if result == - <NUM_LIT:1> : <EOL> errno = ctypes . set_errno ( <NUM_LIT:0> ) <EOL> raise IOError ( errno , '<STR_LIT>' % os . strerror ( errno ) ) <EOL> else : <EOL> return result <EOL> c_tee . errcheck = errcheck <EOL> self . _c_tee = c_tee <EOL> def __call__ ( self , fd_in , fd_out , len_ , flags ) : <EOL> '''<STR_LIT>''' <EOL> if not self . available : <EOL> raise EnvironmentError ( '<STR_LIT>' ) <EOL> if not isinstance ( flags , six . integer_types ) : <EOL> c_flags = six . moves . reduce ( operator . or_ , flags , <NUM_LIT:0> ) <EOL> else : <EOL> c_flags = flags <EOL> c_fd_in = getattr ( fd_in , '<STR_LIT>' , lambda : fd_in ) ( ) <EOL> c_fd_out = getattr ( fd_out , '<STR_LIT>' , lambda : fd_out ) ( ) <EOL> return self . _c_tee ( c_fd_in , c_fd_out , len_ , c_flags ) <EOL> @ property <EOL> def available ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _c_tee is not None <EOL> tee = Tee ( ) <EOL> del Tee <EOL> class Splice ( object ) : <EOL> '''<STR_LIT>''' <EOL> SPLICE_F_MOVE = <NUM_LIT:1> <EOL> SPLICE_F_NONBLOCK = <NUM_LIT:2> <EOL> SPLICE_F_MORE = <NUM_LIT:4> <EOL> SPLICE_F_GIFT = <NUM_LIT:8> <EOL> __slots__ = '<STR_LIT>' , <EOL> def __init__ ( self ) : <EOL> libc = ctypes . CDLL ( ctypes . util . find_library ( '<STR_LIT:c>' ) , use_errno = True ) <EOL> try : <EOL> c_splice = libc . splice <EOL> except AttributeError : <EOL> self . _c_splice = None <EOL> return <EOL> c_loff_t_p = ctypes . POINTER ( c_loff_t ) <EOL> c_splice . argtypes = [ <EOL> ctypes . c_int , c_loff_t_p , <EOL> ctypes . c_int , c_loff_t_p , <EOL> ctypes . c_size_t , <EOL> ctypes . c_uint <EOL> ] <EOL> c_splice . restype = c_ssize_t <EOL> def errcheck ( result , func , arguments ) : <EOL> if result == - <NUM_LIT:1> : <EOL> errno = ctypes . set_errno ( <NUM_LIT:0> ) <EOL> raise IOError ( errno , '<STR_LIT>' % os . strerror ( errno ) ) <EOL> else : <EOL> off_in = arguments [ <NUM_LIT:1> ] <EOL> off_out = arguments [ <NUM_LIT:3> ] <EOL> return ( <EOL> result , <EOL> off_in . contents . value if off_in is not None else None , <EOL> off_out . contents . value if off_out is not None else None ) <EOL> c_splice . errcheck = errcheck <EOL> self . _c_splice = c_splice <EOL> def __call__ ( self , fd_in , off_in , fd_out , off_out , len_ , flags ) : <EOL> '''<STR_LIT>''' <EOL> if not self . available : <EOL> raise EnvironmentError ( '<STR_LIT>' ) <EOL> if not isinstance ( flags , six . integer_types ) : <EOL> c_flags = six . moves . reduce ( operator . or_ , flags , <NUM_LIT:0> ) <EOL> else : <EOL> c_flags = flags <EOL> c_fd_in = getattr ( fd_in , '<STR_LIT>' , lambda : fd_in ) ( ) <EOL> c_fd_out = getattr ( fd_out , '<STR_LIT>' , lambda : fd_out ) ( ) <EOL> c_off_in = ctypes . pointer ( c_loff_t ( off_in ) ) if off_in is not None else None <EOL> c_off_out = ctypes . pointer ( c_loff_t ( off_out ) ) if off_out is not None else None <EOL> return self . _c_splice ( <EOL> c_fd_in , c_off_in , c_fd_out , c_off_out , len_ , c_flags ) <EOL> @ property <EOL> def available ( self ) : <EOL> '''<STR_LIT>''' <EOL> return self . _c_splice is not None <EOL> splice = Splice ( ) <EOL> del Splice </s>
