/usr/lib/python3/dist-packages/twisted/internet
NameSizeModeActions
iocpreactor/-0755rm
test/-0755rm
__pycache__/-0755rm
abstract.py192950644editdlrm
address.py52440644editdlrm
asyncioreactor.py111310644editdlrm
base.py473920644editdlrm
cfreactor.py174990644editdlrm
default.py18930644editdlrm
defer.py856540644editdlrm
endpoints.py774400644editdlrm
epollreactor.py89410644editdlrm
error.py134820644editdlrm
fdesc.py32370644editdlrm
gireactor.py46200644editdlrm
glib2reactor.py11150644editdlrm
gtk2reactor.py36400644editdlrm
gtk3reactor.py15270644editdlrm
inotify.py143960644editdlrm
interfaces.py980480644editdlrm
kqreactor.py108180644editdlrm
main.py10060644editdlrm
pollreactor.py59740644editdlrm
posixbase.py276040644editdlrm
process.py385160644editdlrm
protocol.py273910644editdlrm
pyuisupport.py8430644editdlrm
reactor.py18160644editdlrm
selectreactor.py61020644editdlrm
serialport.py22720644editdlrm
ssl.py86430644editdlrm
stdio.py10000644editdlrm
task.py336080644editdlrm
tcp.py549800644editdlrm
testing.py292320644editdlrm
threads.py38120644editdlrm
tksupport.py19710644editdlrm
udp.py186190644editdlrm
unix.py225080644editdlrm
utils.py86820644editdlrm
win32eventreactor.py152660644editdlrm
wxreactor.py53150644editdlrm
wxsupport.py13050644editdlrm
_baseprocess.py20030644editdlrm
_dumbwin32proc.py127760644editdlrm
_glibbase.py127060644editdlrm
_idna.py14220644editdlrm
_newtls.py91570644editdlrm
_pollingfile.py87910644editdlrm
_posixserialport.py20810644editdlrm
_posixstdio.py49960644editdlrm
_producer_helpers.py39090644editdlrm
_resolver.py84650644editdlrm
_signals.py26700644editdlrm
_sslverify.py727960644editdlrm
_threadedselect.py115820644editdlrm
_win32serialport.py49140644editdlrm
_win32stdio.py31400644editdlrm
__init__.py5210644editdlrm
Edit: /usr/lib/python3/dist-packages/twisted/internet/fdesc.py (3237B)
# -*- test-case-name: twisted.test.test_fdesc -*- # Copyright (c) Twisted Matrix Laboratories. # See LICENSE for details. """ Utility functions for dealing with POSIX file descriptors. """ import errno import os try: import fcntl as _fcntl except ImportError: fcntl = None else: fcntl = _fcntl # twisted imports from twisted.internet.main import CONNECTION_DONE, CONNECTION_LOST def setNonBlocking(fd): """ Set the file description of the given file descriptor to non-blocking. """ flags = fcntl.fcntl(fd, fcntl.F_GETFL) flags = flags | os.O_NONBLOCK fcntl.fcntl(fd, fcntl.F_SETFL, flags) def setBlocking(fd): """ Set the file description of the given file descriptor to blocking. """ flags = fcntl.fcntl(fd, fcntl.F_GETFL) flags = flags & ~os.O_NONBLOCK fcntl.fcntl(fd, fcntl.F_SETFL, flags) if fcntl is None: # fcntl isn't available on Windows. By default, handles aren't # inherited on Windows, so we can do nothing here. _setCloseOnExec = _unsetCloseOnExec = lambda fd: None else: def _setCloseOnExec(fd): """ Make a file descriptor close-on-exec. """ flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags = flags | fcntl.FD_CLOEXEC fcntl.fcntl(fd, fcntl.F_SETFD, flags) def _unsetCloseOnExec(fd): """ Make a file descriptor close-on-exec. """ flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags = flags & ~fcntl.FD_CLOEXEC fcntl.fcntl(fd, fcntl.F_SETFD, flags) def readFromFD(fd, callback): """ 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. """ try: output = os.read(fd, 8192) except OSError as ioe: if ioe.args[0] in (errno.EAGAIN, errno.EINTR): return else: return CONNECTION_LOST if not output: return CONNECTION_DONE callback(output) def writeToFD(fd, data): """ 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. """ try: return os.write(fd, data) except OSError as io: if io.errno in (errno.EAGAIN, errno.EINTR): return 0 return CONNECTION_LOST __all__ = ["setNonBlocking", "setBlocking", "readFromFD", "writeToFD"]