我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用twisted.internet.defer.gatherResults()。
def render_POST(self, request): paths = request.args['paths[]'] def got_data(responses): reply = {} for path, data in zip(paths, responses): try: reply[path] = data['result'] except KeyError: reply[path] = data['error'] request.sdata.add_to_push_queue('explorer', text=dumps(reply)) request.sdata.log('got reply {}'.format(paths)) reqs = map(request.sdata.api.get_schema, paths) d = defer.gatherResults(reqs) d.addCallback(got_data) request.setHeader('Content-Type', 'application/json') return '{}'
def testWriter(self): f = protocol.Factory() f.protocol = WriterProtocol f.done = 0 f.problem = 0 wrappedF = WiredFactory(f) p = reactor.listenTCP(0, wrappedF, interface="127.0.0.1") n = p.getHost().port self.ports.append(p) clientF = WriterClientFactory() wrappedClientF = WiredFactory(clientF) reactor.connectTCP("127.0.0.1", n, wrappedClientF) def check(ignored): self.failUnless(f.done, "writer didn't finish, it probably died") self.failUnless(f.problem == 0, "writer indicated an error") self.failUnless(clientF.done, "client didn't see connection dropped") expected = "".join(["Hello Cleveland!\n", "Goodbye", " cruel", " world", "\n"]) self.failUnless(clientF.data == expected, "client didn't receive all the data it expected") d = defer.gatherResults([wrappedF.onDisconnect, wrappedClientF.onDisconnect]) return d.addCallback(check)
def _testPool_3(self, res): sql = "select count(1) from simple" inserts = [] # add some rows to simple table (runOperation) for i in range(self.num_iterations): sql = "insert into simple(x) values(%d)" % i inserts.append(self.dbpool.runOperation(sql)) d = defer.gatherResults(inserts) def _select(res): # make sure they were added (runQuery) sql = "select x from simple order by x"; d = self.dbpool.runQuery(sql) return d d.addCallback(_select) def _check(rows): self.failUnless(len(rows) == self.num_iterations, "Wrong number of rows") for i in range(self.num_iterations): self.failUnless(len(rows[i]) == 1, "Wrong size row") self.failUnless(rows[i][0] == i, "Values not returned.") d.addCallback(_check) return d
def testPIDFile(self): filename = self.mktemp() f = Factory(self, filename) l = reactor.listenUNIX(filename, f, mode = 0600, wantPID=1) self.failUnless(lockfile.isLocked(filename + ".lock")) tcf = TestClientFactory(self, filename) c = reactor.connectUNIX(filename, tcf, checkPID=1) d = defer.gatherResults([f.deferred, tcf.deferred]) def _portStuff(ignored): self._addPorts(l, c.transport, tcf.protocol.transport, f.protocol.transport) return self.cleanPorts(*self.ports) def _check(ignored): self.failIf(lockfile.isLocked(filename + ".lock"), 'locked') d.addCallback(_portStuff) d.addCallback(_check) return d
def test_interface(self): """ Test C{getOutgoingInterface} and C{setOutgoingInterface}. """ self.assertEqual( self.client.transport.getOutgoingInterface(), "0.0.0.0") self.assertEqual( self.server.transport.getOutgoingInterface(), "0.0.0.0") d1 = self.client.transport.setOutgoingInterface("127.0.0.1") d2 = self.server.transport.setOutgoingInterface("127.0.0.1") result = gatherResults([d1, d2]) def cbInterfaces(ignored): self.assertEqual( self.client.transport.getOutgoingInterface(), "127.0.0.1") self.assertEqual( self.server.transport.getOutgoingInterface(), "127.0.0.1") result.addCallback(cbInterfaces) return result
def testNamespace(self): self.namespaceArgs = None def login(): return self.client.login('testuser', 'password-test') def namespace(): def gotNamespace(args): self.namespaceArgs = args self._cbStopClient(None) return self.client.namespace().addCallback(gotNamespace) d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(namespace)) d1.addErrback(self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEquals(self.namespaceArgs, [[['', '/']], [], []])) return d
def testExamine(self): SimpleServer.theAccount.addMailbox('test-mailbox') self.examinedArgs = None def login(): return self.client.login('testuser', 'password-test') def examine(): def examined(args): self.examinedArgs = args self._cbStopClient(None) d = self.client.examine('test-mailbox') d.addCallback(examined) return d d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(examine)) d1.addErrback(self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) return d.addCallback(self._cbTestExamine)
def testCreate(self): succeed = ('testbox', 'test/box', 'test/', 'test/box/box', 'INBOX') fail = ('testbox', 'test/box') def cb(): self.result.append(1) def eb(failure): self.result.append(0) def login(): return self.client.login('testuser', 'password-test') def create(): for name in succeed + fail: d = self.client.create(name) d.addCallback(strip(cb)).addErrback(eb) d.addCallbacks(self._cbStopClient, self._ebGeneral) self.result = [] d1 = self.connected.addCallback(strip(login)).addCallback(strip(create)) d2 = self.loopback() d = defer.gatherResults([d1, d2]) return d.addCallback(self._cbTestCreate, succeed, fail)
def testIllegalInboxDelete(self): self.stashed = None def login(): return self.client.login('testuser', 'password-test') def delete(): return self.client.delete('inbox') def stash(result): self.stashed = result d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(delete), self._ebGeneral) d1.addBoth(stash) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.failUnless(isinstance(self.stashed, failure.Failure))) return d
def testNonExistentDelete(self): def login(): return self.client.login('testuser', 'password-test') def delete(): return self.client.delete('delete/me') def deleteFailed(failure): self.failure = failure self.failure = None d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(delete)).addErrback(deleteFailed) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEquals(str(self.failure.value), 'No such mailbox')) return d
def testRename(self): SimpleServer.theAccount.addMailbox('oldmbox') def login(): return self.client.login('testuser', 'password-test') def rename(): return self.client.rename('oldmbox', 'newname') d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(rename), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEquals(SimpleServer.theAccount.mailboxes.keys(), ['NEWNAME'])) return d
def testIllegalInboxRename(self): self.stashed = None def login(): return self.client.login('testuser', 'password-test') def rename(): return self.client.rename('inbox', 'frotz') def stash(stuff): self.stashed = stuff d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(rename), self._ebGeneral) d1.addBoth(stash) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.failUnless(isinstance(self.stashed, failure.Failure))) return d
def testUnsubscribe(self): SimpleServer.theAccount.subscriptions = ['THIS/MBOX', 'THAT/MBOX'] def login(): return self.client.login('testuser', 'password-test') def unsubscribe(): return self.client.unsubscribe('this/mbox') d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(unsubscribe), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEquals(SimpleServer.theAccount.subscriptions, ['THAT/MBOX'])) return d
def testStatus(self): SimpleServer.theAccount.addMailbox('root/subthing') def login(): return self.client.login('testuser', 'password-test') def status(): return self.client.status('root/subthing', 'MESSAGES', 'UIDNEXT', 'UNSEEN') def statused(result): self.statused = result self.statused = None d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(status), self._ebGeneral) d1.addCallbacks(statused, self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEquals( self.statused, {'MESSAGES': 9, 'UIDNEXT': '10', 'UNSEEN': 4} )) return d
def testFailedStatus(self): def login(): return self.client.login('testuser', 'password-test') def status(): return self.client.status('root/nonexistent', 'MESSAGES', 'UIDNEXT', 'UNSEEN') def statused(result): self.statused = result def failed(failure): self.failure = failure self.statused = self.failure = None d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(status), self._ebGeneral) d1.addCallbacks(statused, failed) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() return defer.gatherResults([d1, d2]).addCallback(self._cbTestFailedStatus)
def testFullAppend(self): infile = util.sibpath(__file__, 'rfc822.message') message = open(infile) SimpleServer.theAccount.addMailbox('root/subthing') def login(): return self.client.login('testuser', 'password-test') def append(): return self.client.append( 'root/subthing', message, ('\\SEEN', '\\DELETED'), 'Tue, 17 Jun 2003 11:22:16 -0600 (MDT)', ) d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(append), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) return d.addCallback(self._cbTestFullAppend, infile)
def testPartialAppend(self): infile = util.sibpath(__file__, 'rfc822.message') message = open(infile) SimpleServer.theAccount.addMailbox('PARTIAL/SUBTHING') def login(): return self.client.login('testuser', 'password-test') def append(): message = file(infile) return self.client.sendCommand( imap4.Command( 'APPEND', 'PARTIAL/SUBTHING (\\SEEN) "Right now" {%d}' % os.path.getsize(infile), (), self.client._IMAP4Client__cbContinueAppend, message ) ) d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(append), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) return d.addCallback(self._cbTestPartialAppend, infile)
def testClose(self): m = SimpleMailbox() m.messages = [ ('Message 1', ('\\Deleted', 'AnotherFlag'), None, 0), ('Message 2', ('AnotherFlag',), None, 1), ('Message 3', ('\\Deleted',), None, 2), ] SimpleServer.theAccount.addMailbox('mailbox', m) def login(): return self.client.login('testuser', 'password-test') def select(): return self.client.select('mailbox') def close(): return self.client.close() d = self.connected.addCallback(strip(login)) d.addCallbacks(strip(select), self._ebGeneral) d.addCallbacks(strip(close), self._ebGeneral) d.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() return defer.gatherResults([d, d2]).addCallback(self._cbTestClose, m)
def testCramMD5(self): self.server.challengers['CRAM-MD5'] = cred.credentials.CramMD5Credentials cAuth = imap4.CramMD5ClientAuthenticator('testuser') self.client.registerAuthenticator(cAuth) def auth(): return self.client.authenticate('secret') def authed(): self.authenticated = 1 d1 = self.connected.addCallback(strip(auth)) d1.addCallbacks(strip(authed), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) return d.addCallback(self._cbTestCramMD5)
def testFailedCramMD5(self): self.server.challengers['CRAM-MD5'] = cred.credentials.CramMD5Credentials cAuth = imap4.CramMD5ClientAuthenticator('testuser') self.client.registerAuthenticator(cAuth) def misauth(): return self.client.authenticate('not the secret') def authed(): self.authenticated = 1 def misauthed(): self.authenticated = -1 d1 = self.connected.addCallback(strip(misauth)) d1.addCallbacks(strip(authed), strip(misauthed)) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d = defer.gatherResults([self.loopback(), d1]) return d.addCallback(self._cbTestFailedCramMD5)
def testFailedLOGIN(self): self.server.challengers['LOGIN'] = imap4.LOGINCredentials cAuth = imap4.LOGINAuthenticator('testuser') self.client.registerAuthenticator(cAuth) def misauth(): return self.client.authenticate('not the secret') def authed(): self.authenticated = 1 def misauthed(): self.authenticated = -1 d1 = self.connected.addCallback(strip(misauth)) d1.addCallbacks(strip(authed), strip(misauthed)) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d = defer.gatherResults([self.loopback(), d1]) return d.addCallback(self._cbTestFailedLOGIN)
def testServerTimeout(self): self.server.timeoutTest = True self.client.timeout = 5 #seconds self.selectedArgs = None def login(): d = self.client.login('testuser', 'password-test') d.addErrback(timedOut) return d def timedOut(failure): self._cbStopClient(None) failure.trap(error.TimeoutError) d = self.connected.addCallback(strip(login)) d.addErrback(self._ebGeneral) return defer.gatherResults([d, self.loopback()])
def testLongFetchDoesntTimeout(self): SimpleServer.theAccount.mailboxFactory = SlowMailbox SimpleServer.theAccount.addMailbox('mailbox-test') self.server.setTimeout(0.1) self.stillConnected = False def login(): return self.client.login('testuser', 'password-test') def select(): return self.client.select('mailbox-test') def fetch(): return self.client.fetchUID('1:*') def stillConnected(): self.stillConnected = not self.server.transport.disconnecting d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(select)) d1.addCallback(strip(fetch)) d1.addCallback(strip(stillConnected)) d1.addCallback(self._cbStopClient) d1.addErrback(self._ebGeneral) d = defer.gatherResults([d1, self.loopback()]) return d.addCallback(lambda _: self.failUnless(self.stillConnected))
def fetch_all(feeds): BATCH_SIZE=5 batches = [] for feeds_batch in batch_gen(feeds, BATCH_SIZE): sem = DeferredSemaphore(len(feeds_batch)) batch = [] for feed_ in feeds_batch: batch.append(sem.run(fetch_single, feed_meta=feed_)) batchDef = gatherResults(batch, consumeErrors=False) batchDef.addCallback(store_fetched_data) batches.append(batchDef) # rendez-vous for all feeds that were fetched batchesDef = gatherResults(batches, consumeErrors=False) batchesDef.addCallbacks( clean_up_and_exit, errback=lambda x: None, ) return batchesDef
def test_bootstrap_invalid_ca_cert(self): home = os.path.join(self.home, 'fp') os.mkdir(home) self.addr.fingerprint = "fabadafabada" provider = Provider(self.addr.domain, autoconf=True, basedir=home, cert_path=self.cacert) d = provider.callWhenMainConfigReady(lambda: "CA cert fp matched") yield self.assertFailure(d, NetworkError) self.assertFalse(os.path.isfile(provider._get_ca_cert_path())) provider._http.close() try: yield defer.gatherResults([ d, provider.ongoing_bootstrap]) except: pass Provider.providers[self.addr.domain] = None
def test_create_many(self): store = self._soledad w1 = CounterWrapper() w2 = CounterWrapper(counter=1) w3 = CounterWrapper(counter=2) w4 = CounterWrapper(counter=3) w5 = CounterWrapper(counter=4) d1 = [w1.create(store), w2.create(store), w3.create(store), w4.create(store), w5.create(store)] d = defer.gatherResults(d1) d.addCallback(lambda _: store.get_all_docs()) d.addCallback(partial(self.assert_num_docs, 5)) return d
def test_get_all_mboxes(self): adaptor = self.get_adaptor() mboxes = ("Sent", "Trash", "Personal", "ListFoo") def get_or_create_mboxes(ignored): d = [] for mbox in mboxes: d.append(adaptor.get_or_create_mbox( adaptor.store, mbox)) return defer.gatherResults(d) def get_all_mboxes(ignored): return adaptor.get_all_mboxes(adaptor.store) def assert_mboxes_match_expected(wrappers): names = [m.mbox for m in wrappers] self.assertEqual(set(names), set(mboxes)) d = adaptor.initialize_store(adaptor.store) d.addCallback(get_or_create_mboxes) d.addCallback(get_all_mboxes) d.addCallback(assert_mboxes_match_expected) return d
def testDelete(self): """ Test whether we can delete mailboxes """ def add_mailbox(): return self.server.theAccount.addMailbox('test-delete/me') def login(): return self.client.login(TEST_USER, TEST_PASSWD) def delete(): return self.client.delete('test-delete/me') acc = self.server.theAccount.account d1 = self.connected.addCallback(add_mailbox) d1.addCallback(strip(login)) d1.addCallbacks(strip(delete), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: acc.list_all_mailbox_names()) d.addCallback(lambda mboxes: self.assertEqual( set(mboxes), set(DEFAULT_MBOXES))) return d
def testIllegalInboxDelete(self): """ Test what happens if we try to delete the user Inbox. We expect that operation to fail. """ self.stashed = None def login(): return self.client.login(TEST_USER, TEST_PASSWD) def delete(): return self.client.delete('inbox') def stash(result): self.stashed = result d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(delete), self._ebGeneral) d1.addBoth(stash) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.failUnless(isinstance(self.stashed, failure.Failure))) return d
def testNonExistentDelete(self): """ Test what happens if we try to delete a non-existent mailbox. We expect an error raised stating 'No such mailbox' """ def login(): return self.client.login(TEST_USER, TEST_PASSWD) def delete(): return self.client.delete('delete/me') self.failure = failure def deleteFailed(failure): self.failure = failure self.failure = None d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(delete)).addErrback(deleteFailed) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertTrue( str(self.failure.value).startswith('No such mailbox'))) return d
def testRename(self): """ Test whether we can rename a mailbox """ def create_mbox(): return self.server.theAccount.addMailbox('oldmbox') def login(): return self.client.login(TEST_USER, TEST_PASSWD) def rename(): return self.client.rename('oldmbox', 'newname') d1 = self.connected.addCallback(strip(create_mbox)) d1.addCallback(strip(login)) d1.addCallbacks(strip(rename), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.server.theAccount.account.list_all_mailbox_names()) d.addCallback(lambda mboxes: self.assertItemsEqual( mboxes, DEFAULT_MBOXES + ['newname'])) return d
def testHierarchicalRename(self): """ Try to rename hierarchical mailboxes """ acc = self.server.theAccount def add_mailboxes(): return defer.gatherResults([ acc.addMailbox('oldmbox/m1'), acc.addMailbox('oldmbox/m2')]) def login(): return self.client.login(TEST_USER, TEST_PASSWD) def rename(): return self.client.rename('oldmbox', 'newname') d1 = self.connected.addCallback(strip(add_mailboxes)) d1.addCallback(strip(login)) d1.addCallbacks(strip(rename), self._ebGeneral) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: acc.account.list_all_mailbox_names()) return d.addCallback(self._cbTestHierarchicalRename)
def testCapability(self): caps = {} def getCaps(): def gotCaps(c): caps.update(c) self.server.transport.loseConnection() return self.client.getCapabilities().addCallback(gotCaps) d1 = self.connected d1.addCallback( strip(getCaps)).addErrback(self._ebGeneral) d = defer.gatherResults([self.loopback(), d1]) expected = {'IMAP4rev1': None, 'NAMESPACE': None, 'LITERAL+': None, 'IDLE': None} d.addCallback(lambda _: self.assertEqual(expected, caps)) return d
def testNamespace(self): """ Test retrieving namespace """ self.namespaceArgs = None def login(): return self.client.login(TEST_USER, TEST_PASSWD) def namespace(): def gotNamespace(args): self.namespaceArgs = args self._cbStopClient(None) return self.client.namespace().addCallback(gotNamespace) d1 = self.connected.addCallback(strip(login)) d1.addCallback(strip(namespace)) d1.addErrback(self._ebGeneral) d2 = self.loopback() d = defer.gatherResults([d1, d2]) d.addCallback(lambda _: self.assertEqual(self.namespaceArgs, [[['', '/']], [], []])) return d
def testFailedStatus(self): """ Test failed status command with a non-existent mailbox """ def login(): return self.client.login(TEST_USER, TEST_PASSWD) def status(): return self.client.status( 'root/nonexistent', 'MESSAGES', 'UIDNEXT', 'UNSEEN') def statused(result): self.statused = result def failed(failure): self.failure = failure self.statused = self.failure = None d1 = self.connected.addCallback(strip(login)) d1.addCallbacks(strip(status), self._ebGeneral) d1.addCallbacks(statused, failed) d1.addCallbacks(self._cbStopClient, self._ebGeneral) d2 = self.loopback() return defer.gatherResults([d1, d2]).addCallback( self._cbTestFailedStatus)
def _get_config_for_all_services(self, session): services_dict = self._load_provider_configs() configs_path = self._get_configs_path() with open(configs_path) as jsonf: services_dict = Record(**json.load(jsonf)).services pending = [] base = self._disco.get_base_uri() for service in self._provider_config.services: if service in self.SERVICES_MAP.keys(): for subservice in self.SERVICES_MAP[service]: uri = base + str(services_dict[subservice]) path = self._get_service_config_path(subservice) if session: d = session.fetch_provider_configs( uri, path, method='GET') else: d = self._fetch_provider_configs_unauthenticated( uri, path, method='GET') pending.append(d) return defer.gatherResults(pending)
def _repair_docs(self, doclist, cmp_func, log_func): self.log.error("BUG -------------------------------------------------") self.log.error("There is more than one doc of type %s:" % (doclist[0].content[KEY_TYPE_KEY],)) doclist.sort(cmp=cmp_func, reverse=True) log_func(doclist[0]) deferreds = [] for doc in doclist[1:]: log_func(doc) d = self._soledad.delete_doc(doc) deferreds.append(d) self.log.error('Error repairing') self.log.error("BUG (please report above info) ----------------------") d = defer.gatherResults(deferreds, consumeErrors=True) d.addCallback(lambda _: doclist[0]) return d
def _buildKeyDict(self, keys, actives): keydict = { fp2id(key.content[doc.KEY_FINGERPRINT_KEY]): KeyDocs(key, []) for key in keys} deferreds = [] for active in actives: if KEY_ID_KEY in active.content: key_id = active.content[KEY_ID_KEY] if key_id not in keydict: d = self._soledad.delete_doc(active) deferreds.append(d) continue keydict[key_id].active.append(active) d = gatherResults(deferreds) d.addCallback(lambda _: keydict) return d
def delete_all_keys(self, km): def delete_keys(keys): deferreds = [] for key in keys: d = km._openpgp.delete_key(key) deferreds.append(d) return gatherResults(deferreds) def check_deleted(_, private): d = km.get_all_keys(private=private) d.addCallback(lambda keys: self.assertEqual(keys, [])) return d deferreds = [] for private in [True, False]: d = km.get_all_keys(private=private) d.addCallback(delete_keys) d.addCallback(check_deleted, private) deferreds.append(d) return gatherResults(deferreds)
def _cbSelectWork(self, mbox, cmdName, tag): """ Callback for selectWork * patched to avoid conformance errors due to incomplete UIDVALIDITY line. * patched to accept deferreds for messagecount and recent count """ if mbox is None: self.sendNegativeResponse(tag, 'No such mailbox') return if '\\noselect' in [s.lower() for s in mbox.getFlags()]: self.sendNegativeResponse(tag, 'Mailbox cannot be selected') return d1 = defer.maybeDeferred(mbox.getMessageCount) d2 = defer.maybeDeferred(mbox.getRecentCount) d3 = defer.maybeDeferred(mbox.getUIDNext) return defer.gatherResults([d1, d2, d3]).addCallback( self.__cbSelectWork, mbox, cmdName, tag)
def delete_all_flagged(self): """ Delete all messages flagged as \\Deleted. Used from IMAPMailbox.expunge() """ def get_uid_list(hashes): d = [] for h in hashes: d.append(self.mbox_indexer.get_uid_from_doc_id( self.mbox_uuid, h)) return defer.gatherResults(d), hashes def delete_uid_entries((uids, hashes)): d = [] for h in hashes: d.append(self.mbox_indexer.delete_doc_by_hash( self.mbox_uuid, h)) def return_uids_when_deleted(ignored): return uids all_deleted = defer.gatherResults(d).addCallback( return_uids_when_deleted) return all_deleted