當前位置: 首頁>>代碼示例>>Python>>正文


Python stdio.StandardIO方法代碼示例

本文整理匯總了Python中twisted.internet.stdio.StandardIO方法的典型用法代碼示例。如果您正苦於以下問題:Python stdio.StandardIO方法的具體用法?Python stdio.StandardIO怎麽用?Python stdio.StandardIO使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.stdio的用法示例。


在下文中一共展示了stdio.StandardIO方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: cbServerGreeting

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def cbServerGreeting(proto, username, password):
    """
    Initial callback - invoked after the server sends us its greet message.
    """
    # Hook up stdio
    tp = TrivialPrompter()
    stdio.StandardIO(tp)

    # And make it easily accessible
    proto.prompt = tp.prompt
    proto.display = tp.display

    # Try to authenticate securely
    return proto.authenticate(
        password).addCallback(
        cbAuthentication, proto).addErrback(
        ebAuthentication, proto, username, password) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:19,代碼來源:imapclient.py

示例2: setUp

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def setUp(self):
        """
        Construct a L{StandardIOEndpoint} with a dummy reactor and a fake
        L{stdio.StandardIO} like object.  Listening on it with a
        L{SpecificFactory}.
        """
        self.reactor = object()
        endpoint = endpoints.StandardIOEndpoint(self.reactor)
        self.assertIs(endpoint._stdio, stdio.StandardIO)

        endpoint._stdio = FakeStdio
        self.specificProtocol = Protocol()

        self.fakeStdio = self.successResultOf(
            endpoint.listen(SpecificFactory(self.specificProtocol))
        ) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_endpoints.py

