Change filter with lambda to list comprehension

It is more readable and returns a list therefore it is compatible both
with Python 2 and 3.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Łukasz Żarnowiecki 2016-05-08 16:55:13 +02:00 committed by Nicolas Sebrecht
parent 068ac7c410
commit 19c43308b9
5 changed files with 11 additions and 17 deletions

View File

@ -438,8 +438,7 @@ def syncfolder(account, remotefolder, quick):
# sync to messages with UIDs >= min_uid from this list. # sync to messages with UIDs >= min_uid from this list.
# #
# local messagelist might contain new messages (with uid's < 0). # local messagelist might contain new messages (with uid's < 0).
positive_uids = filter( positive_uids = [uid for uid in localfolder.getmessageuidlist() if uid > 0]
lambda uid: uid > 0, localfolder.getmessageuidlist())
if len(positive_uids) > 0: if len(positive_uids) > 0:
remotefolder.cachemessagelist(min_uid=min(positive_uids)) remotefolder.cachemessagelist(min_uid=min(positive_uids))
else: else:
@ -482,8 +481,7 @@ def syncfolder(account, remotefolder, quick):
# messagelist.keys() instead of getuidmessagelist() because in # messagelist.keys() instead of getuidmessagelist() because in
# the UID mapped case we want the actual local UIDs, not their # the UID mapped case we want the actual local UIDs, not their
# remote counterparts # remote counterparts
positive_uids = filter( positive_uids = [uid for uid in list(partial.messagelist.keys()) if uid > 0]
lambda uid: uid > 0, partial.messagelist.keys())
if len(positive_uids) > 0: if len(positive_uids) > 0:
min_uid = min(positive_uids) min_uid = min(positive_uids)
else: else:

View File

@ -858,8 +858,7 @@ class BaseFolder(object):
threads = [] threads = []
copylist = filter(lambda uid: not statusfolder.uidexists(uid), copylist = [uid for uid in self.getmessageuidlist() if not statusfolder.uidexists(uid)]
self.getmessageuidlist())
num_to_copy = len(copylist) num_to_copy = len(copylist)
if num_to_copy and self.repository.account.dryrun: if num_to_copy and self.repository.account.dryrun:
self.ui.info("[DRYRUN] Copy {0} messages from {1}[{2}] to {3}".format( self.ui.info("[DRYRUN] Copy {0} messages from {1}[{2}] to {3}".format(
@ -909,10 +908,10 @@ class BaseFolder(object):
# The list of messages to delete. If sync of deletions is disabled we # The list of messages to delete. If sync of deletions is disabled we
# still remove stale entries from statusfolder (neither in local nor # still remove stale entries from statusfolder (neither in local nor
# remote). # remote).
deletelist = filter( deletelist = [uid for uid in statusfolder.getmessageuidlist()
lambda uid: uid >= 0 and not self.uidexists(uid) if uid >= 0 and
and (self._sync_deletes or not dstfolder.uidexists(uid)), not self.uidexists(uid) and
statusfolder.getmessageuidlist()) (self._sync_deletes or not dstfolder.uidexists(uid))]
if len(deletelist): if len(deletelist):
# Delete in statusfolder first to play safe. In case of abort, we # Delete in statusfolder first to play safe. In case of abort, we
@ -921,7 +920,7 @@ class BaseFolder(object):
# user, or not being tracked (e.g. because of maxage). # user, or not being tracked (e.g. because of maxage).
statusfolder.deletemessages(deletelist) statusfolder.deletemessages(deletelist)
# Filter out untracked messages # Filter out untracked messages
deletelist = filter(lambda uid: dstfolder.uidexists(uid), deletelist) deletelist = [uid for uid in deletelist if dstfolder.uidexists(uid)]
if len(deletelist): if len(deletelist):
self.ui.deletingmessages(deletelist, [dstfolder]) self.ui.deletingmessages(deletelist, [dstfolder])
if self.repository.account.dryrun: if self.repository.account.dryrun:

View File

@ -204,7 +204,7 @@ class MaildirFolder(BaseFolder):
retval[uid]['filename'] = filepath retval[uid]['filename'] = filepath
if min_date != None: if min_date != None:
# Re-include messages with high enough uid's. # Re-include messages with high enough uid's.
positive_uids = filter(lambda uid: uid > 0, retval) positive_uids = [uid for uid in retval if uid > 0]
if positive_uids: if positive_uids:
min_uid = min(positive_uids) min_uid = min(positive_uids)
for uid in date_excludees.keys(): for uid in date_excludees.keys():

View File

@ -433,8 +433,7 @@ class IMAPServer:
if not tried_to_authn: if not tried_to_authn:
methods = ", ".join(map( methods = ", ".join(map(
lambda x: x[5:], filter(lambda x: x[0:5] == "AUTH=", lambda x: x[5:], [x for x in imapobj.capabilities if x[0:5] == "AUTH="]
imapobj.capabilities)
)) ))
raise OfflineImapError(u"Repository %s: no supported " raise OfflineImapError(u"Repository %s: no supported "
"authentication mechanisms found; configured %s, " "authentication mechanisms found; configured %s, "

View File

@ -131,9 +131,7 @@ class OLITestLib():
else: else:
sections = [r for r in config.sections() \ sections = [r for r in config.sections() \
if r.startswith('Repository')] if r.startswith('Repository')]
sections = filter(lambda s: \ sections = [s for s in sections if config.get(s, 'Type').lower() == 'imap']
config.get(s, 'Type').lower() == 'imap',
sections)
for sec in sections: for sec in sections:
# Connect to each IMAP repo and delete all folders # Connect to each IMAP repo and delete all folders
# matching the folderfilter setting. We only allow basic # matching the folderfilter setting. We only allow basic