From dd96d95b661b021e766df1f9d77c890021922f19 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Fri, 24 Mar 2017 18:29:15 +0100 Subject: [PATCH] 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. --- overviewer_core/settingsValidators.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/overviewer_core/settingsValidators.py b/overviewer_core/settingsValidators.py index 5f36468..bf5ad5e 100644 --- a/overviewer_core/settingsValidators.py +++ b/overviewer_core/settingsValidators.py @@ -25,22 +25,14 @@ def expand_path(p): return p def checkBadEscape(s): - #If any of these weird characters are in the path, raise an exception instead of fixing - #this should help us educate our users about pathslashes - if "\a" in s: - raise ValueError("Invalid character '\\a' in path. Please use forward slashes ('/'). Please see our docs for more info.") - if "\b" in s: - raise ValueError("Invalid character '\\b' in path. Please use forward slashes ('/'). Please see our docs for more info.") - if "\t" in s: - raise ValueError("Invalid character '\\t' in path. Please use forward slashes ('/'). Please see our docs for more info.") - 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.") + # If any of these weird characters are in the path, raise an exception + # instead of fixing this should help us educate our users about pathslashes + bad_escapes = ['\a', '\b', '\t', '\n', '\v', '\f', '\r'] + for b in bad_escapes: + if b in s: + raise ValueError("Invalid character %s in path. Please use " + "forward slashes ('/'). Please see our docs for " + "more info." % repr(b)) for c in range(10): if chr(c) in s: raise ValueError("Invalid character '\\%s' in path. Please use forward slashes ('/'). Please see our docs for more info." % c)