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.
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 @@
# 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 @@
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