Ticket #2215: django-escape.diff
File django-escape.diff, 1.1 KB (added by , 18 years ago) |
---|
-
django/utils/html.py
1 1 "HTML utilities suitable for global use." 2 2 3 3 import re, string 4 from htmlentitydefs import entitydefs 4 5 5 6 # Configuration for urlize() function 6 7 LEADING_PUNCTUATION = ['(', '<', '<'] … … 21 22 trailing_empty_content_re = re.compile(r'(?:<p>(?: |\s|<br \/>)*?</p>\s*)+\Z') 22 23 del x # Temporary variable 23 24 25 entitytrans = dict([(value, key) for key, value in entitydefs.iteritems() if len(value) == 1]) 26 entitytrans.pop(' ', None) 27 entitytrans["'"] = '#39' 28 24 29 def escape(html): 25 30 "Returns the given HTML with ampersands, quotes and carets encoded" 26 if not isinstance(html, basestring): 27 html = str(html) 28 return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') 31 return ''.join([c in entitytrans and '&%s;' % entitytrans[c] or c for c in html]) 29 32 30 33 def linebreaks(value): 31 34 "Converts newlines into <p> and <br />s"