Kaydet (Commit) 1a7ac359 authored tarafından Guido van Rossum's avatar Guido van Rossum

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.)
üst 05459c5e
# Copyright (C) 2001,2002 Python Software Foundation # Copyright (C) 2001,2002 Python Software Foundation
# Author: che@debian.org (Ben Gertzfield) # 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 from email.Encoders import encode_7or8bit
import email.base64MIME import email.base64MIME
import email.quopriMIME import email.quopriMIME
...@@ -226,7 +234,7 @@ class Charset: ...@@ -226,7 +234,7 @@ class Charset:
Characters that could not be converted to Unicode will be replaced Characters that could not be converted to Unicode will be replaced
with the Unicode replacement character U+FFFD. 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 return s
try: try:
return unicode(s, self.input_codec, 'replace') return unicode(s, self.input_codec, 'replace')
...@@ -254,7 +262,7 @@ class Charset: ...@@ -254,7 +262,7 @@ class Charset:
codec = self.output_codec codec = self.output_codec
else: else:
codec = self.input_codec codec = self.input_codec
if not isinstance(ustr, UnicodeType) or codec is None: if not _is_unicode(ustr) or codec is None:
return ustr return ustr
try: try:
return ustr.encode(codec, 'replace') return ustr.encode(codec, 'replace')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment