diff --git a/filter2.py b/filter2.py index 4af8680..7f30d68 100644 --- a/filter2.py +++ b/filter2.py @@ -60,8 +60,9 @@ def toldapfilter(l): txt = "".join(c for c in pyparsing.printables if c not in '()&|!=') expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != =")) -def human_to_ldap(data): - data='(%s)' % data - l=expr.parseString(data).asList() - return "(%s)" % toldapfilter(collapse(toprefix(prioritize(l)))) +def human_to_list(data): + if data: + return collapse(toprefix(prioritize(expr.parseString("(%s)" % data).asList()))) +def human_to_ldap(data): + return "(%s)" % toldapfilter(human_to_list(data)) diff --git a/filter3.py b/filter3.py index 2989deb..7b75218 100644 --- a/filter3.py +++ b/filter3.py @@ -43,6 +43,10 @@ def toldapfilter(l): return "!(%s=%s)" % (l[1], l[2]) return op + ''.join(['(%s)' % toldapfilter(i) for i in l[1:]]) -def human_to_ldap(str): - return "(%s)" % toldapfilter(toprefix(simplify(expr.parseString(str).asList()))) +def human_to_list(data): + if data: + return toprefix(simplify(expr.parseString(data).asList())) + +def human_to_ldap(data): + return "(%s)" % toldapfilter(human_to_list(data))