def validate_outpath(path):
try:
with tempfile.NamedTemporaryFile(mode='w', dir=path) as tfile:
tfile.write('0')
tfile.close()
except Exception as e:
if isinstance(e, OSError):
if e.errno == errno.ENOENT:
raise mm.ValidationError(
"%s is not in a directory that exists" % path)
elif e.errno == errno.EACCES:
raise mm.ValidationError(
"%s does not appear you can write to path" % path)
else:
raise mm.ValidationError(
"Unknown OSError: {}".format(e.message))
else:
raise mm.ValidationError(
"Unknown Exception: {}".format(e.message))
评论列表
文章目录