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