Skip to content

Commit

Permalink
Merge pull request #35 from a-detiste/master
Browse files Browse the repository at this point in the history
remove Python 2 crumbs
  • Loading branch information
mgedmin committed Apr 19, 2024
2 parents b790c74 + 1dc234b commit fd09b67
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 95 deletions.
9 changes: 7 additions & 2 deletions bootstrap.py
Expand Up @@ -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.

Expand Down Expand Up @@ -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'):
Expand All @@ -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.
Expand Down Expand Up @@ -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])
Expand All @@ -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')

Expand Down
32 changes: 16 additions & 16 deletions porting/test.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)


Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -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'],
Expand Down
18 changes: 2 additions & 16 deletions src/irclog2html/irclog2html.py
Expand Up @@ -45,8 +45,6 @@
# New default style: xhtmltable
#

from __future__ import print_function, unicode_literals

import datetime
import gzip
import io
Expand All @@ -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')
Expand Down Expand Up @@ -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:
Expand Down
18 changes: 2 additions & 16 deletions src/irclog2html/irclogsearch.py
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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"

Expand Down Expand Up @@ -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
Expand Down
9 changes: 1 addition & 8 deletions src/irclog2html/irclogserver.py
Expand Up @@ -25,23 +25,16 @@
# 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
import io
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,
Expand Down
15 changes: 4 additions & 11 deletions src/irclog2html/logs2html.py
Expand Up @@ -11,8 +11,6 @@
YYYYMMDD) in the filename.
"""

from __future__ import print_function, unicode_literals

import datetime
import glob
import optparse
Expand All @@ -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
Expand All @@ -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')
Expand Down
11 changes: 0 additions & 11 deletions src/irclog2html/tests/test_irclog2html.py
@@ -1,5 +1,3 @@
from __future__ import print_function

import doctest
import io
import os
Expand All @@ -26,13 +24,6 @@
)


try:
unicode
except NameError:
# Python 3.x
unicode = str


here = os.path.dirname(__file__)


Expand All @@ -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)

Expand Down
11 changes: 1 addition & 10 deletions src/irclog2html/tests/test_irclogsearch.py
Expand Up @@ -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 (
Expand All @@ -25,13 +25,6 @@
)


try:
unicode
except NameError:
# Python 3.x
unicode = str


here = os.path.dirname(__file__)


Expand Down Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions src/irclog2html/tests/test_irclogserver.py
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions src/irclog2html/xchatlogsplit.py
Expand Up @@ -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
Expand Down

0 comments on commit fd09b67

Please sign in to comment.