Skip to content

Commit

Permalink
Drop support for Python 2.6 (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk authored and sethmlarson committed Aug 23, 2018
1 parent 85e376a commit cb21598
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 492 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Expand Up @@ -23,8 +23,6 @@ env:
# https://github.com/travis-ci/travis-ci/issues/4794
matrix:
include:
- python: 2.6
env: TOXENV=py26
- python: 2.7
env: TOXENV=py27
- python: 3.4
Expand All @@ -37,9 +35,6 @@ matrix:
env: TOXENV=py37
- python: pypy-5.4
env: TOXENV=pypy
- language: generic
os: osx
env: TOXENV=py26
- language: generic
os: osx
env: TOXENV=py27
Expand Down
8 changes: 0 additions & 8 deletions _travis/install.sh
Expand Up @@ -17,18 +17,10 @@ if [[ "$(uname -s)" == 'Darwin' ]]; then
eval "$(pyenv init -)"

case "${TOXENV}" in
py26)
pyenv install 2.6.9
pyenv global 2.6.9
;;
py27)
pyenv install 2.7.14
pyenv global 2.7.14
;;
py33)
pyenv install 3.3.6
pyenv global 3.3.6
;;
py34)
pyenv install 3.4.7
pyenv global 3.4.7
Expand Down
11 changes: 4 additions & 7 deletions dev-requirements.txt
Expand Up @@ -3,12 +3,9 @@ coverage==4.5.1
tox==2.9.1
twine==1.11.0
wheel==0.30.0
tornado==5.0.2; python_version>"2.6"
tornado==4.2.1; python_version<="2.6"
tornado==5.0.2
PySocks==1.6.8
pkginfo==1.4.2
pytest-timeout==1.3.1; python_version>"2.6"
pytest-timeout==1.2.0; python_version<="2.6"
pytest==3.6.4; python_version>"2.6"
pytest==3.2.5; python_version<="2.6"
gcp-devrel-py-tools==0.0.15; python_version>"2.6"
pytest-timeout==1.3.1
pytest==3.6.4
gcp-devrel-py-tools==0.0.15
7 changes: 4 additions & 3 deletions docs/contributing.rst
Expand Up @@ -55,11 +55,12 @@ suite::

$ make test-all
[... tox creates a virtualenv for every platform and runs tests inside of each]
py26: commands succeeded
py27: commands succeeded
py32: commands succeeded
py33: commands succeeded
py34: commands succeeded
py35: commands succeeded
py36: commands succeeded
py37: commands succeeded
pypy: commands succeeded

Our test suite `runs continuously on Travis CI
<https://travis-ci.org/urllib3/urllib3>`_ with every pull request.
Expand Down
7 changes: 1 addition & 6 deletions dummyserver/testcase.py
@@ -1,5 +1,5 @@
import sys
import threading
import unittest

import pytest
from tornado import ioloop, web
Expand All @@ -14,11 +14,6 @@
from dummyserver.handlers import TestingApp
from dummyserver.proxy import ProxyHandler

if sys.version_info >= (2, 7):
import unittest
else:
import unittest2 as unittest


def consume_socket(sock, chunks=65536):
while not sock.recv(chunks).endswith(b'\r\n\r\n'):
Expand Down
7 changes: 3 additions & 4 deletions setup.cfg
Expand Up @@ -11,10 +11,9 @@ provides-extra =
secure
socks
requires-dist =
pyOpenSSL>=0.14,<18.0.0; python_version=="2.6" and extra == 'secure'
pyOpenSSL>=0.14; python_version=="2.7" and extra == 'secure'
cryptography>=1.3.4; python_version<="2.7" and extra == 'secure'
idna>=2.0.0; python_version<="2.7" and extra == 'secure'
cryptography>=1.3.4; python_version=="2.7" and extra == 'secure'
idna>=2.0.0; python_version=="2.7" and extra == 'secure'
certifi; extra == 'secure'
ipaddress; python_version<="2.7" and extra == 'secure'
ipaddress; python_version=="2.7" and extra == 'secure'
PySocks>=1.5.6,<2.0,!=1.5.7; extra == 'socks'
12 changes: 2 additions & 10 deletions setup.py
Expand Up @@ -3,7 +3,6 @@
from setuptools import setup

import os
import sys
import re
import codecs

Expand All @@ -20,12 +19,6 @@
changes = fp.read()
version = VERSION

# pyOpenSSL version 18.0.0 dropped support for Python 2.6
if sys.version_info < (2, 7):
PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14, < 18.0.0'
else:
PYOPENSSL_VERSION = 'pyOpenSSL >= 0.14'

