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


Python defer.Deferred方法代码示例

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


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

示例1: __init__

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def __init__(self, penguin):
        self.penguin = penguin
        self.logger = logging.getLogger(TIMELINE_LOGGER)
        
        super(Refresh, self).__init__()

        self.logger.info("Penguin ASync-Refresh service initialized : Penguin - {}".format(self.penguin['nickname']))
        self.RefreshManagerLoop = LoopingCall(self._refresh)
        self.firstTimeCall = True
        self.CacheInitializedDefer = Deferred()
        self.cache = PenguinObject()

        self.penguin.penguin.data = self.cache # for easier access

        self.cacheHandlers = PenguinObject()

        self.logger.info("Penguin ASync-Refresh Loop started, every {}(s) : Penguin - {}".format
                         (self.REFRESH_INTERVAL, self.penguin['nickname']))

        self.RefreshManagerLoop.start(self.REFRESH_INTERVAL) 
开发者ID:Times-0,项目名称:Timeline,代码行数:22,代码来源:Refresh.py

示例2: _repair_key_docs

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def _repair_key_docs(self, doclist):
        """
        If there is more than one key for a key id try to self-repair it

        :return: a Deferred that will be fired with the valid key doc once all
                 the deletions are completed
        :rtype: Deferred
        """

        def log_key_doc(doc):
            self.log.error("\t%s: %s" % (doc.content[KEY_UIDS_KEY],
                                         doc.content[KEY_FINGERPRINT_KEY]))

        def cmp_key(d1, d2):
            return cmp(d1.content[KEY_REFRESHED_AT_KEY],
                       d2.content[KEY_REFRESHED_AT_KEY])

        return self._repair_docs(doclist, cmp_key, log_key_doc) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:20,代码来源:openpgp.py

示例3: isSubscribed

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def isSubscribed(self, name):
        """
        Returns True if user is subscribed to this mailbox.

        :param name: the mailbox to be checked.
        :type name: str

        :rtype: Deferred (will fire with bool)
        """
        name = normalize_mailbox(name)

        def get_subscribed(mbox):
            return mbox.collection.get_mbox_attr("subscribed")

        d = self.getMailbox(name)
        d.addCallback(get_subscribed)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:19,代码来源:account.py

示例4: subscribe

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def subscribe(self, name):
        """
        Subscribe to this mailbox if not already subscribed.

        :param name: name of the mailbox
        :type name: str
        :rtype: Deferred
        """
        name = normalize_mailbox(name)

        def set_subscribed(mbox):
            return mbox.collection.set_mbox_attr("subscribed", True)

        d = self.getMailbox(name)
        d.addCallback(set_subscribed)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:18,代码来源:account.py

示例5: unsubscribe

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def unsubscribe(self, name):
        """
        Unsubscribe from this mailbox

        :param name: name of the mailbox
        :type name: str
        :rtype: Deferred
        """
        # TODO should raise MailboxException if attempted to unsubscribe
        # from a mailbox that is not currently subscribed.
        # TODO factor out with subscribe method.
        name = normalize_mailbox(name)

        def set_unsubscribed(mbox):
            return mbox.collection.set_mbox_attr("subscribed", False)

        d = self.getMailbox(name)
        d.addCallback(set_unsubscribed)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:21,代码来源:account.py

示例6: send

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def send(self, recipient, message):
        self.log.info(
            'Connecting to SMTP server %s:%s' % (self._host, self._port))

        # we construct a defer to pass to the ESMTPSenderFactory
        d = defer.Deferred()
        # we don't pass an ssl context factory to the ESMTPSenderFactory
        # because ssl will be handled by reactor.connectSSL() below.
        factory = smtp.ESMTPSenderFactory(
            "",  # username is blank, no client auth here
            "",  # password is blank, no client auth here
            self._from_address,
            recipient.dest.addrstr,
            StringIO(message),
            d,
            heloFallback=True,
            requireAuthentication=False,
            requireTransportSecurity=True)
        factory.domain = bytes('leap.bitmask.mail-' + __version__)
        reactor.connectSSL(
            self._host, self._port, factory,
            contextFactory=SSLContextFactory(self._key, self._key))
        d.addCallback(lambda result: result[1][0][0])
        d.addErrback(self._send_errback)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:27,代码来源:sender.py

示例7: __init__

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def __init__(self, store, user_id, ready_cb=None):
        self.store = store
        self.user_id = user_id
        self.adaptor = self.adaptor_class()

        self.mbox_indexer = MailboxIndexer(self.store)

        # This flag is only used from the imap service for the moment.
        # In the future, we should prevent any public method to continue if
        # this is set to True. Also, it would be good to plug to the
        # authentication layer.
        self.session_ended = False

        self.deferred_initialization = defer.Deferred()
        self._ready_cb = ready_cb

        self._init_d = self._initialize_storage()
        self._initialize_sync_hooks() 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:20,代码来源:mail.py

