Mercurial > farol
changeset 100:5535ac5fef37
Be more permissive when parsing dates
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Fri, 10 Oct 2014 10:25:35 +0200 |
parents | 0b9f19f51d79 |
children | 21a1a69b4525 |
files | farol/controller.py farol/document.py farol/vulnerability.py |
diffstat | 3 files changed, 22 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/farol/controller.py Thu Oct 09 16:48:12 2014 +0200 +++ b/farol/controller.py Fri Oct 10 10:25:35 2014 +0200 @@ -27,9 +27,18 @@ is shared for the Document and the Vulnerabilities. """ +import re +from datetime import datetime, timedelta + +try: + from datetime import timezone +except ImportError: + from farolluz.py2 import FixedTimeZone as timezone + from flask import request from farolluz.cvrf import CVRFNote, CVRFReference, CVRFAcknowledgment +from farolluz.parsers.cvrf import parseDate as parseXMLDate def split_fields(field, separator=','): if not field: @@ -72,3 +81,13 @@ ack._description = request.form['description'] or None ack._url = request.form['url'] or None return ack + +def parseDate(string): + """ An extended version of the XML parser's one, that also unsderstand + date without time. """ + try: return parseXMLDate(string) + except AttributeError: pass + # Absorb AttributeError, and try to parse it a second time ... + m = re.match('(\d{4})-(\d{2})-(\d{2})', string) + return datetime(int(m.group(1)), int(m.group(2)), int(m.group(3)), + tzinfo=timezone(timedelta(hours=0, minutes=0)))
--- a/farol/document.py Thu Oct 09 16:48:12 2014 +0200 +++ b/farol/document.py Fri Oct 10 10:25:35 2014 +0200 @@ -25,7 +25,7 @@ from flask import (Blueprint, render_template, abort, redirect, request, url_for, flash) -from farolluz.parsers.cvrf import parseDate, parseVersion +from farolluz.parsers.cvrf import parseVersion from farolluz.cvrf import (CVRFNote, CVRFReference, CVRFPublisher, CVRFTracking, CVRFTrackingID, CVRFGenerator, CVRFRevision, CVRFAggregateSeverity) @@ -34,7 +34,7 @@ from .controller import (update_note_from_request, create_note_from_request, update_reference_from_request, create_reference_from_request, update_acknowledgment_from_request, create_acknowledgment_from_request, - split_fields) + split_fields, parseDate) from .session import document_required, get_current
--- a/farol/vulnerability.py Thu Oct 09 16:48:12 2014 +0200 +++ b/farol/vulnerability.py Fri Oct 10 10:25:35 2014 +0200 @@ -25,14 +25,13 @@ from flask import (Blueprint, render_template, abort, redirect, request, url_for) -from farolluz.parsers.cvrf import parseDate from farolluz.cvrf import (CVRFVulnerability, CVRFVulnerabilityID, CVRFNote, CVRFReference, CVRFCWE, CVRFInvolvement, CVRFThreat, CVRFProductStatus, CVRFCVSSSet, CVRFRemediation) from farolluz.renderer import utcnow from .controller import (update_note_from_request, create_note_from_request, - update_reference_from_request, create_reference_from_request, + update_reference_from_request, create_reference_from_request, parseDate, update_acknowledgment_from_request, create_acknowledgment_from_request) from .session import document_required, get_current