blob: 64d736199260251653605050edcc8102a6c4e30c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# -*- coding: utf-8 -*-
import wlp_parser
__current_file = None
def setfilebyname(name):
global __current_file
__current_file = open(name, 'r')
def setfilebyfd(fd):
global __current_file
__current_file = fd
def mkdict():
dict = {}
if __current_file is None:
raise ValueError('current file has not been set.')
tree = wlp_parser.parser.parse(
wlp_parser.lexer.lex(__current_file.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
|