Check requests version at runtime

This commit is contained in:
Markus Unterwaditzer 2015-02-12 12:24:24 +01:00
parent 6dbe1f5eed
commit 2cd0a26a12
2 changed files with 21 additions and 2 deletions

View file

@ -34,8 +34,7 @@ setup(
install_requires=[
# https://github.com/mitsuhiko/click/issues/200
'click>=3.1',
# https://github.com/shazow/urllib3/pull/444
'requests>=2.4.1',
'requests',
'lxml>=3.0',
'icalendar>=3.6',
# https://github.com/sigmavirus24/requests-toolbelt/pull/28

View file

@ -177,6 +177,23 @@ class _FingerprintAdapter(requests.adapters.HTTPAdapter):
assert_fingerprint=self.fingerprint)
def _verify_fingerprint_works():
try:
import requests
from pkg_resources import parse_version as ver
return ver(requests.__version__) >= ver('2.4.1')
except Exception:
return False
# https://github.com/shazow/urllib3/pull/444
# We check this here instead of setup.py, because:
# - This is critical to security of `verify_fingerprint`, and Python's
# packaging stuff doesn't check installed versions.
# - The people who don't use `verify_fingerprint` wouldn't care.
VERIFY_FINGERPRINT_WORKS = _verify_fingerprint_works()
def request(method, url, session=None, latin1_fallback=True,
verify_fingerprint=None, **kwargs):
'''
@ -198,6 +215,9 @@ def request(method, url, session=None, latin1_fallback=True,
session = requests.Session()
if verify_fingerprint is not None:
if not VERIFY_FINGERPRINT_WORKS:
raise ValueError('`verify_fingerprint` can only be used with '
'requests versions >= 2.4.1')
kwargs['verify'] = False
https_prefix = 'https://'