Skip to content

Commit

Permalink
Remove python 2.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
elapouya committed Jul 21, 2024
1 parent ac38610 commit a10c3c1
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docxtpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@author: Eric Lapouyade
"""
__version__ = "0.17.0"
__version__ = "0.18.0"

# flake8: noqa
from .inline_image import InlineImage
Expand Down
6 changes: 2 additions & 4 deletions docxtpl/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
@author: Eric Lapouyade
"""
import six

try:
from html import escape
except ImportError:
Expand All @@ -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):
Expand Down
8 changes: 3 additions & 5 deletions docxtpl/richtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
@author: Eric Lapouyade
"""
import six

try:
from html import escape
except ImportError:
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 2 additions & 3 deletions docxtpl/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
6 changes: 2 additions & 4 deletions tests/escape_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import os
from unicodedata import name

from six import iteritems, text_type

from docxtpl import DocxTemplate


Expand All @@ -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 <unicode> example \u4f60 & \u6211",
"iteritems": iteritems,
"iteritems": lambda x: x.items(),
}

tpl.render(context, autoescape=True)
Expand Down
5 changes: 2 additions & 3 deletions tests/runtests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import subprocess
import glob
import six
import os

tests = sorted(glob.glob("[A-Za-z]*.py"))
Expand All @@ -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.")
19 changes: 9 additions & 10 deletions tests/template_error.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit a10c3c1

Please sign in to comment.