Permalink
Browse files

XML parser merge conflicts wtf did I do

  • Loading branch information...
1 parent c729dd9 commit 4a370b521b5b20decf8aac1116260347fb62f5a0 Scott Ferguson committed May 26, 2009
Showing with 58 additions and 0 deletions.
  1. +49 −0 src/XMLParser.py
  2. +9 −0 src/plugins/GmailCheck.xml
View
@@ -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" ) )
+
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin name="Gmail Check 0.1">
+ <description>
+ Periodically checks your Gmail account for new messages
+ </description>
+ <main_module>
+ GmailCheck
+ </main_module>
+</plugin>

0 comments on commit 4a370b5

Please sign in to comment.