File: escape_auto.py

package info (click to toggle)
python-docx-template 0.16.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,296 kB
  • sloc: python: 1,552; makefile: 164
file content (29 lines) | stat: -rw-r--r-- 611 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
@author: Max Podolskii
"""

import os
from unicodedata import name

from six import iteritems, text_type

from docxtpl import DocxTemplate


XML_RESERVED = """<"&'>"""

tpl = DocxTemplate('templates/escape_tpl_auto.docx')

context = {
    'nested_dict': {name(text_type(c)): c for c in XML_RESERVED},
    'autoescape': 'Escaped "str & ing"!',
    'autoescape_unicode': u'This is an escaped <unicode> example \u4f60 & \u6211',
    'iteritems': iteritems,
}

tpl.render(context, autoescape=True)

OUTPUT = 'output'
if not os.path.exists(OUTPUT):
    os.makedirs(OUTPUT)
tpl.save(OUTPUT + '/escape_auto.docx')