Kaydet (Commit) 2bdec7bf authored tarafından Raymond Hettinger's avatar Raymond Hettinger

Revert 1.170. Add tests.

üst 803ce801
......@@ -353,6 +353,12 @@ class QuotingTests(unittest.TestCase):
self.assertEqual(expect, result,
"using quote_plus(): %s != %s" % (expect, result))
def test_quoting_plus(self):
self.assertEqual(urllib.quote_plus('alpha+beta gamma'),
'alpha%2Bbeta+gamma')
self.assertEqual(urllib.quote_plus('alpha+beta gamma', '+'),
'alpha+beta+gamma')
class UnquotingTests(unittest.TestCase):
"""Tests for unquote() and unquote_plus()
......
......@@ -1110,9 +1110,12 @@ def quote(s, safe = '/'):
def quote_plus(s, safe = ''):
"""Quote the query fragment of a URL; replacing ' ' with '+'"""
if ' ' in s:
s = s.replace(' ', '+')
safe += '+'
return quote(s, safe)
l = s.split(' ')
for i in range(len(l)):
l[i] = quote(l[i], safe)
return '+'.join(l)
else:
return quote(s, safe)
def urlencode(query,doseq=0):
"""Encode a sequence of two-element tuples or dictionary into a URL query string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment