diff mbox

[v2,05/11] parsemail: Flatten 'try_decode' method

Message ID 1459522667-17192-6-git-send-email-stephen.finucane@intel.com
State Superseded
Headers show

Commit Message

Stephen Finucane April 1, 2016, 2:57 p.m. UTC
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>
---
 patchwork/bin/parsemail.py | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

Comments

Andy Doan April 8, 2016, 6:06 p.m. UTC | #1
On 04/01/2016 09:57 AM, Stephen Finucane wrote:
> 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>
diff mbox

Patch

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: