From 750a23602ab3e966a60e99e2bba09f5ce3285885 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Wed, 28 Nov 2012 15:42:18 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20des=20exceptions=20lev=C3=A9es?= =?UTF-8?q?=20en=20cas=20d'erreur=20afin=20qu'elle=20ne=20crashent=20pas?= =?UTF-8?q?=20elles-m=C3=AAme.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ça consiste essentiellement en du s/%s/%r/ --- attributs.py | 31 +++++++++++++++---------------- lc_ldap.py | 4 ++-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/attributs.py b/attributs.py index 822f27a..95c9696 100644 --- a/attributs.py +++ b/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): diff --git a/lc_ldap.py b/lc_ldap.py index bb7c201..09a2321 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -114,7 +114,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): ldap.ldapobject.LDAPObject.__init__(self, uri) if user and not re.match('[a-z_][a-z0-9_-]*', user): - raise ValueError('Invalid user name: %s' % user) + raise ValueError('Invalid user name: %r' % user) # Si un username, on récupère le dn associé… if user and not dn: @@ -219,7 +219,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject): assert isinstance(owner, adherent) or isinstance(owner, club) # XXX - Vérifier les droits - else: raise ValueError("Realm inconnu: %s" % realm) + else: raise ValueError("Realm inconnu: %r" % realm) # On récupère la plage des mids if realm == 'fil':