From 8772977cbd5611878a1142956d9684333621f0c6 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 00:41:09 +0200 Subject: [PATCH 1/8] remove Python 2 crumbs --- porting/test.py | 24 +++++++++++----------- setup.py | 1 - src/irclog2html/irclog2html.py | 18 ++-------------- src/irclog2html/irclogsearch.py | 17 ++------------- src/irclog2html/irclogserver.py | 9 +------- src/irclog2html/logs2html.py | 8 +------- src/irclog2html/tests/test_irclog2html.py | 14 +------------ src/irclog2html/tests/test_irclogsearch.py | 12 +---------- src/irclog2html/tests/test_irclogserver.py | 3 +-- src/irclog2html/xchatlogsplit.py | 2 -- 10 files changed, 21 insertions(+), 87 deletions(-) diff --git a/porting/test.py b/porting/test.py index 691462a..ce5712e 100755 --- a/porting/test.py +++ b/porting/test.py @@ -52,7 +52,7 @@ def run_in_tempdir(inputfile, script, args): outfilename = newinputfile + '.html' try: return open(outfilename).read().replace(dir, '/tmpdir') - except IOError, e: + except IOError as e: raise AssertionError('%s did not create the output file\n%s' % (cmdline, e)) finally: @@ -95,30 +95,30 @@ def run_and_compare(inputfile, args=""): def testcase(inputfile, args_to_try=DEFAULT_ARGS): """Run both scripts on inputfile with various arguments.""" - print inputfile, + print(inputfile), try: for args in args_to_try: - print ".", + print(".", end='') run_and_compare(inputfile, args) - except AssertionError, e: - print "FAILED" - print - print e - print + except AssertionError as e: + print("FAILED") + print() + print(e) + print() else: - print "ok" + print("ok") def main(): os.chdir(os.path.dirname(__file__)) # the Perl script takes ages to process dircproxy-example.log; ignore it testcases = glob.glob('testcases/test*.log') - print "Comparing outputs produced by the Perl version and the Python port" - print "There are %d test cases" % len(testcases) + print("Comparing outputs produced by the Perl version and the Python port") + print("There are %d test cases" % len(testcases)) n = 0 for inputfile in testcases: n += 1 - print n, + print(n, end='') testcase(inputfile) diff --git a/setup.py b/setup.py index 0d265d7..8c0c0a3 100755 --- a/setup.py +++ b/setup.py @@ -50,7 +50,6 @@ def read(filename): python_requires='>=3.7', keywords='irc log colorizer html wsgi', extras_require=dict(test=[ - "mock", "zope.testing", ]), packages=['irclog2html'], diff --git a/src/irclog2html/irclog2html.py b/src/irclog2html/irclog2html.py index 4d820c3..049d5c6 100755 --- a/src/irclog2html/irclog2html.py +++ b/src/irclog2html/irclog2html.py @@ -45,8 +45,6 @@ # New default style: xhtmltable # -from __future__ import print_function, unicode_literals - import datetime import gzip import io @@ -58,25 +56,13 @@ import shlex import shutil import sys - - -try: - from urllib import quote -except ImportError: - from urllib.parse import quote +from urllib.parse import quote from ._version import __date__ as RELEASE from ._version import __homepage__ as HOMEPAGE from ._version import __version__ as VERSION -try: - unicode -except NameError: - # Python 3.x - unicode = str - - # If someone packages this for a Linux distro, they'll want to patch this to # something like /usr/share/irclog2html/irclog.css, I imagine CSS_FILE = os.path.join(os.path.dirname(__file__), 'irclog.css') @@ -145,7 +131,7 @@ def decode(s): Supports xchat's hybrid Latin/Unicode encoding, as documented here: http://xchat.org/encoding/ """ - if isinstance(s, unicode): + if isinstance(s, str): # Accept input that's already Unicode, for convenience return s try: diff --git a/src/irclog2html/irclogsearch.py b/src/irclog2html/irclogsearch.py index 52878c3..631c1fb 100755 --- a/src/irclog2html/irclogsearch.py +++ b/src/irclog2html/irclogsearch.py @@ -22,8 +22,6 @@ # Released under the terms of the GNU GPL v2 or v3 # https://www.gnu.org/copyleft/gpl.html -from __future__ import print_function, unicode_literals - import cgi import cgitb import io @@ -32,12 +30,7 @@ import sys import time from contextlib import closing - - -try: - from urllib import quote -except ImportError: - from urllib.parse import quote +from urllib.parse import quote from .irclog2html import ( HOMEPAGE, @@ -52,12 +45,6 @@ from .logs2html import find_log_files -try: - unicode -except NameError: - # Python 3.x - unicode = str - DEFAULT_LOGFILE_PATH = os.path.dirname(__file__) DEFAULT_LOGFILE_PATTERN = "*.log" @@ -172,7 +159,7 @@ def search_irc_logs(query, stats=None, where=DEFAULT_LOGFILE_PATH, elif event == LogParser.NICKCHANGE: text, oldnick, newnick = info else: - text = unicode(info) + text = str(info) stats.lines += 1 if query in text.lower(): stats.matches += 1 diff --git a/src/irclog2html/irclogserver.py b/src/irclog2html/irclogserver.py index 4dabb7a..31e09ae 100755 --- a/src/irclog2html/irclogserver.py +++ b/src/irclog2html/irclogserver.py @@ -25,8 +25,6 @@ # Released under the terms of the GNU GPL v2 or v3 # https://www.gnu.org/copyleft/gpl.html -from __future__ import print_function - import argparse import cgi import datetime @@ -34,14 +32,9 @@ import os import time from operator import attrgetter +from urllib.parse import quote_plus from wsgiref.simple_server import make_server - -try: - from urllib import quote_plus # Py2 -except ImportError: - from urllib.parse import quote_plus # Py3 - from ._version import __date__, __version__ from .irclog2html import ( CSS_FILE, diff --git a/src/irclog2html/logs2html.py b/src/irclog2html/logs2html.py index ad1b128..2dd6b7b 100755 --- a/src/irclog2html/logs2html.py +++ b/src/irclog2html/logs2html.py @@ -11,8 +11,6 @@ YYYYMMDD) in the filename. """ -from __future__ import print_function, unicode_literals - import datetime import glob import optparse @@ -29,11 +27,7 @@ # Released under the terms of the GNU GPL v2 or v3 # https://www.gnu.org/copyleft/gpl.html - -try: - from urllib import quote -except ImportError: - from urllib.parse import quote +from urllib.parse import quote from . import irclog2html from .irclog2html import HOMEPAGE, RELEASE, VERSION, escape diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 73df60f..5109520 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -1,11 +1,6 @@ -from __future__ import print_function - import doctest -import io import os -import shutil import sys -import tempfile import unittest from irclog2html.irclog2html import ( @@ -26,13 +21,6 @@ ) -try: - unicode -except NameError: - # Python 3.x - unicode = str - - here = os.path.dirname(__file__) @@ -43,7 +31,7 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, unicode): + elif isinstance(o, str): return repr(o).lstrip('u') else: return repr(o) diff --git a/src/irclog2html/tests/test_irclogsearch.py b/src/irclog2html/tests/test_irclogsearch.py index 7879a0e..9727f69 100644 --- a/src/irclog2html/tests/test_irclogsearch.py +++ b/src/irclog2html/tests/test_irclogsearch.py @@ -1,5 +1,3 @@ -import cgi -import datetime import doctest import gzip import os @@ -10,7 +8,6 @@ import unittest from contextlib import closing -import mock from zope.testing import renormalizing from irclog2html.irclogsearch import ( @@ -25,13 +22,6 @@ ) -try: - unicode -except NameError: - # Python 3.x - unicode = str - - here = os.path.dirname(__file__) @@ -74,7 +64,7 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, unicode): + elif isinstance(o, str): return repr(o).lstrip('u') else: return repr(o) diff --git a/src/irclog2html/tests/test_irclogserver.py b/src/irclog2html/tests/test_irclogserver.py index 4b9006e..48a8702 100644 --- a/src/irclog2html/tests/test_irclogserver.py +++ b/src/irclog2html/tests/test_irclogserver.py @@ -8,8 +8,7 @@ import tempfile import unittest from contextlib import closing - -import mock +from unittest import mock from irclog2html.irclogserver import application, dir_listing, parse_path diff --git a/src/irclog2html/xchatlogsplit.py b/src/irclog2html/xchatlogsplit.py index 727239e..4dffc6d 100755 --- a/src/irclog2html/xchatlogsplit.py +++ b/src/irclog2html/xchatlogsplit.py @@ -11,8 +11,6 @@ restore some actual IRC chat log history from my xchat logs. """ -from __future__ import print_function - import locale import os import re From a2308e5566b8dd2d40b63669572790b2df513f45 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 00:58:59 +0200 Subject: [PATCH 2/8] undo pyflakes3 removal --- src/irclog2html/tests/test_irclog2html.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 5109520..2763915 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -1,6 +1,9 @@ import doctest +import io import os +import shutil import sys +import tmpfile import unittest from irclog2html.irclog2html import ( From d98461f76a537f1a1da4bfa180283ff3c1e5934b Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 01:02:26 +0200 Subject: [PATCH 3/8] undo pyflakes3 removal --- src/irclog2html/tests/test_irclogsearch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/irclog2html/tests/test_irclogsearch.py b/src/irclog2html/tests/test_irclogsearch.py index 9727f69..af9631b 100644 --- a/src/irclog2html/tests/test_irclogsearch.py +++ b/src/irclog2html/tests/test_irclogsearch.py @@ -1,3 +1,5 @@ +import cgi +import datetime import doctest import gzip import os @@ -7,6 +9,7 @@ import tempfile import unittest from contextlib import closing +from unittest import mock from zope.testing import renormalizing From 759da1bf38d816c24e25b2c9ff62e8ca765f9387 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 01:13:53 +0200 Subject: [PATCH 4/8] typo --- src/irclog2html/tests/test_irclog2html.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 2763915..3c13db4 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -3,7 +3,7 @@ import os import shutil import sys -import tmpfile +import tempfile import unittest from irclog2html.irclog2html import ( From 42f654dd4fbc5004f7054481c65014b5495b277b Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 13:17:45 +0200 Subject: [PATCH 5/8] isort --- bootstrap.py | 9 +++++++-- porting/test.py | 8 ++++---- src/irclog2html/irclogsearch.py | 1 - src/irclog2html/logs2html.py | 7 ++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/bootstrap.py b/bootstrap.py index a459921..294bcdd 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -22,9 +22,9 @@ import shutil import sys import tempfile - from optparse import OptionParser + __version__ = '2015-07-01' # See zc.buildout's changelog if this version is up to date. @@ -96,6 +96,7 @@ # this will remove them from the path to ensure that incompatible versions # of setuptools are not in the path import site + # inside a virtualenv, there is no 'getsitepackages'. # We can't remove these reliably if hasattr(site, 'getsitepackages'): @@ -115,8 +116,9 @@ setup_args['to_dir'] = options.setuptools_to_dir ez['use_setuptools'](**setup_args) -import setuptools import pkg_resources +import setuptools + # This does not (always?) update the default working set. We will # do it. @@ -188,6 +190,8 @@ def _final_version(parsed_version): cmd.append(requirement) import subprocess + + if subprocess.call(cmd) != 0: raise Exception( "Failed to execute command:\n%s" % repr(cmd)[1:-1]) @@ -199,6 +203,7 @@ def _final_version(parsed_version): ws.require(requirement) import zc.buildout.buildout + if not [a for a in args if '=' not in a]: args.append('bootstrap') diff --git a/porting/test.py b/porting/test.py index ce5712e..60c807a 100755 --- a/porting/test.py +++ b/porting/test.py @@ -5,13 +5,13 @@ You must run this script in a directory that contains irclog2html.py, irclog2html.pl and testcases/*.log. Both scripts must be executable. """ -import os -import tempfile -import shutil import difflib import glob +import os +import shutil +import tempfile -from irclog2html import VERSION, RELEASE +from irclog2html import RELEASE, VERSION def replace(s, replacements): diff --git a/src/irclog2html/irclogsearch.py b/src/irclog2html/irclogsearch.py index 631c1fb..c5916c2 100755 --- a/src/irclog2html/irclogsearch.py +++ b/src/irclog2html/irclogsearch.py @@ -45,7 +45,6 @@ from .logs2html import find_log_files - DEFAULT_LOGFILE_PATH = os.path.dirname(__file__) DEFAULT_LOGFILE_PATTERN = "*.log" diff --git a/src/irclog2html/logs2html.py b/src/irclog2html/logs2html.py index 2dd6b7b..2a498bb 100755 --- a/src/irclog2html/logs2html.py +++ b/src/irclog2html/logs2html.py @@ -19,6 +19,10 @@ import shutil import sys from operator import attrgetter +from urllib.parse import quote + +from . import irclog2html +from .irclog2html import HOMEPAGE, RELEASE, VERSION, escape # Copyright (c) 2005--2013 Marius Gedminas @@ -27,10 +31,7 @@ # Released under the terms of the GNU GPL v2 or v3 # https://www.gnu.org/copyleft/gpl.html -from urllib.parse import quote -from . import irclog2html -from .irclog2html import HOMEPAGE, RELEASE, VERSION, escape # If someone packages this for a Linux distro, they'll want to patch this to From 3d8ab24555038fe09df8d7ec8b3b450cd25ac2ec Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Thu, 18 Apr 2024 13:19:00 +0200 Subject: [PATCH 6/8] all strings are unicode in Python3 --- src/irclog2html/tests/test_irclog2html.py | 2 -- src/irclog2html/tests/test_irclogsearch.py | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 3c13db4..96934de 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -35,8 +35,6 @@ def myrepr(o): else: return '(%s)' % ', '.join(map(myrepr, o)) elif isinstance(o, str): - return repr(o).lstrip('u') - else: return repr(o) diff --git a/src/irclog2html/tests/test_irclogsearch.py b/src/irclog2html/tests/test_irclogsearch.py index af9631b..0e059b4 100644 --- a/src/irclog2html/tests/test_irclogsearch.py +++ b/src/irclog2html/tests/test_irclogsearch.py @@ -68,8 +68,6 @@ def myrepr(o): else: return '(%s)' % ', '.join(map(myrepr, o)) elif isinstance(o, str): - return repr(o).lstrip('u') - else: return repr(o) From 67031b374dbbc33aa6a0103bff8ca5c99da26308 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 19 Apr 2024 14:52:57 +0300 Subject: [PATCH 7/8] Fix logic in both myrepr() helpers --- src/irclog2html/tests/test_irclog2html.py | 2 +- src/irclog2html/tests/test_irclogsearch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 96934de..dcbbeab 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -34,7 +34,7 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, str): + else: return repr(o) diff --git a/src/irclog2html/tests/test_irclogsearch.py b/src/irclog2html/tests/test_irclogsearch.py index 0e059b4..9c00e41 100644 --- a/src/irclog2html/tests/test_irclogsearch.py +++ b/src/irclog2html/tests/test_irclogsearch.py @@ -67,7 +67,7 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, str): + else: return repr(o) From 1dc234b7558386b63bdc379acad0938b12f1dc28 Mon Sep 17 00:00:00 2001 From: Marius Gedminas Date: Fri, 19 Apr 2024 14:58:16 +0300 Subject: [PATCH 8/8] flake8: too many blank lines I'm doing this through GitHub's review UI, and I have doubts that it will remove the correct number of blank lines (2). --- src/irclog2html/logs2html.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/irclog2html/logs2html.py b/src/irclog2html/logs2html.py index 2a498bb..a6b72d2 100755 --- a/src/irclog2html/logs2html.py +++ b/src/irclog2html/logs2html.py @@ -32,8 +32,6 @@ # https://www.gnu.org/copyleft/gpl.html - - # If someone packages this for a Linux distro, they'll want to patch this to # something like /usr/share/irclog2html/irclog.css, I imagine CSS_FILE = os.path.join(os.path.dirname(__file__), 'irclog.css')