diff options
author | shmel1k <shmel1k@ydb.tech> | 2023-11-26 18:16:14 +0300 |
---|---|---|
committer | shmel1k <shmel1k@ydb.tech> | 2023-11-26 18:43:30 +0300 |
commit | b8cf9e88f4c5c64d9406af533d8948deb050d695 (patch) | |
tree | 218eb61fb3c3b96ec08b4d8cdfef383104a87d63 /contrib/python/Twisted/py2/twisted/internet/_win32stdio.py | |
parent | 523f645a83a0ec97a0332dbc3863bb354c92a328 (diff) | |
download | ydb-b8cf9e88f4c5c64d9406af533d8948deb050d695.tar.gz |
add kikimr_configure
Diffstat (limited to 'contrib/python/Twisted/py2/twisted/internet/_win32stdio.py')
-rw-r--r-- | contrib/python/Twisted/py2/twisted/internet/_win32stdio.py | 133 |
1 files changed, 133 insertions, 0 deletions
diff --git a/contrib/python/Twisted/py2/twisted/internet/_win32stdio.py b/contrib/python/Twisted/py2/twisted/internet/_win32stdio.py new file mode 100644 index 0000000000..6ce3aadda2 --- /dev/null +++ b/contrib/python/Twisted/py2/twisted/internet/_win32stdio.py @@ -0,0 +1,133 @@ +# -*- test-case-name: twisted.test.test_stdio -*- + +""" +Windows-specific implementation of the L{twisted.internet.stdio} interface. +""" + +from __future__ import absolute_import, division + +import win32api +import os +import msvcrt + +from zope.interface import implementer + +from twisted.internet.interfaces import (IHalfCloseableProtocol, ITransport, + IConsumer, IPushProducer, IAddress) + +from twisted.internet import _pollingfile, main +from twisted.python.failure import Failure + +@implementer(IAddress) +class Win32PipeAddress(object): + pass + + +@implementer(ITransport, IConsumer, IPushProducer) +class StandardIO(_pollingfile._PollingTimer): + + disconnecting = False + disconnected = False + + def __init__(self, proto, reactor=None): + """ + Start talking to standard IO with the given protocol. + + Also, put it stdin/stdout/stderr into binary mode. + """ + if reactor is None: + from 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) + + + def dataReceived(self, data): + self.proto.dataReceived(data) + + + def readConnectionLost(self): + if IHalfCloseableProtocol.providedBy(self.proto): + self.proto.readConnectionLost() + self.checkConnLost() + + + def writeConnectionLost(self): + if IHalfCloseableProtocol.providedBy(self.proto): + self.proto.writeConnectionLost() + self.checkConnLost() + + connsLost = 0 + + + def checkConnLost(self): + self.connsLost += 1 + if self.connsLost >= 2: + self.disconnecting = True + self.disconnected = True + self.proto.connectionLost(Failure(main.CONNECTION_DONE)) + + # ITransport + + def write(self, data): + self.stdout.write(data) + + + def writeSequence(self, seq): + self.stdout.write(b''.join(seq)) + + + def loseConnection(self): + self.disconnecting = True + self.stdin.close() + self.stdout.close() + + + def getPeer(self): + return Win32PipeAddress() + + + def getHost(self): + return Win32PipeAddress() + + # IConsumer + + def registerProducer(self, producer, streaming): + return self.stdout.registerProducer(producer, streaming) + + + def unregisterProducer(self): + return self.stdout.unregisterProducer() + + # def write() above + + # IProducer + + def stopProducing(self): + self.stdin.stopProducing() + + # IPushProducer + + def pauseProducing(self): + self.stdin.pauseProducing() + + + def resumeProducing(self): + self.stdin.resumeProducing() |