Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/requests/compat.py: 95%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

37 statements  

1""" 

2requests.compat 

3~~~~~~~~~~~~~~~ 

4 

5This module previously handled import compatibility issues 

6between Python 2 and Python 3. It remains for backwards 

7compatibility until the next major version. 

8""" 

9 

10import importlib 

11import sys 

12 

13# ------------------- 

14# Character Detection 

15# ------------------- 

16 

17 

18def _resolve_char_detection(): 

19 """Find supported character detection libraries.""" 

20 chardet = None 

21 for lib in ("chardet", "charset_normalizer"): 

22 if chardet is None: 

23 try: 

24 chardet = importlib.import_module(lib) 

25 except ImportError: 

26 pass 

27 return chardet 

28 

29 

30chardet = _resolve_char_detection() 

31 

32# ------- 

33# Pythons 

34# ------- 

35 

36# Syntax sugar. 

37_ver = sys.version_info 

38 

39#: Python 2.x? 

40is_py2 = _ver[0] == 2 

41 

42#: Python 3.x? 

43is_py3 = _ver[0] == 3 

44 

45# json/simplejson module import resolution 

46has_simplejson = False 

47try: 

48 import simplejson as json 

49 

50 has_simplejson = True 

51except ImportError: 

52 import json 

53 

54if has_simplejson: 

55 from simplejson import JSONDecodeError 

56else: 

57 from json import JSONDecodeError 

58 

59# Keep OrderedDict for backwards compatibility. 

60from collections import OrderedDict 

61from collections.abc import Callable, Mapping, MutableMapping 

62from http import cookiejar as cookielib 

63from http.cookies import Morsel 

64from io import StringIO 

65 

66# -------------- 

67# Legacy Imports 

68# -------------- 

69from urllib.parse import ( 

70 quote, 

71 quote_plus, 

72 unquote, 

73 unquote_plus, 

74 urldefrag, 

75 urlencode, 

76 urljoin, 

77 urlparse, 

78 urlsplit, 

79 urlunparse, 

80) 

81from urllib.request import ( 

82 getproxies, 

83 getproxies_environment, 

84 parse_http_list, 

85 proxy_bypass, 

86 proxy_bypass_environment, 

87) 

88 

89builtin_str = str 

90str = str 

91bytes = bytes 

92basestring = (str, bytes) 

93numeric_types = (int, float) 

94integer_types = (int,)