diff options
author | Guido van Rossum <guido@python.org> | 2020-05-14 19:01:14 -0700 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2020-05-14 19:01:14 -0700 |
commit | f93a54c48fc1644012aa0d4ee3887c1d121ac40e (patch) | |
tree | 189c841245d15318e5895638105bdbc532cbcdf5 /Lib/email | |
parent | 31641ff0e4b18c8d002d019f4506f0e8fb446983 (diff) | |
parent | 16ab07063cb564c1937714bd39d6915172f005b5 (diff) | |
download | cpython-git-fix-traceback-syntax-error.tar.gz |
Merge branch 'master' into fix-traceback-syntax-errorfix-traceback-syntax-error
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/contentmanager.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/email/contentmanager.py b/Lib/email/contentmanager.py index b904ded94c..2b4b8757f4 100644 --- a/Lib/email/contentmanager.py +++ b/Lib/email/contentmanager.py @@ -146,13 +146,13 @@ def _encode_text(string, charset, cte, policy): def normal_body(lines): return b'\n'.join(lines) + b'\n' if cte==None: # Use heuristics to decide on the "best" encoding. - try: - return '7bit', normal_body(lines).decode('ascii') - except UnicodeDecodeError: - pass - if (policy.cte_type == '8bit' and - max(len(x) for x in lines) <= policy.max_line_length): - return '8bit', normal_body(lines).decode('ascii', 'surrogateescape') + if max(len(x) for x in lines) <= policy.max_line_length: + try: + return '7bit', normal_body(lines).decode('ascii') + except UnicodeDecodeError: + pass + if policy.cte_type == '8bit': + return '8bit', normal_body(lines).decode('ascii', 'surrogateescape') sniff = embedded_body(lines[:10]) sniff_qp = quoprimime.body_encode(sniff.decode('latin-1'), policy.max_line_length) |