Пример #1
0
    def __init__(self, request, response, command, channel=channel):
        super(Command, self).__init__(channel=channel)

        self._request = request
        self._response = response
        self._command = command

        self._state = BUFFERING
        self._buffer = None

        self._p = Popen(
            command, shell=True, stdout=PIPE, stderr=PIPE,
            close_fds=True, preexec_fn=os.setsid
        )

        self._stdin = None
        if self._p.stdin is not None:
            self._stdin = File(self._p.stdin, channel="%s.stdin" % channel)
            self._stdin.register(self)

        self._stdout = File(self._p.stdout, channel="%s.stdout" % channel)
        self.addHandler(
            handler("eof", channel="%s.stdout" % channel)(self._on_stdout_eof)
        )
        self.addHandler(
            handler("read", channel="%s.stdout" % channel)(
                self._on_stdout_read
            )
        )
        self._stdout.register(self)
Пример #2
0
    def _on_source_connect(self, sock, host, port):
        """Explicitly defined connect Event Handler

        This evens is triggered by the underlying TCPServer Component when
        a new client connection has been made.

        Here we dynamically create a Client instance, registere it and add
        custom event handlers to handle the events of the newly created
        client. The client is registered with a unique channel per connection.
        """

        bind = 0
        channel = uuid()

        client = TCPClient(bind, channel=channel)
        client.register(self)

        self.addHandler(
            handler("disconnected", channel=channel)(_on_target_disconnected))

        self.addHandler(handler("ready", channel=channel)(_on_target_ready))

        self.addHandler(handler("read", channel=channel)(_on_target_read))

        self._clients[sock] = client
        self._sockets[client.channel] = sock
Пример #3
0
    def __init__(self, request, response, command, channel=channel):
        super(Command, self).__init__(channel=channel)

        self._request = request
        self._response = response
        self._command = command

        self._state = BUFFERING
        self._buffer = None

        self._p = Popen(
            command, shell=True, stdout=PIPE, stderr=PIPE,
            close_fds=True, preexec_fn=os.setsid
        )

        self._stdin = None
        if self._p.stdin is not None:
            self._stdin = File(self._p.stdin, channel="%s.stdin" % channel)
            self._stdin.register(self)

        self._stdout = File(self._p.stdout, channel="%s.stdout" % channel)
        self.addHandler(
            handler("eof", channel="%s.stdout" % channel)(self._on_stdout_eof)
        )
        self.addHandler(
            handler("read", channel="%s.stdout" % channel)(
                self._on_stdout_read
            )
        )
        self._stdout.register(self)
Пример #4
0
    def _on_source_connect(self, sock, host, port):
        """Explicitly defined connect Event Handler

        This evens is triggered by the underlying TCPServer Component when
        a new client connection has been made.

        Here we dynamically create a Client instance, registere it and add
        custom event handlers to handle the events of the newly created
        client. The client is registered with a unique channel per connection.
        """

        bind = 0
        channel = uuid()

        client = TCPClient(bind, channel=channel)
        client.register(self)

        self.addHandler(
            handler("disconnected", channel=channel)(_on_target_disconnected)
        )

        self.addHandler(
            handler("ready", channel=channel)(_on_target_ready)
        )

        self.addHandler(
            handler("read", channel=channel)(_on_target_read)
        )

        self._clients[sock] = client
        self._sockets[client.channel] = sock
Пример #5
0
    def start(self):
        self.p = Popen(
            self.args,
            cwd=self.cwd,
            shell=self.shell,
            stdin=PIPE,
            stderr=PIPE,
            stdout=PIPE
        )

        self.stderr = BytesIO()
        self.stdout = BytesIO()

        self._status = None

        self._stdin = File(
            self.p.stdin,
            channel="{0:d}.stdin".format(self.p.pid)
        ).register(self)

        self._stderr = File(
            self.p.stderr,
            channel="{0:d}.stderr".format(self.p.pid)
        ).register(self)

        self._stdout = File(
            self.p.stdout,
            channel="{0:d}.stdout".format(self.p.pid)
        ).register(self)

        self._stderr_read_handler = self.addHandler(
            handler("read", channel="{0:d}.stderr".format(self.p.pid))(
                self.__class__._on_stderr_read
            )
        )

        self._stdout_read_handler = self.addHandler(
            handler("read", channel="{0:d}.stdout".format(self.p.pid))(
                self.__class__._on_stdout_read
            )
        )

        self._stderr_closed_handler = self.addHandler(
            handler("closed", channel="{0:d}.stderr".format(self.p.pid))(
                self.__class__._on_stderr_closed
            )
        )

        self._stdout_closed_handler = self.addHandler(
            handler("closed", channel="{0:d}.stdout".format(self.p.pid))(
                self.__class__._on_stdout_closed
            )
        )

        self.fire(started(self))
Пример #6
0
    def start(self):
        self.p = Popen(
            self.args,
            cwd=self.cwd,
            shell=self.shell,
            stdin=PIPE,
            stderr=PIPE,
            stdout=PIPE
        )

        self.stderr = BytesIO()
        self.stdout = BytesIO()

        self._status = None

        self._stdin = File(
            self.p.stdin,
            channel="{0:d}.stdin".format(self.p.pid)
        ).register(self)

        self._stderr = File(
            self.p.stderr,
            channel="{0:d}.stderr".format(self.p.pid)
        ).register(self)

        self._stdout = File(
            self.p.stdout,
            channel="{0:d}.stdout".format(self.p.pid)
        ).register(self)

        self._stderr_read_handler = self.addHandler(
            handler("read", channel=self._stderr.channel)(
                lambda self, data: self.stderr.write(data)
            )
        )

        self._stdout_read_handler = self.addHandler(
            handler("read", channel=self._stdout.channel)(
                lambda self, data: self.stdout.write(data)
            )
        )

        self._stderr_closed_handler = self.addHandler(
            handler("closed", channel=self._stderr.channel)(
                lambda self: setattr(self, '_stderr_closed', True)
            )
        )

        self._stdout_closed_handler = self.addHandler(
            handler("closed", channel=self._stdout.channel)(
                lambda self: setattr(self, '_stdout_closed', True)
            )
        )

        self.fire(started(self))
Пример #7
0
    def start(self):
        self.p = Popen(self.args,
                       cwd=self.cwd,
                       shell=self.shell,
                       stdin=PIPE,
                       stderr=PIPE,
                       stdout=PIPE)

        self.stderr = BytesIO()
        self.stdout = BytesIO()

        self._status = None

        self._stdin = File(self.p.stdin,
                           channel="{0:d}.stdin".format(
                               self.p.pid)).register(self)

        self._stderr = File(self.p.stderr,
                            channel="{0:d}.stderr".format(
                                self.p.pid)).register(self)

        self._stdout = File(self.p.stdout,
                            channel="{0:d}.stdout".format(
                                self.p.pid)).register(self)

        self._stderr_read_handler = self.addHandler(
            handler("read", channel=self._stderr.channel)(
                lambda self, data: self.stderr.write(data)))

        self._stdout_read_handler = self.addHandler(
            handler("read", channel=self._stdout.channel)(
                lambda self, data: self.stdout.write(data)))

        self._stderr_closed_handler = self.addHandler(
            handler("closed", channel=self._stderr.channel)(
                lambda self: setattr(self, '_stderr_closed', True)))

        self._stdout_closed_handler = self.addHandler(
            handler("closed", channel=self._stdout.channel)(
                lambda self: setattr(self, '_stdout_closed', True)))

        self.fire(started(self))
Пример #8
0
    def start(self):
        self.p = Popen(self.args,
                       cwd=self.cwd,
                       shell=self.shell,
                       stdin=PIPE,
                       stderr=PIPE,
                       stdout=PIPE)

        self.stderr = BytesIO()
        self.stdout = BytesIO()

        self._status = None

        self._stdin = File(self.p.stdin,
                           channel="{0:d}.stdin".format(
                               self.p.pid)).register(self)

        self._stderr = File(self.p.stderr,
                            channel="{0:d}.stderr".format(
                                self.p.pid)).register(self)

        self._stdout = File(self.p.stdout,
                            channel="{0:d}.stdout".format(
                                self.p.pid)).register(self)

        self._stderr_read_handler = self.addHandler(
            handler("read", channel="{0:d}.stderr".format(self.p.pid))(
                self.__class__._on_stderr_read))

        self._stdout_read_handler = self.addHandler(
            handler("read", channel="{0:d}.stdout".format(self.p.pid))(
                self.__class__._on_stdout_read))

        self._stderr_closed_handler = self.addHandler(
            handler("closed", channel="{0:d}.stderr".format(self.p.pid))(
                self.__class__._on_stderr_closed))

        self._stdout_closed_handler = self.addHandler(
            handler("closed", channel="{0:d}.stdout".format(self.p.pid))(
                self.__class__._on_stdout_closed))

        self.fire(started(self))