Skip to content

Commit a27aa52

Browse files
committed
Add test that highlights issue #158
1 parent 7448097 commit a27aa52

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_future/test_imports_urllib.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import sys
44
from future.tests.base import unittest
5+
from future.standard_library import install_aliases
6+
57

68
class ImportUrllibTest(unittest.TestCase):
79
def test_urllib(self):
@@ -16,6 +18,27 @@ def test_urllib(self):
1618
import urllib.response
1719
self.assertEqual(orig_file, urllib.__file__)
1820

21+
def test_issue_158(self):
22+
"""
23+
CherryPy conditional import in _cpcompat.py: issue 158
24+
"""
25+
install_aliases()
26+
try:
27+
from urllib.parse import unquote as parse_unquote
28+
29+
def unquote_qs(atom, encoding, errors='strict'):
30+
return parse_unquote(
31+
atom.replace('+', ' '),
32+
encoding=encoding,
33+
errors=errors)
34+
except ImportError:
35+
from urllib import unquote as parse_unquote
36+
37+
def unquote_qs(atom, encoding, errors='strict'):
38+
return parse_unquote(atom.replace('+', ' ')).decode(encoding, errors)
39+
self.assertEqual(unquote_qs('/%7Econnolly/', 'utf-8'),
40+
'/~connolly/')
41+
1942

2043
if __name__ == '__main__':
2144
unittest.main()

0 commit comments

Comments
 (0)