Error messages and explicit test for None

Error messages for validate() are more specific.

Return of standarddir.conf() is explicitly tested for None to avoid ambiguity
with other falsey values.
This commit is contained in:
Lamar Pavel 2015-06-06 14:04:45 +02:00
parent 402aa66756
commit de0686c50a

View File

@ -805,7 +805,7 @@ class File(BaseType):
value = os.path.expanduser(value)
value = os.path.expandvars(value)
if not os.path.isabs(value):
if standarddir.config():
if standarddir.config() is not None:
abspath = os.path.join(standarddir.config(), value)
if os.path.isfile(abspath):
return abspath
@ -821,12 +821,16 @@ class File(BaseType):
try:
if not os.path.isabs(value):
cfgdir = standarddir.config()
if cfgdir and os.path.isfile(os.path.join(cfgdir, value)):
if cfgdir is not None and os.path.isfile(
os.path.join(cfgdir, value)):
return
raise configexc.ValidationError(value,
"must be an absolute path!")
if not os.path.isfile(value):
raise configexc.ValidationError(value, "must be a valid file!")
raise configexc.ValidationError(
value, "must be an absolute path when not using a config "
"directory!")
elif not os.path.isfile(value):
raise configexc.ValidationError(
value, "must be a valid path relative to the config "
"directory!")
except UnicodeEncodeError as e:
raise configexc.ValidationError(value, e)
@ -1195,7 +1199,7 @@ class UserStyleSheet(File):
raise configexc.ValidationError(value, str(e))
return
except UnicodeEncodeError as e:
raise configexc.ValidationError(value, e)
raise configexc.ValidationError(value, str(e))
class AutoSearch(BaseType):