[PATCH 06 of 54] Allow parsing of incomplete documents

Wald Commits scm-commit at wald.intevation.org
Wed Jan 7 10:56:23 CET 2015


# HG changeset patch
# User Benoît Allard <benoit.allard at greenbone.net>
# Date 1412588378 -7200
# Node ID d62264a643fbafed8fae3db68ace686e0502e3ed
# Parent  c5cf387b57857dc7fdc41cd94afd0ff83d0ba7dc
Allow parsing of incomplete documents

diff -r c5cf387b5785 -r d62264a643fb farolluz/parsers/cvrf.py
--- a/farolluz/parsers/cvrf.py	Mon Oct 06 11:24:29 2014 +0200
+++ b/farolluz/parsers/cvrf.py	Mon Oct 06 11:39:38 2014 +0200
@@ -247,47 +247,51 @@
         cvrfdoc.findtext(UN('cvrf', 'DocumentTitle')).strip(),
         cvrfdoc.findtext(UN('cvrf', 'DocumentType')).strip()
     )
+
     cvrfpub = cvrfdoc.find(UN('cvrf', 'DocumentPublisher'))
-    pub = CVRFPublisher(cvrfpub.attrib['Type'], cvrfpub.attrib.get('VendorID'))
-    doc.setPublisher(pub)
-    contact = cvrfpub.find(UN('cvrf', 'ContactDetails'))
-    if contact is not None:
-        pub.setContact(contact.text.strip())
-    authority = cvrfpub.find(UN('cvrf', 'IssuingAuthority'))
-    if authority is not None:
-        pub.setAuthority(authority.text.strip())
+    if cvrfpub is not None:
+        pub = CVRFPublisher(cvrfpub.attrib['Type'], cvrfpub.attrib.get('VendorID'))
+        doc.setPublisher(pub)
+        contact = cvrfpub.find(UN('cvrf', 'ContactDetails'))
+        if contact is not None:
+            pub.setContact(contact.text.strip())
+        authority = cvrfpub.find(UN('cvrf', 'IssuingAuthority'))
+        if authority is not None:
+            pub.setAuthority(authority.text.strip())
+
     cvrftracking = cvrfdoc.find(UN('cvrf', 'DocumentTracking'))
-    identification = CVRFTrackingID(
-        cvrftracking.findtext('/'.join([UN('cvrf', 'Identification'), UN('cvrf', 'ID')])).strip()
-    )
-    for cvrfalias in cvrftracking.findall('/'.join([UN('cvrf', 'Identification'), UN('cvrf', 'Alias')])):
-        identification.addAlias(cvrfalias.text.strip())
-    tracking = CVRFTracking(
-        identification,
-        cvrftracking.findtext(UN('cvrf', 'Status')).strip(),
-        parseVersion(cvrftracking.findtext(UN('cvrf', 'Version')).strip()),
-        parseDate(cvrftracking.findtext(UN('cvrf', 'InitialReleaseDate')).strip()),
-        parseDate(cvrftracking.findtext(UN('cvrf', 'CurrentReleaseDate')).strip())
-    )
-    doc.setTracking(tracking)
-    for cvrfrev in cvrftracking.findall('/'.join([UN('cvrf', 'RevisionHistory'), UN('cvrf', 'Revision')])):
-        rev = CVRFRevision(
-            parseVersion(cvrfrev.findtext(UN('cvrf', 'Number')).strip()),
-            parseDate(cvrfrev.findtext(UN('cvrf', 'Date')).strip()),
-            cvrfrev.findtext(UN('cvrf', 'Description')).strip(),
+    if cvrftracking is not None:
+        identification = CVRFTrackingID(
+            cvrftracking.findtext('/'.join([UN('cvrf', 'Identification'), UN('cvrf', 'ID')])).strip()
         )
-        tracking.addRevision(rev)
+        for cvrfalias in cvrftracking.findall('/'.join([UN('cvrf', 'Identification'), UN('cvrf', 'Alias')])):
+            identification.addAlias(cvrfalias.text.strip())
+        tracking = CVRFTracking(
+            identification,
+            cvrftracking.findtext(UN('cvrf', 'Status')).strip(),
+            parseVersion(cvrftracking.findtext(UN('cvrf', 'Version')).strip()),
+            parseDate(cvrftracking.findtext(UN('cvrf', 'InitialReleaseDate')).strip()),
+            parseDate(cvrftracking.findtext(UN('cvrf', 'CurrentReleaseDate')).strip())
+        )
+        doc.setTracking(tracking)
+        for cvrfrev in cvrftracking.findall('/'.join([UN('cvrf', 'RevisionHistory'), UN('cvrf', 'Revision')])):
+            rev = CVRFRevision(
+                parseVersion(cvrfrev.findtext(UN('cvrf', 'Number')).strip()),
+                parseDate(cvrfrev.findtext(UN('cvrf', 'Date')).strip()),
+                cvrfrev.findtext(UN('cvrf', 'Description')).strip(),
+            )
+            tracking.addRevision(rev)
 
-    xmlgenerator = cvrftracking.find(UN('cvrf', 'Generator'))
-    if xmlgenerator is not None:
-        generator = CVRFGenerator()
-        xmlengine = xmlgenerator.findtext(UN('cvrf', 'Engine'))
-        if xmlengine is not None:
-            generator.setEngine(xmlengine.strip())
-        xmldate = xmlgenerator.findtext(UN('cvrf', 'Date'))
-        if xmldate is not None:
-            generator.setDate(parseDate(xmldate.strip()))
-        tracking.setGenerator(generator)
+        xmlgenerator = cvrftracking.find(UN('cvrf', 'Generator'))
+        if xmlgenerator is not None:
+            generator = CVRFGenerator()
+            xmlengine = xmlgenerator.findtext(UN('cvrf', 'Engine'))
+            if xmlengine is not None:
+                generator.setEngine(xmlengine.strip())
+            xmldate = xmlgenerator.findtext(UN('cvrf', 'Date'))
+            if xmldate is not None:
+                generator.setDate(parseDate(xmldate.strip()))
+            tracking.setGenerator(generator)
 
     for cvrfnote in cvrfdoc.findall('/'.join([UN('cvrf', 'DocumentNotes'), UN('cvrf', 'Note')])):
         doc.addNote(parseNote(cvrfnote))


More information about the Farol-commits mailing list