def _inline_fetch(spec, **kwargs):
taskInput = kwargs.get('task_input', {})
target = taskInput.get('target', 'memory')
if target == 'filepath':
# Ensure we have a trailing slash
tmpDir = os.path.join(kwargs['_tempdir'], '')
if 'filename' in taskInput:
filename = taskInput['filename']
path = os.path.join(tmpDir, filename)
with open(path, 'wb') as out:
out.write(spec['data'])
else:
with tempfile.NamedTemporaryFile(
'wb', prefix=tmpDir, delete=False) as out:
out.write(spec['data'])
path = out.name
return path
elif target == 'memory':
return spec['data']
else:
raise Exception('Invalid fetch target: ' + target)
评论列表
文章目录