view 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
line wrap: on
line source
# -*- 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)