[Zope-CVS] CVS: Packages/TestScripts - xml2dict.py:1.4
Fred L. Drake, Jr.
fred@zope.com
Wed, 26 Feb 2003 15:07:24 -0500
Update of /cvs-repository/Packages/TestScripts
In directory cvs.zope.org:/tmp/cvs-serv13937
Modified Files:
xml2dict.py
Log Message:
normalize whitespace
=== Packages/TestScripts/xml2dict.py 1.3 => 1.4 ===
--- Packages/TestScripts/xml2dict.py:1.3 Fri Mar 8 02:50:13 2002
+++ Packages/TestScripts/xml2dict.py Wed Feb 26 15:07:21 2003
@@ -51,7 +51,7 @@
return "Node<%s,%s,%s>" % (self.name,repr(self.data),self.children)
__repr__=__str__
-
+
def __ne__(self,other):
"""for tests only..."""
try:
@@ -77,8 +77,8 @@
return 1
def __eq__(self,other):
- return not self.__ne__(other)
-
+ return not self.__ne__(other)
+
# SAX Handler Class
class XML2DictHandler(ContentHandler):
@@ -86,11 +86,11 @@
# Manage the data structures we build up as we process the file
# --------------------------------------------------------------------------
def __init__(self):
- self.openElements=[]
+ self.openElements=[]
# --------------------------------------------------------------------------
# sax processing routines
# --------------------------------------------------------------------------
-
+
def startElement(self, name, attrs):
node = Node(name)
elements = self.openElements
@@ -106,21 +106,21 @@
element.data = element.data.encode('iso-8859-1')
if not elements:
self.dict = element
-
+
def characters(self, someText):
- self.openElements[-1].addText(someText)
+ self.openElements[-1].addText(someText)
def xml2dict(xml):
# parse a lump of XML into a dictonary
file=StringIO(xml)
# Create a parser
- theParser = make_parser()
+ theParser = make_parser()
# Tell the parser we are not interested in XML namespaces
- theParser.setFeature(feature_namespaces, 0)
+ theParser.setFeature(feature_namespaces, 0)
# Create the handler
- csh = XML2DictHandler()
+ csh = XML2DictHandler()
# Tell the parser to use our handler
- theParser.setContentHandler(csh)
+ theParser.setContentHandler(csh)
theParser.parse(file)
return csh.dict
@@ -164,7 +164,7 @@
node.addText('fish')
self.assertEqual(node(),'fish')
node.addText(' finger')
- self.assertEqual(node(),'fish finger')
+ self.assertEqual(node(),'fish finger')
node['child1']='child1'
self.assertEqual(node.items(),[('child1',('child1',))])
self.assertEqual(node['child1'],('child1',))
@@ -216,7 +216,7 @@
"""
result = Node('tag1')
result.data='\n \n \n'
-
+
tag2=Node('tag2')
tag2.data='\n \n \n '
tag3=Node('tag3')
@@ -226,7 +226,7 @@
tag3.data='tag3-value2'
tag2['tag3']=tag3
result['tag2']=tag2
-
+
tag2=Node('tag2')
tag2.data='\n \n \n \n '
tag3=Node('tag3')
@@ -239,7 +239,7 @@
tag5.data='value5'
tag2['tag5']=tag5
result['tag2']=tag2
-
+
self.assertEqual(xml2dict(complex),result)
def test_suite():
@@ -247,8 +247,3 @@
if __name__=='__main__':
main()
-
-
-
-
-