pypy / pypy / config /

def parse_info(text):
    text = text.lstrip()
    result = {}
    if (text+':').index(':') > (text+'=').index('='):
        # found a '=' before a ':' means that we have the new format
        current = {0: ''}
        indentation_prefix = None
        for line in text.splitlines():
            line = line.rstrip()
            if not line:
            realline = line.lstrip()
            indent = len(line) - len(realline)
            # 'indentation_prefix' is set when the previous line was a [group]
            if indentation_prefix is not None:
                assert indent > max(current)     # missing indent?
                current[indent] = indentation_prefix
                indentation_prefix = None
                # in case of dedent, must kill the extra items from 'current'
                for n in current.keys():
                    if n > indent:
                        del current[n]
            prefix = current[indent]      # KeyError if bad dedent
            if realline.startswith('[') and realline.endswith(']'):
                indentation_prefix = prefix + realline[1:-1] + '.'
                # build the whole dotted key and evaluate the value
                i = realline.index(' = ')
                key = prefix + realline[:i]
                value = realline[i+3:]
                value = eval(value, {})
                result[key] = value
        # old format
        for line in text.splitlines():
            i = line.index(':')
            key = line[:i].strip()
            value = line[i+1:].strip()
                value = int(value)
            except ValueError:
                if value in ('True', 'False', 'None'):
                    value = eval(value, {})
            result[key] = value
    return result
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.