From aa573c3c35635dff3539b2ddf074db45a3422e51 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Sun, 17 Nov 2013 20:20:57 +0100 Subject: [PATCH] =?UTF-8?q?[filter]=20Fonction=20pour=20r=C3=A9cup=C3=A9re?= =?UTF-8?q?r=20une=20structure=20de=20donn=C3=A9e=20manipulable=20en=20pyt?= =?UTF-8?q?hon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filter2.py | 9 +++++---- filter3.py | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) 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))