Ϫf dZddlZddlZ ddlZeZddlmZmZdZ dZ edxZ Z ndZ dZ d Z d Zgd Zy#e$rdZY0wxYw) z< Utility functions for dealing with POSIX file descriptors. N)CONNECTION_DONECONNECTION_LOSTctj|tj}|tjz}tj|tj|y)zP Set the file description of the given file descriptor to non-blocking. NfcntlF_GETFLos O_NONBLOCKF_SETFLfdflagss 8/usr/lib/python3/dist-packages/twisted/internet/fdesc.pysetNonBlockingrs: KKEMM *E BMM !E KKEMM5)ctj|tj}|tjz}tj|tj|y)zL Set the file description of the given file descriptor to blocking. Nrr s r setBlockingr!s< KKEMM *E R]]N "E KKEMM5)rcy)N)r s rr-srctj|tj}|tjz}tj|tj|yz7 Make a file descriptor close-on-exec. NrF_GETFD FD_CLOEXECF_SETFDr s r_setCloseOnExecr0s< B .((( B u-rctj|tj}|tjz}tj|tj|yrrr s r_unsetCloseOnExecr8s? B .)))) B u-rc tj|d}|stS||y#t$rD}|jdtj tj fvrYd}~ytcYd}~Sd}~wwxYw)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 readOSErrorargserrnoEAGAINEINTRrr)r callbackoutputioes r readFromFDr*Asb.#T"  V # 88A;5<<5 5 " " #s ) A6/A1&A1+A61A6c tj||S#t$rA}|jtjtj fvrYd}~yt cYd}~Sd}~wwxYw)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 writer"r$r%r&r)r dataios r writeToFDr/dsJxxD!!  88 ekk2 2s  A",AAA"A")rrr*r/)__doc__r$r r_fcntl ImportErrortwisted.internet.mainrrrrrrr*r/__all__rrrr5sy   EC** =+:9O'.. F* GU Es9AA