summaryrefslogtreecommitdiff
path: root/src
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
commit63e643466882996f32eba1c0f79ebdd3ceb5f3b3 (patch)
tree37b37d87a0e496b398f3754ba9a53f7ac493d53a /src
parentbb132dcc1b558cfdfd0bf438779fe2ed07827fd5 (diff)
Pep8 warns about lambdas being assigned to a variable, changed walk and sync_hooks to lambdas to real functions
Diffstat (limited to 'src')
-rw-r--r--src/leap/mail/sync_hooks.py5
-rw-r--r--src/leap/mail/walk.py84
2 files changed, 56 insertions, 33 deletions
diff --git a/src/leap/mail/sync_hooks.py b/src/leap/mail/sync_hooks.py
index bd8d88d..8efbb7c 100644
--- a/src/leap/mail/sync_hooks.py
+++ b/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/src/leap/mail/walk.py b/src/leap/mail/walk.py
index 6d79b83..f613309 100644
--- a/src/leap/mail/walk.py
+++ b/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