From 27f11a66eac969833dd7873e353a1e322d75b9a2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 24 Dec 2020 16:49:45 +0530 Subject: [PATCH] Fix #1909217 [Error saving books on disk](https://bugs.launchpad.net/calibre/+bug/1909217) --- src/calibre/utils/formatter.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index a6d0486a00..7c90881ae7 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -851,22 +851,22 @@ class TemplateFormatter(string.Formatter): # ######### a formatter that throws exceptions ############ - def unsafe_format(self, fmt, kwargs, book, strip_results=True): + def unsafe_format(self, fmt, kwargs, book, strip_results=True, global_vars=None): self.strip_results = strip_results self.column_name = self.template_cache = None self.kwargs = kwargs self.book = book self.composite_values = {} self.locals = {} - self.global_vars = {} - return self.evaluate(fmt, [], kwargs) + self.global_vars = global_vars if isinstance(global_vars, dict) else {} + return self.evaluate(fmt, [], kwargs, self.global_vars) # ######### a formatter guaranteed not to throw an exception ############ def safe_format(self, fmt, kwargs, error_value, book, column_name=None, template_cache=None, strip_results=True, template_functions=None, - global_vars={}): + global_vars=None): self.strip_results = strip_results self.column_name = column_name self.template_cache = template_cache @@ -880,7 +880,7 @@ class TemplateFormatter(string.Formatter): self.composite_values = {} self.locals = {} try: - ans = self.evaluate(fmt, [], kwargs, global_vars) + ans = self.evaluate(fmt, [], kwargs, self.global_vars) except Exception as e: if DEBUG: # and getattr(e, 'is_locking_error', False): traceback.print_exc()