Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__init__.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. # -*- coding: utf-8 -*-
  2. # __
  3. # /__) _ _ _ _ _/ _
  4. # / ( (- (/ (/ (- _) / _)
  5. # /
  6. """
  7. Requests HTTP Library
  8. ~~~~~~~~~~~~~~~~~~~~~
  9. Requests is an HTTP library, written in Python, for human beings. Basic GET
  10. usage:
  11. >>> import requests
  12. >>> r = requests.get('https://www.python.org')
  13. >>> r.status_code
  14. 200
  15. >>> 'Python is a programming language' in r.content
  16. True
  17. ... or POST:
  18. >>> payload = dict(key1='value1', key2='value2')
  19. >>> r = requests.post('http://httpbin.org/post', data=payload)
  20. >>> print(r.text)
  21. {
  22. ...
  23. "form": {
  24. "key2": "value2",
  25. "key1": "value1"
  26. },
  27. ...
  28. }
  29. The other HTTP methods are supported - see `requests.api`. Full documentation
  30. is at <http://python-requests.org>.
  31. :copyright: (c) 2017 by Kenneth Reitz.
  32. :license: Apache 2.0, see LICENSE for more details.
  33. """
  34. from pip._vendor import urllib3
  35. from pip._vendor import chardet
  36. import warnings
  37. from .exceptions import RequestsDependencyWarning
  38. def check_compatibility(urllib3_version, chardet_version):
  39. urllib3_version = urllib3_version.split('.')
  40. assert urllib3_version != ['dev'] # Verify urllib3 isn't installed from git.
  41. # Sometimes, urllib3 only reports its version as 16.1.
  42. if len(urllib3_version) == 2:
  43. urllib3_version.append('0')
  44. # Check urllib3 for compatibility.
  45. major, minor, patch = urllib3_version # noqa: F811
  46. major, minor, patch = int(major), int(minor), int(patch)
  47. # urllib3 >= 1.21.1, <= 1.23
  48. assert major == 1
  49. assert minor >= 21
  50. assert minor <= 23
  51. # Check chardet for compatibility.
  52. major, minor, patch = chardet_version.split('.')[:3]
  53. major, minor, patch = int(major), int(minor), int(patch)
  54. # chardet >= 3.0.2, < 3.1.0
  55. assert major == 3
  56. assert minor < 1
  57. assert patch >= 2
  58. def _check_cryptography(cryptography_version):
  59. # cryptography < 1.3.4
  60. try:
  61. cryptography_version = list(map(int, cryptography_version.split('.')))
  62. except ValueError:
  63. return
  64. if cryptography_version < [1, 3, 4]:
  65. warning = 'Old version of cryptography ({0}) may cause slowdown.'.format(cryptography_version)
  66. warnings.warn(warning, RequestsDependencyWarning)
  67. # Check imported dependencies for compatibility.
  68. try:
  69. check_compatibility(urllib3.__version__, chardet.__version__)
  70. except (AssertionError, ValueError):
  71. warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "
  72. "version!".format(urllib3.__version__, chardet.__version__),
  73. RequestsDependencyWarning)
  74. # Attempt to enable urllib3's SNI support, if possible
  75. from pip._internal.utils.compat import WINDOWS
  76. if not WINDOWS:
  77. try:
  78. from pip._vendor.urllib3.contrib import pyopenssl
  79. pyopenssl.inject_into_urllib3()
  80. # Check cryptography version
  81. from cryptography import __version__ as cryptography_version
  82. _check_cryptography(cryptography_version)
  83. except ImportError:
  84. pass
  85. # urllib3's DependencyWarnings should be silenced.
  86. from pip._vendor.urllib3.exceptions import DependencyWarning
  87. warnings.simplefilter('ignore', DependencyWarning)
  88. from .__version__ import __title__, __description__, __url__, __version__
  89. from .__version__ import __build__, __author__, __author_email__, __license__
  90. from .__version__ import __copyright__, __cake__
  91. from . import utils
  92. from . import packages
  93. from .models import Request, Response, PreparedRequest
  94. from .api import request, get, head, post, patch, put, delete, options
  95. from .sessions import session, Session
  96. from .status_codes import codes
  97. from .exceptions import (
  98. RequestException, Timeout, URLRequired,
  99. TooManyRedirects, HTTPError, ConnectionError,
  100. FileModeWarning, ConnectTimeout, ReadTimeout
  101. )
  102. # Set default logging handler to avoid "No handler found" warnings.
  103. import logging
  104. try: # Python 2.7+
  105. from logging import NullHandler
  106. except ImportError:
  107. class NullHandler(logging.Handler):
  108. def emit(self, record):
  109. pass
  110. logging.getLogger(__name__).addHandler(NullHandler())
  111. # FileModeWarnings go off per the default.
  112. warnings.simplefilter('default', FileModeWarning, append=True)