Mercurial > farol > farolluz
view farolluz/common.py @ 55:7653ffbec88b tip
Update setup.py
author | Benoît Allard <benoit.allard@greenbone.net> |
---|---|
date | Wed, 07 Jan 2015 12:02:23 +0100 |
parents | 809db989cac5 |
children |
line wrap: on
line source
# -*- coding: utf-8 -*- # # 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. """\ Common Objects related to CVRF Documents """ class ValidationError(Exception): pass class CVRFNote(object): TYPES = ('General', 'Details', 'Description', 'Summary', 'FAQ', 'Legal Disclaimer', 'Other') def __init__(self, _type, ordinal, note, title=None, audience=None): self._type = _type self._ordinal = ordinal self._note = note self._title = title self._audience = audience def getTitle(self): """ returns something that can be used as a title """ if self._title is None: return "%s (#%d)" % (self._type, self._ordinal) return "%s (%s)" % (self._title, self._type) def validate(self): if not self._type: raise ValidationError('A Note needs to have a Type set') if self._type not in self.TYPES: raise ValidationError('A Note Type needs to be one of %s' % ', '.join(self.TYPES)) if self._ordinal < 0: raise ValidationError('A Note ordinal must be a positive integer') if not self._note: raise ValidationError('A Note must contain some text') def __str__(self): return self._note class CVRFReference(object): TYPES = ('Self', 'External') def __init__(self, url, description, _type=None): self._url = url self._description = description self._type = _type def validate(self): if (self._type is not None) and (self._type not in self.TYPES): raise ValidationError('If a Reference type is set, it mist be one of %s' % ', '.join(self.TYPES)) if not self._url: raise ValidationError('A Reference must contain an URL') if not self._description: raise ValidationError('A Reference must contain a description') class CVRFAcknowledgment(object): def __init__(self, names=[], organizations=[], description=None, url=None): self._names = names self._organizations = organizations self._description = description self._url = url def getTitle(self): return "%s - %s" % (', '.join(self._names), ', '.join(self._organizations)) def validate(self): if (not self._names) and (not self._organizations) and (not self._description): raise ValidationError('An Acknowledgment must have at least a Name, an Organization or a Description')