From: noah morrison Date: Sat, 29 Nov 2014 21:34:38 +0000 (-0500) Subject: Move html_escape out of render X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=524b1f9444ebfcb127b85bc4e50c9e52f9f20520;p=chevron.git Move html_escape out of render Also "hid" it (Put an underscore in front of it) --- 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':