minor refactoring

This commit is contained in:
Miroslav Stampar
2011-12-21 14:25:39 +00:00
parent 81bd9a201b
commit 41b60b26fc
15 changed files with 39 additions and 39 deletions

View File

@@ -152,6 +152,9 @@ def htmlescape(value):
return value.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;').replace(' ', '&nbsp;')
def htmlunescape(value):
retVal = value.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&#39;', "'").replace('&nbsp;', ' ')
retVal = re.sub('&#(\d+);', lambda x: unichr(int(x.group(1))), retVal)
retVal = value
if value and isinstance(value, basestring):
if '&' in retVal:
retVal = retVal.replace('&amp;', '&').replace('&lt;', '<').replace('&gt;', '>').replace('&quot;', '"').replace('&nbsp;', ' ')
retVal = re.sub('&#(\d+);', lambda x: unichr(int(x.group(1))), retVal)
return retVal