remove final remnants from 2.6
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nate Prewitt · committed by Nate Prewitt · parent 6ae8a21 · Browse files · 12 files·+42 added−70 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
12 files+42 added−70 removed
- tests:+22 added−31 removed
- other:+20 added−39 removed
Provenance
- Commit
7fd9267- Tree
dcfc697- Author
Nate Prewitt <Nate.Prewitt@gmail.com>- Committer
Nate Prewitt <Nate.Prewitt@gmail.com>- Parent
6ae8a21
12 files changed+42 added−70 removed
modified:requests/__init__.py+3 added-8 removed
77 unmodified lines78 except ValueError:79 return80 81 if cryptography_version < [1, 3, 4]:82- warning = 'Old version of cryptography ({0}) may cause slowdown.'.format(cryptography_version)82+ warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)83 warnings.warn(warning, RequestsDependencyWarning)84 85 # Check imported dependencies for compatibility.86 try:87 check_compatibility(urllib3.__version__, chardet.__version__)88 except (AssertionError, ValueError):89- warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "89+ warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "90 "version!".format(urllib3.__version__, chardet.__version__),91 RequestsDependencyWarning)92 93 # Attempt to enable urllib3's SNI support, if possible28 unmodified lines122 )123 124 # Set default logging handler to avoid "No handler found" warnings.125 import logging126-try: # Python 2.7+127- from logging import NullHandler126+from logging import NullHandler128-except ImportError:129- class NullHandler(logging.Handler):130- def emit(self, record):131- pass127 128 logging.getLogger(__name__).addHandler(NullHandler())129 130 # FileModeWarnings go off per the default.1 unmodified linemodified:requests/adapters.py+6 added-7 removed
223 unmodified lines224 cert_loc = extract_zipped_paths(DEFAULT_CA_BUNDLE_PATH)225 226 if not cert_loc or not os.path.exists(cert_loc):227 raise IOError("Could not find a suitable TLS CA certificate bundle, "228- "invalid path: {0}".format(cert_loc))228+ "invalid path: {}".format(cert_loc))229 230 conn.cert_reqs = 'CERT_REQUIRED'231 232 if not os.path.isdir(cert_loc):13 unmodified lines246 conn.cert_file = cert247 conn.key_file = None248 if conn.cert_file and not os.path.exists(conn.cert_file):249 raise IOError("Could not find the TLS certificate file, "250- "invalid path: {0}".format(conn.cert_file))250+ "invalid path: {}".format(conn.cert_file))251 if conn.key_file and not os.path.exists(conn.key_file):252 raise IOError("Could not find the TLS key file, "253- "invalid path: {0}".format(conn.key_file))253+ "invalid path: {}".format(conn.key_file))254 255 def build_response(self, req, resp):256 """Builds a :class:`Response <requests.Response>` object from a urllib3257 response. This should not be called from user code, and is only exposed166 unmodified lines424 connect, read = timeout425 timeout = TimeoutSauce(connect=connect, read=read)426 except ValueError as e:427 # this may raise a string formatting error.428- err = ("Invalid timeout {0}. Pass a (connect, read) "428+ err = ("Invalid timeout {}. Pass a (connect, read) "429 "timeout tuple, or a single float to set "430 "both timeouts to the same value".format(timeout))431 raise ValueError(err)432 elif isinstance(timeout, TimeoutSauce):41 unmodified lines474 low_conn.send(b'0\r\n\r\n')475 476 # Receive the response from the server477 try:478- # For Python 2.7+ versions, use buffering of HTTP479- # responses478+ # For Python 2.7, use buffering of HTTP responses479 r = low_conn.getresponse(buffering=True)480 except TypeError:482- # For compatibility with Python 2.6 versions and back481+ # For compatibility with Python 3.3+482 r = low_conn.getresponse()483 484 resp = HTTPResponse.from_httplib(485 r,48 unmodified linesmodified:requests/auth.py+2 added-2 removed
36 unmodified lines37 # for things like ints. This will be removed in 3.0.0.38 if not isinstance(username, basestring):39 warnings.warn(40 "Non-string usernames will no longer be supported in Requests "41- "3.0.0. Please convert the object you've passed in ({0!r}) to "41+ "3.0.0. Please convert the object you've passed in ({!r}) to "42 "a string or bytes object in the near future to avoid "43 "problems.".format(username),44 category=DeprecationWarning,45 )1 unmodified line47 48 if not isinstance(password, basestring):49 warnings.warn(50 "Non-string passwords will no longer be supported in Requests "51- "3.0.0. Please convert the object you've passed in ({0!r}) to "51+ "3.0.0. Please convert the object you've passed in ({!r}) to "52 "a string or bytes object in the near future to avoid "53 "problems.".format(password),54 category=DeprecationWarning,55 )250 unmodified linesmodified:requests/compat.py+1 added-2 removed
41 unmodified lines42 from urllib2 import parse_http_list43 import cookielib44 from Cookie import Morsel45 from StringIO import StringIO46- from collections import Callable, Mapping, MutableMapping46+ from collections import Callable, Mapping, MutableMapping, OrderedDict47 48- from urllib3.packages.ordered_dict import OrderedDict48 49 builtin_str = str50 bytes = str51 str = unicode19 unmodified linesmodified:requests/help.py+1 added-2 removed
87 unmodified lines88 idna_info = {89 'version': getattr(idna, '__version__', ''),90 }91 92- # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module.93- system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None)92+ system_ssl = ssl.OPENSSL_VERSION_NUMBER93 system_ssl_info = {94 'version': '%x' % system_ssl if system_ssl is not None else ''95 }96 23 unmodified linesmodified:requests/utils.py+3 added-8 removed
171 unmodified lines172 netrc_path = None173 174 for f in NETRC_FILES:175 try:176- loc = os.path.expanduser('~/{0}'.format(f))176+ loc = os.path.expanduser('~/{}'.format(f))177 except KeyError:178 # os.path.expanduser can fail when $HOME is undefined and179 # getpwuid fails. See https://bugs.python.org/issue20164 &180 # https://github.com/requests/requests/issues/1846547 unmodified lines728 return True729 else:730 host_with_port = parsed.hostname731 if parsed.port:732- host_with_port += ':{0}'.format(parsed.port)732+ host_with_port += ':{}'.format(parsed.port)733 734 for host in no_proxy:735 if parsed.hostname.endswith(host) or host_with_port.endswith(host):736 # The URL does match something in no_proxy, so we don't want737 # to apply the proxies on this URL.738 return True739 740- # If the system proxy settings indicate that this URL should be bypassed,741- # don't proxy.742- # The proxy_bypass function is incredibly buggy on OS X in early versions743- # of Python 2.6, so allow this call to fail. Only catch the specific744- # exceptions we've seen, though: this call failing in other ways can reveal745- # legitimate problems.740 with set_environ('no_proxy', no_proxy_arg):741+ # parsed.hostname can be `None` in cases such as a file URI.742 try:743 bypass = proxy_bypass(parsed.hostname)744 except (TypeError, socket.gaierror):745 bypass = False230 unmodified linesmodified:tests/test_help.py-9 removed
5 unmodified lines6 7 from requests.help import info8 9 10-@pytest.mark.skipif(sys.version_info[:2] != (2,6), reason="Only run on Python 2.6")11-def test_system_ssl_py26():12- """OPENSSL_VERSION_NUMBER isn't provided in Python 2.6, verify we don't13- blow up in this case.14- """15- assert info()['system_ssl'] == {'version': ''}16-17-18-@pytest.mark.skipif(sys.version_info < (2,7), reason="Only run on Python 2.7+")10 def test_system_ssl():11 """Verify we're actually setting system_ssl when it should be available."""12 assert info()['system_ssl']['version'] != ''13 18 unmodified linesmodified:tests/test_lowlevel.py+14 added-14 removed
14 unmodified lines15 server = Server.basic_response_server(wait_to_close_event=close_server)16 data = iter([b'a', b'b', b'c'])17 18 with server as (host, port):19- url = 'http://{0}:{1}/'.format(host, port)19+ url = 'http://{}:{}/'.format(host, port)20 r = requests.post(url, data=data, stream=True)21 close_server.set() # release server block22 23 assert r.status_code == 20052 unmodified lines76 close_server = threading.Event()77 server = Server(digest_response_handler, wait_to_close_event=close_server)78 79 with server as (host, port):80- url = 'http://{0}:{1}/'.format(host, port)80+ url = 'http://{}:{}/'.format(host, port)81 r = requests.get(url, auth=auth)82 # Verify server succeeded in authenticating.83 assert r.status_code == 20084 # Verify Authorization was sent in final request.41 unmodified lines126 close_server = threading.Event()127 server = Server(digest_failed_response_handler, wait_to_close_event=close_server)128 129 with server as (host, port):130- url = 'http://{0}:{1}/'.format(host, port)130+ url = 'http://{}:{}/'.format(host, port)131 r = requests.get(url, auth=auth)132 # Verify server didn't authenticate us.133 assert r.status_code == 401134 assert r.history[0].status_code == 40128 unmodified lines163 close_server = threading.Event()164 server = Server(digest_response_handler, wait_to_close_event=close_server)165 166 with server as (host, port):167- url = 'http://{0}:{1}/'.format(host, port)167+ url = 'http://{}:{}/'.format(host, port)168 r = requests.get(url, auth=auth)169 # Verify server didn't receive auth from us.170 assert r.status_code == 200171 assert len(r.history) == 08 unmodified lines180 181 _proxy_combos = []182 for prefix, schemes in _schemes_by_var_prefix:183 for scheme in schemes:184- _proxy_combos.append(("{0}_proxy".format(prefix), scheme))184+ _proxy_combos.append(("{}_proxy".format(prefix), scheme))185 186 _proxy_combos += [(var.upper(), scheme) for var, scheme in _proxy_combos]187 188 189 @pytest.mark.parametrize("var,scheme", _proxy_combos)190 def test_use_proxy_from_environment(httpbin, var, scheme):191- url = "{0}://httpbin.org".format(scheme)191+ url = "{}://httpbin.org".format(scheme)192 fake_proxy = Server() # do nothing with the requests; just close the socket193 with fake_proxy as (host, port):194- proxy_url = "socks5://{0}:{1}".format(host, port)194+ proxy_url = "socks5://{}:{}".format(host, port)195 kwargs = {var: proxy_url}196 with override_environ(**kwargs):197 # fake proxy's lack of response will cause a ConnectionError198 with pytest.raises(requests.exceptions.ConnectionError):12 unmodified lines211 redirect_request = [] # stores the second request to the server212 213 def redirect_resp_handler(sock):214 consume_socket_content(sock, timeout=0.5)215- location = u'//{0}:{1}/{2}'.format(host, port, path)215+ location = u'//{}:{}/{}'.format(host, port, path)216 sock.send(217 b'HTTP/1.1 301 Moved Permanently\r\n'218 b'Content-Length: 0\r\n'219 b'Location: ' + location.encode('utf8') + b'\r\n'5 unmodified lines225 close_server = threading.Event()226 server = Server(redirect_resp_handler, wait_to_close_event=close_server)227 228 with server as (host, port):229- url = u'http://{0}:{1}'.format(host, port)229+ url = u'http://{}:{}'.format(host, port)230 r = requests.get(url=url, allow_redirects=True)231 assert r.status_code == 200232 assert len(r.history) == 1233 assert r.history[0].status_code == 301234 assert redirect_request[0].startswith(b'GET /' + expected_path + b' HTTP/1.1')235- assert r.url == u'{0}/{1}'.format(url, expected_path.decode('ascii'))235+ assert r.url == u'{}/{}'.format(url, expected_path.decode('ascii'))236 237 close_server.set()238 239 def test_fragment_not_sent_with_request():9 unmodified lines249 close_server = threading.Event()250 server = Server(response_handler, wait_to_close_event=close_server)251 252 with server as (host, port):253- url = 'http://{0}:{1}/path/to/thing/#view=edit&token=hunter2'.format(host, port)253+ url = 'http://{}:{}/path/to/thing/#view=edit&token=hunter2'.format(host, port)254 r = requests.get(url)255 raw_request = r.content256 257 assert r.status_code == 20034 unmodified lines292 close_server = threading.Event()293 server = Server(response_handler, wait_to_close_event=close_server)294 295 with server as (host, port):296- url = 'http://{0}:{1}/path/to/thing/#view=edit&token=hunter2'.format(host, port)296+ url = 'http://{}:{}/path/to/thing/#view=edit&token=hunter2'.format(host, port)297 r = requests.get(url)298 raw_request = r.content299 300 assert r.status_code == 200301 assert len(r.history) == 2302 assert r.history[0].request.url == url303 304 # Verify we haven't overwritten the location with our previous fragment.305- assert r.history[1].request.url == 'http://{0}:{1}/get#relevant-section'.format(host, port)305+ assert r.history[1].request.url == 'http://{}:{}/get#relevant-section'.format(host, port)306 # Verify previous fragment is used and not the original.307- assert r.url == 'http://{0}:{1}/final-url/#relevant-section'.format(host, port)307+ assert r.url == 'http://{}:{}/final-url/#relevant-section'.format(host, port)308 309 close_server.set()modified:tests/test_requests.py+5 added-5 removed
156 unmodified lines157 parts = urlparse(httpbin('get'))158 url = scheme + parts.netloc + parts.path159 r = requests.Request('GET', url)160 r = s.send(r.prepare())161- assert r.status_code == 200, 'failed for scheme {0}'.format(scheme)161+ assert r.status_code == 200, 'failed for scheme {}'.format(scheme)162 163 def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):164 r = requests.Request('GET', httpbin('get'))165 s = requests.Session()649 unmodified lines815 def test_invalid_ca_certificate_path(self, httpbin_secure):816 INVALID_PATH = '/garbage'817 with pytest.raises(IOError) as e:818 requests.get(httpbin_secure(), verify=INVALID_PATH)819- assert str(e.value) == 'Could not find a suitable TLS CA certificate bundle, invalid path: {0}'.format(INVALID_PATH)819+ assert str(e.value) == 'Could not find a suitable TLS CA certificate bundle, invalid path: {}'.format(INVALID_PATH)820 821 def test_invalid_ssl_certificate_files(self, httpbin_secure):822 INVALID_PATH = '/garbage'823 with pytest.raises(IOError) as e:824 requests.get(httpbin_secure(), cert=INVALID_PATH)825- assert str(e.value) == 'Could not find the TLS certificate file, invalid path: {0}'.format(INVALID_PATH)825+ assert str(e.value) == 'Could not find the TLS certificate file, invalid path: {}'.format(INVALID_PATH)826 827 with pytest.raises(IOError) as e:828 requests.get(httpbin_secure(), cert=('.', INVALID_PATH))829- assert str(e.value) == 'Could not find the TLS key file, invalid path: {0}'.format(INVALID_PATH)829+ assert str(e.value) == 'Could not find the TLS key file, invalid path: {}'.format(INVALID_PATH)830 831 def test_http_with_certificate(self, httpbin):832 r = requests.get(httpbin(), cert='.')833 assert r.status_code == 200623 unmodified lines1457 r = s.get(httpbin('get'), params={'FOO': 'bar'})1458 assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}1459 1460 def test_long_authinfo_in_url(self):1461- url = 'http://{0}:{1}@{2}:9000/path?query#frag'.format(1461+ url = 'http://{}:{}@{}:9000/path?query#frag'.format(1462 'E8A3BE87-9E3F-4620-8858-95478E385B5B',1463 'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',1464 'exactly-------------sixty-----------three------------characters',1465 )1042 unmodified linesmodified:tests/test_testserver.py+3 added-3 removed
48 unmodified lines49 "\r\nroflol"50 )51 52 with server as (host, port):53- r = requests.get('http://{0}:{1}'.format(host, port))53+ r = requests.get('http://{}:{}'.format(host, port))54 55 assert r.status_code == 20056 assert r.text == u'roflol'57 assert r.headers['Content-Length'] == '6'58 59 def test_basic_response(self):60 """the basic response server returns an empty http response"""61 with Server.basic_response_server() as (host, port):62- r = requests.get('http://{0}:{1}'.format(host, port))62+ r = requests.get('http://{}:{}'.format(host, port))63 assert r.status_code == 20064 assert r.text == u''65 assert r.headers['Content-Length'] == '0'66 15 unmodified lines82 83 server = Server.basic_response_server(requests_to_handle=requests_to_handle)84 85 with server as (host, port):86- server_url = 'http://{0}:{1}'.format(host, port)86+ server_url = 'http://{}:{}'.format(host, port)87 for _ in range(requests_to_handle):88 r = requests.get(server_url)89 assert r.status_code == 20090 76 unmodified linesmodified:setup.py+3 added-9 removed
37 unmodified lines38 os.system('python setup.py sdist bdist_wheel')39 os.system('twine upload dist/*')40 sys.exit()41 42-# pyOpenSSL version 18.0.0 dropped support for Python 2.643-if sys.version_info < (2, 7):44- PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14, < 18.0.0'45-else:46- PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14'47-42 packages = ['requests']43 44 requires = [45 'chardet>=3.0.2,<3.1.0',32 unmodified lines78 packages=packages,79 package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']},80 package_dir={'requests': 'requests'},81 include_package_data=True,88- python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",82+ python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",83 install_requires=requires,84 license=about['__license__'],85 zip_safe=False,86 classifiers=[14 unmodified lines101 ],102 cmdclass={'test': PyTest},103 tests_require=test_requirements,104 extras_require={111- 'security': [PYOPENSSL_VERSION, 'cryptography>=1.3.4', 'idna>=2.0.0'],105+ 'security': ['pyOpenSSL >= 0.14', 'cryptography>=1.3.4', 'idna>=2.0.0'],106 'socks': ['PySocks>=1.5.6, !=1.5.7'],113- 'socks:sys_platform == "win32" and (python_version == "2.7" or python_version == "2.6")': ['win_inet_pton'],107+ 'socks:sys_platform == "win32" and python_version == "2.7"': ['win_inet_pton'],108 },109 )modified:tox.ini+1 added-1 removed
1 [tox]2-envlist = py26,py27,py34,py35,py362+envlist = py27,py34,py35,py363 4 [testenv]5 6 commands =2 unmodified lines