- 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.
diff --git a/CHANGES b/CHANGES
index a622408..65d54ce 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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,
diff --git a/mako/filters.py b/mako/filters.py
index ce11168..23b77e1 100644
--- a/mako/filters.py
+++ b/mako/filters.py
@@ -8,7 +8,6 @@
import re, urllib, htmlentitydefs, codecs
from StringIO import StringIO
from mako import util
-import markupsafe
xml_escapes = {
'&' : '&',
@@ -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)