Mercurial > farol > farol
diff farol/controller.py @ 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 | b4fb652484b4 |
children | d49c1ee6bc07 |
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)))