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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#! /usr/bin/python
#
# Copyright(c) 2006, 2008, James Le Cuirot <chewi@aura-online.co.uk>
#
# Licensed under the GNU General Public License, v2
#
# $Header: $
from tree import *
import parser
class ManifestParser(parser.Parser):
def parse(self, ins):
""" Parse an input stream containing a MANIFEST.MF file. Return a
structured document represented by tree.Node
@param ins - input stream
@return tree.Node containing the structured representation
"""
lineno = 0
attrib = ""
value = ""
root = Node()
for x in ins.readlines():
lineno += 1
if len(x.strip()) == 0:
continue
if x[:1] == " ":
if attrib == "":
raise ParseError("Malformed line " + str(lineno))
value += x.strip()
continue
xs = x.split(": ", 2)
if len(xs) > 1:
if attrib != "":
root.add_kid(Node(attrib,value))
attrib = xs[0]
value = xs[1].strip()
else:
raise ParseError("Malformed line " + str(lineno))
if attrib != "":
root.add_kid(Node(attrib,value))
return root
def output(self, ous, tree):
tree.output(ous, "", ": ", "", ",", " ")
def wrapped_value(self, node):
return node.output_value(",")
if __name__ == "__main__":
print "This is not an executable module"
|