def _instancecheck_impl(self, value, info: Info) -> InfoMsg:
if not isinstance(value, str) or value == "":
return info.errormsg(self)
value = os.path.expanduser(value)
if self.allow_std and value == "-" and (self.constraint is None or self.constraint(value)):
return info.wrap(True)
is_valid = True
if os.path.exists(value):
if os.path.isfile(value) and os.access(os.path.abspath(value), os.W_OK)\
and (self.constraint is None or self.constraint(value)):
return info.wrap(True)
return info.errormsg(self)
if not self.allow_non_existent:
return info.errormsg(self, "File doesn't exist")
abs_name = os.path.abspath(value)
dir_name = os.path.dirname(abs_name)
if os.path.exists(dir_name) and os.access(dir_name, os.EX_OK) and os.access(dir_name, os.W_OK) \
and (self.constraint is None or self.constraint(value)):
return info.wrap(True)
return info.errormsg(self)
评论列表
文章目录