1 """This module reads and writes (actually, write not implemented yet)
2 files in the OBF stanza format.
3
4 """
10
12 """Contains information about one stanza in a file."""
13 - def __init__(self, name, tag_value_pairs):
14 self.name = name
15 self.tag_value_pairs = tag_value_pairs
16
17 dict = {}
18 for tag, value in tag_value_pairs:
19 dict[tag] = value
20 self.tag_value_dict = dict
21
23 """load(handle) -> StanzaFormat object"""
24 import ConfigParser
25 parser = ConfigParser.ConfigParser()
26
27
28 line = handle.readline()
29 while line and not line.startswith("VERSION"):
30 line = handle.readline()
31 assert line, "I could not find the VERSION line"
32 x, version = line.split("=")
33 version = version.strip()
34
35 try:
36 parser.readfp(handle)
37 except ConfigParser.Error, x:
38 raise ValueError, x
39 stanzas = []
40 for section in parser.sections():
41 pairs = []
42 for tag in parser.options(section):
43 value = parser.get(section, tag)
44 pairs.append((tag, value))
45 stanzas.append(Stanza(section, pairs))
46 return StanzaFormat(version, stanzas)
47