Debian Codegraph @

rpython/config/parse.py

raw symbols SCIP
1
2
3 def parse_info(text):
4 """See test_parse.py."""
5 text = text.lstrip()
6 result = {}
7 if (text+':').index(':') > (text+'=').index('='):
8 # found a '=' before a ':' means that we have the new format
9 current = {0: ''}
10 indentation_prefix = None
11 for line in text.splitlines():
12 line = line.rstrip()
13 if not line:
14 continue
15 realline = line.lstrip()
16 indent = len(line) - len(realline)
17 #
18 # 'indentation_prefix' is set when the previous line was a [group]
19 if indentation_prefix is not None:
20 assert indent > max(current) # missing indent?
21 current[indent] = indentation_prefix
22 indentation_prefix = None
23 #
24 else:
25 # in case of dedent, must kill the extra items from 'current'
26 for n in current.keys():
27 if n > indent:
28 del current[n]
29 #
30 prefix = current[indent] # KeyError if bad dedent
31 #
32 if realline.startswith('[') and realline.endswith(']'):
33 indentation_prefix = prefix + realline[1:-1] + '.'
34 else:
35 # build the whole dotted key and evaluate the value
36 i = realline.index(' = ')
37 key = prefix + realline[:i]
38 value = realline[i+3:]
39 value = eval(value, {})
40 result[key] = value
41 #
42 else:
43 # old format
44 for line in text.splitlines():
45 i = line.index(':')
46 key = line[:i].strip()
47 value = line[i+1:].strip()
48 try:
49 value = int(value)
50 except ValueError:
51 if value in ('True', 'False', 'None'):
52 value = eval(value, {})
53 result[key] = value
54 #
55 return result