# HG changeset patch # User BenoƮt Allard # Date 1412929535 -7200 # Node ID 5535ac5fef3786b8401761362e8bfde742823f50 # Parent 0b9f19f51d79a57e75e6443ffcf9e9415d75719b Be more permissive when parsing dates diff -r 0b9f19f51d79 -r 5535ac5fef37 farol/controller.py --- 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))) diff -r 0b9f19f51d79 -r 5535ac5fef37 farol/document.py --- 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 diff -r 0b9f19f51d79 -r 5535ac5fef37 farol/vulnerability.py --- 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