This commit is contained in:
Kovid Goyal 2020-12-24 16:49:45 +05:30
parent 2ccfa5140e
commit 27f11a66ea
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -851,22 +851,22 @@ class TemplateFormatter(string.Formatter):
# ######### a formatter that throws exceptions ############ # ######### 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.strip_results = strip_results
self.column_name = self.template_cache = None self.column_name = self.template_cache = None
self.kwargs = kwargs self.kwargs = kwargs
self.book = book self.book = book
self.composite_values = {} self.composite_values = {}
self.locals = {} self.locals = {}
self.global_vars = {} self.global_vars = global_vars if isinstance(global_vars, dict) else {}
return self.evaluate(fmt, [], kwargs) return self.evaluate(fmt, [], kwargs, self.global_vars)
# ######### a formatter guaranteed not to throw an exception ############ # ######### a formatter guaranteed not to throw an exception ############
def safe_format(self, fmt, kwargs, error_value, book, def safe_format(self, fmt, kwargs, error_value, book,
column_name=None, template_cache=None, column_name=None, template_cache=None,
strip_results=True, template_functions=None, strip_results=True, template_functions=None,
global_vars={}): global_vars=None):
self.strip_results = strip_results self.strip_results = strip_results
self.column_name = column_name self.column_name = column_name
self.template_cache = template_cache self.template_cache = template_cache
@ -880,7 +880,7 @@ class TemplateFormatter(string.Formatter):
self.composite_values = {} self.composite_values = {}
self.locals = {} self.locals = {}
try: try:
ans = self.evaluate(fmt, [], kwargs, global_vars) ans = self.evaluate(fmt, [], kwargs, self.global_vars)
except Exception as e: except Exception as e:
if DEBUG: # and getattr(e, 'is_locking_error', False): if DEBUG: # and getattr(e, 'is_locking_error', False):
traceback.print_exc() traceback.print_exc()