Example #1
0
    def _load_template_file(self, file_path):
        """Loads and returns the template file from disk"""
        f = open(file_path, "r")

        try:
            template = f.read()
            if self.template_encoding:
                template = pystache.unistr(template, self.template_encoding)
        finally:
            f.close()

        return template
Example #2
0
import re
import cgi
import collections
import os
import copy
import pystache

try:
    import markupsafe
    escape = markupsafe.escape
    literal = markupsafe.Markup

except ImportError:
    escape = lambda x: cgi.escape(pystache.unistr(x))
    literal = pystache.unistr


class Modifiers(dict):
    """Dictionary with a decorator for assigning functions to keys."""

    def set(self, key):
        """
        Decorator function to set the given key to the decorated function.

            >>> modifiers = {}
            >>> @modifiers.set('P')
            ... def render_tongue(self, tag_name=None, context=None):
            ...     return ":P %s" % tag_name
            >>> modifiers
            {'P': <function render_tongue at 0x...>}
        """