X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=t%2Fmoe%2Fconfig_parser.py;h=2da6facfa2daa9062c78b2cfc9d9fe52cdddaf16;hb=3b2c0c783bf7284037f4c5c5ffd6582ee7b1f89c;hp=b3131cccf78e7e8ed616b0d03ae2faa4aa0dbe4f;hpb=f1197017785dc3b28835cad97de45db673304eb3;p=moe.git diff --git a/t/moe/config_parser.py b/t/moe/config_parser.py index b3131cc..2da6fac 100644 --- a/t/moe/config_parser.py +++ b/t/moe/config_parser.py @@ -37,7 +37,7 @@ The configuration syntax is the following:: .. todo:: should whitespace (incl. '\n') be allowed (almost) everywhere? can comment be anywhere whitespace can? -.. note:: ';' or '\n' is currently required even after CONDITION and SUBTREE block +.. note:: ';' or '\\n' is currently required even after CONDITION and SUBTREE block .. note:: Formula can contain additional/unnecessary parentheses """ @@ -47,6 +47,16 @@ import traceback import moe.config as cf +def config_escape(s): + """ + Escape any ``{``, ``}``, ``"`` and ``\\`` in the given string, making it safe for parsing. + """ + s = s.replace('\\', '\\\\') + s = s.replace('{', '\\{') + s = s.replace('}', '\\}') + s = s.replace('"', '\\"') + return s + class ConfigSyntaxError(cf.ConfigError): def __init__(self, msg, source='', line=None, column=None):