From a10c3c16e4c093f4dc771cff7fa2bc21c81d9e4b Mon Sep 17 00:00:00 2001 From: Eric Lapouyade Date: Sun, 21 Jul 2024 16:42:41 +0200 Subject: [PATCH] Remove python 2.x support --- docxtpl/__init__.py | 2 +- docxtpl/listing.py | 6 ++---- docxtpl/richtext.py | 8 +++----- docxtpl/template.py | 5 ++--- poetry.lock | 2 +- pyproject.toml | 1 - setup.py | 12 +++++++----- tests/escape_auto.py | 6 ++---- tests/runtests.py | 5 ++--- tests/template_error.py | 19 +++++++++---------- 10 files changed, 29 insertions(+), 37 deletions(-) diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index b2d6d3a..c5d79cf 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -4,7 +4,7 @@ @author: Eric Lapouyade """ -__version__ = "0.17.0" +__version__ = "0.18.0" # flake8: noqa from .inline_image import InlineImage diff --git a/docxtpl/listing.py b/docxtpl/listing.py index afe637e..62cde54 100644 --- a/docxtpl/listing.py +++ b/docxtpl/listing.py @@ -4,8 +4,6 @@ @author: Eric Lapouyade """ -import six - try: from html import escape except ImportError: @@ -23,8 +21,8 @@ class Listing(object): def __init__(self, text): # If not a string : cast to string (ex: int, dict etc...) - if not isinstance(text, (six.text_type, six.binary_type)): - text = six.text_type(text) + if not isinstance(text, (str, bytes)): + text = str(text) self.xml = escape(text) def __unicode__(self): diff --git a/docxtpl/richtext.py b/docxtpl/richtext.py index 453ce2a..75c3b1c 100644 --- a/docxtpl/richtext.py +++ b/docxtpl/richtext.py @@ -4,8 +4,6 @@ @author: Eric Lapouyade """ -import six - try: from html import escape except ImportError: @@ -48,9 +46,9 @@ def add( return # If not a string : cast to string (ex: int, dict etc...) - if not isinstance(text, (six.text_type, six.binary_type)): - text = six.text_type(text) - if not isinstance(text, six.text_type): + if not isinstance(text, (str, bytes)): + text = str(text) + if not isinstance(text, str): text = text.decode("utf-8", errors="ignore") text = escape(text) diff --git a/docxtpl/template.py b/docxtpl/template.py index e6a895c..d6d28ec 100644 --- a/docxtpl/template.py +++ b/docxtpl/template.py @@ -25,7 +25,6 @@ # cgi.escape is deprecated in python 3.7 from cgi import escape # noqa: F401 import re -import six import binascii import os import zipfile @@ -771,7 +770,7 @@ def _replace_pics(self): self._replace_docx_part_pics(part, replaced_pics) # Header/Footer - for relid, rel in six.iteritems(part.rels): + for relid, rel in part.rels.items(): if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER): self._replace_docx_part_pics(rel.target_part, replaced_pics) @@ -832,7 +831,7 @@ def _replace_docx_part_pics(self, doc_part, replaced_pics): ) # replace data - for img_id, img_data in six.iteritems(self.pics_to_replace): + for img_id, img_data in self.pics_to_replace.items(): if img_id == filename or img_id == title or img_id == description: part_map[filename][1]._blob = img_data replaced_pics[img_id] = True diff --git a/poetry.lock b/poetry.lock index 7cb1d13..999d53b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -502,4 +502,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "43818448bde523eafcedcdaeb6541d8205a5d52eef5cb4d0e1a0563a7134a579" +content-hash = "77f21c2a463fb31b565180c907e29738afd2f0df60e6418ef73f05bec0a4f015" diff --git a/pyproject.toml b/pyproject.toml index cf402f4..e64cb65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,6 @@ readme = "README.rst" [tool.poetry.dependencies] python = "^3.11" -six = "^1.16.0" python-docx = "^1.1.2" docxcompose = "^1.4.0" jinja2 = "^3.1.4" diff --git a/setup.py b/setup.py index 2eae6c5..bd889ae 100644 --- a/setup.py +++ b/setup.py @@ -50,18 +50,20 @@ def get_version(pkg): classifiers=[ "Intended Audience :: Developers", "Development Status :: 4 - Beta", - "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], keywords='jinja2', url='https://github.com/elapouya/python-docx-template', author='Eric Lapouyade', license='LGPL 2.1', packages=['docxtpl'], - install_requires=['six', - 'python-docx>=1.1.1', + install_requires=['python-docx>=1.1.1', 'docxcompose', 'jinja2', 'lxml'], diff --git a/tests/escape_auto.py b/tests/escape_auto.py index bd4d676..70e8195 100644 --- a/tests/escape_auto.py +++ b/tests/escape_auto.py @@ -5,8 +5,6 @@ import os from unicodedata import name -from six import iteritems, text_type - from docxtpl import DocxTemplate @@ -15,10 +13,10 @@ tpl = DocxTemplate("templates/escape_tpl_auto.docx") context = { - "nested_dict": {name(text_type(c)): c for c in XML_RESERVED}, + "nested_dict": {name(str(c)): c for c in XML_RESERVED}, "autoescape": 'Escaped "str & ing"!', "autoescape_unicode": "This is an escaped example \u4f60 & \u6211", - "iteritems": iteritems, + "iteritems": lambda x: x.items(), } tpl.render(context, autoescape=True) diff --git a/tests/runtests.py b/tests/runtests.py index 083ae0c..b0a3bf3 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -1,6 +1,5 @@ import subprocess import glob -import six import os tests = sorted(glob.glob("[A-Za-z]*.py")) @@ -12,7 +11,7 @@ for test in tests: if test not in excludes: - six.print_("%s ..." % test) + print("%s ..." % test) subprocess.call(["python", "./%s" % test]) -six.print_("Done.") +print("Done.") diff --git a/tests/template_error.py b/tests/template_error.py index 4a7d909..66c6428 100644 --- a/tests/template_error.py +++ b/tests/template_error.py @@ -1,20 +1,19 @@ from docxtpl import DocxTemplate from jinja2.exceptions import TemplateError -import six -six.print_("=" * 80) -six.print_("Generating template error for testing (so it is safe to ignore) :") -six.print_("." * 80) +print("=" * 80) +print("Generating template error for testing (so it is safe to ignore) :") +print("." * 80) try: tpl = DocxTemplate("templates/template_error_tpl.docx") tpl.render({"test_variable": "test variable value"}) except TemplateError as the_error: - six.print_(six.text_type(the_error)) + print(str(the_error)) if hasattr(the_error, "docx_context"): - six.print_("Context:") + print("Context:") for line in the_error.docx_context: - six.print_(line) + print(line) tpl.save("output/template_error.docx") -six.print_("." * 80) -six.print_(" End of TemplateError Test ") -six.print_("=" * 80) +print("." * 80) +print(" End of TemplateError Test ") +print("=" * 80)