__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ 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: ~ $
"""
Extend the regular Twisted reactor with event-handling features.
"""
import logging
import time

from twisted.internet.threads import deferToThread

from landscape.lib.format import format_object


class InvalidID(Exception):
    """Raised when an invalid ID is used with reactor.cancel_call()."""


class CallHookError(Exception):
    """Raised when hooking on a reactor incorrectly."""


class EventID:
    """Unique identifier for an event handler.

    @param event_type: Name of the event type handled by the handler.
    @param pair: Binary tuple C{(handler, priority)} holding the handler
        function and its priority.
    """

    def __init__(self, event_type, pair):
        self._event_type = event_type
        self._pair = pair


class EventHandlingReactorMixin:
    """Fire events identified by strings and register handlers for them.

    Note that event handlers are executed synchronously when the C{fire} method
    is called, so unit-tests can generally exercise events without needing to
    run the real Twisted reactor (except of course if the event handlers
    themselves contain asynchronous calls that need the Twisted reactor
    running).
    """

    def __init__(self):
        super().__init__()
        self._event_handlers = {}

    def call_on(self, event_type, handler, priority=0):
        """Register an event handler.

        The handler will be invoked every time an event of the given type
        is fired (there's no need to re-register the handler after the
        event is fired).

        @param event_type: The name of the event type to handle.
        @param handler: The function handling the given event type.
        @param priority: The priority of the given handler function.

        @return: The L{EventID} of the registered handler.
        """
        pair = (handler, priority)

        handlers = self._event_handlers.setdefault(event_type, [])
        handlers.append(pair)
        handlers.sort(key=lambda pair: pair[1])

        return EventID(event_type, pair)

    def fire(self, event_type, *args, **kwargs):
        """Fire an event of a given type.

        Call all handlers registered for the given C{event_type}, in order
        of priority.

        @param event_type: The name of the event type to fire.
        @param args: Positional arguments to pass to the registered handlers.
        @param kwargs: Keyword arguments to pass to the registered handlers.
        """
        logging.debug("Started firing %s.", event_type)
        results = []
        # Make a copy of the handlers that are registered at this point in
        # time, so we have a stable list in case handlers are cancelled
        # dynamically by executing the handlers themselves.
        handlers = list(self._event_handlers.get(event_type, ()))
        for handler, priority in handlers:
            try:
                logging.debug(
                    "Calling %s for %s with priority %d.",
                    format_object(handler),
                    event_type,
                    priority,
                )
                results.append(handler(*args, **kwargs))
            except KeyboardInterrupt:
                logging.exception(
                    "Keyboard interrupt while running event "
                    "handler %s for event type %r with "
                    "args %r %r.",
                    format_object(handler),
                    event_type,
                    args,
                    kwargs,
                )
                self.stop()
                raise
            except Exception:
                logging.exception(
                    "Error running event handler %s for "
                    "event type %r with args %r %r.",
                    format_object(handler),
                    event_type,
                    args,
                    kwargs,
                )
        logging.debug("Finished firing %s.", event_type)
        return results

    def cancel_call(self, id):
        """Unregister an event handler.

        @param id: the L{EventID} of the handler to unregister.
        """
        if type(id) is EventID:
            self._event_handlers[id._event_type].remove(id._pair)
        else:
            raise InvalidID(f"EventID instance expected, received {id!r}")


class ReactorID:
    def __init__(self, timeout):
        self._timeout = timeout


