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

Skip to content

Commit 4b46c0a

Browse files
committed
Don't require Unicode support.
1 parent 0cc8c37 commit 4b46c0a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/urllib.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,18 @@ def basejoin(base, url):
906906
# unquote('abc%20def') -> 'abc def'
907907
# quote('abc def') -> 'abc%20def')
908908

909+
if hasattr(types, "UnicodeType"):
910+
def _is_unicode(x):
911+
return isinstance(x, unicode)
912+
else:
913+
def _is_unicode(x):
914+
return 0
915+
909916
def toBytes(url):
910917
"""toBytes(u"URL") --> 'URL'."""
911918
# Most URL schemes require ASCII. If that changes, the conversion
912919
# can be relaxed
913-
if type(url) is types.UnicodeType:
920+
if _is_unicode(url):
914921
try:
915922
url = url.encode("ASCII")
916923
except UnicodeError:
@@ -1189,7 +1196,7 @@ def urlencode(query,doseq=0):
11891196
if type(v) == types.StringType:
11901197
v = quote_plus(v)
11911198
l.append(k + '=' + v)
1192-
elif type(v) == types.UnicodeType:
1199+
elif _is_unicode(v):
11931200
# is there a reasonable way to convert to ASCII?
11941201
# encode generates a string, but "replace" or "ignore"
11951202
# lose information and "strict" can raise UnicodeError

0 commit comments

Comments
 (0)