Skip to content

Commit

Permalink
Remove Python 2.7 compatibility constructs. Ref #153.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 21, 2018
1 parent ef504bc commit c6a2cba
Show file tree
Hide file tree
Showing 15 changed files with 13 additions and 80 deletions.
8 changes: 1 addition & 7 deletions irc/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,17 @@
write simpler bots.
"""

from __future__ import absolute_import

import sys
import collections
import warnings
import abc
import itertools
import random

import six
import irc.client
import irc.modes
from .dict import IRCDict

__metaclass__ = type


class ServerSpec:
"""
Expand Down Expand Up @@ -51,8 +46,7 @@ def __repr__(self):
)


@six.add_metaclass(abc.ABCMeta)
class ReconnectStrategy:
class ReconnectStrategy(metaclass=abc.ABCMeta):
"""
An abstract base class describing the interface used by
SingleServerIRCBot for handling reconnect following
Expand Down
18 changes: 5 additions & 13 deletions irc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
.. [IRC specifications] http://www.irchelp.org/irchelp/rfc/
"""

from __future__ import absolute_import, division

import bisect
import re
import select
Expand All @@ -63,7 +61,6 @@
import itertools
import contextlib

import six
import jaraco.functools
from jaraco.itertools import always_iterable, infinite_call
from jaraco.functools import Throttler
Expand All @@ -82,8 +79,6 @@
from . import message
from . import schedule

__metaclass__ = type

log = logging.getLogger(__name__)

# set the version tuple
Expand All @@ -107,8 +102,7 @@ class MessageTooLong(ValueError):
"Message is too long"


@six.add_metaclass(abc.ABCMeta)
class Connection:
class Connection(metaclass=abc.ABCMeta):
"""
Base class for IRC connections.
"""
Expand Down Expand Up @@ -1276,7 +1270,7 @@ def ip_quad_to_numstr(quad):
return str(struct.unpack('>L', packed)[0])


class NickMask(six.text_type):
class NickMask(str):
"""
A nickmask (the source of an Event)
Expand All @@ -1290,14 +1284,12 @@ class NickMask(six.text_type):
>>> nm.user
'username'
>>> isinstance(nm, six.text_type)
>>> isinstance(nm, str)
True
>>> nm = 'красный!red@yahoo.ru'
>>> if not six.PY3: nm = nm.decode('utf-8')
>>> nm = NickMask(nm)
>>> nm = NickMask('красный!red@yahoo.ru')
>>> isinstance(nm.nick, six.text_type)
>>> isinstance(nm.nick, str)
True
Some messages omit the userhost. In that case, None is returned.
Expand Down
2 changes: 0 additions & 2 deletions irc/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import socket

__metaclass__ = type


def identity(x):
return x
Expand Down
2 changes: 0 additions & 2 deletions irc/ctcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
spec <http://www.irchelp.org/irchelp/rfc/ctcpspec.html>`_.
"""

from __future__ import absolute_import

import re

LOW_LEVEL_QUOTE = '\x10'
Expand Down
3 changes: 1 addition & 2 deletions irc/dict.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import unicode_literals, absolute_import

import six
from jaraco.collections import KeyTransformingDict

from . import strings
Expand Down Expand Up @@ -42,6 +41,6 @@ class IRCDict(KeyTransformingDict):
"""
@staticmethod
def transform_key(key):
if isinstance(key, six.string_types):
if isinstance(key, str):
key = strings.IRCFoldedCase(key)
return key
4 changes: 0 additions & 4 deletions irc/features.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from __future__ import absolute_import

import collections

__metaclass__ = type


class FeatureSet:
"""
Expand Down
5 changes: 0 additions & 5 deletions irc/message.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from __future__ import print_function

__metaclass__ = type