class EventHandlingReactor(EventHandlingReactorMixin):
    """Wrap and add functionalities to the Twisted reactor.

    This is essentially a facade around the twisted.internet.reactor and
    will delegate to it for mostly everything except event handling features
    which are implemented using EventHandlingReactorMixin.
    """

    def __init__(self):
        from twisted.internet import reactor
        from twisted.internet.task import LoopingCall

        self._LoopingCall = LoopingCall
        self._reactor = reactor
        self._cleanup()
        self.callFromThread = reactor.callFromThread
        super().__init__()

    def time(self):
        """Get current time.

        @see L{time.time}
        """
        return time.time()

    def call_later(self, *args, **kwargs):
        """Call a function later.

        Simply call C{callLater(*args, **kwargs)} and return its result.

        @see: L{twisted.internet.interfaces.IReactorTime.callLater}.

        """
        return self._reactor.callLater(*args, **kwargs)

    def call_every(self, seconds, f, *args, **kwargs):
        """Call a function repeatedly.

        Create a new L{twisted.internet.task.LoopingCall} object and
        start it.

        @return: the created C{LoopingCall} object.
        """
        lc = self._LoopingCall(f, *args, **kwargs)
        lc.start(seconds, now=False)
        return lc

    def cancel_call(self, id):
        """Cancel a scheduled function or event handler.

        @param id: The function call or handler to remove. It can be an
            L{EventID}, a L{LoopingCall} or a C{IDelayedCall}, as returned
            by L{call_on}, L{call_every} and L{call_later} respectively.
        """
        if isinstance(id, EventID):
            return EventHandlingReactorMixin.cancel_call(self, id)
        if isinstance(id, self._LoopingCall):
            return id.stop()
        if id.active():
            id.cancel()

    def call_when_running(self, f):
        """Schedule a function to be called when the reactor starts running."""
        self._reactor.callWhenRunning(f)

    def call_in_main(self, f, *args, **kwargs):
        """Cause a function to be executed by the reactor thread.

        @param f: The callable object to execute.
        @param args: The arguments to call it with.
        @param kwargs: The keyword arguments to call it with.

        @see: L{twisted.internet.interfaces.IReactorThreads.callFromThread}
        """
        self._reactor.callFromThread(f, *args, **kwargs)

    def call_in_thread(self, callback, errback, f, *args, **kwargs):
        """
        Execute a callable object in a new separate thread.

        @param callback: A function to call in case C{f} was successful, it
            will be passed the return value of C{f}.
        @param errback: A function to call in case C{f} raised an exception,
            it will be pass a C{(type, value, traceback)} tuple giving
            information about the raised exception (see L{sys.exc_info}).

        @note: Both C{callback} and C{errback} will be executed in the
            the parent thread.
        """

        def on_success(result):
            if callback:
                return callback(result)

        def on_failure(failure):
            exc_info = (failure.type, failure.value, failure.tb)
            if errback:
                errback(*exc_info)
            else:
                logging.error(exc_info[1], exc_info=exc_info)

        deferred = deferToThread(f, *args, **kwargs)
        deferred.addCallback(on_success)
        deferred.addErrback(on_failure)

    def listen_unix(self, socket, factory):
        """Start listening on a Unix socket."""
        return self._reactor.listenUNIX(socket, factory, wantPID=True)

    def connect_unix(self, socket, factory):
        """Connect to a Unix socket."""
        return self._reactor.connectUNIX(socket, factory)

    def run(self):
        """Start the reactor, a C{"run"} event will be fired."""

        self.fire("run")
        self._reactor.run()
        self.fire("stop")

    def stop(self):
        """Stop the reactor, a C{"stop"} event will be fired."""
        self._reactor.stop()
        self._cleanup()

    def _cleanup(self):
        # Since the reactor is global, we should clean it up when we
        # initialize one of our wrappers.
        for call in self._reactor.getDelayedCalls():
            if call.active():
                call.cancel()

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
apt Folder 0755
__init__.py File 198 B 0644
amp.py File 21.87 KB 0644
backoff.py File 1.65 KB 0644
base64.py File 156 B 0644
bootstrap.py File 1.36 KB 0644
bpickle.py File 6.68 KB 0644
cli.py File 457 B 0644
cloud.py File 1.69 KB 0644
compat.py File 621 B 0644
config.py File 12.36 KB 0644
disk.py File 5.09 KB 0644
encoding.py File 545 B 0644
fd.py File 750 B 0644
fetch.py File 6.65 KB 0644
format.py File 1.96 KB 0644
fs.py File 3.8 KB 0644
gpg.py File 1.88 KB 0644
hashlib.py File 264 B 0644
jiffies.py File 1.59 KB 0644
juju.py File 828 B 0644
lock.py File 705 B 0644
log.py File 444 B 0644
logging.py File 2.94 KB 0644
machine_id.py File 1.02 KB 0644
message.py File 2.57 KB 0644
monitor.py File 6.19 KB 0644
network.py File 9.74 KB 0644
os_release.py File 1.78 KB 0644
persist.py File 20.57 KB 0644
plugin.py File 1.69 KB 0644
process.py File 6.66 KB 0644
reactor.py File 8.65 KB 0644
schema.py File 6.61 KB 0644
scriptcontent.py File 519 B 0644
sequenceranges.py File 5.58 KB 0644
store.py File 1.42 KB 0644
sysstats.py File 7.71 KB 0644
tag.py File 506 B 0644
testing.py File 24.48 KB 0644
timestamp.py File 233 B 0644
twisted_util.py File 4.54 KB 0644
user.py File 1.44 KB 0644
versioning.py File 1.25 KB 0644
vm_info.py File 3.12 KB 0644
warning.py File 393 B 0644
Filemanager