and is what is returned if we do not find anything. So you
can use that to set a default.
-get_quoted_value(lines, token, start[, end[, default]):
+get_quoted_value(lines, token, start[, end[, default]]):
Similar to get_value, but it will strip quotes off the
value, if they are present. So use this one for cases
where the value is normally quoted.
option="value"
and returns value. Returns "" if not found.
+get_bool_value(lines, token, start[, end[, default]]):
+ Like get_value, but returns a boolean.
+
del_token(lines, token, start[, end]):
Like find_token, but deletes the line if it finds one.
Returns True if a line got deleted, otherwise False.
return val.strip('"')
+def get_bool_value(lines, token, start, end = 0, default = None):
+ """ get_value(lines, token, start[[, end], default]) -> string
+
+ Find the next line that looks like:
+ token bool_value
+
+ Returns True if bool_value is 1 or true and
+ False if bool_value is 0 or false
+ """
+
+ val = get_quoted_value(lines, token, start, end, "")
+
+ if val == "1" or val == "true":
+ return True
+ if val == "0" or val == "false":
+ return False
+ return default
+
+
def get_option_value(line, option):
rx = option + '\s*=\s*"([^"]+)"'
rx = re.compile(rx)