summaryrefslogtreecommitdiff
path: root/mail/src/leap
diff options
context:
space:
mode:
authorBruno Wagner <bwgpro@gmail.com>2015-07-21 19:44:47 -0300
committerBruno Wagner <bwgpro@gmail.com>2015-07-21 19:44:47 -0300
commitac6502194114a0e20c17c1801204b318731fece8 (patch)
tree47fd81ef4c3d8d0f0b4f82cafa7572f732a1af79 /mail/src/leap
parent16378bf2aeab4cb8da61299d34a8413902d614ae (diff)
Pep8 warns about lambdas being assigned to a variable, changed walk and sync_hooks to lambdas to real functions
Diffstat (limited to 'mail/src/leap')
-rw-r--r--mail/src/leap/mail/sync_hooks.py5
-rw-r--r--mail/src/leap/mail/walk.py84
2 files changed, 56 insertions, 33 deletions
diff --git a/mail/src/leap/mail/sync_hooks.py b/mail/src/leap/mail/sync_hooks.py
index bd8d88d1..8efbb7ce 100644
--- a/mail/src/leap/mail/sync_hooks.py
+++ b/mail/src/leap/mail/sync_hooks.py
@@ -32,10 +32,11 @@ from twisted.python import log
from leap.soledad.client.interfaces import ISoledadPostSyncPlugin
from leap.mail import constants
-
logger = logging.getLogger(__name__)
-_get_doc_type_preffix = lambda s: s[:2]
+
+def _get_doc_type_preffix(s):
+ return s[:2]
class MailProcessingPostSyncHook(object):
diff --git a/mail/src/leap/mail/walk.py b/mail/src/leap/mail/walk.py
index 6d79b83c..f6133094 100644
--- a/mail/src/leap/mail/walk.py
+++ b/mail/src/leap/mail/walk.py
@@ -26,35 +26,49 @@ from leap.mail.utils import first
DEBUG = os.environ.get("BITMASK_MAIL_DEBUG")
if DEBUG:
- get_hash = lambda s: sha256.SHA256(s).hexdigest()[:10]
+ def get_hash(s):
+ return sha256.SHA256(s).hexdigest()[:10]
else:
- get_hash = lambda s: sha256.SHA256(s).hexdigest()
+ def get_hash(s):
+ return sha256.SHA256(s).hexdigest()
"""
Get interesting message parts
"""
-get_parts = lambda msg: [
- {'multi': part.is_multipart(),
- 'ctype': part.get_content_type(),
- 'size': len(part.as_string()),
- 'parts': len(part.get_payload())
- if isinstance(part.get_payload(), list)
- else 1,
- 'headers': part.items(),
- 'phash': get_hash(part.get_payload())
- if not part.is_multipart() else None}
- for part in msg.walk()]
+
+
+def get_parts(msg):
+ return [
+ {
+ 'multi': part.is_multipart(),
+ 'ctype': part.get_content_type(),
+ 'size': len(part.as_string()),
+ 'parts':
+ len(part.get_payload())
+ if isinstance(part.get_payload(), list)
+ else 1,
+ 'headers': part.items(),
+ 'phash':
+ get_hash(part.get_payload())
+ if not part.is_multipart()
+ else None
+ } for part in msg.walk()]
"""
Utility lambda functions for getting the parts vector and the
payloads from the original message.
"""
-get_parts_vector = lambda parts: (x.get('parts', 1) for x in parts)
-get_payloads = lambda msg: ((x.get_payload(),
- dict(((str.lower(k), v) for k, v in (x.items()))))
- for x in msg.walk())
+
+def get_parts_vector(parts):
+ return (x.get('parts', 1) for x in parts)
+
+
+def get_payloads(msg):
+ return ((x.get_payload(),
+ dict(((str.lower(k), v) for k, v in (x.items()))))
+ for x in msg.walk())
def get_body_phash(msg):
@@ -73,18 +87,22 @@ index the content. Here we remove any mutable part, as the the filename
in the content disposition.
"""
-get_raw_docs = lambda msg, parts: (
- {"type": "cnt", # type content they'll be
- "raw": payload if not DEBUG else payload[:100],
- "phash": get_hash(payload),
- "content-disposition": first(headers.get(
- 'content-disposition', '').split(';')),
- "content-type": headers.get(
- 'content-type', ''),
- "content-transfer-encoding": headers.get(
- 'content-transfer-type', '')}
- for payload, headers in get_payloads(msg)
- if not isinstance(payload, list))
+
+def get_raw_docs(msg, parts):
+ return (
+ {
+ "type": "cnt", # type content they'll be
+ "raw": payload if not DEBUG else payload[:100],
+ "phash": get_hash(payload),
+ "content-disposition": first(headers.get(
+ 'content-disposition', '').split(';')),
+ "content-type": headers.get(
+ 'content-type', ''),
+ "content-transfer-encoding": headers.get(
+ 'content-transfer-type', '')
+ } for payload, headers in get_payloads(msg)
+ if not isinstance(payload, list))
+
"""
Groucho Marx: Now pay particular attention to this first clause, because it's
@@ -155,8 +173,12 @@ def walk_msg_tree(parts, body_phash=None):
print
# wrappers vector
- getwv = lambda pv: [True if pv[i] != 1 and pv[i + 1] == 1 else False
- for i in range(len(pv) - 1)]
+ def getwv(pv):
+ return [
+ True if pv[i] != 1 and pv[i + 1] == 1
+ else False
+ for i in range(len(pv) - 1)
+ ]
wv = getwv(pv)
# do until no wrapper document is left