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

30 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:05 +0000

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 

10try: 

11 import chardet 

12except ImportError: 

13 import charset_normalizer as chardet 

14 

15import sys 

16 

17# ------- 

18# Pythons 

19# ------- 

20 

21# Syntax sugar. 

22_ver = sys.version_info 

23 

24#: Python 2.x? 

25is_py2 = _ver[0] == 2 

26 

27#: Python 3.x? 

28is_py3 = _ver[0] == 3 

29 

30# json/simplejson module import resolution 

31has_simplejson = False 

32try: 

33 import simplejson as json 

34 

35 has_simplejson = True 

36except ImportError: 

37 import json 

38 

39if has_simplejson: 

40 from simplejson import JSONDecodeError 

41else: 

42 from json import JSONDecodeError 

43 

44# Keep OrderedDict for backwards compatibility. 

45from collections import OrderedDict 

46from collections.abc import Callable, Mapping, MutableMapping 

47from http import cookiejar as cookielib 

48from http.cookies import Morsel 

49from io import StringIO 

50 

51# -------------- 

52# Legacy Imports 

53# -------------- 

54from urllib.parse import ( 

55 quote, 

56 quote_plus, 

57 unquote, 

58 unquote_plus, 

59 urldefrag, 

60 urlencode, 

61 urljoin, 

62 urlparse, 

63 urlsplit, 

64 urlunparse, 

65) 

66from urllib.request import ( 

67 getproxies, 

68 getproxies_environment, 

69 parse_http_list, 

70 proxy_bypass, 

71 proxy_bypass_environment, 

72) 

73 

74builtin_str = str 

75str = str 

76bytes = bytes 

77basestring = (str, bytes) 

78numeric_types = (int, float) 

79integer_types = (int,)