本文整理汇总了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)
示例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))
)
示例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())
示例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())
示例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())
示例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())
示例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())
示例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)
示例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)
示例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()
示例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)
示例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))
示例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)
示例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
示例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)