setup(name='urllib3',
version=version,
description="HTTP library with thread-safe connection pooling, file post, and more.",
Expand All @@ -37,7 +30,6 @@
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
Expand All @@ -60,7 +52,7 @@
],
package_dir={'': 'src'},
requires=[],
python_requires=">=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
tests_require=[
# These are a less-specific subset of dev-requirements.txt, for the
# convenience of distro package maintainers.
Expand All @@ -71,7 +63,7 @@
test_suite='test',
extras_require={
'secure': [
PYOPENSSL_VERSION,
'pyOpenSSL >= 0.14',
'cryptography>=1.3.4',
'idna>=2.0.0',
'certifi',
Expand Down
7 changes: 1 addition & 6 deletions src/urllib3/__init__.py
Expand Up @@ -22,12 +22,7 @@

# Set default logging handler to avoid "No handler found" warnings.
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):
def emit(self, record):
pass
from logging import NullHandler

__author__ = 'Andrey Petrov (andrey.petrov@shazow.net)'
__license__ = 'MIT'
Expand Down
5 changes: 1 addition & 4 deletions src/urllib3/_collections.py
Expand Up @@ -14,10 +14,7 @@ def __exit__(self, exc_type, exc_value, traceback):
pass


try: # Python 2.7+
from collections import OrderedDict
except ImportError:
from .packages.ordered_dict import OrderedDict
from collections import OrderedDict
from .exceptions import InvalidHeader
from .packages.six import iterkeys, itervalues, PY3

Expand Down
14 changes: 1 addition & 13 deletions src/urllib3/connection.py
Expand Up @@ -2,7 +2,6 @@
import datetime
import logging
import os
import sys
import socket
from socket import error as SocketError, timeout as SocketTimeout
import warnings
Expand Down Expand Up @@ -78,9 +77,6 @@ class HTTPConnection(_HTTPConnection, object):
- ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
- ``source_address``: Set the source address for the current connection.
.. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x
- ``socket_options``: Set specific options on the underlying socket. If not specified, then
defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.
Expand Down Expand Up @@ -108,21 +104,13 @@ def __init__(self, *args, **kw):
if six.PY3: # Python 3
kw.pop('strict', None)

# Pre-set source_address in case we have an older Python like 2.6.
# Pre-set source_address.
self.source_address = kw.get('source_address')

if sys.version_info < (2, 7): # Python 2.6
# _HTTPConnection on Python 2.6 will balk at this keyword arg, but
# not newer versions. We can still use it when creating a
# connection though, so we pop it *after* we have saved it as
# self.source_address.
kw.pop('source_address', None)

#: The socket options provided by the user. If no options are
#: provided, we use the default options.
self.socket_options = kw.pop('socket_options', self.default_socket_options)

# Superclass also sets self.source_address in Python 2.7+.
_HTTPConnection.__init__(self, *args, **kw)

@property
Expand Down
16 changes: 3 additions & 13 deletions src/urllib3/connectionpool.py
Expand Up @@ -89,7 +89,7 @@ def close(self):


# This is taken from http://hg.python.org/cpython/file/7aaba721ebc0/Lib/socket.py#l252
_blocking_errnos = set([errno.EAGAIN, errno.EWOULDBLOCK])
_blocking_errnos = {errno.EAGAIN, errno.EWOULDBLOCK}


class HTTPConnectionPool(ConnectionPool, RequestMethods):
Expand Down Expand Up @@ -375,7 +375,7 @@ def _make_request(self, conn, method, url, timeout=_Default, chunked=False,
try:
try: # Python 2.7, use buffering of HTTP responses
httplib_response = conn.getresponse(buffering=True)
except TypeError: # Python 2.6 and older, Python 3
except TypeError: # Python 3
try:
httplib_response = conn.getresponse()
except Exception as e:
Expand Down Expand Up @@ -801,17 +801,7 @@ def _prepare_proxy(self, conn):
Establish tunnel connection early, because otherwise httplib
would improperly set Host: header to proxy's IP:port.
"""
# Python 2.7+
try:
set_tunnel = conn.set_tunnel
except AttributeError: # Platform-specific: Python 2.6
set_tunnel = conn._set_tunnel

if sys.version_info <= (2, 6, 4) and not self.proxy_headers: # Python 2.6.4 and older
set_tunnel(self._proxy_host, self.port)
else:
set_tunnel(self._proxy_host, self.port, self.proxy_headers)

conn.set_tunnel(self._proxy_host, self.port, self.proxy_headers)
conn.connect()

def _new_conn(self):
Expand Down
3 changes: 1 addition & 2 deletions src/urllib3/contrib/ntlmpool.py
Expand Up @@ -43,8 +43,7 @@ def _new_conn(self):
log.debug('Starting NTLM HTTPS connection no. %d: https://%s%s',
self.num_connections, self.host, self.authurl)

headers = {}
headers['Connection'] = 'Keep-Alive'
headers = {'Connection': 'Keep-Alive'}
req_header = 'Authorization'
resp_header = 'www-authenticate'

Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/packages/backports/makefile.py
Expand Up @@ -16,7 +16,7 @@ def backport_makefile(self, mode="r", buffering=None, encoding=None,
"""
Backport of ``socket.makefile`` from Python 3.5.
"""
if not set(mode) <= set(["r", "w", "b"]):
if not set(mode) <= {"r", "w", "b"}:
raise ValueError(
"invalid mode %r (only r, w, b allowed)" % (mode,)
)
Expand Down

0 comments on commit cb21598

Please sign in to comment.