From c4afb785f2860e07efa10717d08842fc47e38847 Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Sat, 16 Nov 2024 19:31:55 +0100 Subject: [PATCH] Update the benchmarks to support Python 3.13 (the "cgi" module was removed in 3.13) (#90) --- examples/bench/basic.py | 12 ++++++++++-- examples/bench/bigtable.py | 14 +++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/examples/bench/basic.py b/examples/bench/basic.py index c0318eeb..79c6049c 100644 --- a/examples/bench/basic.py +++ b/examples/bench/basic.py @@ -5,12 +5,20 @@ from __future__ import print_function -from cgi import escape import os -from StringIO import StringIO import sys import timeit +try: + from html import escape +except ImportError: + from cgi import escape + +try: + from io import StringIO +except ImportError: + from StringIO import StringIO + __all__ = ['clearsilver', 'mako', 'django', 'kid', 'genshi', 'genshi_text', 'simpletal'] diff --git a/examples/bench/bigtable.py b/examples/bench/bigtable.py index 521f6c38..b51a540e 100644 --- a/examples/bench/bigtable.py +++ b/examples/bench/bigtable.py @@ -7,15 +7,23 @@ from __future__ import print_function -import cgi import sys import timeit -from StringIO import StringIO from genshi.builder import tag from genshi.filters.i18n import Translator from genshi.filters.tests.i18n import DummyTranslations from genshi.template import MarkupTemplate, NewTextTemplate +try: + from html import escape +except ImportError: + from cgi import escape + +try: + from io import StringIO +except ImportError: + from StringIO import StringIO + try: from elementtree import ElementTree as et except ImportError: @@ -202,7 +210,7 @@ def test_clearsilver(): hdf = neo_util.HDF() for i, row in enumerate(table): for j, c in enumerate(row.values()): - hdf.setValue("rows.%d.cell.%d" % (i, j), cgi.escape(str(c))) + hdf.setValue("rows.%d.cell.%d" % (i, j), escape(str(c))) cs = neo_cs.CS(hdf) cs.parseStr("""