summaryrefslogtreecommitdiffstats
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-05-24 17:58:05 (GMT)
committerGuido van Rossum <guido@python.org>2002-05-24 17:58:05 (GMT)
commit4b46c0a15f1bdb8987ce78c0ded40dbc92b6e03e (patch)
tree48c84553a85bd0c965b6cc2f4c10a05f7058c5d7 /Lib/urllib.py
parent0cc8c3735746eb9dcbb912dae7f5d890acdbb792 (diff)
downloadcpython-4b46c0a15f1bdb8987ce78c0ded40dbc92b6e03e.zip
cpython-4b46c0a15f1bdb8987ce78c0ded40dbc92b6e03e.tar.gz
cpython-4b46c0a15f1bdb8987ce78c0ded40dbc92b6e03e.tar.bz2
Don't require Unicode support.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 50bed84..eb7e496 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -906,11 +906,18 @@ def basejoin(base, url):
# unquote('abc%20def') -> 'abc def'
# 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 type(url) is types.UnicodeType:
+ if _is_unicode(url):
try:
url = url.encode("ASCII")
except UnicodeError:
@@ -1189,7 +1196,7 @@ def urlencode(query,doseq=0):
if type(v) == types.StringType:
v = quote_plus(v)
l.append(k + '=' + v)
- elif type(v) == types.UnicodeType:
+ elif _is_unicode(v):
# is there a reasonable way to convert to ASCII?
# encode generates a string, but "replace" or "ignore"
# lose information and "strict" can raise UnicodeError