Skip to content

Commit

Permalink
Py2 removal (#153)
Browse files Browse the repository at this point in the history
* remove all future imports

* remove all six imports

* change StringIO parent

* fix StringIO imports

* final removals of six

* remove unused vars

* remove u keyword for strings

* remove  u keyword for strings (more)

* Make flake8 happy
  • Loading branch information
om26er authored and oberstet committed Jan 21, 2020
1 parent 735eb60 commit 62b0e7e
Show file tree
Hide file tree
Showing 19 changed files with 44 additions and 89 deletions.
12 changes: 6 additions & 6 deletions docs/conf.py
Expand Up @@ -94,13 +94,13 @@ def _warn_node(self, msg, node, **kwargs):
master_doc = 'contents'

# General information about the project.
project = u'txaio'
author = u'Crossbar.io Project'
this_year = u'{0}'.format(time.strftime('%Y'))
if this_year != u'2015':
copyright = u'2015-{0}, Crossbar.io Technologies GmbH'.format(this_year)
project = 'txaio'
author = 'Crossbar.io Project'
this_year = '{0}'.format(time.strftime('%Y'))
if this_year != '2015':
copyright = '2015-{0}, Crossbar.io Technologies GmbH'.format(this_year)
else:
copyright = u'2015, Crossbar.io Technologies GmbH'
copyright = '2015, Crossbar.io Technologies GmbH'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
1 change: 0 additions & 1 deletion examples/basic.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import print_function
import txaio
txaio.use_twisted()

Expand Down
1 change: 0 additions & 1 deletion examples/log_interop_stdlib.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import print_function
import sys
import logging

Expand Down
1 change: 0 additions & 1 deletion examples/log_interop_twisted.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import print_function
import sys
import txaio

Expand Down
1 change: 0 additions & 1 deletion examples/multiloop.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import print_function

# This example only works with asyncio

Expand Down
6 changes: 0 additions & 6 deletions setup.py
Expand Up @@ -24,15 +24,12 @@
#
###############################################################################

from __future__ import absolute_import

import sys
import platform
from setuptools import setup

CPY = platform.python_implementation() == 'CPython'
PY3 = sys.version_info >= (3,)
PY33 = (3, 3) <= sys.version_info < (3, 4)

with open('txaio/_version.py') as f:
exec(f.read()) # defines __version__
Expand Down Expand Up @@ -84,9 +81,6 @@
url='https://github.com/crossbario/txaio',
platforms=('Any'),
python_requires='>=3.5',
install_requires=[
'six'
],
extras_require={
'twisted': extras_require_twisted,
'asyncio': extras_require_asyncio,
Expand Down
16 changes: 5 additions & 11 deletions test/_asyncio_test_utils.py
Expand Up @@ -55,15 +55,15 @@ def data_file(filename):
'caIssuers': ('http://testca.pythontest.net/testca/pycacert.cer',),
'crlDistributionPoints': ('http://testca.pythontest.net/testca/revocation.crl',),
'issuer': ((('countryName', 'XY'),),
(('organizationName', 'Python Software Foundation CA'),),
(('commonName', 'our-ca-server'),)),
(('organizationName', 'Python Software Foundation CA'),),
(('commonName', 'our-ca-server'),)),
'notAfter': 'Jul 7 14:23:16 2028 GMT',
'notBefore': 'Aug 29 14:23:16 2018 GMT',
'serialNumber': 'CB2D80995A69525C',
'subject': ((('countryName', 'XY'),),
(('localityName', 'Castle Anthrax'),),
(('organizationName', 'Python Software Foundation'),),
(('commonName', 'localhost'),)),
(('localityName', 'Castle Anthrax'),),
(('organizationName', 'Python Software Foundation'),),
(('commonName', 'localhost'),)),
'subjectAltName': (('DNS', 'localhost'),),
'version': 3
}
Expand Down Expand Up @@ -212,7 +212,6 @@ def server_bind(self):
self.server_name = '127.0.0.1'
self.server_port = 80


class UnixWSGIServer(UnixHTTPServer, WSGIServer):

request_timeout = 2
Expand All @@ -232,22 +231,18 @@ def get_request(self):
# to get the tests going
return request, ('127.0.0.1', '')


class SilentUnixWSGIServer(UnixWSGIServer):

def handle_error(self, request, client_address):
pass


class UnixSSLWSGIServer(SSLWSGIServerMixin, SilentUnixWSGIServer):
pass


def gen_unix_socket_path():
with tempfile.NamedTemporaryFile() as file:
return file.name


@contextlib.contextmanager
def unix_socket_path():
path = gen_unix_socket_path()
Expand All @@ -259,7 +254,6 @@ def unix_socket_path():
except OSError:
pass


@contextlib.contextmanager
def run_test_unix_server(*, use_ssl=False):
with unix_socket_path() as path:
Expand Down
1 change: 0 additions & 1 deletion test/test_legacy_logging.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import print_function

import txaio

Expand Down
14 changes: 6 additions & 8 deletions test/test_logging.py
Expand Up @@ -24,13 +24,11 @@
#
###############################################################################

from __future__ import print_function

from collections import namedtuple
from io import BytesIO, StringIO

import os
import six
import pytest
import txaio

Expand Down Expand Up @@ -79,7 +77,7 @@ def test_categories(handler, framework):
"""
logger = txaio.make_logger()

txaio.add_log_categories({"TX100": u"{adjective} {nouns[2]}"})
txaio.add_log_categories({"TX100": "{adjective} {nouns[2]}"})

# do something a little fancy, with attribute access etc.
logger.critical(
Expand All @@ -100,8 +98,8 @@ def test_categories_subsequent(handler, framework):
"""
logger = txaio.make_logger()

txaio.add_log_categories({"TX100": u"{adjective} {nouns[2]}"})
txaio.add_log_categories({"TX100": u"{adjective} {nouns[1]}"})
txaio.add_log_categories({"TX100": "{adjective} {nouns[2]}"})
txaio.add_log_categories({"TX100": "{adjective} {nouns[1]}"})

# do something a little fancy, with attribute access etc.
logger.critical(
Expand Down Expand Up @@ -291,7 +289,7 @@ def test_log_converter(handler, framework):
from twisted.logger import Logger
from txaio.tx import _LogObserver

out = six.StringIO()
out = StringIO()
observer = _LogObserver(out)
logger = Logger(observer=observer)

Expand Down Expand Up @@ -344,7 +342,7 @@ def test_txlog_write_text(handler, framework_tx):
})

output = out_file.getvalue()
assert u"hi: hello" in output
assert "hi: hello" in output


def test_aiolog_write_binary(handler, framework_aio):
Expand Down Expand Up @@ -384,4 +382,4 @@ def test_aiolog_write_text(handler, framework_aio):
}))

output = out_file.getvalue()
assert u"hi: hello" in output
assert "hi: hello" in output
1 change: 0 additions & 1 deletion tox.ini
Expand Up @@ -12,7 +12,6 @@ envlist =

[testenv]
deps =
six
mock
pytest==4.6.9
coverage==4.5.4
Expand Down
1 change: 0 additions & 1 deletion txaio/__init__.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import absolute_import

from txaio._version import __version__
from txaio.interfaces import IFailedFuture, ILogger
Expand Down
4 changes: 2 additions & 2 deletions txaio/_common.py
Expand Up @@ -99,9 +99,9 @@ def notify_one_chunk(calls, chunk_size, chunk_delay_ms):
else:
# done all calls; make sure there were no errors
if len(errors):
msg = u"Error(s) processing call_later bucket:\n"
msg = "Error(s) processing call_later bucket:\n"
for e in errors:
msg += u"{}\n".format(e)
msg += "{}\n".format(e)
raise RuntimeError(msg)
# ceil()ing because we want the number of chunks, and a
# partial chunk is still a chunk
Expand Down
14 changes: 1 addition & 13 deletions txaio/_iotype.py
Expand Up @@ -24,15 +24,6 @@
#
###############################################################################

from __future__ import absolute_import, division

from six import PY3, PY2

if PY3:
unicode = str
else:
unicode = unicode


def guess_stream_needs_encoding(fileobj, default=True):
"""
Expand All @@ -55,7 +46,7 @@ def guess_stream_needs_encoding(fileobj, default=True):

if t is bytes:
return True
elif t is unicode:
elif t is str:
return False

except Exception:
Expand All @@ -64,9 +55,6 @@ def guess_stream_needs_encoding(fileobj, default=True):
try:
mode = fileobj.mode

if PY2 and mode == "w":
mode = "wb"

if "b" in mode:
return True
else:
Expand Down
1 change: 0 additions & 1 deletion txaio/_unframework.py
Expand Up @@ -30,7 +30,6 @@
explicitly by calling .use_twisted() or .use_asyncio()
"""

from __future__ import absolute_import, division, print_function
from txaio import _Config

using_twisted = False
Expand Down
2 changes: 1 addition & 1 deletion txaio/_version.py
@@ -1 +1 @@
__version__ = u'20.1.1'
__version__ = '20.1.1'
16 changes: 7 additions & 9 deletions txaio/aio.py
Expand Up @@ -24,8 +24,7 @@
#
###############################################################################

from __future__ import absolute_import, print_function

import io
import os
import sys
import time
Expand All @@ -43,7 +42,6 @@
from txaio import _util
from txaio import _Config

import six

try:
import asyncio
Expand Down Expand Up @@ -238,7 +236,7 @@ def emit(self, record):
if isinstance(record.args, dict):
fmt = record.args.get(
'log_format',
record.args.get('log_message', u'')
record.args.get('log_message', '')
)
message = fmt.format(**record.args)
dt = datetime.fromtimestamp(record.args.get('log_time', 0))
Expand All @@ -249,7 +247,7 @@ def emit(self, record):
for line in traceback.format_exception(*record.exc_info):
message = message + line
dt = datetime.fromtimestamp(record.created)
msg = u'{0} {1}{2}'.format(
msg = '{0} {1}{2}'.format(
dt.strftime("%Y-%m-%dT%H:%M:%S%z"),
message,
os.linesep
Expand Down Expand Up @@ -359,12 +357,12 @@ def failure_message(self, fail):
returns a unicode error-message
"""
try:
return u'{0}: {1}'.format(
return '{0}: {1}'.format(
fail._value.__class__.__name__,
str(fail._value),
)
except Exception:
return u'Failed to produce failure message for "{0}"'.format(fail)
return 'Failed to produce failure message for "{0}"'.format(fail)

def failure_traceback(self, fail):
"""
Expand All @@ -379,7 +377,7 @@ def failure_format_traceback(self, fail):
returns a string
"""
try:
f = six.StringIO()
f = io.StringIO()
traceback.print_exception(
fail._type,
fail.value,
Expand All @@ -388,7 +386,7 @@ def failure_format_traceback(self, fail):
)
return f.getvalue()
except Exception:
return u"Failed to format failure traceback for '{0}'".format(fail)
return "Failed to format failure traceback for '{0}'".format(fail)

def create_future(self, result=_unspecified, error=_unspecified, canceller=_unspecified):
if result is not _unspecified and error is not _unspecified:
Expand Down
11 changes: 3 additions & 8 deletions txaio/interfaces.py
Expand Up @@ -24,10 +24,8 @@
#
###############################################################################

from __future__ import absolute_import

import abc
import six

#: all the log-levels that txaio recognizes
log_levels = [
Expand All @@ -41,8 +39,7 @@
]


@six.add_metaclass(abc.ABCMeta)
class IBatchedTimer(object):
class IBatchedTimer(abc.ABC):
"""
Objects created by :met:`txaio.make_batched_timer` implement this
interface.
Expand Down Expand Up @@ -81,8 +78,7 @@ def call_later(self, delay, func, *args, **kw):
"""


@six.add_metaclass(abc.ABCMeta)
class ILogger(object):
class ILogger(abc.ABC):
"""
This defines the methods you can call on the object returned from
:meth:`txaio.make_logger` -- although the actual object may have
Expand Down Expand Up @@ -156,8 +152,7 @@ def trace(self, message, **kwargs):
"log a trace-level message"


@six.add_metaclass(abc.ABCMeta)
class IFailedFuture(object):
class IFailedFuture(abc.ABC):
"""
This defines the interface for a common object encapsulating a
failure from either an asyncio task/coroutine or a Twisted
Expand Down
1 change: 0 additions & 1 deletion txaio/testutil.py
Expand Up @@ -24,7 +24,6 @@
#
###############################################################################

from __future__ import absolute_import

import txaio
from contextlib import contextmanager
Expand Down

0 comments on commit 62b0e7e

Please sign in to comment.