PHP 8.5.2
Preview: _win32stdio.py Size: 3.04 KB
//lib/python3/dist-packages/twisted/internet/_win32stdio.py

# -*- test-case-name: twisted.test.test_stdio -*-

"""
Windows-specific implementation of the L{twisted.internet.stdio} interface.
"""


import msvcrt
import os

from zope.interface import implementer

import win32api

from twisted.internet import _pollingfile, main
from twisted.internet.interfaces import (
    IAddress,
    IConsumer,
    IHalfCloseableProtocol,
    IPushProducer,
    ITransport,
)
from twisted.python.failure import Failure


@implementer(IAddress)
class Win32PipeAddress:
    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()

Directory Contents

Dirs: 3 × Files: 57

Name Size Perms Modified Actions
- drwxr-xr-x 2026-01-08 12:56:22
Edit Download
test DIR
- drwxr-xr-x 2026-01-08 12:56:22
Edit Download
- drwxr-xr-x 2026-01-08 12:56:23
Edit Download
18.84 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
5.14 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
10.87 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
46.82 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
22.75 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.85 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
95.88 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
76.59 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.73 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
13.14 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.16 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.42 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.24 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.55 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
512 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
14.06 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
95.89 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
10.56 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1006 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
5.83 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
20.88 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
43.14 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
26.93 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
853 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.77 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
5.96 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
2.20 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.47 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1006 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
32.90 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
53.97 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
29.12 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.13 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.92 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
18.18 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
21.98 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.48 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
14.84 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
5.15 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.27 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.96 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
743 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download
12.29 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
12.61 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.39 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.97 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
8.49 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
1.99 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.88 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.82 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
9.46 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
14.06 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
70.68 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
11.31 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
4.69 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
3.04 KB lrw-r--r-- 2024-08-27 10:30:39
Edit Download
521 B lrw-r--r-- 2024-08-27 10:30:39
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).