def _trace_cmdline(self, *args, **kwargs):
''' Internal function used to trace the values set to the special variable
cmd_line in the function body.
'''
def tracer(frame, event, arg):
if event=='return':
self._locals = frame.f_locals.copy()
# Activate tracer
sys.setprofile(tracer)
try:
# trace the function call
res = self.func(*args, **kwargs)
finally:
# disable tracer and replace with old one
sys.setprofile(None)
return self._locals['cmd_line']
评论列表
文章目录