Skip to content

Commit

Permalink
Drop python 3.3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Oct 1, 2015
1 parent 230bdf3 commit 08cedb8
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 146 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ sudo: no

language: python
python:
- 3.3
- 3.4
- 3.5

Expand Down
27 changes: 12 additions & 15 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
__all__ = ('ClientSession', 'request', 'get', 'options', 'head',
'delete', 'post', 'put', 'patch')

PY_341 = sys.version_info >= (3, 4, 1)
PY_35 = sys.version_info >= (3, 5)


Expand Down Expand Up @@ -77,18 +76,17 @@ def __init__(self, *, connector=None, loop=None, cookies=None,
self._response_class = response_class
self._ws_response_class = ws_response_class

if PY_341:
def __del__(self, _warnings=warnings):
if not self.closed:
self.close()
def __del__(self, _warnings=warnings):
if not self.closed:
self.close()

_warnings.warn("Unclosed client session {!r}".format(self),
ResourceWarning)
context = {'client_session': self,
'message': 'Unclosed client session'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
_warnings.warn("Unclosed client session {!r}".format(self),
ResourceWarning)
context = {'client_session': self,
'message': 'Unclosed client session'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)

def request(self, method, url, *,
params=None,
Expand Down Expand Up @@ -480,9 +478,8 @@ def __init__(self, coro, session):
super().__init__(coro)
self._session = session

if PY_341:
def __del__(self):
self._session.detach()
def __del__(self):
self._session.detach()


def request(method, url, *,
Expand Down
26 changes: 12 additions & 14 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from .multipart import MultipartWriter
from .protocol import HttpMessage

PY_341 = sys.version_info >= (3, 4, 1)
PY_35 = sys.version_info >= (3, 5)

HTTP_PORT = 80
Expand Down Expand Up @@ -551,19 +550,18 @@ def _post_init(self, loop):
if loop.get_debug():
self._source_traceback = traceback.extract_stack(sys._getframe(1))

if PY_341:
def __del__(self, _warnings=warnings):
if self._closed:
return
self.close()

_warnings.warn("Unclosed response {!r}".format(self),
ResourceWarning)
context = {'client_response': self,
'message': 'Unclosed response'}
if self._source_traceback:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
def __del__(self, _warnings=warnings):
if self._closed:
return
self.close()

_warnings.warn("Unclosed response {!r}".format(self),
ResourceWarning)
context = {'client_response': self,
'message': 'Unclosed response'}
if self._source_traceback:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)

def __repr__(self):
out = io.StringIO()
Expand Down
79 changes: 32 additions & 47 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

__all__ = ('BaseConnector', 'TCPConnector', 'ProxyConnector', 'UnixConnector')

PY_341 = sys.version_info >= (3, 4, 1)
PY_343 = sys.version_info >= (3, 4, 3)

HASHFUNC_BY_DIGESTLEN = {
Expand Down Expand Up @@ -53,24 +52,23 @@ def __init__(self, connector, key, request, transport, protocol, loop):
if loop.get_debug():
self._source_traceback = traceback.extract_stack(sys._getframe(1))

if PY_341:
def __del__(self, _warnings=warnings):
if self._transport is not None:
if hasattr(self._loop, 'is_closed'):
if self._loop.is_closed():
return

self._connector._release(
self._key, self._request, self._transport, self._protocol,
should_close=True)

_warnings.warn("Unclosed connection {!r}".format(self),
ResourceWarning)
context = {'client_connection': self,
'message': 'Unclosed connection'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
def __del__(self, _warnings=warnings):
if self._transport is not None:
if hasattr(self._loop, 'is_closed'):
if self._loop.is_closed():
return

self._connector._release(
self._key, self._request, self._transport, self._protocol,
should_close=True)

_warnings.warn("Unclosed connection {!r}".format(self),
ResourceWarning)
context = {'client_connection': self,
'message': 'Unclosed connection'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)

@property
def loop(self):
Expand Down Expand Up @@ -142,22 +140,21 @@ def __init__(self, *, conn_timeout=None, keepalive_timeout=30,

self.cookies = http.cookies.SimpleCookie()

if PY_341:
def __del__(self, _warnings=warnings):
if self._closed:
return
if not self._conns:
return
def __del__(self, _warnings=warnings):
if self._closed:
return
if not self._conns:
return

self.close()
self.close()

_warnings.warn("Unclosed connector {!r}".format(self),
ResourceWarning)
context = {'connector': self,
'message': 'Unclosed connector'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)
_warnings.warn("Unclosed connector {!r}".format(self),
ResourceWarning)
context = {'connector': self,
'message': 'Unclosed connector'}
if self._source_traceback is not None:
context['source_traceback'] = self._source_traceback
self._loop.call_exception_handler(context)

@property
def force_close(self):
Expand Down Expand Up @@ -372,9 +369,6 @@ def _create_connection(self, req):
raise NotImplementedError()


_SSL_OP_NO_COMPRESSION = getattr(ssl, "OP_NO_COMPRESSION", 0)
_SSH_HAS_CREATE_DEFAULT_CONTEXT = hasattr(ssl, 'create_default_context')

_marker = object()


Expand Down Expand Up @@ -455,19 +449,10 @@ def ssl_context(self):
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext.options |= ssl.OP_NO_SSLv2
sslcontext.options |= ssl.OP_NO_SSLv3
sslcontext.options |= _SSL_OP_NO_COMPRESSION
sslcontext.options |= ssl.OP_NO_COMPRESSION
sslcontext.set_default_verify_paths()
elif _SSH_HAS_CREATE_DEFAULT_CONTEXT:
# Python 3.4+
sslcontext = ssl.create_default_context()
else:
# Fallback for Python 3.3.
sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
sslcontext.options |= ssl.OP_NO_SSLv2
sslcontext.options |= ssl.OP_NO_SSLv3
sslcontext.options |= _SSL_OP_NO_COMPRESSION
sslcontext.set_default_verify_paths()
sslcontext.verify_mode = ssl.CERT_REQUIRED
sslcontext = ssl.create_default_context()
self._ssl_context = sslcontext
return self._ssl_context

Expand Down
4 changes: 2 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ Continuous Integration.
Dependencies
------------

- Python 3.3 and :term:`asyncio` or Python 3.4+
- Python Python 3.4.1+
- *chardet* library
- *Optional* :term:`cchardet` library as faster replacement for
:term:`chardet`.

Install it manually via::
Install it explicitly via::

$ pip install cchardet

Expand Down
2 changes: 0 additions & 2 deletions examples/srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import aiohttp
import aiohttp.server

assert sys.version >= '3.3', 'Please use Python 3.3 or higher.'


class HttpRequestHandler(aiohttp.server.ServerHttpProtocol):

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def build_extension(self, ext):

install_requires = ['chardet']

if sys.version_info < (3, 4):
install_requires += ['asyncio', 'enum34']
if sys.version_info < (3, 4, 1):
raise RuntimeError("aiohttp requires Python 3.4.1+")


def read(f):
Expand Down
4 changes: 0 additions & 4 deletions tests/test_client_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import gc
import unittest
import unittest.mock
import sys

import inspect
import io
Expand All @@ -19,9 +18,6 @@
from aiohttp import BaseConnector


PY_341 = sys.version_info >= (3, 4, 1)


class TestClientRequest(unittest.TestCase):

def setUp(self):
Expand Down
4 changes: 0 additions & 4 deletions tests/test_client_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import gc
import unittest
import unittest.mock
import sys

import aiohttp
from aiohttp.client_reqrep import ClientResponse

PY_341 = sys.version_info >= (3, 4, 1)


class TestClientResponse(unittest.TestCase):

Expand All @@ -30,7 +27,6 @@ def tearDown(self):
self.loop.close()
gc.collect()

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
response = ClientResponse('get', 'http://del-cl-resp.org')
response._post_init(self.loop)
Expand Down
5 changes: 0 additions & 5 deletions tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import gc
import unittest
from unittest import mock
import sys

import aiohttp
from aiohttp.client import ClientSession
from aiohttp.multidict import MultiDict, CIMultiDict
from aiohttp.connector import BaseConnector, TCPConnector


PY_341 = sys.version_info >= (3, 4, 1)


class TestClientSession(unittest.TestCase):

maxDiff = None
Expand Down Expand Up @@ -376,7 +372,6 @@ def test_double_close(self):
self.assertTrue(session.closed)
self.assertTrue(conn.closed)

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
conn = self.make_open_connector()
session = ClientSession(loop=self.loop, connector=conn)
Expand Down
8 changes: 0 additions & 8 deletions tests/test_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import socket
import unittest
import ssl
import sys
import tempfile
import shutil
import os.path
Expand All @@ -18,8 +17,6 @@
from aiohttp.client import ClientResponse, ClientRequest
from aiohttp.connector import Connection

PY_341 = sys.version_info >= (3, 4, 1)


class TestHttpConnection(unittest.TestCase):

Expand All @@ -36,7 +33,6 @@ def tearDown(self):
self.loop.close()
gc.collect()

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
conn = Connection(
self.connector, self.key, self.request,
Expand Down Expand Up @@ -122,7 +118,6 @@ def tearDown(self):
self.loop.close()
gc.collect()

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
Expand All @@ -144,7 +139,6 @@ def test_del(self):
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_scheduled_cleanup(self):
conn = aiohttp.BaseConnector(loop=self.loop, keepalive_timeout=0.01)
transp = unittest.mock.Mock()
Expand All @@ -168,7 +162,6 @@ def test_del_with_scheduled_cleanup(self):
msg['source_traceback'] = unittest.mock.ANY
exc_handler.assert_called_with(self.loop, msg)

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_with_closed_loop(self):
conn = aiohttp.BaseConnector(loop=self.loop)
transp = unittest.mock.Mock()
Expand All @@ -188,7 +181,6 @@ def test_del_with_closed_loop(self):
self.assertFalse(transp.close.called)
self.assertTrue(exc_handler.called)

@unittest.skipUnless(PY_341, "Requires Python 3.4.1+")
def test_del_empty_conector(self):
conn = aiohttp.BaseConnector(loop=self.loop)

Expand Down
Loading

0 comments on commit 08cedb8

Please sign in to comment.