comparison farolluz/parsers/xml.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
children
comparison
equal deleted inserted replaced
41:bb1dd2a55643 42:9ed24f48df01
1 # -*- coding: utf-8 -*-
2 # Description:
3 # Methods for parsing CVE XML documents
4 #
5 # Authors:
6 # BenoƮt Allard <benoit.allard@greenbone.net>
7 #
8 # Copyright:
9 # Copyright (C) 2014 Greenbone Networks GmbH
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24
25 """\
26 Methods for parsing of CVE XML Documents
27
28 Ref: http://scap.nist.gov/schema/vulnerability/0.4
29 """
30
31 import re
32
33 from datetime import datetime, timedelta
34
35 try:
36 from datetime import timezone
37 except ImportError:
38 from ..py2 import FixedTimeZone as timezone
39
40 def parseDate(string):
41 m = re.match('(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:([+-])(\d{2}):(\d{2})|(Z))?', string)
42 if (m.group(7) is None) or (m.group(7) == 'Z'):
43 tzhours = 0
44 tzmin = 0
45 else:
46 tzhours = int(m.group(8))
47 if m.group(7) == '-':
48 tzhours = - tzhours
49 tzmin = int(m.group(9))
50 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)