From: Stephen Finucane Date: Sat, 5 Mar 2016 17:07:36 +0000 (+0000) Subject: parsemail: Flatten 'try_decode' method X-Git-Tag: v2.0.0-rc1~361 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=eda3dd7d1968c519470cef0c9115b95476160f03;p=thirdparty%2Fpatchwork.git parsemail: Flatten 'try_decode' method 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 Reviewed-by: Andy Doan --- diff --git a/patchwork/bin/parsemail.py b/patchwork/bin/parsemail.py index ae1ccb23..36fd4cbe 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: