From 4a370b521b5b20decf8aac1116260347fb62f5a0 Mon Sep 17 00:00:00 2001 From: Scott Ferguson Date: Tue, 26 May 2009 10:17:49 -0500 Subject: [PATCH] XML parser merge conflicts wtf did I do --- src/XMLParser.py | 49 ++++++++++++++++++++++++++++++++++++++ src/plugins/GmailCheck.xml | 9 +++++++ 2 files changed, 58 insertions(+) create mode 100644 src/XMLParser.py create mode 100644 src/plugins/GmailCheck.xml diff --git a/src/XMLParser.py b/src/XMLParser.py new file mode 100644 index 0000000..511250f --- /dev/null +++ b/src/XMLParser.py @@ -0,0 +1,49 @@ +'''Created on Apr 19, 2009 + +@author: scott +''' +from xml.parsers import expat + +class Parser( ): + + def startElement( self, name, attrs ): + if name == 'plugin': + self.name = attrs['name'] + elif name == 'description': + self.inDescription = True + self.description = "" + elif name == 'main_module': + self.inMainModule = True + self.main_module = "" + + def endElement( self, name ): + if name == 'description': + self.inDescription = False + self.description = self.normalizeWhitespace( self.description ) + elif name == 'main': + self.inMainModule = False + self.main_module = self.normalizeWhitespace( self.main_module ) + + def characters( self, data ): + if self.inDescription: + self.description = self.description + data + elif self.inMainModule: + self.main_module = self.main_module + self.normalizeWhitespace( data ) + + def normalizeWhitespace( self, text ): + """Remove redundant whitespace from a string""" + return " ".join( text.split( ) ) + + def fetchSet( self ): + return { 'name' : self.name, 'description' : self.description, 'main_module' : self.main_module } + + def __init__( self, file ): + self.inDescription = False + self.inMainModule = False + + parser = expat.ParserCreate( ) + parser.StartElementHandler = self.startElement + parser.EndElementHandler = self.endElement + parser.CharacterDataHandler = self.characters + parser.ParseFile( open( file, "r" ) ) + diff --git a/src/plugins/GmailCheck.xml b/src/plugins/GmailCheck.xml new file mode 100644 index 0000000..4de6104 --- /dev/null +++ b/src/plugins/GmailCheck.xml @@ -0,0 +1,9 @@ + + + + Periodically checks your Gmail account for new messages + + + GmailCheck + +