File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
909916def 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
You can’t perform that action at this time.
0 commit comments