incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r614322 - in /incubator/public/trunk: diff.py tests.py
Date Tue, 22 Jan 2008 21:03:44 GMT
Author: rdonkin
Date: Tue Jan 22 13:03:42 2008
New Revision: 614322

URL: http://svn.apache.org/viewvc?rev=614322&view=rev
Log:
Load audit document

Modified:
    incubator/public/trunk/diff.py
    incubator/public/trunk/tests.py

Modified: incubator/public/trunk/diff.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/diff.py?rev=614322&r1=614321&r2=614322&view=diff
==============================================================================
--- incubator/public/trunk/diff.py (original)
+++ incubator/public/trunk/diff.py Tue Jan 22 13:03:42 2008
@@ -12,6 +12,7 @@
 # limitations under the License.
 #########################################################################################
 
+import xml.parsers.expat
 
 class Document:
     def __init__(self):
@@ -62,4 +63,36 @@
     
     def char_data(self, data):
         if not self.next == None:
-            self.next(data.strip())
\ No newline at end of file
+            self.next(data.strip())
+            
+class Documents:
+    def __init__(self):
+        self.documents = []
+        self.__current = None
+        
+    def load(self, document):
+        self.documents = []
+        self.__current = None
+        parser = xml.parsers.expat.ParserCreate()
+        parser.StartElementHandler = self.start_element
+        parser.EndElementHandler = self.end_element
+        parser.CharacterDataHandler = self.char_data
+        parser.Parse(document)
+    
+    def start_element(self, name, attrs):
+        if name == 'document':
+            self.__current = Document()
+            self.documents.append(self.__current)
+            self.__current.start_element(name, attrs)
+        elif not self.__current == None:
+            self.__current.start_element(name, attrs)
+            
+    def end_element(self, name):
+        if not self.__current == None:
+            self.__current.end_element(name)
+        if name == 'document':
+            self.__current = None
+        
+    def char_data(self, data):
+        if not self.__current == None:
+            self.__current.char_data(data)
\ No newline at end of file

Modified: incubator/public/trunk/tests.py
URL: http://svn.apache.org/viewvc/incubator/public/trunk/tests.py?rev=614322&r1=614321&r2=614322&view=diff
==============================================================================
--- incubator/public/trunk/tests.py (original)
+++ incubator/public/trunk/tests.py Tue Jan 22 13:03:42 2008
@@ -38,4 +38,33 @@
         self.assertEqual('SHA SUM', document.sha)
         self.assertEqual('RIPEMD', document.ripemd)
         
-    
\ No newline at end of file
+    def testLoad(self):
+        documents = diff.Documents()
+        documents.load("""<?xml version="1.0"?><audit><documents>
+ <document dir='a directory' name='a name' >
+  <md5>MD5 SUM</md5>
+  <sha512>SHA SUM</sha512>
+  <ripemd160>RIPEMD</ripemd160>
+ </document>
+  <document dir='another directory' name='another name' >
+  <md5>ANOTHER MD5 SUM</md5>
+  <sha512>ANOTHER SHA SUM</sha512>
+  <ripemd160>ANOTHER RIPEMD</ripemd160>
+ </document>
+ </documents></audit>
+ """)
+        
+        self.assert_(not documents.documents == None)
+        self.assertEqual(2, len(documents.documents))
+        document = documents.documents[0]
+        self.assertEqual('a directory', document.dir)
+        self.assertEqual('a name', document.name)
+        self.assertEqual('MD5 SUM', document.md5)
+        self.assertEqual('SHA SUM', document.sha)
+        self.assertEqual('RIPEMD', document.ripemd)
+        document = documents.documents[1]
+        self.assertEqual('another directory', document.dir)
+        self.assertEqual('another name', document.name)
+        self.assertEqual('ANOTHER MD5 SUM', document.md5)
+        self.assertEqual('ANOTHER SHA SUM', document.sha)
+        self.assertEqual('ANOTHER RIPEMD', document.ripemd)
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message