def replaceFunctionWithSourceString(namespace, functionName, allowEmpty=False):
func = namespace.get(functionName)
if not func:
if allowEmpty:
namespace[functionName] = ''
return
else:
raise Exception('Function %s not found in input source code.' % functionName)
if not inspect.isfunction(func):
raise Exception('Object %s is not a function object.' % functionName)
lines = inspect.getsourcelines(func)[0]
if len(lines) <= 1:
raise Exception('Function %s must not be a single line of code.' % functionName)
# skip first line (the declaration) and then dedent the source code
sourceCode = textwrap.dedent(''.join(lines[1:]))
namespace[functionName] = sourceCode
python_filter_generator.py 文件源码
python
阅读 30
收藏 0
点赞 0
评论 0
评论列表
文章目录