diff options
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/generator.py | 10 | ||||
-rw-r--r-- | Lib/email/header.py | 4 |
2 files changed, 10 insertions, 4 deletions
diff --git a/Lib/email/generator.py b/Lib/email/generator.py index 02b4495..c480229 100644 --- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -21,14 +21,20 @@ NL = '\n' fcre = re.compile(r'^From ', re.MULTILINE) def _is8bitstring(s): - if isinstance(s, str): + if isinstance(s, bytes): try: str(s, 'us-ascii') + return True except UnicodeError: + pass + elif isinstance(s, str): + try: + s.decode('us-ascii') return True + except UnicodeError: + pass return False - class Generator: """Generates output from a Message object tree. diff --git a/Lib/email/header.py b/Lib/email/header.py index 675b68d..5ea1871 100644 --- a/Lib/email/header.py +++ b/Lib/email/header.py @@ -253,7 +253,7 @@ class Header: # We need to test that the string can be converted to unicode and # back to a byte string, given the input and output codecs of the # charset. - if isinstance(s, str): + if isinstance(s, bytes): # Possibly raise UnicodeError if the byte string can't be # converted to a unicode with the input codec of the charset. incodec = charset.input_codec or 'us-ascii' @@ -263,7 +263,7 @@ class Header: # than the iput coded. Still, use the original byte string. outcodec = charset.output_codec or 'us-ascii' ustr.encode(outcodec, errors) - elif isinstance(s, str): + elif isinstance(s, bytes): # Now we have to be sure the unicode string can be converted # to a byte string with a reasonable output codec. We want to # use the byte string in the chunk. |