/offlineimap/head: changeset 230

More of part 1 of the patch
This commit is contained in:
jgoerzen 2002-08-09 22:11:12 +01:00
parent 9be2bec748
commit 442c820f87

View File

@ -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(
'<none>',
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)