comparison 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
comparison
equal deleted inserted replaced
41:bb1dd2a55643 42:9ed24f48df01
25 """\ 25 """\
26 Methods for parsing of CVRF Documents 26 Methods for parsing of CVRF Documents
27 """ 27 """
28 28
29 from __future__ import print_function 29 from __future__ import print_function
30 30 # Allow .xml to be different from xml
31 import re 31 from __future__ import absolute_import
32
32 import textwrap 33 import textwrap
33 import xml.etree.ElementTree as ET 34 import xml.etree.ElementTree as ET
34 from datetime import datetime, timedelta 35
35 36 from .xml import parseDate
36 try:
37 from datetime import timezone
38 except ImportError:
39 from ..py2 import FixedTimeZone as timezone
40 37
41 from ..common import CVRFNote, CVRFAcknowledgment, CVRFReference 38 from ..common import CVRFNote, CVRFAcknowledgment, CVRFReference
42 from ..document import (CVRF, CVRFPublisher, CVRFTracking, CVRFRevision, 39 from ..document import (CVRF, CVRFPublisher, CVRFTracking, CVRFRevision,
43 CVRFGenerator, CVRFAggregateSeverity, CVRFTrackingID) 40 CVRFGenerator, CVRFAggregateSeverity, CVRFTrackingID)
44 from ..producttree import (CVRFProductBranch, CVRFFullProductName, 41 from ..producttree import (CVRFProductBranch, CVRFFullProductName,
59 return "{%s}%s" % (NAMESPACES[ns], name) 56 return "{%s}%s" % (NAMESPACES[ns], name)
60 57
61 58
62 def parseVersion(string): 59 def parseVersion(string):
63 return tuple(int(i) for i in string.split('.')) 60 return tuple(int(i) for i in string.split('.'))
64
65
66 def parseDate(string):
67 m = re.match('(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:([+-])(\d{2}):(\d{2})|(Z))?', string)
68 if (m.group(7) is None) or (m.group(7) == 'Z'):
69 tzhours = 0
70 tzmin = 0
71 else:
72 tzhours = int(m.group(8))
73 if m.group(7) == '-':
74 tzhours = - tzhours
75 tzmin = int(m.group(9))
76 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)))
77 61
78 62
79 def parseNote(elem): 63 def parseNote(elem):
80 return CVRFNote( 64 return CVRFNote(
81 elem.attrib['Type'], 65 elem.attrib['Type'],
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)