Skip to content

Commit

Permalink
Merge pull request aio-libs#392 from rooterkyberian/remove_py33
Browse files Browse the repository at this point in the history
remove py3.3 support
  • Loading branch information
webknjaz authored Jul 31, 2018
2 parents c19101d + 4a7b25b commit 70bb006
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 100 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ branches:
- /^v\d+\.\d+\.\d+$/

python:
- 3.3
- 3.4
- 3.6
env:
Expand All @@ -30,7 +29,7 @@ before_install:
install:
- pip install --upgrade pip setuptools wheel
- pip install flake8
- pip install "pytest<3.3.0" pytest-cov pytest-catchlog docker-py
- pip install pytest pytest-cov pytest-catchlog docker-py
- pip install codecov
- pip install cython
- pip install python-snappy
Expand Down
41 changes: 3 additions & 38 deletions aiokafka/helpers.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,8 @@
import logging
import ssl
from ssl import create_default_context, Purpose

log = logging.getLogger(__name__)

try:
from ssl import create_default_context, Purpose
except ImportError:
# Backport for Python3.3, it's not as good and you probably should consider
# upgrading to a higher version.

def _create_ssl_context(*, cafile=None, capath=None, cadata=None):
"""Create a SSLContext object with default settings."""
log.warn("You are using")
if cadata is not None:
raise ValueError("`cadata` not supported by Python3.3")
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
# SSLv2 considered harmful.
context.options |= ssl.OP_NO_SSLv2
# SSLv3 has problematic security and is only required for really old
# clients such as IE6 on Windows XP
context.options |= ssl.OP_NO_SSLv3
# disable compression to prevent CRIME attacks (OpenSSL 1.0+)
# And we don't really need it in Kafka, as we have client compression
context.options |= getattr(ssl, "OP_NO_COMPRESSION", 0)

context.verify_mode = ssl.CERT_REQUIRED

if cafile or capath:
context.load_verify_locations(cafile, capath)
else:
# This may fail silently.
context.set_default_verify_paths()
return context
else:

def _create_ssl_context(*, cafile=None, capath=None, cadata=None):
"""Create a SSLContext object with default settings."""
return create_default_context(
Purpose.SERVER_AUTH, cafile=cafile, capath=capath, cadata=cadata)


def create_ssl_context(*, cafile=None, capath=None, cadata=None,
certfile=None, keyfile=None, password=None,
Expand Down Expand Up @@ -85,7 +49,8 @@ def create_ssl_context(*, cafile=None, capath=None, cadata=None,
log.info('Loading SSL CA from data provided in `cadata`')
log.debug('`cadata`: %r', cadata)
# Creating context with default params for client sockets.
context = _create_ssl_context(cafile=cafile, capath=capath, cadata=cadata)
context = create_default_context(
Purpose.SERVER_AUTH, cafile=cafile, capath=capath, cadata=cadata)
# Load certificate if one is specified.
if certfile is not None:
log.info('Loading SSL Cert from %s', certfile)
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8==3.5.0
pytest==3.6.3 # Python3.3 dropped in 3.3. And some problems with catchlog
pytest==3.6.3
pytest-cov==2.5.1
pytest-catchlog==1.2.2
docker-py==1.10.6
Expand Down
6 changes: 1 addition & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,8 @@ def build_extension(self, ext):
pass
elif PY_VER >= (3, 4):
install_requires.append('typing')
elif PY_VER >= (3, 3):
install_requires.append('typing')
install_requires.append('asyncio')
else:
raise RuntimeError("aiokafka doesn't suppport Python earlier than 3.3")
raise RuntimeError("aiokafka doesn't suppport Python earlier than 3.4")


def read(f):
Expand All @@ -110,7 +107,6 @@ def read_version():
'License :: OSI Approved :: Apache Software License',
'Intended Audience :: Developers',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand Down
12 changes: 0 additions & 12 deletions tests/_testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import unittest
import pytest
import operator
import sys

from contextlib import contextmanager
from functools import wraps
Expand Down Expand Up @@ -218,17 +217,6 @@ def create_ssl_context(self):
keyfile=str(self.ssl_folder / "cl_client.key"),
password="abcdefgh")

def assertLogs(self, *args, **kw): # noqa
if sys.version_info >= (3, 4, 0):
return super().assertLogs(*args, **kw)
else:
# On Python3.3 just do no-op for now
return self._assert_logs_noop()

@contextmanager
def _assert_logs_noop(self):
yield


def random_string(length):
s = "".join(random.choice(string.ascii_letters) for _ in range(length))
Expand Down
13 changes: 0 additions & 13 deletions tests/test_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import asyncio
import pytest
import unittest
import sys
from contextlib import contextmanager
from unittest import mock

from kafka.protocol.offset import OffsetResponse
Expand Down Expand Up @@ -59,17 +57,6 @@ def test_fetch_result_and_error(loop):
@pytest.mark.usefixtures('setup_test_class_serverless')
class TestFetcher(unittest.TestCase):

def assertLogs(self, *args, **kw): # noqa
if sys.version_info >= (3, 4, 0):
return super().assertLogs(*args, **kw)
else:
# On Python3.3 just do no-op for now
return self._assert_logs_noop()

@contextmanager
def _assert_logs_noop(self):
yield

def setUp(self):
super().setUp()
self._cleanup = []
Expand Down
30 changes: 1 addition & 29 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,9 @@ def _check_ssl_dir(self):
self.assertTrue(keyfile.exists(), str(keyfile))
return cafile, certfile, keyfile

@pytest.mark.skipif(sys.version_info >= (3, 4),
reason="requires python3.4")
def test_create_ssl_context(self):
# TODO: I would realy want to check that proper certificates load, but
# the API is fuzzy, and 3.3 misses a lot of functions, so
# for now this test only checks that no error are raised during
# context creation...
cafile, certfile, keyfile = self._check_ssl_dir()

context = create_ssl_context()
self.assertEqual(context.verify_mode, ssl.CERT_REQUIRED)

context = create_ssl_context(cafile=str(cafile))
self.assertEqual(context.verify_mode, ssl.CERT_REQUIRED)

context = create_ssl_context(
cafile=str(cafile),
certfile=str(certfile),
keyfile=str(keyfile),
password="abcdefgh")
self.assertEqual(context.verify_mode, ssl.CERT_REQUIRED)

with self.assertRaisesRegexp(
ValueError, "`cadata` not supported by Python3.3"):
with cafile.open("rb") as f:
data = f.read()
create_ssl_context(cadata=data.decode("ascii"))

@pytest.mark.skipif(sys.version_info < (3, 4),
reason="requires python3.4")
def test_create_ssl_context_py34(self):
def test_create_ssl_context(self):
cafile, certfile, keyfile = self._check_ssl_dir()

context = create_ssl_context()
Expand Down

0 comments on commit 70bb006

Please sign in to comment.