Remove python 2.x support
This commit is contained in:
parent
ac38610947
commit
a10c3c16e4
@ -4,7 +4,7 @@ Created : 2015-03-12
|
||||
|
||||
@author: Eric Lapouyade
|
||||
"""
|
||||
__version__ = "0.17.0"
|
||||
__version__ = "0.18.0"
|
||||
|
||||
# flake8: noqa
|
||||
from .inline_image import InlineImage
|
||||
|
||||
@ -4,8 +4,6 @@ Created : 2021-07-30
|
||||
|
||||
@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):
|
||||
|
||||
@ -4,8 +4,6 @@ Created : 2021-07-30
|
||||
|
||||
@author: Eric Lapouyade
|
||||
"""
|
||||
import six
|
||||
|
||||
try:
|
||||
from html import escape
|
||||
except ImportError:
|
||||
@ -48,9 +46,9 @@ class RichText(object):
|
||||
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)
|
||||
|
||||
|
||||
@ -25,7 +25,6 @@ except ImportError:
|
||||
# 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 @@ class DocxTemplate(object):
|
||||
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 @@ class DocxTemplate(object):
|
||||
)
|
||||
|
||||
# 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
|
||||
|
||||
2
poetry.lock
generated
2
poetry.lock
generated
@ -502,4 +502,4 @@ files = [
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.11"
|
||||
content-hash = "43818448bde523eafcedcdaeb6541d8205a5d52eef5cb4d0e1a0563a7134a579"
|
||||
content-hash = "77f21c2a463fb31b565180c907e29738afd2f0df60e6418ef73f05bec0a4f015"
|
||||
|
||||
@ -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"
|
||||
|
||||
12
setup.py
12
setup.py
@ -50,18 +50,20 @@ setup(name='docxtpl',
|
||||
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'],
|
||||
|
||||
@ -5,8 +5,6 @@
|
||||
import os
|
||||
from unicodedata import name
|
||||
|
||||
from six import iteritems, text_type
|
||||
|
||||
from docxtpl import DocxTemplate
|
||||
|
||||
|
||||
@ -15,10 +13,10 @@ XML_RESERVED = """<"&'>"""
|
||||
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)
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import subprocess
|
||||
import glob
|
||||
import six
|
||||
import os
|
||||
|
||||
tests = sorted(glob.glob("[A-Za-z]*.py"))
|
||||
@ -12,7 +11,7 @@ if not os.path.exists(output_dir):
|
||||
|
||||
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.")
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user