class Tag:
"""
An IRC message tag ircv3.net/specs/core/message-tags-3.2.html
Expand Down
6 changes: 1 addition & 5 deletions irc/modes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import


def parse_nick_modes(mode_string):
"""Parse a nick mode string.
Expand Down Expand Up @@ -59,10 +56,9 @@ def _parse_modes(mode_string, unary_modes=""):
This function never throws an error:
>>> import random
>>> import six
>>> def random_text(min_len = 3, max_len = 80):
... len = random.randint(min_len, max_len)
... chars_to_choose = [six.unichr(x) for x in range(0,1024)]
... chars_to_choose = [chr(x) for x in range(0,1024)]
... chars = (random.choice(chars_to_choose) for x in range(len))
... return ''.join(chars)
>>> def random_texts(min_len = 3, max_len = 80):
Expand Down
2 changes: 0 additions & 2 deletions irc/rfc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import re


Expand Down
7 changes: 1 addition & 6 deletions irc/schedule.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import abc

import six

from tempora import schedule

__metaclass__ = type


@six.add_metaclass(abc.ABCMeta)
class IScheduler:
class IScheduler(metaclass=abc.ABCMeta):
@abc.abstractmethod
def execute_every(self, period, func):
"execute func every period"
Expand Down
20 changes: 2 additions & 18 deletions irc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,20 @@
# Not Todo (Won't be supported)
# - Server linking.

from __future__ import print_function, absolute_import

import argparse
import errno
import logging
import socket
import select
import re
import socketserver

import six
from six.moves import socketserver
import jaraco.logging
from jaraco.stream import buffer

import irc.client
from . import events

__metaclass__ = type

SRV_WELCOME = "Welcome to {__name__} v{irc.client.VERSION}.".format(**locals())

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -115,13 +110,6 @@ def __init__(self, request, client_address, server):
self.send_queue = [] # Messages to send to client (strings)
self.channels = {} # Channels the client is in

# On Python 2, use old, clunky syntax to call parent init
if six.PY2:
socketserver.BaseRequestHandler.__init__(
self, request,
client_address, server)
return

super().__init__(request, client_address, server)

def handle(self):
Expand Down Expand Up @@ -180,7 +168,7 @@ def _handle_line(self, line):
'%s :Unknown command' % command)
response = handler(params)
except AttributeError as e:
log.error(six.text_type(e))
log.error(str(e))
raise
except IRCError as e:
response = ':%s %s %s' % (self.server.servername, e.code, e.value)
Expand Down Expand Up @@ -506,10 +494,6 @@ def __init__(self, *args, **kwargs):
self.channels = {}
self.clients = {}

if six.PY2:
socketserver.TCPServer.__init__(self, *args, **kwargs)
return

super().__init__(*args, **kwargs)


Expand Down
2 changes: 0 additions & 2 deletions irc/strings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

import string

from jaraco.text import FoldedCase
Expand Down
6 changes: 1 addition & 5 deletions irc/tests/test_bot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import time
import threading

import six

import pytest

import irc.client
Expand Down Expand Up @@ -125,9 +123,7 @@ def test_namreply_no_channel(self):
event = irc.client.Event(
type=None, source=None, target=None,
arguments=['*', '*', 'nick'])
_on_namreply = six.get_unbound_function(
irc.bot.SingleServerIRCBot._on_namreply)
_on_namreply(None, None, event)
irc.bot.SingleServerIRCBot._on_namreply(None, None, event)

def test_reconnects_are_stable(self, disconnecting_server):
"""
Expand Down
7 changes: 1 addition & 6 deletions irc/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from __future__ import print_function

from unittest import mock

import pytest
import six

import irc.client

__metaclass__ = type


def test_version():
assert 'VERSION' in vars(irc.client)
assert 'VERSION_STRING' in vars(irc.client)
assert isinstance(irc.client.VERSION, tuple)
assert irc.client.VERSION, "No VERSION detected."
assert isinstance(irc.client.VERSION_STRING, six.string_types)
assert isinstance(irc.client.VERSION_STRING, str)


@mock.patch('irc.connection.socket')
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
),
python_requires='>=3.4',
install_requires=[
'six',
'jaraco.collections',
'jaraco.text',
'jaraco.itertools>=1.8',
Expand Down

0 comments on commit c6a2cba

Please sign in to comment.