]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parsemail: Flatten 'try_decode' method
authorStephen Finucane <stephen.finucane@intel.com>
Sat, 5 Mar 2016 17:07:36 +0000 (17:07 +0000)
committerStephen Finucane <stephen.finucane@intel.com>
Thu, 14 Apr 2016 16:29:09 +0000 (17:29 +0100)
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@intel.com>
Reviewed-by: Andy Doan <andy.doan@linaro.org>
patchwork/bin/parsemail.py

index ae1ccb230fccf681b654a113c1b8d37ffb42c952..36fd4cbea47b98bd172336f47be8c3d0a7384507 100755 (executable)
@@ -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: