diff farolluz/parsers/cvrf.py @ 42:9ed24f48df01

parsers/CVRF: Move the date parsing method to parsers/XML
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 29 Dec 2014 15:00:59 +0100
parents 934c510f8077
children
line wrap: on
line diff
--- a/farolluz/parsers/cvrf.py	Mon Dec 29 14:58:29 2014 +0100
+++ b/farolluz/parsers/cvrf.py	Mon Dec 29 15:00:59 2014 +0100
@@ -27,16 +27,13 @@
 """
 
 from __future__ import print_function
+# Allow .xml to be different from xml
+from __future__ import absolute_import
 
-import re
 import textwrap
 import xml.etree.ElementTree as ET
-from datetime import datetime, timedelta
 
-try:
-    from datetime import timezone
-except ImportError:
-    from ..py2 import FixedTimeZone as timezone
+from .xml import parseDate
 
 from ..common import CVRFNote, CVRFAcknowledgment, CVRFReference
 from ..document import (CVRF, CVRFPublisher, CVRFTracking, CVRFRevision,
@@ -63,19 +60,6 @@
     return tuple(int(i) for i in string.split('.'))
 
 
-def parseDate(string):
-    m = re.match('(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:([+-])(\d{2}):(\d{2})|(Z))?', string)
-    if (m.group(7) is None) or (m.group(7) == 'Z'):
-        tzhours = 0
-        tzmin = 0
-    else:
-        tzhours = int(m.group(8))
-        if m.group(7) == '-':
-            tzhours = - tzhours
-        tzmin = int(m.group(9))
-    return datetime(int(m.group(1)), int(m.group(2)), int(m.group(3)), int(m.group(4)), int(m.group(5)), int(m.group(6)), tzinfo=timezone(timedelta(hours=tzhours, minutes=tzmin)))
-
-
 def parseNote(elem):
     return CVRFNote(
         elem.attrib['Type'],
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)