summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-10-20 12:00:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2010-10-20 12:00:11 -0400
commit2f40aa94bede1bcfa15140a30ed9211e48d4eedf (patch)
tree00d88e04564a5c52cce3a1f2d0c76e488092f045
parent8bb8f0b520937754a9e833e289149a4547b314dc (diff)
downloadmako-2f40aa94bede1bcfa15140a30ed9211e48d4eedf.tar.gz
- Added a try/except around "import markupsafe".rel_0_3_5
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.
-rw-r--r--CHANGES6
-rw-r--r--mako/filters.py12
2 files changed, 14 insertions, 4 deletions
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 = {
'&' : '&amp;',
@@ -21,13 +20,18 @@ xml_escapes = {
# XXX: &quot; is valid in HTML and XML
# &apos; 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)