From 708b258fa37272ece656f6825e80dc6bcbae849e Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Sat, 16 Sep 2023 22:20:51 +0300 Subject: [PATCH] Fix(Py3): Fix `unicode` compatibility --- Writers/bkmk_wflad.py | 1 + Writers/bkmk_whtml.py | 1 + compat.py | 11 +++++++++++ parse_html/bkmk_parse_html.py | 2 ++ 4 files changed, 15 insertions(+) create mode 100644 compat.py diff --git a/Writers/bkmk_wflad.py b/Writers/bkmk_wflad.py index 0d1acbb..1adc343 100644 --- a/Writers/bkmk_wflad.py +++ b/Writers/bkmk_wflad.py @@ -12,6 +12,7 @@ __all__ = ['writer_flad'] import time from bkmk_objects import Writer +from compat import unicode def strftime(s): diff --git a/Writers/bkmk_whtml.py b/Writers/bkmk_whtml.py index dd43b0d..09d9989 100644 --- a/Writers/bkmk_whtml.py +++ b/Writers/bkmk_whtml.py @@ -11,6 +11,7 @@ __all__ = ['writer_html'] from bkmk_objects import Writer, BKMK_FORMAT, quote_title +from compat import unicode def dump_comment(comment): diff --git a/compat.py b/compat.py new file mode 100644 index 0000000..ab6254c --- /dev/null +++ b/compat.py @@ -0,0 +1,11 @@ +import sys + +# Compatability definitions (inspired by six) +PY2 = sys.version_info[0] < 3 +if PY2: + # disable flake8 checks on python 3 + string_type = basestring # noqa + unicode = unicode # noqa +else: + string_type = str + unicode = str diff --git a/parse_html/bkmk_parse_html.py b/parse_html/bkmk_parse_html.py index 997bf64..8d6cb7c 100644 --- a/parse_html/bkmk_parse_html.py +++ b/parse_html/bkmk_parse_html.py @@ -14,6 +14,8 @@ __all__ = ['parse_html', 'parse_filename', 'universal_charset'] import codecs import os +from ..compat import unicode + try: from . import bkmk_ph_beautifulsoup4 except ImportError: -- 2.39.5