mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
Check requests version at runtime
This commit is contained in:
parent
6dbe1f5eed
commit
2cd0a26a12
2 changed files with 21 additions and 2 deletions
3
setup.py
3
setup.py
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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://'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue