diff farolluz/parsers/cpe.py @ 41:bb1dd2a55643

CPE: Add a generic 'parse' method
author Benoît Allard <benoit.allard@greenbone.net>
date Mon, 29 Dec 2014 14:58:29 +0100
parents 1d9b2b06067e
children 3826f2701ff2
line wrap: on
line diff
--- a/farolluz/parsers/cpe.py	Mon Dec 29 14:30:39 2014 +0100
+++ b/farolluz/parsers/cpe.py	Mon Dec 29 14:58:29 2014 +0100
@@ -1,3 +1,27 @@
+# -*- coding: utf-8 -*-
+# Description:
+# Methods for parsing CPEs
+#
+# 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.
+
 """\
 a cpe class to ease the creation of a producttree based on cpe
 
@@ -257,3 +281,13 @@
                 self.target_hw = v
             elif idx == 12:
                 self.other = v
+
+def parse(s):
+    cpe = CPE()
+    if s[:5] == 'cpe:/':
+        cpe.unbind_URI(s)
+    elif s[:8] == 'cpe:2.3:':
+        cpe.unbind_fs(s)
+    else:
+        raise ValueError(s)
+    return cpe
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)