def __init__(self, config, text = '', attr = None):
""" evaluate last possible expression part in text.
attr can be a string or a filter-function
which accepts/rejects (name,obj)-bindings.
"""
self.config = config
debug("got text %s, attr %s" % (repr(text),repr(attr)))
self.text = text
if attr and type(attr) is str:
self.attrname = attr
self.func = lambda x: x[0].startswith(attr)
else:
self.attrname = ''
self.func = attr or config.viewfilter
# try finding code and evaluting it...
self.code = TryParser.find_code(text)
if inspect.iscode(self.code):
try:
self.obj = eval(self.code, vars(config.mainmodule))
except:
raise Error(sys.exc_info()[1])
else:
self.text = ''
评论列表
文章目录