Utilisation de boolens.
darcs-hash:20060310001255-68412-629988a2afbef9e2c8b404b9371cd19ffdf66d56.gz
This commit is contained in:
parent
aea8585794
commit
97c42d7459
1 changed files with 16 additions and 16 deletions
|
@ -531,11 +531,11 @@ class crans_ldap:
|
|||
result = {'adherent': [], 'machine': [], 'club': []}
|
||||
|
||||
# Fonction utile
|
||||
def build_filtre(champ, expr, neg=0):
|
||||
def build_filtre(champ, expr, neg=False):
|
||||
"""
|
||||
Retourne une chaine pour recherche dans la base LDAP
|
||||
du style (champ=expr) en adaptant les valeurs de expr au champ.
|
||||
Si neg = 1, retourne le négatif : (!(champ=expr))
|
||||
Si neg = True, retourne le négatif : (!(champ=expr))
|
||||
"""
|
||||
el = ''
|
||||
if champ in ['host', 'hostAlias']:
|
||||
|
@ -574,52 +574,52 @@ class crans_ldap:
|
|||
if neg: el = '(!%s)' % el
|
||||
return el
|
||||
|
||||
if expression.find('=') != -1:
|
||||
if '=' in expression:
|
||||
#### Recherche avec conditions explicites
|
||||
## Construction des filtres
|
||||
|
||||
# initialisation
|
||||
filtre = {}
|
||||
filtre_cond = {} # Stokage si filtre avec condition (ne comporte pas que des *)
|
||||
filtre_tout = 1 # Passse à 0 si au moins une condition
|
||||
filtre_cond = {} # Stockage si filtre avec condition (ne comporte pas que des *)
|
||||
filtre_tout = True # Passse à False si au moins une condition
|
||||
|
||||
for i in filtres:
|
||||
filtre[i] = '(&'
|
||||
filtre_cond[i] = 0
|
||||
filtre_cond[i] = False
|
||||
conds = expression.split('&')
|
||||
|
||||
# Test de l'expression de recherche et classement par filtres
|
||||
for cond in conds:
|
||||
neg = 0
|
||||
neg = False
|
||||
try:
|
||||
champ, expr = cond.strip().split('=')
|
||||
if champ[-1] == '!':
|
||||
# Négation pour se champ
|
||||
# Négation pour ce champ
|
||||
champ = champ[:-1]
|
||||
neg = 1
|
||||
neg = True
|
||||
except:
|
||||
raise ValueError(u'Syntaxe de recherche invalide.')
|
||||
|
||||
# transformation de certains champs
|
||||
champ = self.trans.get(champ, champ)
|
||||
|
||||
if expr == '': expr='*'
|
||||
if expr == '': expr = '*'
|
||||
|
||||
ok = 0
|
||||
ok = False
|
||||
|
||||
# Construction du filtre
|
||||
for i in filtres:
|
||||
if champ in self.auto_search_champs[i] + self.non_auto_search_champs[i]:
|
||||
filtre[i] += build_filtre(champ, expr, neg)
|
||||
ok = 1
|
||||
ok = True
|
||||
if expr != '*' or neg:
|
||||
filtre_cond[i] = 1
|
||||
filtre_tout = 0
|
||||
filtre_cond[i] = True
|
||||
filtre_tout = False
|
||||
if not ok:
|
||||
raise ValueError(u'Champ de recherche inconnu (%s)'% champ )
|
||||
|
||||
## Recherche avec chacun des filtres
|
||||
r={} # contiendra les réponses par filtre
|
||||
r = {} # contiendra les réponses par filtre
|
||||
for i in filtres:
|
||||
if (filtre_tout and filtre[i] != '(&' ) or filtre_cond[i]:
|
||||
# Filtre valide
|
||||
|
@ -711,7 +711,7 @@ class crans_ldap:
|
|||
filtre = '(&(|'
|
||||
for champ in self.auto_search_champs[i]:
|
||||
filtre += build_filtre(champ, expression)
|
||||
filtre += ')(objectClass=%s))' %i
|
||||
filtre += ')(objectClass=%s))' % i
|
||||
|
||||
# Recherche
|
||||
for r in self.conn.search_s(self.base_dn, self.scope[i], filtre):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue