Remove fallbacks for old Python versions.

This commit is contained in:
Valentin Lorentz 2022-01-01 18:11:36 +01:00
parent 181e34baf9
commit 74f86654b1
18 changed files with 28 additions and 141 deletions

View File

@ -60,10 +60,7 @@ __url__ = ""
from . import config from . import config
from . import plugin from . import plugin
if sys.version_info >= (3, 4): from importlib import reload
from importlib import reload
else:
from imp import reload
# In case we're being reloaded. # In case we're being reloaded.
reload(config) reload(config)
reload(plugin) reload(plugin)

View File

@ -52,10 +52,7 @@ __url__ = ""
from . import config from . import config
from . import plugin from . import plugin
if sys.version_info >= (3, 4): from importlib import reload
from importlib import reload
else:
from imp import reload
# In case we're being reloaded. # In case we're being reloaded.
reload(config) reload(config)
reload(plugin) reload(plugin)

View File

@ -30,13 +30,8 @@
### ###
import sys import sys
from unittest import skip
if sys.version_info >= (2, 7, 0):
from unittest import skip
else:
# Workaround
def skip(string):
return lambda x:None
from supybot.test import * from supybot.test import *
import supybot.conf as conf import supybot.conf as conf

View File

@ -52,10 +52,7 @@ __url__ = ""
from . import config from . import config
from . import plugin from . import plugin
if sys.version_info >= (3, 4): from importlib import reload
from importlib import reload
else:
from imp import reload
# In case we're being reloaded. # In case we're being reloaded.
reload(config) reload(config)
reload(plugin) reload(plugin)

View File

@ -48,11 +48,6 @@ try:
except ImportError: except ImportError:
_ = lambda x: x _ = lambda x: x
if sys.version_info[0] < 3:
raise ImportError('This plugin requires Python 3. For a legacy version of this plugin that still '
'supports Python 2, consult the python2-legacy branch at '
'https://github.com/jlu5/SupyPlugins/tree/python2-legacy')
from .constants import SED_REGEX, TAG_SEEN, TAG_IS_REGEX from .constants import SED_REGEX, TAG_SEEN, TAG_IS_REGEX
# Replace newlines and friends with things like literal "\n" (backslash and "n") # Replace newlines and friends with things like literal "\n" (backslash and "n")

View File

@ -44,11 +44,6 @@ import atexit
import shutil import shutil
import signal import signal
if sys.version_info < (3, 4, 0):
sys.stderr.write('This program requires Python 3.4 or later.')
sys.stderr.write(os.linesep)
sys.exit(-1)
from io import StringIO # Import this after version check since this will fail on Python 2 from io import StringIO # Import this after version check since this will fail on Python 2
def _termHandler(signalNumber, stackFrame): def _termHandler(signalNumber, stackFrame):

View File

@ -46,9 +46,6 @@ def error(s):
sys.stderr.write(os.linesep) sys.stderr.write(os.linesep)
sys.exit(-1) sys.exit(-1)
if sys.version_info < (3, 4, 0):
error('This script requires Python 3.4 or newer.')
import supybot.conf as conf import supybot.conf as conf
from supybot.questions import * from supybot.questions import *
@ -173,10 +170,7 @@ __url__ = ''
from . import config from . import config
from . import plugin from . import plugin
if sys.version_info >= (3, 4): from importlib import reload
from importlib import reload
else:
from imp import reload
# In case we're being reloaded. # In case we're being reloaded.
reload(config) reload(config)
reload(plugin) reload(plugin)

View File

@ -223,12 +223,8 @@ if __name__ == '__main__':
suite = unittest.TestSuite(test.suites) suite = unittest.TestSuite(test.suites)
if options.fail_fast: if options.fail_fast:
if sys.version_info < (2, 7, 0): runner = unittest.TextTestRunner(verbosity=2,
print('--fail-fast is not supported on Python 2.6.') failfast=True)
sys.exit(1)
else:
runner = unittest.TextTestRunner(verbosity=2,
failfast=True)
else: else:
runner = unittest.TextTestRunner(verbosity=2) runner = unittest.TextTestRunner(verbosity=2)
print('Testing began at %s (pid %s)' % (time.ctime(), os.getpid())) print('Testing began at %s (pid %s)' % (time.ctime(), os.getpid()))

View File

@ -42,9 +42,6 @@ def error(s):
sys.stderr.write(os.linesep) sys.stderr.write(os.linesep)
sys.exit(-1) sys.exit(-1)
if sys.version_info < (3, 4, 0):
error('This program requires Python 3.4 or later.')
import supybot import supybot
import re import re

View File

@ -77,8 +77,7 @@ try:
proc = subprocess.Popen('git show HEAD --format=%ct', shell=True, proc = subprocess.Popen('git show HEAD --format=%ct', shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
date = proc.stdout.readline() date = proc.stdout.readline()
if sys.version_info[0] >= 3: date = date.decode()
date = date.decode()
date = int(date.strip()) date = int(date.strip())
version = ".".join(str(i).zfill(2) for i in version = ".".join(str(i).zfill(2) for i in
time.strptime(time.asctime(time.gmtime(date)))[:3]) time.strptime(time.asctime(time.gmtime(date)))[:3])

View File

@ -325,10 +325,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
self.starttls() self.starttls()
# Suppress this warning for loopback IPs. # Suppress this warning for loopback IPs.
if sys.version_info[0] < 3: if (not network_config.requireStarttls()) and \
# Backported Python 2 ipaddress demands unicode instead of str
address = address.decode('utf-8')
elif (not network_config.requireStarttls()) and \
(not network_config.ssl()) and \ (not network_config.ssl()) and \
(not self.currentServer.force_tls_verification): (not self.currentServer.force_tls_verification):

View File

@ -160,34 +160,6 @@ class SupyTestCase(unittest.TestCase):
irc._reallyDie() irc._reallyDie()
teardownMockTime() teardownMockTime()
if sys.version_info < (2, 7, 0):
def assertIn(self, member, container, msg=None):
"""Just like self.assertTrue(a in b), but with a nicer default message."""
if member not in container:
standardMsg = '%s not found in %s' % (repr(member),
repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertNotIn(self, member, container, msg=None):
"""Just like self.assertTrue(a not in b), but with a nicer default message."""
if member in container:
standardMsg = '%s unexpectedly found in %s' % (repr(member),
repr(container))
self.fail(self._formatMessage(msg, standardMsg))
def assertIs(self, expr1, expr2, msg=None):
"""Just like self.assertTrue(a is b), but with a nicer default message."""
if expr1 is not expr2:
standardMsg = '%s is not %s' % (repr(expr1),
repr(expr2))
self.fail(self._formatMessage(msg, standardMsg))
def assertIsNot(self, expr1, expr2, msg=None):
"""Just like self.assertTrue(a is not b), but with a nicer default message."""
if expr1 is expr2:
standardMsg = 'unexpectedly identical: %s' % (repr(expr1),)
self.fail(self._formatMessage(msg, standardMsg))
class PluginTestCase(SupyTestCase): class PluginTestCase(SupyTestCase):
"""Subclass this to write a test case for a plugin. See """Subclass this to write a test case for a plugin. See

View File

@ -194,8 +194,7 @@ def safeEval(s, namespace=None):
return True return True
else: else:
return False return False
elif sys.version_info[0:2] >= (3, 4) and \ elif node.__class__ is ast.NameConstant:
node.__class__ is ast.NameConstant:
return True return True
elif sys.version_info[0:2] >= (3, 8) and \ elif sys.version_info[0:2] >= (3, 8) and \
node.__class__ is ast.Constant: node.__class__ is ast.Constant:

View File

@ -310,10 +310,7 @@ def splitBytes(word, size):
# I'm going to hell for this function # I'm going to hell for this function
for i in range(4): # a character takes at most 4 bytes in UTF-8 for i in range(4): # a character takes at most 4 bytes in UTF-8
try: try:
if sys.version_info[0] >= 3: word[size-i:].decode()
word[size-i:].decode()
else:
word[size-i:].encode('utf8')
except UnicodeDecodeError: except UnicodeDecodeError:
continue continue
else: else:

View File

@ -72,29 +72,6 @@ class SupyProcess(multiprocessing.Process):
super(SupyProcess, self).__init__(*args, **kwargs) super(SupyProcess, self).__init__(*args, **kwargs)
log.debug('Spawning process %q.', self.name) log.debug('Spawning process %q.', self.name)
if sys.version_info[0:3] == (3, 3, 1) and hasattr(select, 'poll'):
# http://bugs.python.org/issue17707
import multiprocessing.connection
def _poll(fds, timeout):
if timeout is not None:
timeout = int(timeout * 1000) # timeout is in milliseconds
fd_map = {}
pollster = select.poll()
for fd in fds:
pollster.register(fd, select.POLLIN)
if hasattr(fd, 'fileno'):
fd_map[fd.fileno()] = fd
else:
fd_map[fd] = fd
ls = []
for fd, event in pollster.poll(timeout):
if event & select.POLLNVAL:
raise ValueError('invalid file descriptor %i' % fd)
ls.append(fd_map[fd])
return ls
multiprocessing.connection._poll = _poll
commandsProcessed = 0 commandsProcessed = 0
ircs = [] # A list of all the IRCs. ircs = [] # A list of all the IRCs.

View File

@ -231,10 +231,7 @@ class FunctionsTestCase(SupyTestCase):
self.assertEqual(ircutils.stripFormatting(s), '[09:21') self.assertEqual(ircutils.stripFormatting(s), '[09:21')
def testWrap(self): def testWrap(self):
if sys.version_info[0] < 3: pred = lambda s:len(s.encode())
pred = len
else:
pred = lambda s:len(s.encode())
s = ('foo bar baz qux ' * 100)[0:-1] s = ('foo bar baz qux ' * 100)[0:-1]
@ -246,13 +243,7 @@ class FunctionsTestCase(SupyTestCase):
self.assertTrue(max(map(pred, r)) <= 100) self.assertTrue(max(map(pred, r)) <= 100)
self.assertEqual(''.join(r), s) self.assertEqual(''.join(r), s)
if sys.version_info[0] < 3: s = (''.join([chr(0x1f527), chr(0x1f527), chr(0x1f527), ' ']) * 100)\
uchr = unichr
u = lambda s: s.decode('utf8')
else:
uchr = chr
u = lambda x: x
s = (u('').join([uchr(0x1f527), uchr(0x1f527), uchr(0x1f527), u(' ')]) * 100)\
[0:-1] [0:-1]
r = ircutils.wrap(s, 20) r = ircutils.wrap(s, 20)
@ -283,7 +274,7 @@ class FunctionsTestCase(SupyTestCase):
self.assertTrue(max(map(pred, r)) <= 100) self.assertTrue(max(map(pred, r)) <= 100)
self.assertEqual(''.join(r), s) self.assertEqual(''.join(r), s)
s = uchr(233)*500 s = chr(233)*500
r = ircutils.wrap(s, 500) r = ircutils.wrap(s, 500)
self.assertTrue(max(map(pred, r)) <= 500) self.assertTrue(max(map(pred, r)) <= 500)
r = ircutils.wrap(s, 139) r = ircutils.wrap(s, 139)

View File

@ -39,9 +39,6 @@ import supybot.utils as utils
from supybot.utils.structures import * from supybot.utils.structures import *
import supybot.utils.minisix as minisix import supybot.utils.minisix as minisix
if sys.version_info[0] >= 0:
xrange = range
class UtilsTest(SupyTestCase): class UtilsTest(SupyTestCase):
def testReversed(self): def testReversed(self):
L = list(range(10)) L = list(range(10))
@ -54,7 +51,7 @@ class UtilsTest(SupyTestCase):
class SeqTest(SupyTestCase): class SeqTest(SupyTestCase):
def testRenumerate(self): def testRenumerate(self):
for i in xrange(5): for i in range(5):
L = list(enumerate(range(i))) L = list(enumerate(range(i)))
LL = list(utils.seq.renumerate(range(i))) LL = list(utils.seq.renumerate(range(i)))
self.assertEqual(L, LL[::-1]) self.assertEqual(L, LL[::-1])
@ -423,7 +420,7 @@ class IterTest(SupyTestCase):
L = [1, 2] L = [1, 2]
seenList = set() seenList = set()
seenIterable = set() seenIterable = set()
for n in xrange(300): for n in range(300):
# 2**266 > 10**80, the number of atoms in the known universe. # 2**266 > 10**80, the number of atoms in the known universe.
# (ignoring dark matter, but that likely doesn't exist in atoms # (ignoring dark matter, but that likely doesn't exist in atoms
# anyway, so it shouldn't have a significant impact on that #) # anyway, so it shouldn't have a significant impact on that #)
@ -748,13 +745,13 @@ class QueueTest(SupyTestCase):
q = queue() q = queue()
n = 10 n = 10
self.assertRaises(IndexError, q.__getitem__, 0) self.assertRaises(IndexError, q.__getitem__, 0)
for i in xrange(n): for i in range(n):
q.enqueue(i) q.enqueue(i)
for i in xrange(n): for i in range(n):
self.assertEqual(q[i], i) self.assertEqual(q[i], i)
for i in xrange(n, 0, -1): for i in range(n, 0, -1):
self.assertEqual(q[-i], n-i) self.assertEqual(q[-i], n-i)
for i in xrange(len(q)): for i in range(len(q)):
self.assertEqual(list(q), list(q[:i]) + list(q[i:])) self.assertEqual(list(q), list(q[:i]) + list(q[i:]))
self.assertRaises(IndexError, q.__getitem__, -(n+1)) self.assertRaises(IndexError, q.__getitem__, -(n+1))
self.assertRaises(IndexError, q.__getitem__, n) self.assertRaises(IndexError, q.__getitem__, n)
@ -763,7 +760,7 @@ class QueueTest(SupyTestCase):
def testSetitem(self): def testSetitem(self):
q1 = queue() q1 = queue()
self.assertRaises(IndexError, q1.__setitem__, 0, 0) self.assertRaises(IndexError, q1.__setitem__, 0, 0)
for i in xrange(10): for i in range(10):
q1.enqueue(i) q1.enqueue(i)
q2 = eval(repr(q1)) q2 = eval(repr(q1))
for (i, elt) in enumerate(q2): for (i, elt) in enumerate(q2):
@ -913,13 +910,13 @@ class SmallQueueTest(SupyTestCase):
q = queue() q = queue()
n = 10 n = 10
self.assertRaises(IndexError, q.__getitem__, 0) self.assertRaises(IndexError, q.__getitem__, 0)
for i in xrange(n): for i in range(n):
q.enqueue(i) q.enqueue(i)
for i in xrange(n): for i in range(n):
self.assertEqual(q[i], i) self.assertEqual(q[i], i)
for i in xrange(n, 0, -1): for i in range(n, 0, -1):
self.assertEqual(q[-i], n-i) self.assertEqual(q[-i], n-i)
for i in xrange(len(q)): for i in range(len(q)):
self.assertEqual(list(q), list(q[:i]) + list(q[i:])) self.assertEqual(list(q), list(q[:i]) + list(q[i:]))
self.assertRaises(IndexError, q.__getitem__, -(n+1)) self.assertRaises(IndexError, q.__getitem__, -(n+1))
self.assertRaises(IndexError, q.__getitem__, n) self.assertRaises(IndexError, q.__getitem__, n)
@ -928,7 +925,7 @@ class SmallQueueTest(SupyTestCase):
def testSetitem(self): def testSetitem(self):
q1 = queue() q1 = queue()
self.assertRaises(IndexError, q1.__setitem__, 0, 0) self.assertRaises(IndexError, q1.__setitem__, 0, 0)
for i in xrange(10): for i in range(10):
q1.enqueue(i) q1.enqueue(i)
q2 = eval(repr(q1)) q2 = eval(repr(q1))
for (i, elt) in enumerate(q2): for (i, elt) in enumerate(q2):
@ -1161,7 +1158,7 @@ class TestCacheDict(SupyTestCase):
def testMaxNeverExceeded(self): def testMaxNeverExceeded(self):
max = 10 max = 10
d = CacheDict(10) d = CacheDict(10)
for i in xrange(max**2): for i in range(max**2):
d[i] = i d[i] = i
self.assertTrue(len(d) <= max) self.assertTrue(len(d) <= max)
self.assertTrue(i in d) self.assertTrue(i in d)

View File

@ -33,11 +33,6 @@ import unittest
from supybot import questions from supybot import questions
from supybot.test import SupyTestCase from supybot.test import SupyTestCase
if sys.version_info >= (2, 7, 0):
skipif = unittest.skipIf
else:
skipif = lambda x, y: lambda z:None
try: try:
from unittest import mock # Python 3.3+ from unittest import mock # Python 3.3+
except ImportError: except ImportError:
@ -53,7 +48,7 @@ except ImportError:
# better solution is usage of '==' operator ;) # better solution is usage of '==' operator ;)
_yes_answer = ''.join(['', 'y']) _yes_answer = ''.join(['', 'y'])
@skipif(mock is None, 'python-mock is not installed.') @unittest.skipIf(mock is None, 'python-mock is not installed.')
class TestYn(SupyTestCase): class TestYn(SupyTestCase):
def test_default_yes_selected(self): def test_default_yes_selected(self):
questions.expect = mock.Mock(return_value=_yes_answer) questions.expect = mock.Mock(return_value=_yes_answer)