From 524b1f9444ebfcb127b85bc4e50c9e52f9f20520 Mon Sep 17 00:00:00 2001 From: noah morrison Date: Sat, 29 Nov 2014 16:34:38 -0500 Subject: [PATCH] Move html_escape out of render Also "hid" it (Put an underscore in front of it) --- chevron/renderer.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/chevron/renderer.py b/chevron/renderer.py index 2879625..e707bf6 100644 --- a/chevron/renderer.py +++ b/chevron/renderer.py @@ -21,6 +21,25 @@ except: python3 = True +# +# Helper functions +# + +def _html_escape(string): + """HTML escape all of these " & < >""" + + html_codes = { + '"': '"', + '<': '<', + '>': '>', + } + + # & must be handled first + string = string.replace('&', '&') + for char in html_codes: + string = string.replace(char, html_codes[char]) + return string + def render(template='', data={}, partials_path='.', partials_ext='mustache', partials_dict={}, padding=0, def_ldel='{{', def_rdel='}}', scopes=None): @@ -56,21 +75,6 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache', A string containing the rendered template. """ - def html_escape(string): - """HTML escape all of these " & < >""" - - html_codes = { - '"': '"', - '<': '<', - '>': '>', - } - - # & must be handled first - string = string.replace('&', '&') - for char in html_codes: - string = string.replace(char, html_codes[char]) - return string - def get_key(key): """Get a key from the current scope""" @@ -161,7 +165,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache', thing = get_key(key) if type(thing) != unicode: thing = unicode(str(thing), 'utf-8') - output += html_escape(thing) + output += _html_escape(thing) # If we're a no html escape tag elif tag == 'no escape': -- 2.47.3