[Python-checkins] r83294 - in python/branches/py3k/Lib: test/test_urllib.py urllib/parse.py

senthil.kumaran python-checkins at python.org
Fri Jul 30 21:34:37 CEST 2010


Author: senthil.kumaran
Date: Fri Jul 30 21:34:36 2010
New Revision: 83294

Log:
Fix issue9301 - handle unquote({}) kind of case.


Modified:
   python/branches/py3k/Lib/test/test_urllib.py
   python/branches/py3k/Lib/urllib/parse.py

Modified: python/branches/py3k/Lib/test/test_urllib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_urllib.py	(original)
+++ python/branches/py3k/Lib/test/test_urllib.py	Fri Jul 30 21:34:36 2010
@@ -527,6 +527,7 @@
         self.assertEqual(expect, result,
                          "using quote_plus(): %r != %r" % (expect, result))
 
+
 class UnquotingTests(unittest.TestCase):
     """Tests for unquote() and unquote_plus()
 
@@ -555,6 +556,7 @@
                          "using unquote(): not all characters escaped: "
                          "%s" % result)
         self.assertRaises(TypeError, urllib.parse.unquote, None)
+        self.assertRaises(TypeError, urllib.parse.unquote, ())
 
     def test_unquoting_badpercent(self):
         # Test unquoting on bad percent-escapes
@@ -589,8 +591,8 @@
         result = urllib.parse.unquote_to_bytes(given)
         self.assertEqual(expect, result, "using unquote_to_bytes(): %r != %r"
                          % (expect, result))
-
         self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, None)
+        self.assertRaises(TypeError, urllib.parse.unquote_to_bytes, ())
 
     def test_unquoting_mixed_case(self):
         # Test unquoting on mixed-case hex digits in the percent-escapes

Modified: python/branches/py3k/Lib/urllib/parse.py
==============================================================================
--- python/branches/py3k/Lib/urllib/parse.py	(original)
+++ python/branches/py3k/Lib/urllib/parse.py	Fri Jul 30 21:34:36 2010
@@ -313,9 +313,7 @@
     """unquote_to_bytes('abc%20def') -> b'abc def'."""
     # Note: strings are encoded as UTF-8. This is only an issue if it contains
     # unescaped non-ASCII characters, which URIs should not.
-    if not string:
-        if string is None:
-            raise TypeError('None object is invalid for unquote_to_bytes()')
+    if string in (b'', ''):
         return b''
     if isinstance(string, str):
         string = string.encode('utf-8')
@@ -340,9 +338,7 @@
 
     unquote('abc%20def') -> 'abc def'.
     """
-    if not string:
-        if string is None:
-            raise TypeError('None object is invalid for unquote() function.')
+    if string in (b'', ''):
         return string
     res = string.split('%')
     if len(res) == 1:


More information about the Python-checkins mailing list