File: test_imports_urllib.py

package info (click to toggle)
python-future 0.18.2-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,264 kB
  • sloc: python: 43,246; makefile: 136; sh: 29
file content (44 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from __future__ import absolute_import, print_function

import sys
from future.tests.base import unittest
from future.standard_library import install_aliases


class ImportUrllibTest(unittest.TestCase):
    def test_urllib(self):
        """
        Tests that urllib isn't changed from under our feet. (This might not
        even be a problem?)
        """
        from future import standard_library
        import urllib
        orig_file = urllib.__file__
        with standard_library.hooks():
            import urllib.response
        self.assertEqual(orig_file, urllib.__file__)

    def test_issue_158(self):
        """
        CherryPy conditional import in _cpcompat.py: issue 158
        """
        install_aliases()
        try:
            from urllib.parse import unquote as parse_unquote

            def unquote_qs(atom, encoding, errors='strict'):
                return parse_unquote(
                    atom.replace('+', ' '),
                    encoding=encoding,
                    errors=errors)
        except ImportError:
            from urllib import unquote as parse_unquote

            def unquote_qs(atom, encoding, errors='strict'):
                return parse_unquote(atom.replace('+', ' ')).decode(encoding, errors)
        self.assertEqual(unquote_qs('/%7Econnolly/', 'utf-8'),
                         '/~connolly/')


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