comparison roundup/cgi/TAL/TALGenerator.py @ 5800:1a835db41674

Call cgi.escape only on python 2. Replace with html.escapeif it can be found.
author John Rouillard <rouilj@ieee.org>
date Tue, 11 Jun 2019 21:29:24 -0400
parents a391a071d045
children 936275dfe1fa
comparison
equal deleted inserted replaced
5799:7ba0ee980fc7 5800:1a835db41674
22 22
23 from .TALDefs import NAME_RE, TAL_VERSION 23 from .TALDefs import NAME_RE, TAL_VERSION
24 from .TALDefs import I18NError, METALError, TALError 24 from .TALDefs import I18NError, METALError, TALError
25 from .TALDefs import parseSubstitution 25 from .TALDefs import parseSubstitution
26 from .TranslationContext import TranslationContext, DEFAULT_DOMAIN 26 from .TranslationContext import TranslationContext, DEFAULT_DOMAIN
27
28 try:
29 from html import escape as html_escape # python 3
30 except ImportError:
31 from cgi import escape as html_escape # python 2 fallback
27 32
28 I18N_REPLACE = 1 33 I18N_REPLACE = 1
29 I18N_CONTENT = 2 34 I18N_CONTENT = 2
30 I18N_EXPRESSION = 3 35 I18N_EXPRESSION = 3
31 36
259 264
260 def emitRawText(self, text): 265 def emitRawText(self, text):
261 self.emit("rawtext", text) 266 self.emit("rawtext", text)
262 267
263 def emitText(self, text): 268 def emitText(self, text):
264 self.emitRawText(cgi.escape(text)) 269 self.emitRawText(html_escape(text))
265 270
266 def emitDefines(self, defines): 271 def emitDefines(self, defines):
267 for part in TALDefs.splitParts(defines): 272 for part in TALDefs.splitParts(defines):
268 m = re.match( 273 m = re.match(
269 r"(?s)\s*(?:(global|local)\s+)?(%s)\s+(.*)\Z" % NAME_RE, part) 274 r"(?s)\s*(?:(global|local)\s+)?(%s)\s+(.*)\Z" % NAME_RE, part)

Roundup Issue Tracker: http://roundup-tracker.org/