root / pithos / lib / filter.py @ 3d13f97a
History | View | Annotate | Download (2 kB)
1 | 1713c946 | Antony Chazapis | # Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 1713c946 | Antony Chazapis | #
|
3 | 1713c946 | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | 1713c946 | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | 1713c946 | Antony Chazapis | # conditions are met:
|
6 | 1713c946 | Antony Chazapis | #
|
7 | 1713c946 | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | 1713c946 | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | 1713c946 | Antony Chazapis | # disclaimer.
|
10 | 1713c946 | Antony Chazapis | #
|
11 | 1713c946 | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | 1713c946 | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | 1713c946 | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | 1713c946 | Antony Chazapis | # provided with the distribution.
|
15 | 1713c946 | Antony Chazapis | #
|
16 | 1713c946 | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 1713c946 | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 1713c946 | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 1713c946 | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 1713c946 | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 1713c946 | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 1713c946 | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 1713c946 | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 1713c946 | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 1713c946 | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 1713c946 | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 1713c946 | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 1713c946 | Antony Chazapis | #
|
29 | 1713c946 | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | 1713c946 | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | 1713c946 | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | 1713c946 | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | 1713c946 | Antony Chazapis | |
34 | 1713c946 | Antony Chazapis | import re |
35 | 1713c946 | Antony Chazapis | |
36 | 1713c946 | Antony Chazapis | |
37 | 3d13f97a | Sofia Papagiannaki | _regexfilter = re.compile('(!?)\s*(.+)\s*(=|!=|<=|>=|<|>)?\s*(.*)$', re.UNICODE)
|
38 | 1713c946 | Antony Chazapis | |
39 | 1713c946 | Antony Chazapis | |
40 | 1713c946 | Antony Chazapis | def parse_filters(terms): |
41 | 1713c946 | Antony Chazapis | included = [] |
42 | 1713c946 | Antony Chazapis | excluded = [] |
43 | 1713c946 | Antony Chazapis | opers = [] |
44 | 1713c946 | Antony Chazapis | match = _regexfilter.match |
45 | 1713c946 | Antony Chazapis | for term in terms: |
46 | 1713c946 | Antony Chazapis | m = match(term) |
47 | 1713c946 | Antony Chazapis | if m is None: |
48 | 1713c946 | Antony Chazapis | continue
|
49 | 1713c946 | Antony Chazapis | neg, key, op, value = m.groups() |
50 | 1713c946 | Antony Chazapis | if neg:
|
51 | 1713c946 | Antony Chazapis | excluded.append(key) |
52 | 1713c946 | Antony Chazapis | elif not value: |
53 | 1713c946 | Antony Chazapis | included.append(key) |
54 | 1713c946 | Antony Chazapis | elif op:
|
55 | 1713c946 | Antony Chazapis | opers.append((key, op, value)) |
56 | 1713c946 | Antony Chazapis | |
57 | 1713c946 | Antony Chazapis | return included, excluded, opers |