From fe66042bc63c6e8b81e5ab8532ad32af0d3ca375 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 20 Nov 2014 15:20:09 +0530 Subject: [PATCH] Make the functions namespace a little easier to use --- src/calibre/gui2/tweak_book/function_replace.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tweak_book/function_replace.py b/src/calibre/gui2/tweak_book/function_replace.py index 503312540e..84f4614f9d 100644 --- a/src/calibre/gui2/tweak_book/function_replace.py +++ b/src/calibre/gui2/tweak_book/function_replace.py @@ -64,6 +64,7 @@ class Function(object): self.boss = get_boss() self.data = {} self.debug_buf = StringIO() + self.functions = {name:func.mod for name, func in functions().iteritems() if func.mod is not None} def __hash__(self): return hash(self.name) @@ -78,7 +79,7 @@ class Function(object): self.match_index += 1 oo, oe, sys.stdout, sys.stderr = sys.stdout, sys.stderr, self.debug_buf, self.debug_buf try: - return self.func(match, self.match_index, self.context_name, self.boss.current_metadata, dictionaries, self.data, functions()) + return self.func(match, self.match_index, self.context_name, self.boss.current_metadata, dictionaries, self.data, self.functions) finally: sys.stdout, sys.stderr = oo, oe @@ -93,10 +94,10 @@ class Function(object): if getattr(self.func, 'call_after_last_match', False): oo, oe, sys.stdout, sys.stderr = sys.stdout, sys.stderr, self.debug_buf, self.debug_buf try: - return self.func(None, self.match_index, self.context_name, self.boss.current_metadata, dictionaries, self.data, functions()) + return self.func(None, self.match_index, self.context_name, self.boss.current_metadata, dictionaries, self.data, self.functions) finally: sys.stdout, sys.stderr = oo, oe - self.data, self.debug_buf, self.boss = {}, None, None + self.data, self.debug_buf, self.boss, self.functions = {}, None, None, {} class DebugOutput(Dialog):