本文整理汇总了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)
示例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)
示例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
示例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
示例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
示例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
示例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()
示例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
示例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)
示例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()
示例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)
示例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
示例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 = ""
示例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
示例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