1 # vim: set expandtab tabstop=4 shiftwidth=4:
3 from xml.sax import saxutils, make_parser
6 class Parser(xml.sax.saxutils.DefaultHandler):
9 def __init__(self, fallback = None, cache = os.sep + 'tmp'):
11 self.fallback = fallback
13 self.parser = xml.sax.make_parser()
14 self.parser.setFeature(xml.sax.handler.feature_namespaces, 0)
15 self.parser.setContentHandler(self)
17 def startElement(self, name, attrs): # FIXME - arreglar a partir de aca.
18 """Start element handler."""
19 mods = name.lower().split('.')
20 classname = path.pop()
21 modulename = 'bife.' + mods.join('.')
23 module = __import__(modulename, None, None, True)
24 classobj = getattr(module, classname)
28 obj = self.fallback(name, attrs)
30 # raise "Class not found '$class'."
33 def endElement(self, name):
34 """End element handler."""
36 current = self.stack[key(self.stack)]
39 parent = self.stack[key(self.stack)]
41 parent.addContents(current)
45 def characters(self, data):
46 """Caracter data handler."""
48 current = self.stack[key(self.stack)]
49 current.addContents(data)
51 def parse(self, file):
53 if !self.parser.parse(self.parser, file)
55 def parseString(self, string):
56 if !self.parser.parseString(self.parser, string, self)