Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a7ac35

Browse files
committed
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.)
1 parent 05459c5 commit 1a7ac35

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

Lib/email/Charset.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# Copyright (C) 2001,2002 Python Software Foundation
22
# Author: [email protected] (Ben Gertzfield)
33

4-
from types import UnicodeType
4+
try:
5+
unicode
6+
except NameError:
7+
def _is_unicode(x):
8+
return 1==0
9+
else:
10+
def _is_unicode(x):
11+
return isinstance(x, unicode)
12+
513
from email.Encoders import encode_7or8bit
614
import email.base64MIME
715
import email.quopriMIME
@@ -226,7 +234,7 @@ def to_splittable(self, s):
226234
Characters that could not be converted to Unicode will be replaced
227235
with the Unicode replacement character U+FFFD.
228236
"""
229-
if isinstance(s, UnicodeType) or self.input_codec is None:
237+
if _is_unicode(s) or self.input_codec is None:
230238
return s
231239
try:
232240
return unicode(s, self.input_codec, 'replace')
@@ -254,7 +262,7 @@ def from_splittable(self, ustr, to_output=1):
254262
codec = self.output_codec
255263
else:
256264
codec = self.input_codec
257-
if not isinstance(ustr, UnicodeType) or codec is None:
265+
if not _is_unicode(ustr) or codec is None:
258266
return ustr
259267
try:
260268
return ustr.encode(codec, 'replace')

0 commit comments

Comments
 (0)