Skip to content

Commit 7fd9267

Browse files
committed
remove final remnants from 2.6
1 parent 6ae8a21 commit 7fd9267

12 files changed

+42
-70
lines changed

requests/__init__.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ def _check_cryptography(cryptography_version):
7979
return
8080

8181
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)
8383
warnings.warn(warning, RequestsDependencyWarning)
8484

8585
# Check imported dependencies for compatibility.
8686
try:
8787
check_compatibility(urllib3.__version__, chardet.__version__)
8888
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 "
9090
"version!".format(urllib3.__version__, chardet.__version__),
9191
RequestsDependencyWarning)
9292

@@ -123,12 +123,7 @@ def _check_cryptography(cryptography_version):
123123

124124
# Set default logging handler to avoid "No handler found" warnings.
125125
import logging
126-
try: # Python 2.7+
127-
from logging import NullHandler
128-
except ImportError:
129-
class NullHandler(logging.Handler):
130-
def emit(self, record):
131-
pass
126+
from logging import NullHandler
132127

133128
logging.getLogger(__name__).addHandler(NullHandler())
134129

requests/adapters.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def cert_verify(self, conn, url, verify, cert):
225225

226226
if not cert_loc or not os.path.exists(cert_loc):
227227
raise IOError("Could not find a suitable TLS CA certificate bundle, "
228-
"invalid path: {0}".format(cert_loc))
228+
"invalid path: {}".format(cert_loc))
229229

230230
conn.cert_reqs = 'CERT_REQUIRED'
231231

@@ -247,10 +247,10 @@ def cert_verify(self, conn, url, verify, cert):
247247
conn.key_file = None
248248
if conn.cert_file and not os.path.exists(conn.cert_file):
249249
raise IOError("Could not find the TLS certificate file, "
250-
"invalid path: {0}".format(conn.cert_file))
250+
"invalid path: {}".format(conn.cert_file))
251251
if conn.key_file and not os.path.exists(conn.key_file):
252252
raise IOError("Could not find the TLS key file, "
253-
"invalid path: {0}".format(conn.key_file))
253+
"invalid path: {}".format(conn.key_file))
254254

255255
def build_response(self, req, resp):
256256
"""Builds a :class:`Response <requests.Response>` object from a urllib3
@@ -425,7 +425,7 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
425425
timeout = TimeoutSauce(connect=connect, read=read)
426426
except ValueError as e:
427427
# this may raise a string formatting error.
428-
err = ("Invalid timeout {0}. Pass a (connect, read) "
428+
err = ("Invalid timeout {}. Pass a (connect, read) "
429429
"timeout tuple, or a single float to set "
430430
"both timeouts to the same value".format(timeout))
431431
raise ValueError(err)
@@ -475,11 +475,10 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
475475

476476
# Receive the response from the server
477477
try:
478-
# For Python 2.7+ versions, use buffering of HTTP
479-
# responses
478+
# For Python 2.7, use buffering of HTTP responses
480479
r = low_conn.getresponse(buffering=True)
481480
except TypeError:
482-
# For compatibility with Python 2.6 versions and back
481+
# For compatibility with Python 3.3+
483482
r = low_conn.getresponse()
484483

485484
resp = HTTPResponse.from_httplib(

requests/auth.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _basic_auth_str(username, password):
3838
if not isinstance(username, basestring):
3939
warnings.warn(
4040
"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 "
4242
"a string or bytes object in the near future to avoid "
4343
"problems.".format(username),
4444
category=DeprecationWarning,
@@ -48,7 +48,7 @@ def _basic_auth_str(username, password):
4848
if not isinstance(password, basestring):
4949
warnings.warn(
5050
"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 "
5252
"a string or bytes object in the near future to avoid "
5353
"problems.".format(password),
5454
category=DeprecationWarning,

requests/compat.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
import cookielib
4444
from Cookie import Morsel
4545
from StringIO import StringIO
46-
from collections import Callable, Mapping, MutableMapping
46+
from collections import Callable, Mapping, MutableMapping, OrderedDict
4747

48-
from urllib3.packages.ordered_dict import OrderedDict
4948

5049
builtin_str = str
5150
bytes = str

requests/help.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def info():
8989
'version': getattr(idna, '__version__', ''),
9090
}
9191

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_NUMBER
9493
system_ssl_info = {
9594
'version': '%x' % system_ssl if system_ssl is not None else ''
9695
}

requests/utils.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def get_netrc_auth(url, raise_errors=False):
173173

174174
for f in NETRC_FILES:
175175
try:
176-
loc = os.path.expanduser('~/{0}'.format(f))
176+
loc = os.path.expanduser('~/{}'.format(f))
177177
except KeyError:
178178
# os.path.expanduser can fail when $HOME is undefined and
179179
# getpwuid fails. See https://bugs.python.org/issue20164 &
@@ -729,21 +729,16 @@ def should_bypass_proxies(url, no_proxy):
729729
else:
730730
host_with_port = parsed.hostname
731731
if parsed.port:
732-
host_with_port += ':{0}'.format(parsed.port)
732+
host_with_port += ':{}'.format(parsed.port)
733733

734734
for host in no_proxy:
735735
if parsed.hostname.endswith(host) or host_with_port.endswith(host):
736736
# The URL does match something in no_proxy, so we don't want
737737
# to apply the proxies on this URL.
738738
return True
739739

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 versions
743-
# of Python 2.6, so allow this call to fail. Only catch the specific
744-
# exceptions we've seen, though: this call failing in other ways can reveal
745-
# legitimate problems.
746740
with set_environ('no_proxy', no_proxy_arg):
741+
# parsed.hostname can be `None` in cases such as a file URI.
747742
try:
748743
bypass = proxy_bypass(parsed.hostname)
749744
except (TypeError, socket.gaierror):

setup.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ def run_tests(self):
3939
os.system('twine upload dist/*')
4040
sys.exit()
4141

42-
# pyOpenSSL version 18.0.0 dropped support for Python 2.6
43-
if sys.version_info < (2, 7):
44-
PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14, < 18.0.0'
45-
else:
46-
PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14'
47-
4842
packages = ['requests']
4943

5044
requires = [
@@ -85,7 +79,7 @@ def run_tests(self):
8579
package_data={'': ['LICENSE', 'NOTICE'], 'requests': ['*.pem']},
8680
package_dir={'requests': 'requests'},
8781
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.*",
8983
install_requires=requires,
9084
license=about['__license__'],
9185
zip_safe=False,
@@ -108,8 +102,8 @@ def run_tests(self):
108102
cmdclass={'test': PyTest},
109103
tests_require=test_requirements,
110104
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'],
112106
'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'],
114108
},
115109
)

tests/test_help.py

-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
from requests.help import info
88

99

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't
13-
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+")
1910
def test_system_ssl():
2011
"""Verify we're actually setting system_ssl when it should be available."""
2112
assert info()['system_ssl']['version'] != ''

