From 2ad45afdb2e255f1d00e326a3abf1f9971234508 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 26 Jun 2011 14:51:58 +0100 Subject: [PATCH] Remove references to eval_formatter. Note that the tag browser uses it, but has not been changed because it is in the middle of re-architecture. --- src/calibre/devices/usbms/books.py | 4 ++-- src/calibre/utils/formatter.py | 1 + src/calibre/utils/formatter_functions.py | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/calibre/devices/usbms/books.py b/src/calibre/devices/usbms/books.py index 731d3e2b49..4d726e5bde 100644 --- a/src/calibre/devices/usbms/books.py +++ b/src/calibre/devices/usbms/books.py @@ -14,7 +14,7 @@ from calibre.constants import preferred_encoding from calibre import isbytestring, force_unicode from calibre.utils.config import prefs, tweaks from calibre.utils.icu import strcmp -from calibre.utils.formatter import eval_formatter +from calibre.utils.formatter import EvalFormatter class Book(Metadata): def __init__(self, prefix, lpath, size=None, other=None): @@ -116,7 +116,7 @@ class CollectionsBookList(BookList): field_name = field_meta['name'] else: field_name = '' - cat_name = eval_formatter.safe_format( + cat_name = EvalFormatter().safe_format( fmt=tweaks['sony_collection_name_template'], kwargs={'category':field_name, 'value':field_value}, error_value='GET_CATEGORY', book=None) diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index ebf47db854..3a93c2b650 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -347,5 +347,6 @@ class EvalFormatter(TemplateFormatter): key = key.lower() return kwargs.get(key, _('No such variable ') + key) +# DEPRECATED. This is not thread safe. Do not use. eval_formatter = EvalFormatter() diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 55bad6c7e8..c6f4bd1b0e 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -202,9 +202,9 @@ class BuiltinEval(BuiltinFormatterFunction): 'results from local variables.') def evaluate(self, formatter, kwargs, mi, locals, template): - from formatter import eval_formatter + from formatter import EvalFormatter template = template.replace('[[', '{').replace(']]', '}') - return eval_formatter.safe_format(template, locals, 'EVAL', None) + return EvalFormatter().safe_format(template, locals, 'EVAL', None) class BuiltinAssign(BuiltinFormatterFunction): name = 'assign'