diff options
author | Guido van Rossum <guido@python.org> | 2002-05-28 18:49:03 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-05-28 18:49:03 (GMT) |
commit | 1a7ac359a0f0f5466aeed82e8cbd7f2774690c98 (patch) | |
tree | e15895d3c16ad1418e312b8d33540abee3fffc11 /Lib/email | |
parent | 05459c5e5ece64ba8da62455970d1c1479011ff7 (diff) | |
download | cpython-1a7ac359a0f0f5466aeed82e8cbd7f2774690c98.zip cpython-1a7ac359a0f0f5466aeed82e8cbd7f2774690c98.tar.gz cpython-1a7ac359a0f0f5466aeed82e8cbd7f2774690c98.tar.bz2 |
Importing Charset should not fail when Unicode is disabled. (XXX
Using Unicode-aware methods may still die with a NameError on unicode.
Maybe there's a more elegant solution but I doubt anybody cares.)
Diffstat (limited to 'Lib/email')
-rw-r--r-- | Lib/email/Charset.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/Lib/email/Charset.py b/Lib/email/Charset.py index 0de5f80..4a7ef69 100644 --- a/Lib/email/Charset.py +++ b/Lib/email/Charset.py @@ -1,7 +1,15 @@ # Copyright (C) 2001,2002 Python Software Foundation # Author: che@debian.org (Ben Gertzfield) -from types import UnicodeType +try: + unicode +except NameError: + def _is_unicode(x): + return 1==0 +else: + def _is_unicode(x): + return isinstance(x, unicode) + from email.Encoders import encode_7or8bit import email.base64MIME import email.quopriMIME @@ -226,7 +234,7 @@ class Charset: Characters that could not be converted to Unicode will be replaced with the Unicode replacement character U+FFFD. """ - if isinstance(s, UnicodeType) or self.input_codec is None: + if _is_unicode(s) or self.input_codec is None: return s try: return unicode(s, self.input_codec, 'replace') @@ -254,7 +262,7 @@ class Charset: codec = self.output_codec else: codec = self.input_codec - if not isinstance(ustr, UnicodeType) or codec is None: + if not _is_unicode(ustr) or codec is None: return ustr try: return ustr.encode(codec, 'replace') |