summaryrefslogtreecommitdiffstats
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
committerGuido van Rossum <guido@python.org>2007-11-06 21:34:58 (GMT)
commit98297ee7815939b124156e438b22bd652d67b5db (patch)
treea9d239ebd87c73af2571ab48003984c4e18e27e5 /Lib/urllib.py
parenta19f80c6df2df5e8a5d0cff37131097835ef971e (diff)
downloadcpython-98297ee7815939b124156e438b22bd652d67b5db.zip
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz
cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.bz2
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137 branch. The most obvious changes: - str8 renamed to bytes (PyString at the C level); - bytes renamed to buffer (PyBytes at the C level); - PyString and PyUnicode are no longer compatible. I.e. we now have an immutable bytes type and a mutable bytes type. The behavior of PyString was modified quite a bit, to make it more bytes-like. Some changes are still on the to-do list.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py18
1 files changed, 5 insertions, 13 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index b2542fc..81a8cd6 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -925,22 +925,14 @@ class addinfourl(addbase):
# unquote('abc%20def') -> 'abc def'
# quote('abc def') -> 'abc%20def')
-try:
- str
-except NameError:
- def _is_unicode(x):
- return 0
-else:
- def _is_unicode(x):
- return isinstance(x, str)
-
def toBytes(url):
"""toBytes(u"URL") --> 'URL'."""
# Most URL schemes require ASCII. If that changes, the conversion
- # can be relaxed
- if _is_unicode(url):
+ # can be relaxed.
+ # XXX get rid of toBytes()
+ if isinstance(url, str):
try:
- url = url.encode("ASCII")
+ url = url.encode("ASCII").decode()
except UnicodeError:
raise UnicodeError("URL " + repr(url) +
" contains non-ASCII characters")
@@ -1203,7 +1195,7 @@ def urlencode(query,doseq=0):
if isinstance(v, str):
v = quote_plus(v)
l.append(k + '=' + v)
- elif _is_unicode(v):
+ elif isinstance(v, str):
# is there a reasonable way to convert to ASCII?
# encode generates a string, but "replace" or "ignore"
# lose information and "strict" can raise UnicodeError