[lc_ldap/*] (more) pylint compliance
This commit is contained in:
parent
db8b27e6a5
commit
a36bafa021
3 changed files with 35 additions and 23 deletions
41
attributs.py
41
attributs.py
|
@ -30,16 +30,25 @@
|
|||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import re
|
||||
from unicodedata import normalize
|
||||
|
||||
|
||||
def validate_name(value, more_chars=""):
|
||||
"""Valide un nom: ie un unicode qui contient lettres, espaces et
|
||||
apostrophes, et éventuellement des caractères additionnels"""
|
||||
return re.match("[A-Za-z][-' A-Za-z%s]*" % more_chars,
|
||||
normalize('NFKD', decode(a)).encode('ASCII', 'ignore'))
|
||||
normalize('NFKD', value).encode('ASCII', 'ignore'))
|
||||
|
||||
def validate_mac(value):
|
||||
"""Vérifie qu'une adresse mac est valide"""
|
||||
return True
|
||||
|
||||
class Attr:
|
||||
legend = "Human-readable description of attribute"
|
||||
singlevalue = None
|
||||
optional = None
|
||||
|
||||
def validate(self, values, uldif):
|
||||
"validates"
|
||||
self._check_cardinality(values)
|
||||
|
@ -52,19 +61,19 @@ class Attr:
|
|||
"normalizes"
|
||||
return values
|
||||
|
||||
def self._check_cardinality(values):
|
||||
def _check_cardinality(self, values):
|
||||
"""Vérifie qu'il y a un nombre correct de valeur =1, <=1, {0,1},
|
||||
etc..."""
|
||||
if self.singlevalue and len(vals) > 1:
|
||||
raise ValueError(u'%s doit avoir au maximum une valeur (affecte %s)' % self.__class__, values)
|
||||
if not self.optional and len(vals) == 0:
|
||||
raise ValueError('%s doit avoir au moins une valeur' % attr)
|
||||
if self.singlevalue and len(values) > 1:
|
||||
raise ValueError(u'%s doit avoir au maximum une valeur (affecte %s)' % self.__class__, values)
|
||||
if not self.optional and len(values) == 0:
|
||||
raise ValueError('%s doit avoir au moins une valeur' % self.__class__)
|
||||
|
||||
def _check_type(self, values):
|
||||
"""Vérifie que les valeurs ont le bon type (nom est un mot, tel
|
||||
est un nombre, etc...)"""
|
||||
for v in values:
|
||||
assert isunicode(v)
|
||||
assert isinstance(v, unicode)
|
||||
|
||||
def _check_uniqueness(self, values):
|
||||
"""Vérifie l'unicité dans la base de la valeur (mailAlias, chbre,
|
||||
|
@ -89,18 +98,20 @@ class nom(Attr):
|
|||
singlevalue = True
|
||||
optional = False
|
||||
legend = "Nom"
|
||||
def _check_type(self, values): return validate_name()
|
||||
def _check_type(self, values):
|
||||
return [ validate_name(v) for v in values]
|
||||
|
||||
def normalize(self, values):
|
||||
return [ values.strip().capitalize() for v in values ]
|
||||
def normalize(self, values, uldif):
|
||||
return [ v.strip().capitalize() for v in values ]
|
||||
|
||||
class prenom(Attr):
|
||||
singlevalue = True
|
||||
optional = False
|
||||
legend = u"Prénom"
|
||||
def _check_type(self, values): return validate_name()
|
||||
def _check_type(self, values):
|
||||
return [ validate_name(v) for v in values ]
|
||||
|
||||
def normalize(self, values):
|
||||
def normalize(self, values, uldif):
|
||||
return [ values.strip().capitalize() for v in values ]
|
||||
|
||||
class tel(Attr):
|
||||
|
@ -108,7 +119,7 @@ class tel(Attr):
|
|||
optional = False
|
||||
legend = u"Téléphone"
|
||||
|
||||
def normalize(self, value):
|
||||
def normalize(self, value, uldif):
|
||||
return value # XXX - To implement
|
||||
|
||||
class paiement(Attr):
|
||||
|
@ -116,7 +127,7 @@ class paiement(Attr):
|
|||
optional = True
|
||||
legend = u"Paiement"
|
||||
|
||||
def normalize(self, values):
|
||||
def normalize(self, values, uldif):
|
||||
return values # XXX - To implement
|
||||
|
||||
class carteEtudiant(Attr):
|
||||
|
@ -212,7 +223,7 @@ class cid(Attr):
|
|||
|
||||
class responsable(Attr):
|
||||
singlevalue = True
|
||||
optional =True
|
||||
optional = True
|
||||
legend = u"Responsable du club"
|
||||
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
import netaddr, time, smtplib
|
||||
import config
|
||||
from unicodedata import normalize
|
||||
|
||||
def ip_of_mid(mid):
|
||||
"""Convertit un mid en son IP associée"""
|
||||
|
@ -44,7 +45,7 @@ def ip_of_mid(mid):
|
|||
|
||||
def strip_accents(a):
|
||||
""" Supression des accents de la chaîne fournie"""
|
||||
res = normalize('NFKD', decode(a)).encode('ASCII', 'ignore')
|
||||
res = normalize('NFKD', a).encode('ASCII', 'ignore')
|
||||
return res.replace(' ', '_').replace("'", '')
|
||||
|
||||
def mailexist(mail):
|
||||
|
@ -53,7 +54,7 @@ def mailexist(mail):
|
|||
|
||||
mail = mail.split('@', 1)[0]
|
||||
try:
|
||||
s = smtplib.SMTP(smtpserv)
|
||||
s = smtplib.SMTP(config.smtpserv)
|
||||
s.putcmd("vrfy", mail)
|
||||
r = s.getreply()[0] in [250, 252]
|
||||
s.close()
|
||||
|
|
12
lc_ldap.py
12
lc_ldap.py
|
@ -151,7 +151,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject):
|
|||
|
||||
plage = config.NETs[realm]
|
||||
mid = uldif.setdefault('mid', [ unicode(self._find_id('mid', plage)) ])
|
||||
return self._create_entity('mid=%s,%s' % (aid[0], parent), uldif)
|
||||
return self._create_entity('mid=%s,%s' % (mid[0], parent), uldif)
|
||||
|
||||
def newAdherent(self, uldif):
|
||||
"""Crée un nouvel adhérent"""
|
||||
|
@ -171,7 +171,7 @@ class lc_ldap(ldap.ldapobject.LDAPObject):
|
|||
'''Crée une nouvelle entité ldap en dn, avec attributs ldif:
|
||||
uniquement en unicode'''
|
||||
for attr, vals in uldif:
|
||||
nuldiff = self.normalize_and_validate(attr, vals)
|
||||
nuldif = self.normalize_and_validate(attr, vals)
|
||||
lock = CransLock(self)
|
||||
for item in ['aid', 'uid', 'chbre', 'mailAlias', 'canonicalAlias',
|
||||
'fid', 'cid', 'mid', 'macAddress', 'host', 'hostAlias' ]:
|
||||
|
@ -191,15 +191,15 @@ class lc_ldap(ldap.ldapobject.LDAPObject):
|
|||
nonfree = [ int(r[1].get(attr)[0]) for r in res if r[1].get(attr) ]
|
||||
nonfree.sort()
|
||||
|
||||
for id in plage:
|
||||
if nonfree and nonfree[0] <= id:
|
||||
while nonfree and nonfree[0] <= id:
|
||||
for i in plage:
|
||||
if nonfree and nonfree[0] <= i:
|
||||
while nonfree and nonfree[0] <= i:
|
||||
nonfree = nonfree[1:]
|
||||
else:
|
||||
break
|
||||
else:
|
||||
raise EnvironmentError(u'Aucun %s libre dans la plage [%d, %d]' %
|
||||
(attr, plage[0], id))
|
||||
(attr, plage[0], i))
|
||||
return id
|
||||
|
||||
def _hist(self, msg):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue