changeset 5:d62264a643fb

Allow parsing of incomplete documents
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 06 Oct 2014 11:39:38 +0200
parents c5cf387b5785
children 633ebfcff0d0
files farolluz/parsers/cvrf.py
diffstat 1 files changed, 41 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- 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))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)