[PATCH v2 05/11] parsemail: Flatten 'try_decode' method
Stephen Finucane
stephen.finucane at intel.com
Sat Apr 2 01:57:41 AEDT 2016
This function is small, is only called once and isn't unit tested. Save
a few lines and some cognitive effort by folding it in where it's used.
Signed-off-by: Stephen Finucane <stephen.finucane at intel.com>
---
patchwork/bin/parsemail.py | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py
index ae1ccb2..36fd4cb 100755
--- a/patchwork/bin/parsemail.py
+++ b/patchwork/bin/parsemail.py
@@ -185,14 +185,6 @@ def find_pull_request(content):
return None
-def try_decode(payload, charset):
- try:
- payload = six.text_type(payload, charset)
- except UnicodeDecodeError:
- return None
- return payload
-
-
def build_references_list(mail):
"""Construct a list of possible reply message ids."""
refs = []
@@ -264,10 +256,11 @@ def find_content(project, mail):
try_charsets = [charset]
for cset in try_charsets:
- decoded_payload = try_decode(payload, cset)
- if decoded_payload is not None:
+ try:
+ payload = six.text_type(payload, cset)
break
- payload = decoded_payload
+ except UnicodeDecodeError:
+ payload = None
# Could not find a valid decoded payload. Fail.
if payload is None:
--
2.0.0
More information about the Patchwork
mailing list