示例8: initialize_store

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def initialize_store(self, store):
        """
        Initialize the indexes in the database.

        :param store: store
        :returns: a Deferred that will fire when the store is correctly
                  initialized.
        :rtype: deferred
        """
        # TODO I think we *should* get another deferredLock in here, but
        # global to the soledad namespace, to protect from several points
        # initializing soledad indexes at the same time.
        self._wait_for_indexes()

        d = self._init_indexes(store)
        d.addCallback(self._restore_waiting_methods)
        return d 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:19,代码来源:soledad.py

示例9: getReply

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def getReply(self, line, proto, transport):
        proto.lineReceived(line)

        if line[:4] not in ['HELO', 'MAIL', 'RCPT', 'DATA']:
            return succeed("")

        def check_transport(_):
            reply = transport.value()
            if reply:
                transport.clear()
                return succeed(reply)

            d = Deferred()
            d.addCallback(check_transport)
            reactor.callLater(0, lambda: d.callback(None))
            return d

        return check_transport(None) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:20,代码来源:test_gateway.py

示例10: main

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def main():
    hostname = raw_input('IMAP4 Server Hostname: ')
    port = raw_input('IMAP4 Server Port (the default is 143): ')
    username = raw_input('IMAP4 Username: ')
    password = util.getPassword('IMAP4 Password: ')

    onConn = defer.Deferred(
    ).addCallback(cbServerGreeting, username, password
                  ).addErrback(ebConnection
                               ).addBoth(cbClose)

    factory = SimpleIMAP4ClientFactory(username, onConn)

    from twisted.internet import reactor
    conn = reactor.connectTCP(hostname, int(port), factory)
    reactor.run() 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:18,代码来源:imapclient.py

示例11: start

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def start(klass, address, pdid, realm='paradrop', start_reactor=False,
              debug=False, extra=None, reconnect=True):
        '''
        Creates a new instance of this session and attaches it to the router
        at the given address and realm.

        reconnect: The session will attempt to reconnect on connection failure
            and continue trying indefinitely.
        '''
        # Enable log messages of autobahn for debugging
        #import txaio
        #txaio.start_logging()

        dee = Deferred()

        component_config = ComponentConfig(realm=u''+realm, extra=u''+pdid)
        session_factory = BaseSessionFactory(config=component_config, deferred=dee)
        session_factory.session = klass

        transport_factory = BaseClientFactory(session_factory, url=address)
        if not reconnect:
            transport_factory.maxRetries = 0
        transport_factory.setProtocolOptions(autoPingInterval=8., autoPingTimeout=4.,)
        context_factory = ClientContextFactory()
        websocket.connectWS(transport_factory, context_factory)

        if start_reactor:
            reactor.run()

        return dee

        # This the the recommended way to start the WAMP component,
        # but it is friendly to customize the component
        #runner = ApplicationRunner(url=u''+address, realm=u''+realm)
        #return runner.run(klass, start_reactor=start_reactor, auto_reconnect=reconnect) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:37,代码来源:cxbr.py

示例12: execute

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def execute(address, command):
    deferred = Deferred()
    consumer = SingleItemConsumer(deferred)

    protocol = HostapdControlProtocol(consumer, command=command)
    consumer.registerProducer(protocol, True)

    reactor.connectUNIXDatagram(address, protocol, bindAddress=protocol.bindAddress())
    return deferred 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:11,代码来源:hostapd_control.py

示例13: __init__

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def __init__(self, response, finished):
        """
        response: a twisted Response object
        finished: a Deferred object
        """
        self.response = response
        self.finished = finished
        self.data = "" 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:10,代码来源:http.py

示例14: receive

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def receive(self, response):
        """
        Receive response from twisted web client and convert it to a
        PDServerResponse object.
        """
        deferred = Deferred()
        response.deliverBody(JSONReceiver(response, deferred))
        return deferred 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:10,代码来源:http.py

示例15: wait_for_flow_control

# 需要导入模块: from twisted.internet import defer [as 别名]
# 或者: from twisted.internet.defer import Deferred [as 别名]
def wait_for_flow_control(self, stream_id):
        """
        Returns a Deferred that fires when the flow control window is opened.
        """
        d = Deferred()
        self._flow_control_deferreds[stream_id] = d
        return d 
开发者ID:python-hyper,项目名称:hyper-h2,代码行数:9,代码来源:twisted-server.py


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