mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Drop support for requests <2.16.2
This commit is contained in:
42
vcr/patch.py
42
vcr/patch.py
@@ -44,14 +44,16 @@ else:
|
||||
|
||||
# Try to save the original types for requests
|
||||
try:
|
||||
if not cpool:
|
||||
import requests.packages.urllib3.connectionpool as cpool
|
||||
import requests
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
else:
|
||||
_VerifiedHTTPSConnection = cpool.VerifiedHTTPSConnection
|
||||
_cpoolHTTPConnection = cpool.HTTPConnection
|
||||
_cpoolHTTPSConnection = cpool.HTTPSConnection
|
||||
if requests.__build__ < 0x021602:
|
||||
raise RuntimeError(
|
||||
"vcrpy >=4.2.2 and requests <2.16.2 are not compatible"
|
||||
"; please upgrade requests (or downgrade vcrpy)"
|
||||
)
|
||||
|
||||
|
||||
# Try to save the original types for httplib2
|
||||
try:
|
||||
@@ -407,36 +409,6 @@ def reset_patchers():
|
||||
yield mock.patch.object(httplib, "HTTPConnection", _HTTPConnection)
|
||||
yield mock.patch.object(httplib, "HTTPSConnection", _HTTPSConnection)
|
||||
|
||||
try:
|
||||
import requests
|
||||
|
||||
if requests.__build__ < 0x021603:
|
||||
# Avoid double unmock if requests 2.16.3
|
||||
# First, this is pointless, requests.packages.urllib3 *IS* urllib3 (see packages.py)
|
||||
# Second, this is unmocking twice the same classes with different namespaces
|
||||
# and is creating weird issues and bugs:
|
||||
# > AssertionError: assert <class 'urllib3.connection.HTTPConnection'>
|
||||
# > is <class 'requests.packages.urllib3.connection.HTTPConnection'>
|
||||
# This assert should work!!!
|
||||
# Note that this also means that now, requests.packages is never imported
|
||||
# if requests 2.16.3 or greater is used with VCRPy.
|
||||
import requests.packages.urllib3.connectionpool as cpool
|
||||
else:
|
||||
raise ImportError("Skip requests not vendored anymore")
|
||||
except ImportError: # pragma: no cover
|
||||
pass
|
||||
else:
|
||||
# unpatch requests v1.x
|
||||
yield mock.patch.object(cpool, "VerifiedHTTPSConnection", _VerifiedHTTPSConnection)
|
||||
yield mock.patch.object(cpool, "HTTPConnection", _cpoolHTTPConnection)
|
||||
# unpatch requests v2.x
|
||||
if hasattr(cpool.HTTPConnectionPool, "ConnectionCls"):
|
||||
yield mock.patch.object(cpool.HTTPConnectionPool, "ConnectionCls", _cpoolHTTPConnection)
|
||||
yield mock.patch.object(cpool.HTTPSConnectionPool, "ConnectionCls", _cpoolHTTPSConnection)
|
||||
|
||||
if hasattr(cpool, "HTTPSConnection"):
|
||||
yield mock.patch.object(cpool, "HTTPSConnection", _cpoolHTTPSConnection)
|
||||
|
||||
try:
|
||||
import urllib3.connectionpool as cpool
|
||||
except ImportError: # pragma: no cover
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
"""Stubs for requests"""
|
||||
|
||||
try:
|
||||
from urllib3.connectionpool import HTTPConnection, VerifiedHTTPSConnection
|
||||
except ImportError:
|
||||
from requests.packages.urllib3.connectionpool import HTTPConnection, VerifiedHTTPSConnection
|
||||
|
||||
from ..stubs import VCRHTTPConnection, VCRHTTPSConnection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user