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
|
@author: Eric Lapouyade
|
||||||
"""
|
"""
|
||||||
__version__ = "0.17.0"
|
__version__ = "0.18.0"
|
||||||
|
|
||||||
# flake8: noqa
|
# flake8: noqa
|
||||||
from .inline_image import InlineImage
|
from .inline_image import InlineImage
|
||||||
|
|||||||
@ -4,8 +4,6 @@ Created : 2021-07-30
|
|||||||
|
|
||||||
@author: Eric Lapouyade
|
@author: Eric Lapouyade
|
||||||
"""
|
"""
|
||||||
import six
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from html import escape
|
from html import escape
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -23,8 +21,8 @@ class Listing(object):
|
|||||||
|
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
# If not a string : cast to string (ex: int, dict etc...)
|
# If not a string : cast to string (ex: int, dict etc...)
|
||||||
if not isinstance(text, (six.text_type, six.binary_type)):
|
if not isinstance(text, (str, bytes)):
|
||||||
text = six.text_type(text)
|
text = str(text)
|
||||||
self.xml = escape(text)
|
self.xml = escape(text)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
|
|||||||
@ -4,8 +4,6 @@ Created : 2021-07-30
|
|||||||
|
|
||||||
@author: Eric Lapouyade
|
@author: Eric Lapouyade
|
||||||
"""
|
"""
|
||||||
import six
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from html import escape
|
from html import escape
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -48,9 +46,9 @@ class RichText(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# If not a string : cast to string (ex: int, dict etc...)
|
# If not a string : cast to string (ex: int, dict etc...)
|
||||||
if not isinstance(text, (six.text_type, six.binary_type)):
|
if not isinstance(text, (str, bytes)):
|
||||||
text = six.text_type(text)
|
text = str(text)
|
||||||
if not isinstance(text, six.text_type):
|
if not isinstance(text, str):
|
||||||
text = text.decode("utf-8", errors="ignore")
|
text = text.decode("utf-8", errors="ignore")
|
||||||
text = escape(text)
|
text = escape(text)
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,6 @@ except ImportError:
|
|||||||
# cgi.escape is deprecated in python 3.7
|
# cgi.escape is deprecated in python 3.7
|
||||||
from cgi import escape # noqa: F401
|
from cgi import escape # noqa: F401
|
||||||
import re
|
import re
|
||||||
import six
|
|
||||||
import binascii
|
import binascii
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
@ -771,7 +770,7 @@ class DocxTemplate(object):
|
|||||||
self._replace_docx_part_pics(part, replaced_pics)
|
self._replace_docx_part_pics(part, replaced_pics)
|
||||||
|
|
||||||
# Header/Footer
|
# 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):
|
if rel.reltype in (REL_TYPE.HEADER, REL_TYPE.FOOTER):
|
||||||
self._replace_docx_part_pics(rel.target_part, replaced_pics)
|
self._replace_docx_part_pics(rel.target_part, replaced_pics)
|
||||||
|
|
||||||
@ -832,7 +831,7 @@ class DocxTemplate(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# replace data
|
# 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:
|
if img_id == filename or img_id == title or img_id == description:
|
||||||
part_map[filename][1]._blob = img_data
|
part_map[filename][1]._blob = img_data
|
||||||
replaced_pics[img_id] = True
|
replaced_pics[img_id] = True
|
||||||
|
|||||||
2
poetry.lock
generated
2
poetry.lock
generated
@ -502,4 +502,4 @@ files = [
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.11"
|
python-versions = "^3.11"
|
||||||
content-hash = "43818448bde523eafcedcdaeb6541d8205a5d52eef5cb4d0e1a0563a7134a579"
|
content-hash = "77f21c2a463fb31b565180c907e29738afd2f0df60e6418ef73f05bec0a4f015"
|
||||||
|
|||||||
@ -7,7 +7,6 @@ readme = "README.rst"
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = "^3.11"
|
python = "^3.11"
|
||||||
six = "^1.16.0"
|
|
||||||
python-docx = "^1.1.2"
|
python-docx = "^1.1.2"
|
||||||
docxcompose = "^1.4.0"
|
docxcompose = "^1.4.0"
|
||||||
jinja2 = "^3.1.4"
|
jinja2 = "^3.1.4"
|
||||||
|
|||||||
12
setup.py
12
setup.py
@ -50,18 +50,20 @@ setup(name='docxtpl',
|
|||||||
classifiers=[
|
classifiers=[
|
||||||
"Intended Audience :: Developers",
|
"Intended Audience :: Developers",
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 4 - Beta",
|
||||||
"Programming Language :: Python :: 2",
|
|
||||||
"Programming Language :: Python :: 2.7",
|
|
||||||
"Programming Language :: Python :: 3",
|
"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',
|
keywords='jinja2',
|
||||||
url='https://github.com/elapouya/python-docx-template',
|
url='https://github.com/elapouya/python-docx-template',
|
||||||
author='Eric Lapouyade',
|
author='Eric Lapouyade',
|
||||||
license='LGPL 2.1',
|
license='LGPL 2.1',
|
||||||
packages=['docxtpl'],
|
packages=['docxtpl'],
|
||||||
install_requires=['six',
|
install_requires=['python-docx>=1.1.1',
|
||||||
'python-docx>=1.1.1',
|
|
||||||
'docxcompose',
|
'docxcompose',
|
||||||
'jinja2',
|
'jinja2',
|
||||||
'lxml'],
|
'lxml'],
|
||||||
|
|||||||
@ -5,8 +5,6 @@
|
|||||||
import os
|
import os
|
||||||
from unicodedata import name
|
from unicodedata import name
|
||||||
|
|
||||||
from six import iteritems, text_type
|
|
||||||
|
|
||||||
from docxtpl import DocxTemplate
|
from docxtpl import DocxTemplate
|
||||||
|
|
||||||
|
|
||||||
@ -15,10 +13,10 @@ XML_RESERVED = """<"&'>"""
|
|||||||
tpl = DocxTemplate("templates/escape_tpl_auto.docx")
|
tpl = DocxTemplate("templates/escape_tpl_auto.docx")
|
||||||
|
|
||||||
context = {
|
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": 'Escaped "str & ing"!',
|
||||||
"autoescape_unicode": "This is an escaped <unicode> example \u4f60 & \u6211",
|
"autoescape_unicode": "This is an escaped <unicode> example \u4f60 & \u6211",
|
||||||
"iteritems": iteritems,
|
"iteritems": lambda x: x.items(),
|
||||||
}
|
}
|
||||||
|
|
||||||
tpl.render(context, autoescape=True)
|
tpl.render(context, autoescape=True)
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
import glob
|
import glob
|
||||||
import six
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
tests = sorted(glob.glob("[A-Za-z]*.py"))
|
tests = sorted(glob.glob("[A-Za-z]*.py"))
|
||||||
@ -12,7 +11,7 @@ if not os.path.exists(output_dir):
|
|||||||
|
|
||||||
for test in tests:
|
for test in tests:
|
||||||
if test not in excludes:
|
if test not in excludes:
|
||||||
six.print_("%s ..." % test)
|
print("%s ..." % test)
|
||||||
subprocess.call(["python", "./%s" % test])
|
subprocess.call(["python", "./%s" % test])
|
||||||
|
|
||||||
six.print_("Done.")
|
print("Done.")
|
||||||
|
|||||||
@ -1,20 +1,19 @@
|
|||||||
from docxtpl import DocxTemplate
|
from docxtpl import DocxTemplate
|
||||||
from jinja2.exceptions import TemplateError
|
from jinja2.exceptions import TemplateError
|
||||||
import six
|
|
||||||
|
|
||||||
six.print_("=" * 80)
|
print("=" * 80)
|
||||||
six.print_("Generating template error for testing (so it is safe to ignore) :")
|
print("Generating template error for testing (so it is safe to ignore) :")
|
||||||
six.print_("." * 80)
|
print("." * 80)
|
||||||
try:
|
try:
|
||||||
tpl = DocxTemplate("templates/template_error_tpl.docx")
|
tpl = DocxTemplate("templates/template_error_tpl.docx")
|
||||||
tpl.render({"test_variable": "test variable value"})
|
tpl.render({"test_variable": "test variable value"})
|
||||||
except TemplateError as the_error:
|
except TemplateError as the_error:
|
||||||
six.print_(six.text_type(the_error))
|
print(str(the_error))
|
||||||
if hasattr(the_error, "docx_context"):
|
if hasattr(the_error, "docx_context"):
|
||||||
six.print_("Context:")
|
print("Context:")
|
||||||
for line in the_error.docx_context:
|
for line in the_error.docx_context:
|
||||||
six.print_(line)
|
print(line)
|
||||||
tpl.save("output/template_error.docx")
|
tpl.save("output/template_error.docx")
|
||||||
six.print_("." * 80)
|
print("." * 80)
|
||||||
six.print_(" End of TemplateError Test ")
|
print(" End of TemplateError Test ")
|
||||||
six.print_("=" * 80)
|
print("=" * 80)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user