[filter,printing/templates] Import de jinja2 et pyparsing paresseux
Comme ça, pas besoin d'installer les lib correspondante là où on ne fait pas des input/output utilisateur.
This commit is contained in:
parent
702f941469
commit
99b9f8bc12
2 changed files with 34 additions and 22 deletions
16
filter2.py
16
filter2.py
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf8 -*-
|
||||
"""Plus rapide"""
|
||||
|
||||
import pyparsing
|
||||
|
||||
def simplify(l):
|
||||
if not isinstance(l, list):
|
||||
return l
|
||||
|
@ -57,12 +56,19 @@ def toldapfilter(l):
|
|||
return op + ''.join(['(%s)' % toldapfilter(i) for i in l[1:]])
|
||||
|
||||
|
||||
txt = "".join(c for c in pyparsing.printables if c not in '()&|!=')
|
||||
expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != ="))
|
||||
# Import et definition de la grammaire de parsing de façon paresseuse
|
||||
expr=None
|
||||
def pypexpr():
|
||||
global expr
|
||||
if not expr:
|
||||
import pyparsing
|
||||
txt = "".join(c for c in pyparsing.printables if c not in '()&|!=')
|
||||
expr = pyparsing.nestedExpr("(", ")", pyparsing.Word(txt) | pyparsing.oneOf("& | != ="))
|
||||
return expr
|
||||
|
||||
def human_to_list(data):
|
||||
if data:
|
||||
return collapse(toprefix(prioritize(expr.parseString("(%s)" % data).asList())))
|
||||
return collapse(toprefix(prioritize(pypexpr().parseString("(%s)" % data).asList())))
|
||||
|
||||
def human_to_ldap(data):
|
||||
return "(%s)" % toldapfilter(human_to_list(data))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue