1 # Copyright 2014-2015, Tresys Technology, LLC 2 # 3 # This file is part of SETools. 4 # 5 # SETools is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU Lesser General Public License as 7 # published by the Free Software Foundation, either version 2.1 of 8 # the License, or (at your option) any later version. 9 # 10 # SETools is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU Lesser General Public License for more details. 14 # 15 # You should have received a copy of the GNU Lesser General Public 16 # License along with SETools. If not, see 17 # <http://www.gnu.org/licenses/>. 18 # 19 # pylint: disable=no-member,attribute-defined-outside-init,abstract-method 20 import re 21 22 from . import query 23 from .descriptors import CriteriaDescriptor 24 25 26 class ComponentQuery(query.PolicyQuery): 27 28 """Base class for SETools component queries.""" 29 30 name = CriteriaDescriptor("name_regex") 31 name_regex = False 32 33 def _match_name(self, obj): 34 """Match the object to the name criteria.""" 35 if not self.name: 36 # if there is no criteria, everything matches. 37 return True 38 39 return self._match_regex(obj, self.name, self.name_regex) 40