From c65ba721b7b80297798ae18791ba736c6535b71c Mon Sep 17 00:00:00 2001 From: Alexandre Detiste Date: Wed, 13 Nov 2024 10:27:06 +0100 Subject: [PATCH] trim old Python2 code --- tempita/__init__.py | 2 +- tempita/compat3.py | 40 +++++----------------------------------- tests/test_tempita.py | 1 - 3 files changed, 6 insertions(+), 37 deletions(-) diff --git a/tempita/__init__.py b/tempita/__init__.py index f6eb990..1e5f05e 100644 --- a/tempita/__init__.py +++ b/tempita/__init__.py @@ -39,7 +39,7 @@ def foo(bar): from io import StringIO from urllib.parse import quote as url_quote from tempita._looper import looper -from tempita.compat3 import bytes, basestring_, next, is_unicode, coerce_text +from tempita.compat3 import basestring_, is_unicode, coerce_text __all__ = ['TemplateError', 'Template', 'sub', 'HTMLTemplate', 'sub_html', 'html', 'bunch'] diff --git a/tempita/compat3.py b/tempita/compat3.py index f17f588..be987cb 100644 --- a/tempita/compat3.py +++ b/tempita/compat3.py @@ -1,43 +1,13 @@ -import sys +__all__ = ['basestring_', 'is_unicode', 'coerce_text'] -__all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode'] - -if sys.version < "3": - b = bytes = str - basestring_ = str -else: - - def b(s): - if isinstance(s, str): - return s.encode('latin1') - return bytes(s) - basestring_ = (bytes, str) - bytes = bytes -text = str - -if sys.version < "3": - - def next(obj): - return obj.__next__() -else: - next = next - -if sys.version < "3": - - def is_unicode(obj): - return isinstance(obj, str) -else: - - def is_unicode(obj): - return isinstance(obj, str) +basestring_ = (bytes, str) +def is_unicode(obj): + return isinstance(obj, str) def coerce_text(v): if not isinstance(v, basestring_): - if sys.version < "3": - attr = '__unicode__' - else: - attr = '__str__' + attr = '__str__' if hasattr(v, attr): return str(v) else: diff --git a/tests/test_tempita.py b/tests/test_tempita.py index acb03ce..362fe28 100644 --- a/tests/test_tempita.py +++ b/tests/test_tempita.py @@ -1,4 +1,3 @@ -import os import unittest import doctest