+ for i in xrange(start, -1, -1):
+ line = lines[i]
+ if line[:m] == token:
+ return i
+ return -1
+
+
+def find_tokens_backwards(lines, tokens, start):
+ """ find_tokens_backwards(lines, token, start) -> int
+
+ Return the highest line where token is found, and is the first
+ element, in lines[end, start].
+
+ Return -1 on failure."""
+ for i in xrange(start, -1, -1):
+ line = lines[i]
+ for token in tokens:
+ if line[:len(token)] == token:
+ return i
+ return -1
+
+
+def get_value(lines, token, start, end = 0, default = ""):
+ """ get_value(lines, token, start[[, end], default]) -> list of strings
+
+ Return tokens after token for the first line, in lines, where
+ token is the first element."""
+
+ i = find_token_exact(lines, token, start, end)
+ if i == -1:
+ return ""
+ if len(lines[i].split()) > 1:
+ return lines[i].split()[1]
+ else:
+ return default
+
+
+def del_token(lines, token, start, end):
+ """ del_token(lines, token, start, end) -> int
+
+ Find the lower line in lines where token is the first element and
+ delete that line.
+
+ Returns the number of lines remaining."""
+
+ k = find_token_exact(lines, token, start, end)
+ if k == -1:
+ return end
+ else:
+ del lines[k]
+ return end - 1
+
+
+def find_beginning_of(lines, i, start_token, end_token):
+ count = 1
+ while i > 0:
+ i = find_tokens_backwards(lines, [start_token, end_token], i-1)
+ if i == -1:
+ return -1
+ if check_token(lines[i], end_token):
+ count = count+1
+ else:
+ count = count-1
+ if count == 0:
+ return i