[filter] Fonction pour récupérer une structure de donnée manipulable en python

This commit is contained in:
Valentin Samir 2013-11-17 20:20:57 +01:00
parent cb4ac3ca18
commit aa573c3c35
2 changed files with 11 additions and 6 deletions

View file

@ -60,8 +60,9 @@ def toldapfilter(l):
txt = "".join(c for c in pyparsing.printables if c not in '()&|!=') txt = "".join(c for c in pyparsing.printables if c not in '()&|!=')
expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != =")) expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != ="))
def human_to_ldap(data): def human_to_list(data):
data='(%s)' % data if data:
l=expr.parseString(data).asList() return collapse(toprefix(prioritize(expr.parseString("(%s)" % data).asList())))
return "(%s)" % toldapfilter(collapse(toprefix(prioritize(l))))
def human_to_ldap(data):
return "(%s)" % toldapfilter(human_to_list(data))

View file

@ -43,6 +43,10 @@ def toldapfilter(l):
return "!(%s=%s)" % (l[1], l[2]) return "!(%s=%s)" % (l[1], l[2])
return op + ''.join(['(%s)' % toldapfilter(i) for i in l[1:]]) return op + ''.join(['(%s)' % toldapfilter(i) for i in l[1:]])
def human_to_ldap(str): def human_to_list(data):
return "(%s)" % toldapfilter(toprefix(simplify(expr.parseString(str).asList()))) if data:
return toprefix(simplify(expr.parseString(data).asList()))
def human_to_ldap(data):
return "(%s)" % toldapfilter(human_to_list(data))