• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python protocol.ClientCreator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中twisted.internet.protocol.ClientCreator的典型用法代码示例。如果您正苦于以下问题:Python ClientCreator类的具体用法?Python ClientCreator怎么用?Python ClientCreator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ClientCreator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: run

 def run(self):
     text = str(self.cmd.text())
     if text:
         self.output.clear()
         c = ClientCreator(reactor, NovacomRun, self)
         d = c.connectTCP('localhost', self.port)
         d.addCallback(cmd_run, True, text)
开发者ID:wosigh,项目名称:pydoctor,代码行数:7,代码来源:novatool.py


示例2: writeMetric

def writeMetric(metric_path, value, timestamp, host, port, username, password,
                vhost, exchange, spec=None, channel_number=1, ssl=False):

    if not spec:
        spec = txamqp.spec.load(os.path.normpath(
            os.path.join(os.path.dirname(__file__), 'amqp0-8.xml')))

    delegate = TwistedDelegate()

    connector = ClientCreator(reactor, AMQClient, delegate=delegate,
                              vhost=vhost, spec=spec)
    if ssl:
        from twisted.internet.ssl import ClientContextFactory
        conn = yield connector.connectSSL(host, port, ClientContextFactory())
    else:
        conn = yield connector.connectTCP(host, port)

    yield conn.authenticate(username, password)
    channel = yield conn.channel(channel_number)
    yield channel.channel_open()

    yield channel.exchange_declare(exchange=exchange, type="topic",
                                   durable=True, auto_delete=False)

    message = Content( "%f %d" % (value, timestamp) )
    message["delivery mode"] = 2

    channel.basic_publish(exchange=exchange, content=message, routing_key=metric_path)
    yield channel.channel_close()
开发者ID:3ofcoins,项目名称:graphite_stack,代码行数:29,代码来源:amqp_publisher.py


示例3: getList

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:eventable,项目名称:CalendarServer,代码行数:25,代码来源:agent.py


示例4: callCommand

def callCommand(signaler, host, port, user, password, command):
	print "at callCommand"
	print "Running", command, "at", host, port
	d = ClientCreator(reactor, ClientCommandTransport, signaler,
						user, password, command).connectTCP(host, int(port))

	d.addErrback(signaler.errback)
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:7,代码来源:sshRPC.py


示例5: connect

	def connect(self, server):
		self.disconnect()

		self.server = server

		if not server:
			return

		username = server.getUsername()
		if not username:
			username = 'anonymous'
			password = '[email protected]'
		else:
			password = server.getPassword()

		host = server.getAddress()
		passive = server.getPassive()
		port = server.getPort()
		timeout = 30 # TODO: make configurable

		# XXX: we might want to add a guard so we don't try to connect to another host while a previous attempt is not timed out

		if server.getConnectionType():
			try:
				ftps = ftplib.FTP_TLS()
				ftps.connect(host,port)
				ftps.login(username, password)
				ftps.prot_p()
				self.controlConnectionMade(ftps)
			except ftplib.all_errors as e:
				self.connectionFailed(e)
		else:
			creator = ClientCreator(reactor, FTPClient, username, password, passive = passive)
			creator.connectTCP(host, port, timeout).addCallback(self.controlConnectionMade).addErrback(self.connectionFailed)
开发者ID:ebazot,项目名称:FTPBrowser-enigma2,代码行数:34,代码来源:FTPBrowser.py


示例6: run

    def run(self):
        delegate = TwistedDelegate()
        cc = ClientCreator(reactor, AMQClient, delegate=delegate,
                           vhost=self.vhost, spec=self.specfile)

        connection = yield cc.connectTCP(self.host, self.port)
        yield connection.authenticate(self.user, self.password)

        channel = yield connection.channel(1)
        yield channel.channel_open()

        channel.queue_declare(queue="process_queue", durable=True)

        # yield channel.queue_bind(
        #     queue="process_queue", exchange="worker",
        #     routing_key="test_routing_key")

        yield channel.basic_consume(queue="process_queue", consumer_tag="test_consumer_tag", no_ack=True)

        queue = yield connection.queue("test_consumer_tag")
        while True:
            pkg = yield queue.get()
            msg = pickle.loads(pkg.content.body)
            print msg
            self.reply(channel, msg)
开发者ID:DrunkJedi,项目名称:twisted_smpp_client_server,代码行数:25,代码来源:worker.py


示例7: run

def run():
    # Create the client
    FTPClient.debug = 1
    creator = ClientCreator(reactor, FTPClient, "admin", '1', passive=1)
    creator.connectSSL("localhost", 2121,
            ssl.ClientContextFactory()).addCallback(connectionMade).addErrback(connectionFailed)
    reactor.run(installSignalHandlers=0)
开发者ID:dalinhuang,项目名称:gybprojects,代码行数:7,代码来源:ftp_client.py


示例8: connect

    def connect(self, user, targetserver):
        if targetserver not in self.ircd.servconfig["serverlinks"]:
            if user:
                user.sendMessage(irc.ERR_NOSUCHSERVER, targetserver, ":No link block exists")
            return

        def sendServerHandshake(protocol, password):
            protocol.callRemote(
                IntroduceServer,
                name=self.ircd.name,
                password=password,
                description=self.ircd.servconfig["server_description"],
                version=protocol_version,
                commonmodules=self.ircd.common_modules,
            )
            protocol.sentDataBurst = False

        servinfo = self.ircd.servconfig["serverlinks"][targetserver]
        if "ip" not in servinfo or "port" not in servinfo:
            return
        if "bindaddress" in servinfo and "bindport" in servinfo:
            bind = (servinfo["bindaddress"], servinfo["bindport"])
        else:
            bind = None
        creator = ClientCreator(reactor, ServerProtocol, self.ircd)
        if "ssl" in servinfo and servinfo["ssl"]:
            d = creator.connectSSL(servinfo["ip"], servinfo["port"], self.ircd.ssl_cert, bindAddress=bind)
        else:
            d = creator.connectTCP(servinfo["ip"], servinfo["port"], bindAddress=bind)
        d.addCallback(sendServerHandshake, servinfo["outgoing_password"])
开发者ID:smillaedler,项目名称:txircd,代码行数:30,代码来源:cmd_connect.py


示例9: __init__

	def __init__(self, host, port, path, fileOrName, username = 'anonymous', \
		password = '[email protected]', writeProgress = None, passive = True, \
		supportPartial = False, *args, **kwargs):

		timeout = 30

		# We need this later
		self.path = path
		self.resume = supportPartial

		# Initialize
		self.currentlength = 0
		self.totallength = None
		if writeProgress and type(writeProgress) is not list:
			writeProgress = [ writeProgress ]
		self.writeProgress = writeProgress

		# Output
		if isinstance(fileOrName, str):
			self.filename = fileOrName
			self.file = None
		else:
			self.file = fileOrName

		creator = ClientCreator(reactor, FTPClient, username, password, passive = passive)

		creator.connectTCP(host, port, timeout).addCallback(self.controlConnectionMade).addErrback(self.connectionFailed)

		self.deferred = defer.Deferred()
开发者ID:Johnny-Dopp,项目名称:enigma2-plugins,代码行数:29,代码来源:FTPProgressDownloader.py


示例10: connect_to_rez

 def connect_to_rez(rez_info):
     dyno_id = rez_info.get('dyno_id')
     cc = ClientCreator(reactor, ProcLiteProtocol)
     (cc.connectSSL(rez_info.get('host'),
                    self.settings['dynohost_rendezvous_port'],
                    ssl.ClientContextFactory()).
      addCallback(buildProtoCallback(dyno_id)))
开发者ID:boffbowsh,项目名称:gitmouth,代码行数:7,代码来源:session.py


示例11: initialise

    def initialise(self):
        self.perle = None

        c = ClientCreator(reactor, PerleProtocol, self, self.user, self.password, self.relay)
        deferred = c.connectTCP(self.ip, self.port)

        deferred.addCallbacks(self.connected, self.error)
开发者ID:Jonty,项目名称:doord,代码行数:7,代码来源:actuators.py


示例12: get_vbucket_data

def get_vbucket_data(host, port, vbucket, credentials):
    cli = ClientCreator(reactor, DcpProtocol, vbucket, credentials)
    conn = cli.connectTCP(host, port)
    conn.addCallback(lambda x: x.authenticate()) \
        .addCallback(lambda x: x.connect()) \
        .addCallback(lambda x: x.failover_request())
    reactor.run()
开发者ID:ricardinho,项目名称:couchbase-dcp,代码行数:7,代码来源:client.py


示例13: execute

def execute(host, port, df):
	d = ClientCreator(reactor, ClientCommandTransport, df,
					'root', '192168061', 'server',
					'/etc/init.d/ossec restart',
	).connectTCP(host, port)

	d.addErrback(df.errback, **{'how': False})
开发者ID:ComputerNetworks-UFRGS,项目名称:ManP2P-ng,代码行数:7,代码来源:healing.py


示例14: installPreware

 def installPreware(self):
     port = self.getActivePort()
     if port:
         print 'Install preware'
         c = ClientCreator(reactor, NovacomInstallIPKG, self, port)
         d = c.connectTCP('localhost', port)
         d.addCallback(cmd_installIPKG_URL, PREWARE)
开发者ID:wosigh,项目名称:pydoctor,代码行数:7,代码来源:novatool.py


示例15: do_connect

    def do_connect():
        """Connect and authenticate."""
        client_creator = ClientCreator(reactor, MemCacheProtocol)
        client = yield client_creator.connectTCP(host=host, port=port,
                                                 timeout=timeout)

        version = yield client.version()
开发者ID:mariusionescu,项目名称:conn-check,代码行数:7,代码来源:checks.py


示例16: connect_to_peer

 def connect_to_peer(contact):
   if contact == None:
     self.log("The host that published this file is no longer on-line.\n")
   else:
     c = ClientCreator(reactor, MetadataRequestProtocol, self.l)
     df = c.connectTCP(contact.address, contact.port)
     return df
开发者ID:darka,项目名称:p2pfs,代码行数:7,代码来源:file_sharing_service.py


示例17: main

def main(reactor):
    cc = ClientCreator(reactor, AMP)
    d = cc.connectTCP('localhost', 7805)
    d.addCallback(login, UsernamePassword("testuser", "examplepass"))
    d.addCallback(add)
    d.addCallback(display)
    return d
开发者ID:pombredanne,项目名称:epsilon,代码行数:7,代码来源:auth_client.py


示例18: sendCommand

def sendCommand(command):
    def test(d):
        print "Invio ->", command
        d.sendCommand(command)

    c = ClientCreator(reactor, Sender)
    c.connectTCP(HOST, PORT).addCallback(test)
开发者ID:sorryone,项目名称:baofeng_server,代码行数:7,代码来源:client-2.py


示例19: collect

    def collect(self):
        # Start connecting to carbon first, it's remote...
        carbon_c = ClientCreator(reactor, CarbonClient)
        carbon = carbon_c.connectTCP(*self.carbon_addr)

        munin_c = ClientCreator(reactor, MuninClient)
        try:
            munin = yield munin_c.connectTCP(*self.munin_addr)
        except Exception:
            log.err("Unable to connect to munin-node")
            return
        services = yield munin.do_list()
        stats = yield munin.collect_metrics(services)
        munin.do_quit()

        reverse_name = '.'.join(munin.node_name.split('.')[::-1])
        flattened = []
        for service, metrics in stats.iteritems():
            for metric, (value, timestamp) in metrics.iteritems():
                path = 'servers.%s.%s.%s' % (reverse_name, service, metric)
                flattened.append((path, (timestamp, value)))

        try:
            carbon = yield carbon
        except Exception:
            log.err("Unable to connect to carbon")
            return
        yield carbon.sendStats(flattened)
        carbon.transport.loseConnection()
开发者ID:stefanor,项目名称:txmunin-graphite,代码行数:29,代码来源:client.py


示例20: create_robot

def create_robot(cb):
    from consts import HOST, PORT
    from client import AppProtocol
    from user_manager import request_handler
    from twisted.internet.protocol import ClientCreator
    f = ClientCreator(reactor, AppProtocol, request_handler)
    f.connectTCP(HOST, PORT).addCallback(partial(cb))
开发者ID:TTXDM,项目名称:firstGame,代码行数:7,代码来源:admin.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python protocol.ClientFactory类代码示例发布时间:2022-05-27
下一篇:
Python protocol.makeConnection函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap