Commit b9bd807a by Carl Whittaker

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

parents c9dcb076 a00b5688
...@@ -4,6 +4,15 @@ import collections ...@@ -4,6 +4,15 @@ import collections
import os import os
import copy 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): class Modifiers(dict):
"""Dictionary with a decorator for assigning functions to keys.""" """Dictionary with a decorator for assigning functions to keys."""
...@@ -89,7 +98,7 @@ class Template(object): ...@@ -89,7 +98,7 @@ class Template(object):
elif (not it and section[2] == '^') or (it and section[2] != '^'): elif (not it and section[2] == '^') or (it and section[2] != '^'):
replacer = self._render_dictionary(inner, it) replacer = self._render_dictionary(inner, it)
template = template.replace(section, replacer) template = literal(template.replace(section, replacer))
return template return template
...@@ -132,7 +141,7 @@ class Template(object): ...@@ -132,7 +141,7 @@ class Template(object):
else: else:
return '' return ''
return cgi.escape(unicode(raw)) return escape(raw)
@modifiers.set('!') @modifiers.set('!')
def _render_comment(self, tag_name): def _render_comment(self, tag_name):
...@@ -156,7 +165,7 @@ class Template(object): ...@@ -156,7 +165,7 @@ class Template(object):
@modifiers.set('&') @modifiers.set('&')
def render_unescaped(self, tag_name): def render_unescaped(self, tag_name):
"""Render a tag without escaping it.""" """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): def render(self, encoding=None):
template = self._render_sections(self.template, self.view) template = self._render_sections(self.template, self.view)
......
...@@ -3,7 +3,10 @@ ...@@ -3,7 +3,10 @@
import os import os
import sys import sys
from distutils.core import setup try:
from setuptools import setup
except ImportError:
from distutils.core import setup
def publish(): def publish():
"""Publish to Pypi""" """Publish to Pypi"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment