benoit@0: # -*- coding: utf-8 -*- benoit@0: # benoit@0: # Authors: benoit@0: # BenoƮt Allard benoit@0: # benoit@0: # Copyright: benoit@0: # Copyright (C) 2014 Greenbone Networks GmbH benoit@0: # benoit@0: # This program is free software; you can redistribute it and/or benoit@0: # modify it under the terms of the GNU General Public License benoit@0: # as published by the Free Software Foundation; either version 2 benoit@0: # of the License, or (at your option) any later version. benoit@0: # benoit@0: # This program is distributed in the hope that it will be useful, benoit@0: # but WITHOUT ANY WARRANTY; without even the implied warranty of benoit@0: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the benoit@0: # GNU General Public License for more details. benoit@0: # benoit@0: # You should have received a copy of the GNU General Public License benoit@0: # along with this program; if not, write to the Free Software benoit@0: # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. benoit@0: benoit@0: """\ benoit@26: Common Objects related to CVRF Documents benoit@0: """ benoit@0: benoit@0: class ValidationError(Exception): pass benoit@0: benoit@0: benoit@0: class CVRFNote(object): benoit@0: TYPES = ('General', 'Details', 'Description', 'Summary', 'FAQ', benoit@0: 'Legal Disclaimer', 'Other') benoit@0: def __init__(self, _type, ordinal, note, title=None, audience=None): benoit@0: self._type = _type benoit@0: self._ordinal = ordinal benoit@0: self._note = note benoit@0: self._title = title benoit@0: self._audience = audience benoit@0: benoit@0: def getTitle(self): benoit@0: """ returns something that can be used as a title """ benoit@0: if self._title is None: benoit@0: return "%s (#%d)" % (self._type, self._ordinal) benoit@0: return "%s (%s)" % (self._title, self._type) benoit@0: benoit@0: def validate(self): benoit@0: if not self._type: benoit@0: raise ValidationError('A Note needs to have a Type set') benoit@0: if self._type not in self.TYPES: benoit@0: raise ValidationError('A Note Type needs to be one of %s' % ', '.join(self.TYPES)) benoit@0: if self._ordinal < 0: benoit@0: raise ValidationError('A Note ordinal must be a positive integer') benoit@0: if not self._note: benoit@0: raise ValidationError('A Note must contain some text') benoit@0: benoit@0: benoit@0: def __str__(self): benoit@0: return self._note benoit@0: benoit@0: benoit@0: class CVRFReference(object): benoit@0: TYPES = ('Self', 'External') benoit@0: def __init__(self, url, description, _type=None): benoit@0: self._url = url benoit@0: self._description = description benoit@0: self._type = _type benoit@0: benoit@0: def validate(self): benoit@0: if (self._type is not None) and (self._type not in self.TYPES): benoit@0: raise ValidationError('If a Reference type is set, it mist be one of %s' % ', '.join(self.TYPES)) benoit@0: if not self._url: benoit@0: raise ValidationError('A Reference must contain an URL') benoit@0: if not self._description: benoit@0: raise ValidationError('A Reference must contain a description') benoit@0: benoit@0: benoit@0: class CVRFAcknowledgment(object): benoit@8: def __init__(self, names=[], organizations=[], description=None, benoit@0: url=None): benoit@8: self._names = names benoit@8: self._organizations = organizations benoit@0: self._description = description benoit@0: self._url = url benoit@0: benoit@0: def getTitle(self): benoit@8: return "%s - %s" % (', '.join(self._names), benoit@8: ', '.join(self._organizations)) benoit@0: benoit@0: def validate(self): benoit@8: if (not self._names) and (not self._organizations) and (not self._description): benoit@0: raise ValidationError('An Acknowledgment must have at least a Name, an Organization or a Description') benoit@0: benoit@0: