Esempio n. 1
0
    def __init__(self, proto):
        """
        Start talking to standard IO with the given protocol.

        Also, put it stdin/stdout/stderr into binary mode.
        """
        from reqs.twisted.internet import reactor

        for stdfd in range(0, 1, 2):
            msvcrt.setmode(stdfd, os.O_BINARY)

        _pollingfile._PollingTimer.__init__(self, reactor)
        self.proto = proto

        hstdin = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)
        hstdout = win32api.GetStdHandle(win32api.STD_OUTPUT_HANDLE)

        self.stdin = _pollingfile._PollableReadPipe(
            hstdin, self.dataReceived, self.readConnectionLost)

        self.stdout = _pollingfile._PollableWritePipe(
            hstdout, self.writeConnectionLost)

        self._addPollableResource(self.stdin)
        self._addPollableResource(self.stdout)

        self.proto.makeConnection(self)
Esempio n. 2
0
    def __init__(self, proto):
        """
        Start talking to standard IO with the given protocol.

        Also, put it stdin/stdout/stderr into binary mode.
        """
        from reqs.twisted.internet import reactor

        for stdfd in range(0, 1, 2):
            msvcrt.setmode(stdfd, os.O_BINARY)

        _pollingfile._PollingTimer.__init__(self, reactor)
        self.proto = proto

        hstdin = win32api.GetStdHandle(win32api.STD_INPUT_HANDLE)
        hstdout = win32api.GetStdHandle(win32api.STD_OUTPUT_HANDLE)

        self.stdin = _pollingfile._PollableReadPipe(hstdin, self.dataReceived,
                                                    self.readConnectionLost)

        self.stdout = _pollingfile._PollableWritePipe(hstdout,
                                                      self.writeConnectionLost)

        self._addPollableResource(self.stdin)
        self._addPollableResource(self.stdout)

        self.proto.makeConnection(self)
Esempio n. 3
0
    def test_checkWorkUnicode(self):
        """
        When one tries to pass unicode to L{_pollingfile._PollableWritePipe}, a
        C{TypeError} is raised instead of passing the data to C{WriteFile}
        call which is going to mangle it.
        """
        p = _pollingfile._PollableWritePipe(1, lambda: None)
        p.write("test")
        p.checkWork()

        p.write(u"test")
        self.assertRaises(TypeError, p.checkWork)
    def test_checkWorkUnicode(self):
        """
        When one tries to pass unicode to L{_pollingfile._PollableWritePipe}, a
        C{TypeError} is raised instead of passing the data to C{WriteFile}
        call which is going to mangle it.
        """
        p = _pollingfile._PollableWritePipe(1, lambda: None)
        p.write("test")
        p.checkWork()

        p.write(u"test")
        self.assertRaises(TypeError, p.checkWork)
Esempio n. 5
0
        win32file.CloseHandle(hStderrW)
        win32file.CloseHandle(hStdoutW)
        win32file.CloseHandle(hStdinR)

        # set up everything
        self.stdout = _pollingfile._PollableReadPipe(
            self.hStdoutR,
            lambda data: self.proto.childDataReceived(1, data),
            self.outConnectionLost)

        self.stderr = _pollingfile._PollableReadPipe(
                self.hStderrR,
                lambda data: self.proto.childDataReceived(2, data),
                self.errConnectionLost)

        self.stdin = _pollingfile._PollableWritePipe(
            self.hStdinW, self.inConnectionLost)

        for pipewatcher in self.stdout, self.stderr, self.stdin:
            self._addPollableResource(pipewatcher)


        # notify protocol
        self.proto.makeConnection(self)

        self._addPollableResource(_Reaper(self))


    def signalProcess(self, signalID):
        if self.pid is None:
            raise error.ProcessExitedAlready()
        if signalID in ("INT", "TERM", "KILL"):
        # close handles which only the child will use
        win32file.CloseHandle(hStderrW)
        win32file.CloseHandle(hStdoutW)
        win32file.CloseHandle(hStdinR)

        # set up everything
        self.stdout = _pollingfile._PollableReadPipe(
            self.hStdoutR, lambda data: self.proto.childDataReceived(1, data), self.outConnectionLost
        )

        self.stderr = _pollingfile._PollableReadPipe(
            self.hStderrR, lambda data: self.proto.childDataReceived(2, data), self.errConnectionLost
        )

        self.stdin = _pollingfile._PollableWritePipe(self.hStdinW, self.inConnectionLost)

        for pipewatcher in self.stdout, self.stderr, self.stdin:
            self._addPollableResource(pipewatcher)

        # notify protocol
        self.proto.makeConnection(self)

        self._addPollableResource(_Reaper(self))

    def signalProcess(self, signalID):
        if self.pid is None:
            raise error.ProcessExitedAlready()
        if signalID in ("INT", "TERM", "KILL"):
            win32process.TerminateProcess(self.hProcess, 1)