]> mj.ucw.cz Git - moe.git/blobdiff - t/moe/config_parser.py
Merge branch 'python-newpipe' into python
[moe.git] / t / moe / config_parser.py
index b3131cccf78e7e8ed616b0d03ae2faa4aa0dbe4f..ad10b02ed365d2d2cc47b2ca842039d169b3aa45 100644 (file)
@@ -37,16 +37,26 @@ 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
 """
 
-import re, types, itertools, logging as log
+import re, types, itertools
 import traceback
-
+from logs import log
 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='<unknown>', line=None, column=None):