本文整理汇总了Python中twisted.internet.protocol.Factory.noisy方法的典型用法代码示例。如果您正苦于以下问题:Python Factory.noisy方法的具体用法?Python Factory.noisy怎么用?Python Factory.noisy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol.Factory
的用法示例。
在下文中一共展示了Factory.noisy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sign
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import noisy [as 别名]
def sign(self, challenge):
if "SSH_AUTH_SOCK" not in os.environ:
raise Exception("no ssh-agent is running!")
factory = Factory()
factory.noisy = False
factory.protocol = SSHAgentClient
endpoint = UNIXClientEndpoint(self._reactor, os.environ["SSH_AUTH_SOCK"])
d = endpoint.connect(factory)
@inlineCallbacks
def on_connect(agent):
# we are now connected to the locally running ssh-agent
# that agent might be the openssh-agent, or eg on Ubuntu 14.04 by
# default the gnome-keyring / ssh-askpass-gnome application
blob = pack(['ssh-ed25519', self.public_key(binary=True)])
# now ask the agent
signature_blob = yield agent.signData(blob, challenge)
algo, signature = unpack(signature_blob)
agent.transport.loseConnection()
returnValue(signature)
return d.addCallback(on_connect)
示例2: new
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import noisy [as 别名]
def new(cls, pubkey=None, reactor=None):
"""
Create a proxy for a key held in SSH agent.
:param pubkey: A string with a public Ed25519 key in SSH format.
:type pubkey: unicode
"""
pubkey = _read_ssh_ed25519_pubkey(pubkey)
if not reactor:
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.protocol import Factory
from twisted.internet.endpoints import UNIXClientEndpoint
from twisted.conch.ssh.agent import SSHAgentClient
if "SSH_AUTH_SOCK" not in os.environ:
raise Exception("no ssh-agent is running!")
factory = Factory()
factory.noisy = False
factory.protocol = SSHAgentClient
endpoint = UNIXClientEndpoint(reactor, os.environ["SSH_AUTH_SOCK"])
d = endpoint.connect(factory)
@inlineCallbacks
def on_connect(agent):
keys = yield agent.requestIdentities()
# if the key is found in ssh-agent, the raw public key (32 bytes), and the
# key comment as returned from ssh-agent
key_data = None
key_comment = None
for blob, comment in keys:
raw = unpack(blob)
algo = raw[0]
if algo == u'ssh-ed25519':
algo, _pubkey = raw
if _pubkey == pubkey:
key_data = _pubkey
key_comment = comment.decode('utf8')
break
agent.transport.loseConnection()
if key_data:
key = signing.VerifyKey(key_data)
returnValue(cls(key, key_comment, reactor))
else:
raise Exception("Ed25519 key not held in ssh-agent")
return d.addCallback(on_connect)
示例3: testFailedRETR
# 需要导入模块: from twisted.internet.protocol import Factory [as 别名]
# 或者: from twisted.internet.protocol.Factory import noisy [as 别名]
def testFailedRETR(self):
try:
f = Factory()
f.noisy = 0
f.protocol = Protocol
port = reactor.listenTCP(0, f, interface="127.0.0.1")
n = port.getHost()[2]
# This test data derived from a bug report by ranty on #twisted
responses = ['220 ready, dude (vsFTPd 1.0.0: beat me, break me)',
# USER anonymous
'331 Please specify the password.',
# PASS [email protected]
'230 Login successful. Have fun.',
# TYPE I
'200 Binary it is, then.',
# PASV
'227 Entering Passive Mode (127,0,0,1,%d,%d)' %
(n>>8, n&0xff),
# RETR /file/that/doesnt/exist
'550 Failed to open file.']
b = StringIOWithoutClosing()
client = ftp.FTPClient(passive=1)
client.makeConnection(FileWrapper(b))
self.writeResponses(client, responses)
p = Protocol()
d = client.retrieveFile('/file/that/doesnt/exist', p)
d.addCallback(lambda r, self=self:
self.fail('Callback incorrectly called: %r' % r))
d.addBoth(lambda ignored,r=reactor: r.crash())
id = reactor.callLater(2, self.timeout)
reactor.run()
log.flushErrors(ftp.FTPError)
try:
id.cancel()
except:
pass
finally:
try:
port.stopListening()
reactor.iterate()
except:
pass