本文整理汇总了Python中twisted.internet.protocol.ClientCreator方法的典型用法代码示例。如果您正苦于以下问题:Python protocol.ClientCreator方法的具体用法?Python protocol.ClientCreator怎么用?Python protocol.ClientCreator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.protocol
的用法示例。
在下文中一共展示了protocol.ClientCreator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def setUp(self):
"""
Set up a server and connect a client to it. Return a Deferred which
only fires once this is done.
"""
self.serverFactory = MyHCFactory()
self.serverFactory.protocolConnectionMade = defer.Deferred()
self.port = reactor.listenTCP(
0, self.serverFactory, interface="127.0.0.1")
self.addCleanup(self.port.stopListening)
addr = self.port.getHost()
creator = protocol.ClientCreator(reactor, MyHCProtocol)
clientDeferred = creator.connectTCP(addr.host, addr.port)
def setClient(clientProtocol):
self.clientProtocol = clientProtocol
clientDeferred.addCallback(setClient)
return defer.gatherResults([
self.serverFactory.protocolConnectionMade,
clientDeferred])
示例2: test_tooManyConnections
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def test_tooManyConnections(self):
"""
When the connection limit is reached, the server should send an
appropriate response
"""
self.factory.connectionLimit = 1
cc = protocol.ClientCreator(reactor, _BufferingProtocol)
d = cc.connectTCP("127.0.0.1", self.port.getHost().port)
@d.addCallback
def gotClient(proto):
return proto.d
@d.addCallback
def onConnectionLost(proto):
self.assertEqual(
b'421 Too many users right now, try again in a few minutes.'
b'\r\n',
proto.buffer)
return d
示例3: getList
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def getList():
# For the sample client, below:
from twisted.internet import reactor
from twisted.internet.protocol import ClientCreator
creator = ClientCreator(reactor, amp.AMP)
host = '127.0.0.1'
import sys
if len(sys.argv) > 1:
host = sys.argv[1]
d = creator.connectTCP(host, 62308)
def connected(ampProto):
return ampProto.callRemote(GatewayAMPCommand, command=command)
d.addCallback(connected)
def resulted(result):
return result['result']
d.addCallback(resulted)
def done(result):
print('Done: %s' % (result,))
reactor.stop()
d.addCallback(done)
reactor.run()
示例4: connectClass
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def connectClass(self, addr, port, klass, *args):
return protocol.ClientCreator(self.reactor, klass, *args).connectTCP(addr, port)
示例5: connectClass
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def connectClass(self, addr, port, klass, *args):
"""
Instantiate the outgoing connection.
This is overriden so that our sub-classed SOCKSv5Outgoing gets created,
and a proxy is optionally used for the outgoing connection.
"""
if self.pt_config.proxy:
instance = OBFSSOCKSv5OutgoingFactory(self)
return network.create_proxy_client(addr, port, self.pt_config.proxy, instance)
else:
return protocol.ClientCreator(reactor, OBFSSOCKSv5Outgoing, self).connectTCP(addr, port)
示例6: oscar_01_05
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def oscar_01_05(self, snac, d = None):
"""
data for a new service connection
d might be a deferred to be called back when the service is ready
"""
tlvs = readTLVs(snac[3][2:])
service = struct.unpack('!H',tlvs[0x0d])[0]
ip = tlvs[5]
cookie = tlvs[6]
#c = serviceClasses[service](self, cookie, d)
c = protocol.ClientCreator(reactor, serviceClasses[service], self, cookie, d)
def addService(x):
self.services[service] = x
c.connectTCP(ip, 5190).addCallback(addService)
#self.services[service] = c
示例7: connectToBOS
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def connectToBOS(self, server, port):
c = protocol.ClientCreator(reactor, self.BOSClass, self.username, self.cookie)
return c.connectTCP(server, int(port))
示例8: _startLogOn
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def _startLogOn(self, chatui):
logonDeferred = defer.Deferred()
cc = protocol.ClientCreator(reactor, IRCProto, self, chatui,
logonDeferred)
d = cc.connectTCP(self.host, self.port)
d.addErrback(logonDeferred.errback)
return logonDeferred
示例9: channelOpen
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def channelOpen(self, specificData):
cc = protocol.ClientCreator(reactor, SSHAgentForwardingLocal)
d = cc.connectUNIX(os.environ['SSH_AUTH_SOCK'])
d.addCallback(self._cbGotLocal)
d.addErrback(lambda x:self.loseConnection())
self.buf = ''
示例10: serviceStarted
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def serviceStarted(self):
if 'SSH_AUTH_SOCK' in os.environ and not self.options['noagent']:
log.msg('using agent')
cc = protocol.ClientCreator(reactor, agent.SSHAgentClient)
d = cc.connectUNIX(os.environ['SSH_AUTH_SOCK'])
d.addCallback(self._setAgent)
d.addErrback(self._ebSetAgent)
else:
userauth.SSHUserAuthClient.serviceStarted(self)
示例11: _connect
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def _connect(self):
"""
Connect to the server, which is often a third-party process.
Tries to reconnect if it fails because we have no way of determining
exactly when the port becomes available for listening -- we can only
know when the process starts.
"""
cc = protocol.ClientCreator(reactor, ConchTestForwardingPort, self,
self.data)
d = cc.connectTCP('127.0.0.1', self.port)
d.addErrback(self._ebConnect)
return d
示例12: connectClient
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def connectClient(self, address, portNumber, clientCreator):
"""
Establish a connection to the given address using the given
L{ClientCreator} instance.
@return: A Deferred which will fire with the connected protocol instance.
"""
raise NotImplementedError()
示例13: _makeDataConnection
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def _makeDataConnection(self, ignored=None):
"""
Establish a passive data connection (i.e. client connecting to
server).
@param ignored: ignored
@return: L{Deferred.addCallback}
"""
d = self.client.queueStringCommand('PASV')
def gotPASV(responseLines):
host, port = ftp.decodeHostPort(responseLines[-1][4:])
cc = protocol.ClientCreator(reactor, _BufferingProtocol)
return cc.connectTCP('127.0.0.1', port)
return d.addCallback(gotPASV)
示例14: test_FailedRETR
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def test_FailedRETR(self):
"""
RETR fails.
"""
f = protocol.Factory()
f.noisy = 0
port = reactor.listenTCP(0, f, interface="127.0.0.1")
self.addCleanup(port.stopListening)
portNum = port.getHost().port
# 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 twisted@twistedmatrix.com
'230 Login successful. Have fun.',
# TYPE I
'200 Binary it is, then.',
# PASV
'227 Entering Passive Mode (127,0,0,1,%d,%d)' %
(portNum >> 8, portNum & 0xff),
# RETR /file/that/doesnt/exist
'550 Failed to open file.']
f.buildProtocol = lambda addr: PrintLines(responses)
cc = protocol.ClientCreator(reactor, ftp.FTPClient, passive=1)
d = cc.connectTCP('127.0.0.1', portNum)
def gotClient(client):
p = protocol.Protocol()
return client.retrieveFile('/file/that/doesnt/exist', p)
d.addCallback(gotClient)
return self.assertFailure(d, ftp.CommandFailed)
示例15: download_request
# 需要导入模块: from twisted.internet import protocol [as 别名]
# 或者: from twisted.internet.protocol import ClientCreator [as 别名]
def download_request(self, request, spider):
parsed_url = urlparse_cached(request)
user = request.meta.get("ftp_user", self.default_user)
password = request.meta.get("ftp_password", self.default_password)
passive_mode = 1 if bool(request.meta.get("ftp_passive",
self.passive_mode)) else 0
creator = ClientCreator(reactor, FTPClient, user, password,
passive=passive_mode)
return creator.connectTCP(parsed_url.hostname, parsed_url.port or 21).addCallback(self.gotClient,
request, unquote(parsed_url.path))