1 #@ MODIF ascheckers Noyau DATE 23/05/2007 AUTEUR PELLET J.PELLET
2 # -*- coding: iso-8859-1 -*-
3 # CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2007 EDF R&D WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
9 # (AT YOUR OPTION) ANY LATER VERSION.
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
18 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
22 """Classe qui exprime une contrainte multiple pour un attribut"""
23 def __init__(self, *args):
24 self.values = list(args)
26 def add_value(self, value ):
27 if value not in self.values:
28 self.values.append( value )
30 def __call__(self, obj, name, value, log ):
31 if value not in self.values:
32 log.err( obj, "l'attribut %s=%r n'est pas dans %r" % (name, value, self.values) )
36 g = [ repr(v) for v in self.values ]
37 l.append( ", ".join(g) )
41 class CheckLog(object):
42 """Un validateur qui enregistre toutes
43 les erreurs trouvées"""
49 def log(self, level, obj, msg ):
51 self.msg.append( (level, obj.nomj(), msg) )
53 self.msg.append( (level, 'None', msg) )
55 def err(self, obj, msg ):
56 self.log( 0, obj, msg )
58 def warn(self, obj, msg ):
59 self.log( 1, obj, msg )
61 def visit(self, obj ):
62 self.names[obj.nomj()] = 1
66 return "\n".join( [ "%s:%s: %s" % (d[l],n,m)
67 for l,n,m in self.msg ])
69 class CheckFail(CheckLog):
70 """Un validateur qui lève une exception
71 dès la première erreur"""
72 def err(self, obj, msg ):
73 raise AssertionError("%s: %s" % (obj.nomj(), msg) )