def get_content(self, context=None): """ Does all context binding and pathing to get content, templated out """ if self.is_file: path = self.content if self.is_template_path and context: path = string.Template(path).safe_substitute( context.get_values()) with open(path, 'r') as f: data = f.read() if self.is_template_content and context: return string.Template(data).safe_substitute(context.get_values()) else: return data else: if self.is_template_content and context: return Parser.safe_substitute_unicode_template(self.content, context.get_values()) else: return self.content
def test_safe_substitute_unicode_template(self): result = Parser.safe_substitute_unicode_template( "This is $x test", {'x': 'unit'}) self.assertEqual("This is unit test", result)