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

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

29 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 sys 

11 

12# ------- 

13# urllib3 

14# ------- 

15from pip._vendor.urllib3 import __version__ as urllib3_version 

16 

17# Detect which major version of urllib3 is being used. 

18try: 

19 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1 

20except (TypeError, AttributeError): 

21 # If we can't discern a version, prefer old functionality. 

22 is_urllib3_1 = True 

23 

24# ------------------- 

25# Character Detection 

26# ------------------- 

27 

28 

29def _resolve_char_detection(): 

30 """Find supported character detection libraries.""" 

31 chardet = None 

32 return chardet 

33 

34 

35chardet = _resolve_char_detection() 

36 

37# ------- 

38# Pythons 

39# ------- 

40 

41# Syntax sugar. 

42_ver = sys.version_info 

43 

44#: Python 2.x? 

45is_py2 = _ver[0] == 2 

46 

47#: Python 3.x? 

48is_py3 = _ver[0] == 3 

49 

50# Note: We've patched out simplejson support in pip because it prevents 

51# upgrading simplejson on Windows. 

52import json 

53from json import JSONDecodeError 

54 

55# Keep OrderedDict for backwards compatibility. 

56from collections import OrderedDict 

57from collections.abc import Callable, Mapping, MutableMapping 

58from http import cookiejar as cookielib 

59from http.cookies import Morsel 

60from io import StringIO 

61 

62# -------------- 

63# Legacy Imports 

64# -------------- 

65from urllib.parse import ( 

66 quote, 

67 quote_plus, 

68 unquote, 

69 unquote_plus, 

70 urldefrag, 

71 urlencode, 

72 urljoin, 

73 urlparse, 

74 urlsplit, 

75 urlunparse, 

76) 

77from urllib.request import ( 

78 getproxies, 

79 getproxies_environment, 

80 parse_http_list, 

81 proxy_bypass, 

82 proxy_bypass_environment, 

83) 

84 

85builtin_str = str 

86str = str 

87bytes = bytes 

88basestring = (str, bytes) 

89numeric_types = (int, float) 

90integer_types = (int,)