1
# Copyright (c) 2011 OpenStack, LLC.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
18
# 1. The following operations are supported:
19
# =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
20
# 2. Note that <or> is handled in a different way below.
21
# 3. If the first word in the extra_specs is not one of the operators,
23
_op_methods = {'=': lambda x, y: float(x) >= float(y),
24
'<in>': lambda x, y: y in x,
25
'==': lambda x, y: float(x) == float(y),
26
'!=': lambda x, y: float(x) != float(y),
27
'>=': lambda x, y: float(x) >= float(y),
28
'<=': lambda x, y: float(x) <= float(y),
37
def match(value, req):
43
method = _op_methods.get(op)
45
if op != '<or>' and not method:
51
if op == '<or>': # Ex: <or> v1 <or> v2 <or> v3
53
if words.pop(0) == value:
57
op = words.pop(0) # remove a keyword <or>
62
if words and method(value, words[0]):