# Copyright 2016, Tresys Technology, LLC
#
# This file is part of SETools.
#
# SETools is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 2.1 of
# the License, or (at your option) any later version.
#
# SETools is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with SETools.  If not, see
# <http://www.gnu.org/licenses/>.
#
from .difference import SymbolWrapper, Wrapper


class LevelWrapper(Wrapper):

    """Wrap levels to allow comparisons."""

    def __init__(self, level):
        self.origin = level
        self.sensitivity = SymbolWrapper(level.sensitivity)
        self.categories = set(SymbolWrapper(c) for c in level.categories())

    def __eq__(self, other):
        return self.sensitivity == other.sensitivity and \
               self.categories == other.categories


class RangeWrapper(Wrapper):

    """
    Wrap ranges to allow comparisons.

    This only compares the low and high levels of the range.
    It does not detect additions/removals/modifications
    to levels between the low and high levels of the range.
    """

    def __init__(self, range_):
        self.origin = range_
        self.low = LevelWrapper(range_.low)
        self.high = LevelWrapper(range_.high)

    def __eq__(self, other):
        return self.low == other.low and \
               self.high == other.high

@@ -1057,32 +1057,49 @@
 _(self, other):%0A
+        try:%0A    
         return s
@@ -1148,32 +1148,36 @@
 %0A               
+    
 self.categories 
@@ -1196,16 +1196,174 @@
 egories%0A
+        except AttributeError:%0A            # comparing an MLS policy to non-MLS policy will result in%0A            # other being None%0A            return False%0A
 %0A%0Aclass 
@@ -1792,32 +1792,49 @@
 _(self, other):%0A
+        try:%0A    
         return s
@@ -1867,32 +1867,36 @@
 %0A               
+    
 self.high == oth
@@ -1903,8 +1903,166 @@
 er.high%0A
+        except AttributeError:%0A            # comparing an MLS policy to non-MLS policy will result in%0A            # other being None%0A            return False%0A

handle MLS to non-MLS comparisons