[Python-checkins] python/dist/src/Lib urllib.py,1.143,1.144
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 24 May 2002 10:58:07 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv6720
Modified Files:
urllib.py
Log Message:
Don't require Unicode support.
Index: urllib.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/urllib.py,v
retrieving revision 1.143
retrieving revision 1.144
diff -C2 -d -r1.143 -r1.144
*** urllib.py 15 Apr 2002 00:25:01 -0000 1.143
--- urllib.py 24 May 2002 17:58:05 -0000 1.144
***************
*** 907,915 ****
# quote('abc def') -> 'abc%20def')
def toBytes(url):
"""toBytes(u"URL") --> 'URL'."""
# Most URL schemes require ASCII. If that changes, the conversion
# can be relaxed
! if type(url) is types.UnicodeType:
try:
url = url.encode("ASCII")
--- 907,922 ----
# quote('abc def') -> 'abc%20def')
+ if hasattr(types, "UnicodeType"):
+ def _is_unicode(x):
+ return isinstance(x, unicode)
+ else:
+ def _is_unicode(x):
+ return 0
+
def toBytes(url):
"""toBytes(u"URL") --> 'URL'."""
# Most URL schemes require ASCII. If that changes, the conversion
# can be relaxed
! if _is_unicode(url):
try:
url = url.encode("ASCII")
***************
*** 1190,1194 ****
v = quote_plus(v)
l.append(k + '=' + v)
! elif type(v) == types.UnicodeType:
# is there a reasonable way to convert to ASCII?
# encode generates a string, but "replace" or "ignore"
--- 1197,1201 ----
v = quote_plus(v)
l.append(k + '=' + v)
! elif _is_unicode(v):
# is there a reasonable way to convert to ASCII?
# encode generates a string, but "replace" or "ignore"