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


Python ClientCreator.addCallback方法代码示例

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


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

示例1: connectClient

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def connectClient(self):
     d = ClientCreator(reactor, txprotobuf.Protocol).connectTCP(self.port.getHost().host, self.port.getHost().port)
     def setProtocol(protocol):
         self.protocols.append(protocol)
         return protocol
     d.addCallback(setProtocol)
     return d
开发者ID:rense,项目名称:txprotobuf,代码行数:9,代码来源:test_service.py

示例2: connect

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def connect(self):
     spec = txamqp.spec.load(self.config.spec())
     delegate = TwistedDelegate()
     d = ClientCreator(reactor, AMQClient, delegate=delegate, vhost=self.config.vhost(), spec=spec)\
         .connectTCP(self.config.host(), self.config.port())
     d.addCallback(self.got_connection)
     self.d = defer.Deferred()
     yield self.d
开发者ID:k1nkreet,项目名称:txamqpwrap,代码行数:10,代码来源:txamqpwrap.py

示例3: __init__

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
    def __init__(self):
        spec = txamqp.spec.load('amqp-spec-0-9-1.xml')
        self.connected = False
        d = ClientCreator(reactor, AMQClient, delegate=TwistedDelegate(), vhost='/',
                spec=spec).connectTCP('127.0.0.1', 5672)
        d.addCallback(self.amqp_connected)

        self.flowCache = {}
        self.flowSeen = []
开发者ID:calston,项目名称:flowcloud,代码行数:11,代码来源:server.py

示例4: main

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
def main():
    creator = ClientCreator(reactor,
                          TTwisted.ThriftClientProtocol,
                          Infrastructure.Client,
                          TBinaryProtocol.TBinaryProtocolFactory(),
                          ).connectTCP(config.IAAS_INTERFACE_IPV4, config.IAAS_PORT)
    creator.addCallback(lambda conn: conn.client)
    creator.addCallback(connected)
    reactor.run()
开发者ID:jacksonicson,项目名称:paper.IS2015,代码行数:11,代码来源:test_iaas.py

示例5: callback

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
            def callback(res): # res zawiera dane serwera na ktorym moze byc klucz
                # podłączamy się do niego
                d1 = ClientCreator(reactor, amp.AMP).connectTCP(res['address'], res['port'])
                d1.addCallback(lambda p: p.callRemote(commands.Get, key=key))

                def trapError(result):
                    result.trap(Exception)
                    raise result.type()
                d1.addErrback(trapError)
                
                return d1 # deffer, który zawierać będzie wynik metody get na właściwym serwerze
开发者ID:grapo,项目名称:dht-database,代码行数:13,代码来源:server.py

示例6: setup

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
def setup(vm):
    print 'Connecting with new domain...'
    
    creator = ClientCreator(reactor,
                          TTwisted.ThriftClientProtocol,
                          RelayService.Client,
                          TBinaryProtocol.TBinaryProtocolFactory(),
                          ).connectTCP(DEFAULT_SETUP_IP, config.RELAY_PORT)
    creator.addCallback(lambda conn: conn.client)
    
    creator.addCallback(connection_established, vm)
    creator.addErrback(error, vm)
开发者ID:strategist922,项目名称:sonar,代码行数:14,代码来源:clone.py

示例7: addcall

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def addcall(self, obj, callback=None, **kwargs):
     d = ClientCreator(reactor, amp.AMP).connectTCP(self.address, self.port)
     d.addCallback(lambda p: p.callRemote(obj, **kwargs))
     if callback is None:
         def callback(res):
             print "Otrzymano: ", res
     d.addCallback(callback)
     def trapError(result):
         result.trap(Exception)
         print "Błąd!: {0}".format(result.type)
     d.addErrback(trapError)
     return d
开发者ID:grapo,项目名称:dht-database,代码行数:14,代码来源:client.py

示例8: connect

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def connect(self):
     d = ClientCreator(reactor,
             TTwisted.ThriftClientProtocol,
             Scheduler.Client,
             TBinaryProtocol.TBinaryProtocolFactory(),
         ).connectTCP(self.host, 
             self.port, self.timeout)
     d.addCallback(self.set_connect)
     d.addErrback(self.close_conn)
     log.msg("try connect to Master[%s:%s]" % \
         (self.host, self.port))
     return d
开发者ID:falood,项目名称:smart-buyer,代码行数:14,代码来源:masterclient.py

示例9: new_node

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def new_node(res2):
     # dostajemy jego db, i nastepnika
     self.node = Node(self.address, self.port, 
     self.key, loads(res2['stop']),
         Neighbor(loads(res2['node']), res2['address'], res2['port']), 
         Neighbor(res['node'], res['address'], res['port']),
         loads(res2['db']))
     # dodajemy node do ProtoFactory bo tego mu brakuje
     self.pf.node = self.node
     
     # kontaktujemy się z następnikiem i informujemy, że jesteśmy jego poprzednikiem
     d2 = ClientCreator(reactor, amp.AMP).connectTCP(res2['address'], res2['port'])
     d2.addCallback(lambda p: p.callRemote(commands.NewPrev, node=dumps(self.key), address=self.address, port=self.port))
开发者ID:grapo,项目名称:dht-database,代码行数:15,代码来源:server.py

示例10: start

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
    def start(self):
        vhost = self.amqp_conn['vhost']
        host = self.amqp_conn['host']
        port = self.amqp_conn['port']

        d = ClientCreator(reactor,
                          AMQClient,
                          delegate=TwistedDelegate(),
                          vhost=vhost,
                          spec=self.spec).connectTCP(host, port)

        d.addCallback(self.gotConnection)
        d.addErrback(self.whoops)
开发者ID:dmtmalin,项目名称:jasmin-smsdev,代码行数:15,代码来源:sms_logger.py

示例11: _try_connecting

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
def _try_connecting(domain, defer):
    '''
    Connects with the domain's Relay service. If it does not respond in 5 seconds
    it is assumed that the domain is not available right now 
    '''
    creator = ClientCreator(reactor,
                          TTwisted.ThriftClientProtocol,
                          RelayService.Client,
                          TBinaryProtocol.TBinaryProtocolFactory(),
                          ).connectTCP(domain, config.RELAY_PORT, timeout=10)
    creator.addCallback(lambda conn: conn.client)
    
    creator.addCallback(lambda value: defer.callback(True))
    creator.addErrback(lambda value: defer.callback(False))
开发者ID:jacksonicson,项目名称:paper.IS2015,代码行数:16,代码来源:clone.py

示例12: main

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
def main(all_args=None):
    """The main"""
    all_args = all_args or []
    parser = optparse.OptionParser()
    options, args = parse_cmd_line(parser, all_args)
    (port, example, message, count_, topics) = check_cmd_line(
        options, args, parser.error)

    host = 'localhost'
    vhost = '/'
    username = 'guest'
    password = 'guest'
    spec = txamqp.spec.load('your_specs_path.xml')

    delegate = TwistedDelegate()

    d = ClientCreator(reactor, AMQClient, delegate=delegate, vhost=vhost,
                      spec=spec).connectTCP(host, port)

    d.addCallback(gotConnection, username, password)
    if example in PUBLISH_EXAMPLES:
        d.addCallback(ALL_EXAMPLES[example], message, count_)
    else:
        d.addCallback(ALL_EXAMPLES[example], topics)
    d.addCallback(publisher_cleanup)
    d.addErrback(lambda f: sys.stderr.write(str(f)))
    reactor.run()
开发者ID:olegpshenichniy,项目名称:RabbitMQ-Python,代码行数:29,代码来源:rabbit.py

示例13: configure_domain

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def configure_domain(self, clone_entry):
     '''
     Reconfigures a domain by running the reconfiguration drone 
     '''
     
     print 'Connecting with new domain.'
     creator = ClientCreator(reactor,
                           TTwisted.ThriftClientProtocol,
                           RelayService.Client,
                           TBinaryProtocol.TBinaryProtocolFactory(),
                           ).connectTCP(DEFAULT_SETUP_IP, config.RELAY_PORT, timeout=10)
     creator.addCallback(lambda conn: conn.client)
     creator.addCallback(self._launch_drone, clone_entry)
     creator.addErrback(self._configuration_error, clone_entry)
开发者ID:jacksonicson,项目名称:paper.IS2015,代码行数:16,代码来源:configure.py

示例14: main

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
def main(all_args=None):
    """The main"""
    #    all_args = all_args or []
    #    parser = optparse.OptionParser()
    #    options, args = parse_cmd_line(parser, all_args)
    #    (port, example, message, count_, topics) = check_cmd_line(
    #        options, args, parser.error)

    host = "localhost"
    port = 5672
    vhost = "/"
    username = "guest"
    password = "guest"
    example = "publish2"
    topics = "#"
    message = "hello"
    count = 1000

    spec = txamqp.spec.load("./specs/rabbitmq/amqp0-8.stripped.rabbitmq.xml")

    delegate = TwistedDelegate()

    d = ClientCreator(reactor, AMQClient, delegate=delegate, vhost=vhost, spec=spec).connectTCP(host, port)

    d.addCallback(gotConnection, username, password)
    if example in PUBLISH_EXAMPLES:
        d.addCallback(ALL_EXAMPLES[example], message, count)
    else:
        d.addCallback(ALL_EXAMPLES[example], topics)
    d.addCallback(publisher_cleanup)
    d.addErrback(lambda f: sys.stderr.write(str(f)))
    reactor.run()
开发者ID:pushdotccgzs,项目名称:beaglebone-iot,代码行数:34,代码来源:txamqp-example.py

示例15: _makeNewProtocol

# 需要导入模块: from twisted.internet.protocol import ClientCreator [as 别名]
# 或者: from twisted.internet.protocol.ClientCreator import addCallback [as 别名]
 def _makeNewProtocol(self, tosend):
     import twisted.internet.reactor as reactor
     deferred = Deferred()
     def makeProtocol():
         return SoapProtocol(con=self.con)
     def sendPacket(protocol):
         if protocol is None:
             return # silently fail - log this? TODO
         protocol.sendPacket(tosend).addCallback(deferred.callback)
         return protocol
     conn_d = ClientCreator(reactor, makeProtocol).connectTCP(
             host=self.con._message_maker._host, port=self.con._message_maker._port)
     conn_d.addCallback(sendPacket)
     conn_d.addCallbacks(self._newProtocolConnected, self._onConnectionError)
     return deferred
开发者ID:alon,项目名称:burst,代码行数:17,代码来源:pynaoqi_twisted.py


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