o ¯b¥ ã@sždZddlZddlZzddlZWn eydZYnweZddlmZmZdd„Z dd„Z edur9dd „Z Z nd d „Z d d „Z dd„Z dd„Zgd¢ZdS)z< Utility functions for dealing with POSIX file descriptors. éN)ÚCONNECTION_DONEÚCONNECTION_LOSTcCs,t |tj¡}|tjB}t |tj|¡dS)zP Set the file description of the given file descriptor to non-blocking. N©ÚfcntlÚF_GETFLÚosÚ O_NONBLOCKÚF_SETFL©ÚfdÚflags©r ú8/usr/lib/python3/dist-packages/twisted/internet/fdesc.pyÚsetNonBlockingó rcCs.t |tj¡}|tj@}t |tj|¡dS)zL Set the file description of the given file descriptor to blocking. Nrr r r rÚ setBlocking!ó rcCsdS)Nr )r r r rÚ-srcCs,t |tj¡}|tjB}t |tj|¡dS©z7 Make a file descriptor close-on-exec. N©rÚF_GETFDÚ FD_CLOEXECÚF_SETFDr r r rÚ_setCloseOnExec0rrcCs.t |tj¡}|tj@}t |tj|¡dSrrr r r rÚ_unsetCloseOnExec8rrc Csrzt |d¡}Wn&ty.}z|jdtjtjfvr"WYd}~dStWYd}~Sd}~ww|s3tS||ƒdS)a Read from file descriptor, calling callback with resulting data. If successful, call 'callback' with a single argument: the resulting data. Returns same thing FileDescriptor.doRead would: CONNECTION_LOST, CONNECTION_DONE, or None. @type fd: C{int} @param fd: non-blocking file descriptor to be read from. @param callback: a callable which accepts a single argument. If data is read from the file descriptor it will be called with this data. Handling exceptions from calling the callback is up to the caller. Note that if the descriptor is still connected but no data is read, None will be returned but callback will not be called. @return: CONNECTION_LOST on error, CONNECTION_DONE when fd is closed, otherwise None. i rN) rÚreadÚOSErrorÚargsÚerrnoÚEAGAINÚEINTRrr)r ÚcallbackÚoutputÚioer r rÚ readFromFDAs€ü r$c CsXzt ||¡WSty+}z|jtjtjfvrWYd}~dStWYd}~Sd}~ww)a> Write data to file descriptor. Returns same thing FileDescriptor.writeSomeData would. @type fd: C{int} @param fd: non-blocking file descriptor to be written to. @type data: C{str} or C{buffer} @param data: bytes to write to fd. @return: number of bytes written, or CONNECTION_LOST. Nr)rÚwriterrrr r)r ÚdataÚior r rÚ writeToFDds €ýr()rrr$r()Ú__doc__rrrÚ_fcntlÚ ImportErrorÚtwisted.internet.mainrrrrrrr$r(Ú__all__r r r rÚs&  ÿ   #