changeset 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 bb1dd2a55643
children b87f2a6e613a
files farolluz/parsers/cvrf.py farolluz/parsers/xml.py
diffstat 2 files changed, 53 insertions(+), 19 deletions(-) [+]
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'],
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/farolluz/parsers/xml.py	Mon Dec 29 15:00:59 2014 +0100
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+# Description:
+# Methods for parsing CVE XML documents
+#
+# Authors:
+# BenoƮt Allard <benoit.allard@greenbone.net>
+#
+# Copyright:
+# Copyright (C) 2014 Greenbone Networks GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+
+"""\
+Methods for parsing of CVE XML Documents
+
+Ref: http://scap.nist.gov/schema/vulnerability/0.4
+"""
+
+import re
+
+from datetime import datetime, timedelta
+
+try:
+    from datetime import timezone
+except ImportError:
+    from ..py2 import FixedTimeZone as timezone
+
+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)))
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)