Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.8KB

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