/offlineimap/head: changeset 230
More of part 1 of the patch
This commit is contained in:
parent
9be2bec748
commit
442c820f87
23
offlineimap/head/offlineimap/localeval.py
Normal file
23
offlineimap/head/offlineimap/localeval.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user