0

settingsValidators: clean up checkBadEscapes

A side-effect of these changes is that \a no longer gets shown as
'\a', but '\0x07'. Some characters, i.e. \n and \t, are still shown
as '\n' and '\t' respectively, so this comes simply down to repr()
behaviour.

However, I do believe it's worth it to get rid of that ugly code
duplication.
This commit is contained in:
Nicolas F
2017-03-24 18:29:15 +01:00
parent 8cf47935e4
commit dd96d95b66

View File

@@ -25,22 +25,14 @@ def expand_path(p):
return p return p
def checkBadEscape(s): def checkBadEscape(s):
#If any of these weird characters are in the path, raise an exception instead of fixing # If any of these weird characters are in the path, raise an exception
#this should help us educate our users about pathslashes # instead of fixing this should help us educate our users about pathslashes
if "\a" in s: bad_escapes = ['\a', '\b', '\t', '\n', '\v', '\f', '\r']
raise ValueError("Invalid character '\\a' in path. Please use forward slashes ('/'). Please see our docs for more info.") for b in bad_escapes:
if "\b" in s: if b in s:
raise ValueError("Invalid character '\\b' in path. Please use forward slashes ('/'). Please see our docs for more info.") raise ValueError("Invalid character %s in path. Please use "
if "\t" in s: "forward slashes ('/'). Please see our docs for "
raise ValueError("Invalid character '\\t' in path. Please use forward slashes ('/'). Please see our docs for more info.") "more info." % repr(b))
if "\n" in s:
raise ValueError("Invalid character '\\n' in path. Please use forward slashes ('/'). Please see our docs for more info.")
if "\v" in s:
raise ValueError("Invalid character '\\v' in path. Please use forward slashes ('/'). Please see our docs for more info.")
if "\f" in s:
raise ValueError("Invalid character '\\f' in path. Please use forward slashes ('/'). Please see our docs for more info.")
if "\r" in s:
raise ValueError("Invalid character '\\r' in path. Please use forward slashes ('/'). Please see our docs for more info.")
for c in range(10): for c in range(10):
if chr(c) in s: if chr(c) in s:
raise ValueError("Invalid character '\\%s' in path. Please use forward slashes ('/'). Please see our docs for more info." % c) raise ValueError("Invalid character '\\%s' in path. Please use forward slashes ('/'). Please see our docs for more info." % c)