Skip to content

Commit

Permalink
- Added a try/except around "import markupsafe".
Browse files Browse the repository at this point in the history
  This to support GAE which can't run markupsafe.
  [ticket:151] No idea whatsoever if the
  install_requires in setup.py also breaks GAE,
  couldn't get an answer on this.
  • Loading branch information
zzzeek committed Oct 20, 2010
1 parent 8bb8f0b commit 2f40aa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
inside of a tag element that doesn't allow
them raises a CompileException instead of
silently failing.

- Added a try/except around "import markupsafe".
This to support GAE which can't run markupsafe.
[ticket:151] No idea whatsoever if the
install_requires in setup.py also breaks GAE,
couldn't get an answer on this.

0.3.4
- Now using MarkupSafe for HTML escaping,
Expand Down
12 changes: 8 additions & 4 deletions mako/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re, urllib, htmlentitydefs, codecs
from StringIO import StringIO
from mako import util
import markupsafe

xml_escapes = {
'&' : '&',
Expand All @@ -21,13 +20,18 @@
# XXX: " is valid in HTML and XML
# ' is not valid HTML, but is valid XML

def html_escape(string):
return markupsafe.escape(string)

def legacy_html_escape(string):
"""legacy HTML escape for non-unicode mode."""

return re.sub(r'([&<"\'>])', lambda m: xml_escapes[m.group()], string)

try:
import markupsafe
def html_escape(string):
return markupsafe.escape(string)
except ImportError:
html_escape = legacy_html_escape


def xml_escape(string):
return re.sub(r'([&<"\'>])', lambda m: xml_escapes[m.group()], string)
Expand Down

0 comments on commit 2f40aa9

Please sign in to comment.