当前位置: 首页>>代码示例>>Python>>正文


Python protocol.ClientCreator方法代码示例

本文整理汇总了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]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_tcp.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_ftp.py

示例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() 
开发者ID:apple,项目名称:ccs-calendarserver,代码行数:27,代码来源:agent.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:4,代码来源:socks5.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:socks.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:17,代码来源:oscar.py

示例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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:5,代码来源:oscar.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:ircsupport.py

示例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 = '' 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:8,代码来源:agent.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:default.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:14,代码来源:test_conch.py

示例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() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_tcp.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_ftp.py

示例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) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:33,代码来源:test_ftp.py

示例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)) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:12,代码来源:ftp.py


注:本文中的twisted.internet.protocol.ClientCreator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。