summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2015-07-13 18:54:45 +0200
committerVictor Stinner <vstinner@redhat.com>2015-07-13 18:55:47 +0200
commitd444158a05eb2d1dd171f8659f48e2a9f78eb3c6 (patch)
treeed838e61fe6f5847808f9898073d5cef77d89cf3
parenta0bad4611ab403b261c86a629e05abd331415032 (diff)
downloadtrollius-git-d444158a05eb2d1dd171f8659f48e2a9f78eb3c6.tar.gz
Use the six module
-rw-r--r--doc/install.rst2
-rw-r--r--setup.py2
-rw-r--r--tests/test_events.py3
-rw-r--r--tests/test_futures.py3
-rw-r--r--tests/test_streams.py3
-rw-r--r--tox.ini7
-rw-r--r--trollius/compat.py13
-rw-r--r--trollius/futures.py3
-rw-r--r--trollius/test_utils.py2
-rw-r--r--trollius/windows_utils.py2
10 files changed, 24 insertions, 16 deletions
diff --git a/doc/install.rst b/doc/install.rst
index 4dd6b1a..db4a8b1 100644
--- a/doc/install.rst
+++ b/doc/install.rst
@@ -65,6 +65,8 @@ Tulip project, Trollius repository is a fork of the Tulip repository.
Dependencies
============
+Trollius requires the `six <https://pypi.python.org/pypi/six>`_ module.
+
On Python older than 3.2, the `futures <https://pypi.python.org/pypi/futures>`_
project is needed to get a backport of ``concurrent.futures``.
diff --git a/setup.py b/setup.py
index 05e96c9..012429a 100644
--- a/setup.py
+++ b/setup.py
@@ -38,7 +38,7 @@ if os.name == 'nt':
)
extensions.append(ext)
-requirements = []
+requirements = ['six']
if sys.version_info < (2, 7):
requirements.append('ordereddict')
if sys.version_info < (3,):
diff --git a/tests/test_events.py b/tests/test_events.py
index af7113b..59c25d4 100644
--- a/tests/test_events.py
+++ b/tests/test_events.py
@@ -8,6 +8,7 @@ import os
import platform
import re
import signal
+import six
import socket
import subprocess
import sys
@@ -981,7 +982,7 @@ class EventLoopTestsMixin(object):
if hasattr(sslcontext_client, 'check_hostname'):
sslcontext_client.check_hostname = True
- if compat.PY3:
+ if six.PY3:
err_msg = "hostname '127.0.0.1' doesn't match 'localhost'"
else:
# http://bugs.python.org/issue22861
diff --git a/tests/test_futures.py b/tests/test_futures.py
index 6467bef..78a097b 100644
--- a/tests/test_futures.py
+++ b/tests/test_futures.py
@@ -5,6 +5,7 @@ try:
except ImportError:
concurrent = None
import re
+import six
import sys
import threading
@@ -347,7 +348,7 @@ class FutureTests(test_utils.TestCase):
r'MemoryError$'
).format(filename=re.escape(frame[0]),
lineno=frame[1])
- elif compat.PY3:
+ elif six.PY3:
regex = (r'^Future/Task exception was never retrieved\n'
r'Traceback \(most recent call last\):\n'
r'.*\n'
diff --git a/tests/test_streams.py b/tests/test_streams.py
index d20e9fe..9ecbb66 100644
--- a/tests/test_streams.py
+++ b/tests/test_streams.py
@@ -4,6 +4,7 @@ import gc
import io
import os
import socket
+import six
import sys
try:
import ssl
@@ -609,7 +610,7 @@ os.close(fd)
try:
asyncio.set_child_watcher(watcher)
kw = {'loop': self.loop}
- if compat.PY3:
+ if six.PY3:
kw['pass_fds'] = set((wfd,))
create = asyncio.create_subprocess_exec(*args, **kw)
proc = self.loop.run_until_complete(create)
diff --git a/tox.ini b/tox.ini
index 6f0a342..2dde943 100644
--- a/tox.ini
+++ b/tox.ini
@@ -5,6 +5,7 @@ envlist = py26,py27,py2_release,py2_no_ssl,py2_no_concurrent,py32,py33,py34,py3_
[testenv]
deps=
aiotest
+ six
setenv =
TROLLIUSDEBUG = 1
commands=
@@ -31,6 +32,7 @@ deps=
futures
mock==1.0.1
ordereddict
+ six
unittest2
[testenv:py27]
@@ -38,6 +40,7 @@ deps=
aiotest
futures
mock
+ six
unittest2
[testenv:py2_release]
@@ -47,6 +50,7 @@ deps=
aiotest
futures
mock
+ six
unittest2
setenv =
TROLLIUSDEBUG =
@@ -57,6 +61,7 @@ deps=
aiotest
futures
mock
+ six
unittest2
commands=
python -Wd runtests.py --no-ssl -r {posargs}
@@ -67,6 +72,7 @@ deps=
aiotest
futures
mock
+ six
unittest2
commands=
python -Wd runtests.py --no-concurrent -r {posargs}
@@ -75,6 +81,7 @@ commands=
deps=
aiotest
mock
+ six
[testenv:py35]
basepython = python3.5
diff --git a/trollius/compat.py b/trollius/compat.py
index 2b4e621..df64aba 100644
--- a/trollius/compat.py
+++ b/trollius/compat.py
@@ -1,16 +1,11 @@
"""Compatibility helpers for the different Python versions."""
+import six
import sys
-# Python 2 or older?
-PY2 = (sys.version_info <= (2,))
-
# Python 2.6 or older?
PY26 = (sys.version_info < (2, 7))
-# Python 3.0 or newer?
-PY3 = (sys.version_info >= (3,))
-
# Python 3.3 or newer?
PY33 = (sys.version_info >= (3, 3))
@@ -20,7 +15,7 @@ PY34 = sys.version_info >= (3, 4)
# Python 3.5 or newer?
PY35 = sys.version_info >= (3, 5)
-if PY3:
+if six.PY3:
integer_types = (int,)
bytes_type = bytes
text_type = str
@@ -37,7 +32,7 @@ else:
BYTES_TYPES = (str, bytearray, memoryview, buffer)
-if PY3:
+if six.PY3:
def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise value.with_traceback(tb)
@@ -60,7 +55,7 @@ def flatten_bytes(data):
return data
if not data:
return b''
- if not PY3 and isinstance(data, (buffer, bytearray)):
+ if six.PY2 and isinstance(data, (buffer, bytearray)):
return str(data)
elif not PY26 and isinstance(data, memoryview):
return data.tobytes()
diff --git a/trollius/futures.py b/trollius/futures.py
index 9899ae5..4d4e20f 100644
--- a/trollius/futures.py
+++ b/trollius/futures.py
@@ -6,6 +6,7 @@ __all__ = ['CancelledError', 'TimeoutError',
]
import logging
+import six
import sys
import traceback
try:
@@ -370,7 +371,7 @@ class Future(object):
if exc_tb is not None:
self._exception_tb = exc_tb
exc_tb = None
- elif self._loop.get_debug() and not compat.PY3:
+ elif self._loop.get_debug() and not six.PY3:
self._exception_tb = sys.exc_info()[2]
self._state = _FINISHED
self._schedule_callbacks()
diff --git a/trollius/test_utils.py b/trollius/test_utils.py
index f67475d..dbff44b 100644
--- a/trollius/test_utils.py
+++ b/trollius/test_utils.py
@@ -519,7 +519,7 @@ class TestCase(unittest.TestCase):
# Detect CPython bug #23353: ensure that yield/yield-from is not used
# in an except block of a generator
if sys.exc_info()[0] == SkipTest:
- if compat.PY2:
+ if six.PY2:
sys.exc_clear()
else:
self.assertEqual(sys.exc_info(), (None, None, None))
diff --git a/trollius/windows_utils.py b/trollius/windows_utils.py
index 2a10ce8..d25d2a4 100644
--- a/trollius/windows_utils.py
+++ b/trollius/windows_utils.py
@@ -168,7 +168,7 @@ class PipeHandle(object):
def __del__(self):
if self._handle is not None:
- if compat.PY3:
+ if six.PY3:
warnings.warn("unclosed %r" % self, ResourceWarning)
self.close()