aboutsummaryrefslogtreecommitdiffstats
path: root/src/wlp.py
blob: e3bcddd8a2e5465454eb3676aa00beaec0d4f735 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import wlp_parser


def mkdict(infile):
    dict = {}

    tree = wlp_parser.parser.parse(
        wlp_parser.lexer.lex(infile.read()))

    for subtree in tree:
        current_key = subtree[0].getstr().strip('<>')
        if current_key not in dict:
            dict[current_key] = {}

        for key, value in subtree[1]:
            key = key.getstr()
            value = value.getstr().strip("'\"")
            dict[current_key][key] = value

    return dict