本文整理汇总了Python中twisted.internet.protocol.Factory.sdata方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.sdata方法的具体用法?Python Factory.sdata怎么用?Python Factory.sdata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.sdata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import sdata [as 别名]
def connect(sdata, command, username, host, port=22, key_file=None, password=None):
"""
Connect to an SSH host (as it happens, persistently).
"""
sdata.set_conn_state('connecting')
try:
keys = [Key.fromFile(key_file)] if key_file else None
except exceptions.IOError as e:
print('### key load error:', str(e))
push_failure_message(str(e), sdata)
return
endpoint = SSHCommandClientEndpoint.newConnection(
reactor, command, username, host, port=int(port),
keys=keys, password=password, ui=None,
knownHosts=PermissiveKnownHosts())
factory = Factory()
factory.protocol = LineProtocol
factory.sdata = sdata
d = endpoint.connect(factory)
# Very small race condition between here and the replacement
# in connectionMade() above, but I've never managed to hit it.
def disconnect():
sdata.log('Disconnecting while still attempting to connect, by request')
d.cancel()
sdata.transport_drop_cb = disconnect
d.addErrback(lambda reason: push_failure_message(reason, sdata))
return d