mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ensure that the Python template returns a string
This commit is contained in:
parent
8d42c86479
commit
28db54436b
@ -1602,11 +1602,16 @@ class TemplateFormatter(string.Formatter):
|
||||
db=get_database(self.book, get_database(self.book, None)),
|
||||
globals=self.global_vars,
|
||||
arguments=arguments)
|
||||
return compiled_template(self.book, self.python_context_object)
|
||||
rslt = compiled_template(self.book, self.python_context_object)
|
||||
except Exception as e:
|
||||
ss = traceback.extract_tb(exc_info()[2])[-1]
|
||||
raise ValueError(_('Error in function {0} on line {1} : {2} - {3}').format(
|
||||
ss.name, ss.lineno, type(e).__name__, str(e)))
|
||||
|
||||
if not isinstance(rslt, str):
|
||||
raise ValueError(_('The Python template does not return a string'))
|
||||
|
||||
return rslt
|
||||
|
||||
def compile_python_template(self, template):
|
||||
def replace_func(mo):
|
||||
|
Loading…
x
Reference in New Issue
Block a user