Modification des exceptions levées en cas d'erreur afin qu'elle ne crashent pas elles-même.
Ça consiste essentiellement en du s/%s/%r/
This commit is contained in:
parent
1c6af7a15d
commit
750a23602a
2 changed files with 17 additions and 18 deletions
31
attributs.py
31
attributs.py
|
@ -141,8 +141,7 @@ class objectClass(Attr):
|
|||
'adherent', 'club', 'machine', 'machineCrans',
|
||||
'borneWifi', 'machineWifi', 'machineFixe',
|
||||
'cransAccount', 'service', 'facture', 'freeMid' ]:
|
||||
print(val)
|
||||
raise ValueError("Pourquoi insérer un objectClass=%s ?" % val)
|
||||
raise ValueError("Pourquoi insérer un objectClass=%r ?" % val)
|
||||
else:
|
||||
self.value = unicode(val)
|
||||
|
||||
|
@ -150,7 +149,7 @@ class objectClass(Attr):
|
|||
class intAttr(Attr):
|
||||
def parse_value(self, val, ldif):
|
||||
if int(val) <= 0:
|
||||
raise ValueError("Valeur entière invalide : %s" % val)
|
||||
raise ValueError("Valeur entière invalide : %r" % val)
|
||||
self.value = int(val)
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -196,7 +195,7 @@ class tel(Attr):
|
|||
def parse_value(self, val, ldif):
|
||||
self.value = format_tel(val)
|
||||
if len(self.value) == 0:
|
||||
raise ValueError("Numéro de téléphone invalide ('%s')" % val)
|
||||
raise ValueError("Numéro de téléphone invalide (%r)" % val)
|
||||
|
||||
|
||||
class yearAttr(intAttr):
|
||||
|
@ -205,7 +204,7 @@ class yearAttr(intAttr):
|
|||
|
||||
def parse_value(self, val, ldif):
|
||||
if int(val) < 1998:
|
||||
raise ValueError("Annee invalide (%s)" % val)
|
||||
raise ValueError("Année invalide (%r)" % val)
|
||||
self.value = int(val)
|
||||
|
||||
|
||||
|
@ -226,7 +225,7 @@ class mailAlias(Attr):
|
|||
def parse_value(self, val, ldif):
|
||||
val = val.lower()
|
||||
if not re.match('[a-z][-_.0-9a-z]+', val):
|
||||
raise ValueError("Alias mail invalide (%s)" % val)
|
||||
raise ValueError("Alias mail invalide (%r)" % val)
|
||||
self.value = val
|
||||
|
||||
|
||||
|
@ -266,7 +265,7 @@ class chbre(Attr):
|
|||
self.value = val
|
||||
return
|
||||
else:
|
||||
raise ValueError("Club devrait etre en XclN, pas en %s" % val)
|
||||
raise ValueError("Club devrait etre en XclN, pas en %r" % val)
|
||||
|
||||
if val in (u"EXT", u"????"):
|
||||
self.value = val
|
||||
|
@ -289,7 +288,7 @@ class droits(Attr):
|
|||
def parse_value(self, val, ldif):
|
||||
if val.lower() not in ['apprenti', 'nounou', 'cableur', 'tresorier', 'bureau',
|
||||
'webmaster', 'webradio', 'imprimeur', 'multimachines', 'victime', 'moderateur', 'nounours']:
|
||||
raise ValueError("Ces droits n'existent pas ('%s')" % val)
|
||||
raise ValueError("Ces droits n'existent pas (%r)" % val)
|
||||
if val.lower() == 'webmaster':
|
||||
self.value = u'WebMaster'
|
||||
else:
|
||||
|
@ -304,7 +303,7 @@ class solde(Attr):
|
|||
def parse_value(self, solde, ldif):
|
||||
# on évite les dépassements, sauf si on nous dit de ne pas vérifier
|
||||
if self.ctxt_check and not (float(solde) >= config.impression.decouvert and float(solde) <= 1024.):
|
||||
raise ValueError("Solde invalide: %s" % solde)
|
||||
raise ValueError("Solde invalide: %r" % solde)
|
||||
self.value = solde
|
||||
|
||||
class dnsAttr(Attr):
|
||||
|
@ -313,7 +312,7 @@ class dnsAttr(Attr):
|
|||
name, net = dns.split('.', 1)
|
||||
if self.ctxt_check and (net not in ['crans.org', 'wifi.crans.org'] or
|
||||
not re.match('[a-z][-_a-z0-9]+', name)):
|
||||
raise ValueError("Nom d'hote invalide '%s'" % dns)
|
||||
raise ValueError("Nom d'hote invalide %r" % dns)
|
||||
self.value = dns
|
||||
|
||||
|
||||
|
@ -395,18 +394,18 @@ class portAttr(Attr):
|
|||
a,b = port.split(":", 1)
|
||||
if a:
|
||||
if int(a) <0 or int(a)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
else:
|
||||
a = 0
|
||||
if b:
|
||||
if int(a) <0 or int(a)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
else:
|
||||
b = 65535
|
||||
self.value = [int(a), int(b)]
|
||||
else:
|
||||
if int(port) <0 or int(port)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
self.value = [int(port)]
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -512,7 +511,7 @@ class charteMA(Attr):
|
|||
|
||||
def parse_value(self, signed, ldif):
|
||||
if signed.upper() not in ["TRUE", "FALSE"]:
|
||||
raise ValueError("La charte MA est soit TRUE ou FALSE, pas %s" % signed)
|
||||
raise ValueError("La charte MA est soit TRUE ou FALSE, pas %r" % signed)
|
||||
self.value = signed.upper()
|
||||
|
||||
class homeDirectory(Attr):
|
||||
|
@ -525,7 +524,7 @@ class homeDirectory(Attr):
|
|||
if uid.startswith('club-'):
|
||||
uid = uid.split('-',1)[1]
|
||||
if home != u'/home/%s' % uid and home != u'/home/club/%s' % uid:
|
||||
raise ValueError("Le répertoire personnel n'est pas bon: %s (devrait être %s ou %s)" %
|
||||
raise ValueError("Le répertoire personnel n'est pas bon: %r (devrait être %r ou %r)" %
|
||||
(home, '/home/%s' % ldif['uid'][0], '/home/club/%s' % ldif['uid'][0]))
|
||||
self.value = home
|
||||
|
||||
|
@ -562,7 +561,7 @@ class loginShell(Attr):
|
|||
'/bin//zsh'
|
||||
'']
|
||||
if self.ctxt_check and (shell not in shells):
|
||||
raise ValueError("Shell %s invalide" % shell)
|
||||
raise ValueError("Shell %r invalide" % shell)
|
||||
self.value = shell
|
||||
|
||||
class uidNumber(intAttr):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue