[Python-3000-checkins] r58821 - python/branches/py3k-pep3137/Lib/urllib.py

christian.heimes python-3000-checkins at python.org
Sat Nov 3 02:11:03 CET 2007


Author: christian.heimes
Date: Sat Nov  3 02:11:03 2007
New Revision: 58821

Modified:
   python/branches/py3k-pep3137/Lib/urllib.py
Log:
Fixed urllib. Can we get rid of toBytes()?

Modified: python/branches/py3k-pep3137/Lib/urllib.py
==============================================================================
--- python/branches/py3k-pep3137/Lib/urllib.py	(original)
+++ python/branches/py3k-pep3137/Lib/urllib.py	Sat Nov  3 02:11:03 2007
@@ -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


More information about the Python-3000-checkins mailing list