mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
parent
0a35e27d5d
commit
575d270e06
6 changed files with 31 additions and 17 deletions
|
|
@ -9,7 +9,7 @@ env:
|
||||||
# Radicale with filesystem storage (default)
|
# Radicale with filesystem storage (default)
|
||||||
|
|
||||||
- BUILD=test DAV_SERVER=radicale RADICALE_BACKEND=filesystem REQUIREMENTS=release
|
- BUILD=test DAV_SERVER=radicale RADICALE_BACKEND=filesystem REQUIREMENTS=release
|
||||||
PKGS='lxml==3.0 requests==2.4.1 requests_toolbelt==0.3.0 click==3.1'
|
PKGS='lxml==3.0 requests==2.4.1 requests_toolbelt==0.4.0 click==3.1'
|
||||||
# Minimal requirements
|
# Minimal requirements
|
||||||
|
|
||||||
#- BUILD=test DAV_SERVER=radicale RADICALE_BACKEND=filesystem REQUIREMENTS=devel
|
#- BUILD=test DAV_SERVER=radicale RADICALE_BACKEND=filesystem REQUIREMENTS=devel
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ Version 0.5.0
|
||||||
|
|
||||||
*yet to be released*
|
*yet to be released*
|
||||||
|
|
||||||
|
- Raise version of required requests-toolbelt to ``0.4.0``.
|
||||||
|
|
||||||
Version 0.4.4
|
Version 0.4.4
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
|
|
||||||
2
setup.py
2
setup.py
|
|
@ -37,7 +37,7 @@ setup(
|
||||||
'requests',
|
'requests',
|
||||||
'lxml>=3.0',
|
'lxml>=3.0',
|
||||||
# https://github.com/sigmavirus24/requests-toolbelt/pull/28
|
# https://github.com/sigmavirus24/requests-toolbelt/pull/28
|
||||||
'requests_toolbelt>=0.3.0',
|
'requests_toolbelt>=0.4.0',
|
||||||
'atomicwrites'
|
'atomicwrites'
|
||||||
],
|
],
|
||||||
extras_require={'keyring': ['keyring']}
|
extras_require={'keyring': ['keyring']}
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,12 @@ def test_prepare_auth():
|
||||||
|
|
||||||
@pytest.mark.parametrize('auth', (None, 'guess'))
|
@pytest.mark.parametrize('auth', (None, 'guess'))
|
||||||
def test_prepare_auth_guess(monkeypatch, auth):
|
def test_prepare_auth_guess(monkeypatch, auth):
|
||||||
import requests_toolbelt
|
import requests_toolbelt.auth.guess
|
||||||
|
|
||||||
assert isinstance(prepare_auth(auth, 'user', 'pwd'),
|
assert isinstance(prepare_auth(auth, 'user', 'pwd'),
|
||||||
requests_toolbelt.GuessAuth)
|
requests_toolbelt.auth.guess.GuessAuth)
|
||||||
|
|
||||||
if hasattr(requests_toolbelt, 'GuessAuth'):
|
monkeypatch.delattr(requests_toolbelt.auth.guess, 'GuessAuth')
|
||||||
monkeypatch.delattr(requests_toolbelt, 'GuessAuth')
|
|
||||||
|
|
||||||
with pytest.raises(RuntimeError) as excinfo:
|
with pytest.raises(RuntimeError) as excinfo:
|
||||||
prepare_auth(auth, 'user', 'pwd')
|
prepare_auth(auth, 'user', 'pwd')
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,14 @@ def prepare_auth(auth, username, password):
|
||||||
from requests.auth import HTTPDigestAuth
|
from requests.auth import HTTPDigestAuth
|
||||||
return HTTPDigestAuth(username, password)
|
return HTTPDigestAuth(username, password)
|
||||||
elif auth == 'guess' or auth is None:
|
elif auth == 'guess' or auth is None:
|
||||||
import requests_toolbelt
|
try:
|
||||||
if not hasattr(requests_toolbelt, 'GuessAuth'):
|
from requests_toolbelt.auth.guess import GuessAuth
|
||||||
|
except ImportError:
|
||||||
raise RuntimeError('Your version of requests_toolbelt is too '
|
raise RuntimeError('Your version of requests_toolbelt is too '
|
||||||
'old.')
|
'old for `guess` authentication. At least '
|
||||||
return requests_toolbelt.GuessAuth(username, password)
|
'version 0.4.0 is required.')
|
||||||
|
else:
|
||||||
|
return GuessAuth(username, password)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown authentication method: {}'.format(auth))
|
raise ValueError('Unknown authentication method: {}'.format(auth))
|
||||||
elif auth:
|
elif auth:
|
||||||
|
|
|
||||||
|
|
@ -201,6 +201,20 @@ VERIFY_FINGERPRINT_WORKS = _verify_fingerprint_works()
|
||||||
del _verify_fingerprint_works
|
del _verify_fingerprint_works
|
||||||
|
|
||||||
|
|
||||||
|
def _install_fingerprint_adapter(session, fingerprint):
|
||||||
|
prefix = 'https://'
|
||||||
|
try:
|
||||||
|
from requests_toolbelt.adapters.fingerprint import \
|
||||||
|
FingerprintAdapter
|
||||||
|
except ImportError:
|
||||||
|
raise RuntimeError('`verify_fingerprint` can only be used with '
|
||||||
|
'requests-toolbelt versions >= 0.4.0')
|
||||||
|
|
||||||
|
if not isinstance(session.adapters[prefix], FingerprintAdapter):
|
||||||
|
fingerprint_adapter = FingerprintAdapter(fingerprint)
|
||||||
|
session.mount(prefix, fingerprint_adapter)
|
||||||
|
|
||||||
|
|
||||||
def request(method, url, session=None, latin1_fallback=True,
|
def request(method, url, session=None, latin1_fallback=True,
|
||||||
verify_fingerprint=None, **kwargs):
|
verify_fingerprint=None, **kwargs):
|
||||||
'''
|
'''
|
||||||
|
|
@ -223,14 +237,10 @@ def request(method, url, session=None, latin1_fallback=True,
|
||||||
|
|
||||||
if verify_fingerprint is not None:
|
if verify_fingerprint is not None:
|
||||||
if not VERIFY_FINGERPRINT_WORKS:
|
if not VERIFY_FINGERPRINT_WORKS:
|
||||||
raise ValueError('`verify_fingerprint` can only be used with '
|
raise RuntimeError('`verify_fingerprint` can only be used with '
|
||||||
'requests versions >= 2.4.1')
|
'requests versions >= 2.4.1')
|
||||||
|
_install_fingerprint_adapter(session, verify_fingerprint)
|
||||||
kwargs['verify'] = False
|
kwargs['verify'] = False
|
||||||
https_prefix = 'https://'
|
|
||||||
|
|
||||||
if not isinstance(session.adapters[https_prefix], _FingerprintAdapter):
|
|
||||||
fingerprint_adapter = _FingerprintAdapter(verify_fingerprint)
|
|
||||||
session.mount(https_prefix, fingerprint_adapter)
|
|
||||||
|
|
||||||
func = session.request
|
func = session.request
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue