Author: dmeyer
Date: Mon Mar 19 10:16:58 2007
New Revision: 2574
Modified:
trunk/metadata/src/misc/xmlfile.py
Log:
use sax parser for xmlfile
Modified: trunk/metadata/src/misc/xmlfile.py
==============================================================================
--- trunk/metadata/src/misc/xmlfile.py (original)
+++ trunk/metadata/src/misc/xmlfile.py Mon Mar 19 10:16:58 2007
@@ -32,7 +32,7 @@
# python imports
import os
import logging
-import libxml2
+import xml.sax
# kaa.metadata imports
import kaa.metadata.core as core
@@ -43,9 +43,13 @@
XML_TAG_INFO = {
'image': 'Bins Image Description',
+ 'album': 'Bins Album Description',
'freevo': 'Freevo XML Definition'
}
+class Identified:
+ pass
+
class XML(core.Media):
def __init__(self,file):
@@ -64,25 +68,23 @@
self.type = 'HTML Document'
return
- ctxt = libxml2.createFileParserCtxt(file.name)
- # Silence parse errors
- ctxt.setErrorHandler(lambda *args: None, None)
- ctxt.parseDocument()
-
+ handler = xml.sax.ContentHandler()
+ handler.startElement = self.startElement
+ parser = xml.sax.make_parser()
+ parser.setContentHandler(handler)
try:
- doc = ctxt.doc()
- except libxml2.parserError:
- raise core.ParseError()
-
- if not doc or not doc.children or not doc.children.name:
- raise core.ParseError()
-
- tag = doc.children.name
- if tag in XML_TAG_INFO:
- self.type = XML_TAG_INFO[tag]
+ parser.parse(file)
+ except (KeyboardInterrupt, SystemExit):
+ sys.exit(0)
+ except Identified:
+ pass
+
+
+ def startElement(self, name, attr):
+ if name in XML_TAG_INFO:
+ self.type = XML_TAG_INFO[name]
else:
self.type = 'XML file'
- doc.freeDoc()
-
-
+ raise Identified
+
factory.register( 'text/xml', ('xml', 'fxd', 'html', 'htm'), XML )
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog