From 98bdc7c86a28eafbab15061e9a5d0fd4f5cdace1 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 28 Jun 2006 16:57:49 -0400 Subject: Make cobbler use the Howell-Evans YAML parser now, so RHEL4 support will be possible (Syck needs Python 2.4). --- cobbler/yaml/implicit.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 cobbler/yaml/implicit.py (limited to 'cobbler/yaml/implicit.py') diff --git a/cobbler/yaml/implicit.py b/cobbler/yaml/implicit.py new file mode 100644 index 0000000..6172564 --- /dev/null +++ b/cobbler/yaml/implicit.py @@ -0,0 +1,46 @@ +import re +import string +from timestamp import timestamp, matchTime + +DATETIME_REGEX = re.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}$") +FLOAT_REGEX = re.compile("^[-+]?[0-9][0-9,]*\.[0-9]*$") +SCIENTIFIC_REGEX = re.compile("^[-+]?[0-9]+(\.[0-9]*)?[eE][-+][0-9]+$") +OCTAL_REGEX = re.compile("^[-+]?([0][0-7,]*)$") +HEX_REGEX = re.compile("^[-+]?0x[0-9a-fA-F,]+$") +INT_REGEX = re.compile("^[-+]?(0|[1-9][0-9,]*)$") + +def convertImplicit(val): + if val == '~': + return None + if val == '+': + return 1 + if val == '-': + return 0 + if val[0] == "'" and val[-1] == "'": + val = val[1:-1] + return string.replace(val, "''", "\'") + if val[0] == '"' and val[-1] == '"': + if re.search(r"\u", val): + val = "u" + val + unescapedStr = eval (val) + return unescapedStr + if matchTime.match(val): + return timestamp(val) + if INT_REGEX.match(val): + return int(cleanseNumber(val)) + if OCTAL_REGEX.match(val): + return int(val, 8) + if HEX_REGEX.match(val): + return int(val, 16) + if FLOAT_REGEX.match(val): + return float(cleanseNumber(val)) + if SCIENTIFIC_REGEX.match(val): + return float(cleanseNumber(val)) + return val + +def cleanseNumber(str): + if str[0] == '+': + str = str[1:] + str = string.replace(str,',','') + return str + -- cgit