Exemplo n.º 1
0
class JsonRenderer:
    def __init__(self, info):
        pkg, path = info.name.split(':', 1)
        if not pkg_resources.resource_exists(pkg, path):
            raise ValueError('Missing template resource: %s' % spec)
        abspath = pkg_resources.resource_filename(pkg, path)
        self.path = abspath

    def __call__(self, value, system):
        file = open(self.path, 'r')
        # TODO: Assumes templates UTF-8
        template = file.read().decode('utf-8')
        self.template = FromString(template, more_formatters=MoreFormatters)
        return self.template.expand(value)
Exemplo n.º 2
0
 def __call__(self, value, system):
     file = open(self.path, 'r')
     # TODO: Assumes templates UTF-8
     template = file.read().decode('utf-8')
     self.template = FromString(template, more_formatters=MoreFormatters)
     return self.template.expand(value)