示例3: test_removeReader

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_removeReader(self):
        """
        Removing a filesystem file reader from a reactor will make sure it is
        no longer polled.
        """
        reactor = self.buildReactor()
        self.addCleanup(self.unbuildReactor, reactor)

        path = self.mktemp()
        open(path, "wb").close()

        with open(path, "rb") as f:
            # Have the reader added:
            stdio = StandardIO(Protocol(), stdin=f.fileno(),
                               stdout=self.extraFile.fileno(),
                               reactor=reactor)
            self.assertIn(stdio._reader, reactor.getReaders())
            stdio._reader.stopReading()
            self.assertNotIn(stdio._reader, reactor.getReaders()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:21,代碼來源:test_stdio.py

示例4: test_removeWriter

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_removeWriter(self):
        """
        Removing a filesystem file writer from a reactor will make sure it is
        no longer polled.
        """
        reactor = self.buildReactor()
        self.addCleanup(self.unbuildReactor, reactor)

        # Cleanup might fail if file is GCed too soon:
        self.f = f = open(self.mktemp(), "wb")

        # Have the reader added:
        protocol = Protocol()
        stdio = StandardIO(protocol, stdout=f.fileno(),
                           stdin=self.extraFile.fileno(),
                           reactor=reactor)
        protocol.transport.write(b"hello")
        self.assertIn(stdio._writer, reactor.getWriters())
        stdio._writer.stopWriting()
        self.assertNotIn(stdio._writer, reactor.getWriters()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_stdio.py

示例5: test_removeAll

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_removeAll(self):
        """
        Calling C{removeAll} on a reactor includes descriptors that are
        filesystem files.
        """
        reactor = self.buildReactor()
        self.addCleanup(self.unbuildReactor, reactor)

        path = self.mktemp()
        open(path, "wb").close()

        # Cleanup might fail if file is GCed too soon:
        self.f = f = open(path, "rb")

        # Have the reader added:
        stdio = StandardIO(Protocol(), stdin=f.fileno(),
                           stdout=self.extraFile.fileno(), reactor=reactor)
        # And then removed:
        removed = reactor.removeAll()
        self.assertIn(stdio._reader, removed)
        self.assertNotIn(stdio._reader, reactor.getReaders()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:23,代碼來源:test_stdio.py

示例6: test_getReaders

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_getReaders(self):
        """
        C{reactor.getReaders} includes descriptors that are filesystem files.
        """
        reactor = self.buildReactor()
        self.addCleanup(self.unbuildReactor, reactor)

        path = self.mktemp()
        open(path, "wb").close()

        # Cleanup might fail if file is GCed too soon:
        with open(path, "rb") as f:
            # Have the reader added:
            stdio = StandardIO(Protocol(), stdin=f.fileno(),
                               stdout=self.extraFile.fileno(), reactor=reactor)
            self.assertIn(stdio._reader, reactor.getReaders()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_stdio.py

示例7: test_getWriters

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_getWriters(self):
        """
        C{reactor.getWriters} includes descriptors that are filesystem files.
        """
        reactor = self.buildReactor()
        self.addCleanup(self.unbuildReactor, reactor)

        # Cleanup might fail if file is GCed too soon:
        self.f = f = open(self.mktemp(), "wb")

        # Have the reader added:
        stdio = StandardIO(Protocol(), stdout=f.fileno(),
                           stdin=self.extraFile.fileno(), reactor=reactor)
        self.assertNotIn(stdio._writer, reactor.getWriters())
        stdio._writer.startWriting()
        self.assertIn(stdio._writer, reactor.getWriters()) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_stdio.py

示例8: test_loseConnection

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_loseConnection(self):
        """
        Verify that a protocol connected to L{StandardIO} can disconnect
        itself using C{transport.loseConnection}.
        """
        errorLogFile = self.mktemp()
        log.msg("Child process logging to " + errorLogFile)
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion
        self._spawnProcess(p, b'stdio_test_loseconn', errorLogFile)

        def processEnded(reason):
            # Copy the child's log to ours so it's more visible.
            with open(errorLogFile, 'r') as f:
                for line in f:
                    log.msg("Child logged: " + line.rstrip())

            self.failIfIn(1, p.data)
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:22,代碼來源:test_stdio.py

示例9: test_consumer

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_consumer(self):
        """
        Verify that the transport of a protocol connected to L{StandardIO}
        is a working L{IConsumer} provider.
        """
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion

        junkPath = self._junkPath()

        self._spawnProcess(p, b'stdio_test_consumer', junkPath)

        def processEnded(reason):
            with open(junkPath, 'rb') as f:
                self.assertEqual(p.data[1], f.read())
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:19,代碼來源:test_stdio.py

示例10: main

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def main(**kwargs):
    app = QtApplication()
    qreactor.install()

    filename = kwargs.get('file', '-')
    frameless = kwargs.get('frameless', False)
    watch = kwargs.get('watch', False)

    if not frameless and not os.path.exists(filename):
        raise ValueError("File %s does not exist!" % filename)

    view = ViewerWindow(filename='-', frameless=frameless)
    view.protocol = ViewerProtocol(view, watch)
    view.show()
    app.deferred_call(lambda: StandardIO(view.protocol))
    app.deferred_call(view.protocol.handle_filename, filename)
    app.start() 
開發者ID:codelv,項目名稱:declaracad,代碼行數:19,代碼來源:viewer.py

示例11: test_loseConnection

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_loseConnection(self):
        """
        Verify that a protocol connected to L{StandardIO} can disconnect
        itself using C{transport.loseConnection}.
        """
        errorLogFile = self.mktemp()
        log.msg("Child process logging to " + errorLogFile)
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion
        self._spawnProcess(p, 'stdio_test_loseconn.py', errorLogFile)

        def processEnded(reason):
            # Copy the child's log to ours so it's more visible.
            for line in file(errorLogFile):
                log.msg("Child logged: " + line.rstrip())

            self.failIfIn(1, p.data)
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:21,代碼來源:test_stdio.py

示例12: test_lastWriteReceived

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_lastWriteReceived(self):
        """
        Verify that a write made directly to stdout using L{os.write}
        after StandardIO has finished is reliably received by the
        process reading that stdout.
        """
        p = StandardIOTestProcessProtocol()

        # Note: the OS X bug which prompted the addition of this test
        # is an apparent race condition involving non-blocking PTYs.
        # Delaying the parent process significantly increases the
        # likelihood of the race going the wrong way.  If you need to
        # fiddle with this code at all, uncommenting the next line
        # will likely make your life much easier.  It is commented out
        # because it makes the test quite slow.

        # p.onConnection.addCallback(lambda ign: __import__('time').sleep(5))

        try:
            self._spawnProcess(
                p, 'stdio_test_lastwrite.py', UNIQUE_LAST_WRITE_STRING,
                usePTY=True)
        except ValueError, e:
            # Some platforms don't work with usePTY=True
            raise unittest.SkipTest(str(e)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:27,代碼來源:test_stdio.py

示例13: test_consumer

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_consumer(self):
        """
        Verify that the transport of a protocol connected to L{StandardIO}
        is a working L{IConsumer} provider.
        """
        p = StandardIOTestProcessProtocol()
        d = p.onCompletion

        junkPath = self._junkPath()

        self._spawnProcess(p, 'stdio_test_consumer.py', junkPath)

        def processEnded(reason):
            self.assertEquals(p.data[1], file(junkPath).read())
            reason.trap(error.ProcessDone)
        return self._requireFailure(d, processEnded) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:18,代碼來源:test_stdio.py

示例14: __init__

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def __init__(self, protocolInstance, reactor=None):
        """
        @param protocolInstance: like the first argument of L{stdio.StandardIO}

        @param reactor: like the reactor keyword argument of
            L{stdio.StandardIO}
        """
        self.protocolInstance = protocolInstance
        self.reactor = reactor 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:test_endpoints.py

示例15: test_protocolCreation

# 需要導入模塊: from twisted.internet import stdio [as 別名]
# 或者: from twisted.internet.stdio import StandardIO [as 別名]
def test_protocolCreation(self):
        """
        L{StandardIOEndpoint} returns a L{Deferred} that fires with an instance
        of a L{stdio.StandardIO} like object that was passed the result of
        L{SpecificFactory.buildProtocol} which was passed a L{PipeAddress}.
        """
        self.assertIs(self.fakeStdio.protocolInstance,
                             self.specificProtocol)
        self.assertIsInstance(self.fakeStdio.protocolInstance.passedAddress,
                              PipeAddress) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:test_endpoints.py


注:本文中的twisted.internet.stdio.StandardIO方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。