From 37b5dc5a0c398284b253b21a606411f9be94ef95 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Wed, 19 Feb 2014 19:27:43 +0100 Subject: [PATCH] [filter2, filter3] pyparsing.printables ne prend en compte que de l'ASCII, donc on utilise les char unicode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pour ça on est obligé (si on utilise pyparsing) de générer la liste de tous les charactère unicode. Daniel fait remarquer que ça n'est pas joli d'instancier une chaine de 63Ko quand on veux parser quelque chose. On ne le fait tout de même que de façon paresseuse la première fois que l'on a besoin de parser quelquechose (dans filter2, filter3 est juste un proof of concept). Pour faire du human_to_ldap, on peut utiliser directement la fonction de filter.py qui n'est pas impacté par le problème, mais pour ressucite, on a pour le moment pas le choix puisqu'on utilise la fonction human_to_list qui n'est fournie que dans les modules filter2 et filter3. --- filter2.py | 3 ++- filter3.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/filter2.py b/filter2.py index 3ba44a3..e696373 100644 --- a/filter2.py +++ b/filter2.py @@ -62,7 +62,8 @@ def pypexpr(): global expr if not expr: import pyparsing - txt = "".join(c for c in pyparsing.printables if c not in '()&|!=') + unicodePrintables = u''.join(unichr(c) for c in xrange(65536) if not unichr(c).isspace()) + txt = "".join(c for c in unicodePrintables if c not in '()&|!=') expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != =")) return expr diff --git a/filter3.py b/filter3.py index 7b75218..27b3c8f 100644 --- a/filter3.py +++ b/filter3.py @@ -2,8 +2,9 @@ """Plus joli""" import pyparsing +unicodePrintables = u''.join(unichr(c) for c in xrange(65536) if not unichr(c).isspace()) -txt = pyparsing.Word("".join(c for c in pyparsing.printables if c not in '=()|&'),exact=1) +txt = pyparsing.Word("".join(c for c in unicodePrintables if c not in '=()|&'),exact=1) ne = pyparsing.Literal('!=') eq = pyparsing.Literal('=')