tests/test_lowlevel.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def test_chunked_upload():
1616
data = iter([b'a', b'b', b'c'])
1717

1818
with server as (host, port):
19-
url = 'http://{0}:{1}/'.format(host, port)
19+
url = 'http://{}:{}/'.format(host, port)
2020
r = requests.post(url, data=data, stream=True)
2121
close_server.set() # release server block
2222

@@ -77,7 +77,7 @@ def digest_response_handler(sock):
7777
server = Server(digest_response_handler, wait_to_close_event=close_server)
7878

7979
with server as (host, port):
80-
url = 'http://{0}:{1}/'.format(host, port)
80+
url = 'http://{}:{}/'.format(host, port)
8181
r = requests.get(url, auth=auth)
8282
# Verify server succeeded in authenticating.
8383
assert r.status_code == 200
@@ -127,7 +127,7 @@ def digest_failed_response_handler(sock):
127127
server = Server(digest_failed_response_handler, wait_to_close_event=close_server)
128128

129129
with server as (host, port):
130-
url = 'http://{0}:{1}/'.format(host, port)
130+
url = 'http://{}:{}/'.format(host, port)
131131
r = requests.get(url, auth=auth)
132132
# Verify server didn't authenticate us.
133133
assert r.status_code == 401
@@ -164,7 +164,7 @@ def digest_response_handler(sock):
164164
server = Server(digest_response_handler, wait_to_close_event=close_server)
165165

166166
with server as (host, port):
167-
url = 'http://{0}:{1}/'.format(host, port)
167+
url = 'http://{}:{}/'.format(host, port)
168168
r = requests.get(url, auth=auth)
169169
# Verify server didn't receive auth from us.
170170
assert r.status_code == 200
@@ -181,17 +181,17 @@ def digest_response_handler(sock):
181181
_proxy_combos = []
182182
for prefix, schemes in _schemes_by_var_prefix:
183183
for scheme in schemes:
184-
_proxy_combos.append(("{0}_proxy".format(prefix), scheme))
184+
_proxy_combos.append(("{}_proxy".format(prefix), scheme))
185185

186186
_proxy_combos += [(var.upper(), scheme) for var, scheme in _proxy_combos]
187187

188188

189189
@pytest.mark.parametrize("var,scheme", _proxy_combos)
190190
def test_use_proxy_from_environment(httpbin, var, scheme):
191-
url = "{0}://httpbin.org".format(scheme)
191+
url = "{}://httpbin.org".format(scheme)
192192
fake_proxy = Server() # do nothing with the requests; just close the socket
193193
with fake_proxy as (host, port):
194-
proxy_url = "socks5://{0}:{1}".format(host, port)
194+
proxy_url = "socks5://{}:{}".format(host, port)
195195
kwargs = {var: proxy_url}
196196
with override_environ(**kwargs):
197197
# fake proxy's lack of response will cause a ConnectionError
@@ -212,7 +212,7 @@ def test_redirect_rfc1808_to_non_ascii_location():
212212

213213
def redirect_resp_handler(sock):
214214
consume_socket_content(sock, timeout=0.5)
215-
location = u'//{0}:{1}/{2}'.format(host, port, path)
215+
location = u'//{}:{}/{}'.format(host, port, path)
216216
sock.send(
217217
b'HTTP/1.1 301 Moved Permanently\r\n'
218218
b'Content-Length: 0\r\n'
@@ -226,13 +226,13 @@ def redirect_resp_handler(sock):
226226
server = Server(redirect_resp_handler, wait_to_close_event=close_server)
227227

228228
with server as (host, port):
229-
url = u'http://{0}:{1}'.format(host, port)
229+
url = u'http://{}:{}'.format(host, port)
230230
r = requests.get(url=url, allow_redirects=True)
231231
assert r.status_code == 200
232232
assert len(r.history) == 1
233233
assert r.history[0].status_code == 301
234234
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'))
236236

237237
close_server.set()
238238

@@ -250,7 +250,7 @@ def response_handler(sock):
250250
server = Server(response_handler, wait_to_close_event=close_server)
251251

252252
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)
254254
r = requests.get(url)
255255
raw_request = r.content
256256

@@ -293,7 +293,7 @@ def response_handler(sock):
293293
server = Server(response_handler, wait_to_close_event=close_server)
294294

295295
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)
297297
r = requests.get(url)
298298
raw_request = r.content
299299

@@ -302,8 +302,8 @@ def response_handler(sock):
302302
assert r.history[0].request.url == url
303303

304304
# 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)
306306
# 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)
308308

309309
close_server.set()

tests/test_requests.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_mixed_case_scheme_acceptable(self, httpbin, scheme):
158158
url = scheme + parts.netloc + parts.path
159159
r = requests.Request('GET', url)
160160
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)
162162

163163
def test_HTTP_200_OK_GET_ALTERNATIVE(self, httpbin):
164164
r = requests.Request('GET', httpbin('get'))
@@ -816,17 +816,17 @@ def test_invalid_ca_certificate_path(self, httpbin_secure):
816816
INVALID_PATH = '/garbage'
817817
with pytest.raises(IOError) as e:
818818
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)
820820

821821
def test_invalid_ssl_certificate_files(self, httpbin_secure):
822822
INVALID_PATH = '/garbage'
823823
with pytest.raises(IOError) as e:
824824
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)
826826

827827
with pytest.raises(IOError) as e:
828828
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)
830830

831831
def test_http_with_certificate(self, httpbin):
832832
r = requests.get(httpbin(), cert='.')
@@ -1458,7 +1458,7 @@ def test_params_are_merged_case_sensitive(self, httpbin):
14581458
assert r.json()['args'] == {'foo': 'bar', 'FOO': 'bar'}
14591459

14601460
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(
14621462
'E8A3BE87-9E3F-4620-8858-95478E385B5B',
14631463
'EA770032-DA4D-4D84-8CE9-29C6D910BF1E',
14641464
'exactly-------------sixty-----------three------------characters',

tests/test_testserver.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_text_response(self):
5050
)
5151

5252
with server as (host, port):
53-
r = requests.get('http://{0}:{1}'.format(host, port))
53+
r = requests.get('http://{}:{}'.format(host, port))
5454

5555
assert r.status_code == 200
5656
assert r.text == u'roflol'
@@ -59,7 +59,7 @@ def test_text_response(self):
5959
def test_basic_response(self):
6060
"""the basic response server returns an empty http response"""
6161
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))
6363
assert r.status_code == 200
6464
assert r.text == u''
6565
assert r.headers['Content-Length'] == '0'
@@ -83,7 +83,7 @@ def test_multiple_requests(self):
8383
server = Server.basic_response_server(requests_to_handle=requests_to_handle)
8484

8585
with server as (host, port):
86-
server_url = 'http://{0}:{1}'.format(host, port)
86+
server_url = 'http://{}:{}'.format(host, port)
8787
for _ in range(requests_to_handle):
8888
r = requests.get(server_url)
8989
assert r.status_code == 200

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py26,py27,py34,py35,py36
2+
envlist = py27,py34,py35,py36
33

44
[testenv]
55

0 commit comments

Comments
 (0)