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 691462a..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): @@ -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..c5916c2 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,13 +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 +158,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..a6b72d2 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 @@ -21,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 @@ -30,15 +32,6 @@ # https://www.gnu.org/copyleft/gpl.html -try: - from urllib import quote -except ImportError: - 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 # something like /usr/share/irclog2html/irclog.css, I imagine CSS_FILE = os.path.join(os.path.dirname(__file__), 'irclog.css') diff --git a/src/irclog2html/tests/test_irclog2html.py b/src/irclog2html/tests/test_irclog2html.py index 73df60f..dcbbeab 100644 --- a/src/irclog2html/tests/test_irclog2html.py +++ b/src/irclog2html/tests/test_irclog2html.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import doctest import io import os @@ -26,13 +24,6 @@ ) -try: - unicode -except NameError: - # Python 3.x - unicode = str - - here = os.path.dirname(__file__) @@ -43,8 +34,6 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, unicode): - 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..9c00e41 100644 --- a/src/irclog2html/tests/test_irclogsearch.py +++ b/src/irclog2html/tests/test_irclogsearch.py @@ -9,8 +9,8 @@ import tempfile import unittest from contextlib import closing +from unittest import mock -import mock from zope.testing import renormalizing from irclog2html.irclogsearch import ( @@ -25,13 +25,6 @@ ) -try: - unicode -except NameError: - # Python 3.x - unicode = str - - here = os.path.dirname(__file__) @@ -74,8 +67,6 @@ def myrepr(o): return '(%s, )' % ', '.join(map(myrepr, o)) else: return '(%s)' % ', '.join(map(myrepr, o)) - elif isinstance(o, unicode): - 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