Skip to content
Browse files

Merge branch 'development' of https://github.com/lambacck/pystache in…

…to development
  • Loading branch information...
2 parents c9dcb07 + a00b568 commit b9bd807ac0a89d2009421280e9590290f2fa8b69 Carl Whittaker committed May 31, 2011
Showing with 16 additions and 4 deletions.
  1. +12 −3 pystache/template.py
  2. +4 −1 setup.py
View
15 pystache/template.py
@@ -4,6 +4,15 @@
import os
import copy
+try:
+ import markupsafe
+ escape = markupsafe.escape
+ literal = markupsafe.Markup
+
+except ImportError:
+ escape = lambda x: cgi.escape(unicode(x))
+ literal = unicode
+
class Modifiers(dict):
"""Dictionary with a decorator for assigning functions to keys."""
@@ -89,7 +98,7 @@ def _render_sections(self, template, view):
elif (not it and section[2] == '^') or (it and section[2] != '^'):
replacer = self._render_dictionary(inner, it)
- template = template.replace(section, replacer)
+ template = literal(template.replace(section, replacer))
return template
@@ -132,7 +141,7 @@ def _render_tag(self, tag_name):
else:
return ''
- return cgi.escape(unicode(raw))
+ return escape(raw)
@modifiers.set('!')
def _render_comment(self, tag_name):
@@ -156,7 +165,7 @@ def _change_delimiter(self, tag_name):
@modifiers.set('&')
def render_unescaped(self, tag_name):
"""Render a tag without escaping it."""
- return unicode(self.view.get(tag_name, ''))
+ return literal(self.view.get(tag_name, ''))
def render(self, encoding=None):
template = self._render_sections(self.template, self.view)
View
5 setup.py
@@ -3,7 +3,10 @@
import os
import sys
-from distutils.core import setup
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
def publish():
"""Publish to Pypi"""

0 comments on commit b9bd807

Please sign in to comment.
Something went wrong with that request. Please try again.