From 442c820f877c1ff121f363e12cf838e444228cdc Mon Sep 17 00:00:00 2001 From: jgoerzen Date: Fri, 9 Aug 2002 22:11:12 +0100 Subject: [PATCH] /offlineimap/head: changeset 230 More of part 1 of the patch --- offlineimap/head/offlineimap/localeval.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 offlineimap/head/offlineimap/localeval.py diff --git a/offlineimap/head/offlineimap/localeval.py b/offlineimap/head/offlineimap/localeval.py new file mode 100644 index 0000000..6556073 --- /dev/null +++ b/offlineimap/head/offlineimap/localeval.py @@ -0,0 +1,23 @@ +"""Eval python code with global namespace of a python source file.""" +import imp, errno + +class LocalEval: + def __init__(self, path=None): + self.namespace={} + + if path is not None: + file=open(path, 'r') + module=imp.load_module( + '', + file, + path, + ('', 'r', imp.PY_SOURCE)) + for attr in dir(module): + self.namespace[attr]=getattr(module, attr) + + def eval(self, text, namespace=None): + names = {} + names.update(self.namespace) + if namespace is not None: + names.update(namespace) + return eval(text, names)