本文整理汇总了Python中txtorcon.TorControlProtocol.outReceived方法的典型用法代码示例。如果您正苦于以下问题:Python TorControlProtocol.outReceived方法的具体用法?Python TorControlProtocol.outReceived怎么用?Python TorControlProtocol.outReceived使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类txtorcon.TorControlProtocol
的用法示例。
在下文中一共展示了TorControlProtocol.outReceived方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FakeReactorTcp
# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import outReceived [as 别名]
class FakeReactorTcp(FakeReactor):
implements(IReactorTCP)
failures = 0
_port_generator = port_generator()
def __init__(self, test):
self.protocol = TorControlProtocol()
self.protocol.connectionMade = lambda: None
self.transport = proto_helpers.StringTransport()
self.transport = FakeProcessTransport()
self.transport.protocol = self.protocol
def blam():
self.protocol.outReceived("Bootstrap")
self.transport.closeStdin = blam
self.protocol.makeConnection(self.transport)
FakeReactor.__init__(self, test, self.transport, lambda x: None)
def listenTCP(self, port, factory, **kwargs):
'''returns IListeningPort'''
if self.failures > 0:
self.failures -= 1
raise error.CannotListenError(None, None, None)
if port == 0:
port = self._port_generator.next()
p = FakeListeningPort(port)
p.factory = factory
p.startListening()
return p
def connectTCP(self, host, port, factory, timeout, bindAddress):
'''should return IConnector'''
# print "CONN", host, port, factory
# print dir(factory)
# print "XX", factory
r = tcp.Connector(host, port, factory, timeout, bindAddress, reactor=self)
# print dir(r)
def blam(*args):
print "BLAAAAAM", args
r.connect = blam
return r
示例2: FakeReactorTcp
# 需要导入模块: from txtorcon import TorControlProtocol [as 别名]
# 或者: from txtorcon.TorControlProtocol import outReceived [as 别名]
class FakeReactorTcp(object):
failures = 0
_port_generator = port_generator()
def __init__(self, test):
self.protocol = TorControlProtocol()
self.protocol.connectionMade = lambda: None
self.transport = proto_helpers.StringTransport()
self.transport.protocol = self.protocol
def blam():
self.protocol.outReceived(b"Bootstrap")
self.transport.closeStdin = blam
self.protocol.makeConnection(self.transport)
self.test = test
def spawnProcess(self, processprotocol, bin, args, env, path,
uid=None, gid=None, usePTY=None, childFDs=None):
self.protocol = processprotocol
self.protocol.makeConnection(self.transport)
self.transport.process_protocol = processprotocol
return self.transport
def addSystemEventTrigger(self, *args):
self.test.assertEqual(args[0], 'before')
self.test.assertEqual(args[1], 'shutdown')
# we know this is just for the temporary file cleanup, so we
# nuke it right away to avoid polluting /tmp by calling the
# callback now.
args[2]()
def listenTCP(self, port, factory, **kwargs):
'''returns IListeningPort'''
if self.failures > 0:
self.failures -= 1
raise error.CannotListenError(None, None, None)
if port == 0:
port = next(self._port_generator)
p = FakeListeningPort(port)
p.factory = factory
p.startListening()
return p
def connectTCP(self, host, port, factory, timeout, bindAddress):
'''should return IConnector'''
r = tcp.Connector(
host, port, factory, timeout,
bindAddress, reactor=self
)
def blam(*args):
print("BLAAAAAM", args)
r.connect = blam
return r
def connectUNIX(self, address, factory, timeout=30, checkPID=0):
'''should return IConnector'''
r = unix.Connector(
address, factory, timeout, self, checkPID,
)
def blam(*args):
print("BLAAAAAM", args)
r.connect = blam
return r