1 # Copyright 2016, 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 from ..policyrep.exception import MLSDisabled 20 21 from .difference import SymbolWrapper, Wrapper 22 from .mls import RangeWrapper 23 24 25 class ContextWrapper(Wrapper): 26 27 """Wrap contexts to allow comparisons.""" 28 29 def __init__(self, ctx): 30 self.origin = ctx 31 self.user = SymbolWrapper(ctx.user) 32 self.role = SymbolWrapper(ctx.role) 33 self.type_ = SymbolWrapper(ctx.type_) 34 35 try: 36 self.range_ = RangeWrapper(ctx.range_) 37 except MLSDisabled: 38 self.range_ = None 39 40 def __eq__(self, other): 41 return self.user == other.user and \ 42 self.role == other.role and \ 43 self.type_ == other.type_ and \ 44 self.range_ == other.range_ 45