Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XML parser merge conflicts wtf did I do
- Loading branch information
Scott Ferguson
committed
May 26, 2009
1 parent
c729dd9
commit 4a370b5
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" ) ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |