diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-25 12:54:32 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-08-25 13:03:33 +0300 |
commit | 4a64a813e1d34e732f35d8a65147974f76395a6f (patch) | |
tree | a8da0dede5213f85e45b95047cfbdcf5427cf0b7 /contrib/python/Twisted/py3/twisted/internet/_posixstdio.py | |
parent | e9bbee265681b79a9ef9795bdc84cf6996f9cfec (diff) | |
download | ydb-4a64a813e1d34e732f35d8a65147974f76395a6f.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/Twisted/py3/twisted/internet/_posixstdio.py')
-rw-r--r-- | contrib/python/Twisted/py3/twisted/internet/_posixstdio.py | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/contrib/python/Twisted/py3/twisted/internet/_posixstdio.py b/contrib/python/Twisted/py3/twisted/internet/_posixstdio.py index b7ef9cdac39..e99920ead3f 100644 --- a/contrib/python/Twisted/py3/twisted/internet/_posixstdio.py +++ b/contrib/python/Twisted/py3/twisted/internet/_posixstdio.py @@ -10,11 +10,16 @@ Future Plans:: Maintainer: James Y Knight """ +from __future__ import annotations from zope.interface import implementer -from twisted.internet import error, interfaces, process -from twisted.python import failure, log +from twisted.internet import interfaces, process +from twisted.internet.interfaces import IProtocol, IReactorFDSet +from twisted.logger import Logger +from twisted.python.failure import Failure + +_log = Logger() @implementer(interfaces.IAddress) @@ -34,10 +39,16 @@ class StandardIO: disconnected = False disconnecting = False - def __init__(self, proto, stdin=0, stdout=1, reactor=None): + def __init__( + self, + proto: IProtocol, + stdin: int = 0, + stdout: int = 1, + reactor: IReactorFDSet | None = None, + ): if reactor is None: - from twisted.internet import reactor - self.protocol = proto + from twisted.internet import reactor # type:ignore[assignment] + self.protocol: IProtocol = proto self._writer = process.ProcessWriter(reactor, self, "write", stdout) self._reader = process.ProcessReader(reactor, self, "read", stdin) @@ -75,21 +86,16 @@ class StandardIO: return PipeAddress() # Callbacks from process.ProcessReader/ProcessWriter - def childDataReceived(self, fd, data): + def childDataReceived(self, fd: str, data: bytes) -> None: self.protocol.dataReceived(data) - def childConnectionLost(self, fd, reason): + def childConnectionLost(self, fd: str, reason: Failure) -> None: if self.disconnected: return - - if reason.value.__class__ == error.ConnectionDone: - # Normal close - if fd == "read": - self._readConnectionLost(reason) - else: - self._writeConnectionLost(reason) + if fd == "read": + self._readConnectionLost(reason) else: - self.connectionLost(reason) + self._writeConnectionLost(reason) def connectionLost(self, reason): self.disconnected = True @@ -99,7 +105,7 @@ class StandardIO: _writer = self._writer protocol = self.protocol self._reader = self._writer = None - self.protocol = None + self.protocol = None # type:ignore[assignment] if _writer is not None and not _writer.disconnected: _writer.connectionLost(reason) @@ -107,12 +113,10 @@ class StandardIO: if _reader is not None and not _reader.disconnected: _reader.connectionLost(reason) - try: + with _log.failuresHandled("while calling stdio connectionLost:"): protocol.connectionLost(reason) - except BaseException: - log.err() - def _writeConnectionLost(self, reason): + def _writeConnectionLost(self, reason: Failure) -> None: self._writer = None if self.disconnecting: self.connectionLost(reason) @@ -120,21 +124,21 @@ class StandardIO: p = interfaces.IHalfCloseableProtocol(self.protocol, None) if p: - try: + with _log.failuresHandled( + "while calling stdio writeConnectionLost:" + ) as wcl: p.writeConnectionLost() - except BaseException: - log.err() - self.connectionLost(failure.Failure()) + if wcl.failed: + self.connectionLost(wcl.failure) - def _readConnectionLost(self, reason): + def _readConnectionLost(self, reason: Failure) -> None: self._reader = None p = interfaces.IHalfCloseableProtocol(self.protocol, None) if p: - try: + with _log.failuresHandled("while calling stdio readConnectionLost:") as rcl: p.readConnectionLost() - except BaseException: - log.err() - self.connectionLost(failure.Failure()) + if rcl.failed: + self.connectionLost(rcl.failure) else: self.connectionLost(reason) |