diff --git a/setools/diff/bounds.py b/setools/diff/bounds.py index a46ebec..e0d3799 100644 --- a/setools/diff/bounds.py +++ b/setools/diff/bounds.py @@ -95,6 +95,8 @@ class BoundsWrapper(Wrapper): """Wrap *bounds for diff purposes.""" + __slots__ = ("ruletype", "parent", "child") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype diff --git a/setools/diff/conditional.py b/setools/diff/conditional.py index 95a620e..f72cd31 100644 --- a/setools/diff/conditional.py +++ b/setools/diff/conditional.py @@ -23,6 +23,8 @@ class ConditionalExprWrapper(Wrapper): """Wrap conditional policy expressions to allow comparisons by truth table.""" + __slots__ = ("truth_table") + def __init__(self, cond): self.origin = cond self.truth_table = cond.truth_table() diff --git a/setools/diff/constraints.py b/setools/diff/constraints.py index 5db2d8e..ff064f6 100644 --- a/setools/diff/constraints.py +++ b/setools/diff/constraints.py @@ -186,6 +186,8 @@ class ConstraintWrapper(Wrapper): """Wrap constraints for diff purposes.""" + __slots__ = ("ruletype", "tclass", "perms", "expr") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype diff --git a/setools/diff/context.py b/setools/diff/context.py index 4124aff..79f5b22 100644 --- a/setools/diff/context.py +++ b/setools/diff/context.py @@ -26,6 +26,8 @@ class ContextWrapper(Wrapper): """Wrap contexts to allow comparisons.""" + __slots__ = ("user", "role", "type_", "range_") + def __init__(self, ctx): self.origin = ctx self.user = SymbolWrapper(ctx.user) diff --git a/setools/diff/default.py b/setools/diff/default.py index ce7c569..714f3c4 100644 --- a/setools/diff/default.py +++ b/setools/diff/default.py @@ -96,6 +96,8 @@ class DefaultWrapper(Wrapper): """Wrap default_* to allow comparisons.""" + __slots__ = ("ruletype", "tclass") + def __init__(self, default): self.origin = default self.ruletype = default.ruletype diff --git a/setools/diff/difference.py b/setools/diff/difference.py index f3cde8a..7e4742c 100644 --- a/setools/diff/difference.py +++ b/setools/diff/difference.py @@ -133,9 +133,10 @@ class Wrapper(object): """Base class for policy object wrappers.""" - origin = None + __slots__ = ("origin", "key") def __repr__(self): + # pylint: disable=no-member return "<{0.__class__.__name__}(Wrapping {1})>".format(self, repr(self.origin)) def __hash__(self): @@ -159,12 +160,15 @@ class SymbolWrapper(Wrapper): on its name. """ + __slots__ = ("name") + def __init__(self, symbol): self.origin = symbol self.name = str(symbol) + self.key = hash(self.name) def __hash__(self): - return hash(self.name) + return self.key def __lt__(self, other): return self.name < other.name diff --git a/setools/diff/fsuse.py b/setools/diff/fsuse.py index 3a0c0e1..732ec0e 100644 --- a/setools/diff/fsuse.py +++ b/setools/diff/fsuse.py @@ -72,6 +72,8 @@ class FSUseWrapper(Wrapper): """Wrap fs_use_* rules to allow set operations.""" + __slots__ = ("ruletype", "fs", "context") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype diff --git a/setools/diff/genfscon.py b/setools/diff/genfscon.py index 24f0a7d..fd7d8e6 100644 --- a/setools/diff/genfscon.py +++ b/setools/diff/genfscon.py @@ -72,6 +72,8 @@ class GenfsconWrapper(Wrapper): """Wrap genfscon rules to allow set operations.""" + __slots__ = ("fs", "path", "filetype", "context") + def __init__(self, rule): self.origin = rule self.fs = rule.fs diff --git a/setools/diff/mls.py b/setools/diff/mls.py index efd758f..a1550ce 100644 --- a/setools/diff/mls.py +++ b/setools/diff/mls.py @@ -169,6 +169,8 @@ class LevelDeclWrapper(Wrapper): """Wrap level declarations to allow comparisons.""" + __slots__ = ("sensitivity") + def __init__(self, level): self.origin = level self.sensitivity = SymbolWrapper(level.sensitivity) @@ -190,6 +192,8 @@ class LevelWrapper(Wrapper): """Wrap levels to allow comparisons.""" + __slots__ = ("sensitivity", "categories") + def __init__(self, level): self.origin = level self.sensitivity = SymbolWrapper(level.sensitivity) @@ -215,6 +219,8 @@ class RangeWrapper(Wrapper): to levels between the low and high levels of the range. """ + __slots__ = ("low", "high") + def __init__(self, range_): self.origin = range_ self.low = LevelWrapper(range_.low) diff --git a/setools/diff/mlsrules.py b/setools/diff/mlsrules.py index beb7517..47bd97d 100644 --- a/setools/diff/mlsrules.py +++ b/setools/diff/mlsrules.py @@ -104,6 +104,8 @@ class MLSRuleWrapper(Wrapper): """Wrap MLS rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target", "tclass") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype diff --git a/setools/diff/netifcon.py b/setools/diff/netifcon.py index 8a2b9e3..8ae39cd 100644 --- a/setools/diff/netifcon.py +++ b/setools/diff/netifcon.py @@ -87,6 +87,8 @@ class NetifconWrapper(Wrapper): """Wrap netifcon statements for diff purposes.""" + __slots__ = ("netif") + def __init__(self, ocon): self.origin = ocon self.netif = ocon.netif diff --git a/setools/diff/nodecon.py b/setools/diff/nodecon.py index 6e94c9e..3b09d17 100644 --- a/setools/diff/nodecon.py +++ b/setools/diff/nodecon.py @@ -71,6 +71,8 @@ class NodeconWrapper(Wrapper): """Wrap nodecon statements for diff purposes.""" + __slots__ = ("ip_version", "address", "netmask") + def __init__(self, ocon): self.origin = ocon self.ip_version = ocon.ip_version diff --git a/setools/diff/portcon.py b/setools/diff/portcon.py index 17df377..02b82c1 100644 --- a/setools/diff/portcon.py +++ b/setools/diff/portcon.py @@ -71,6 +71,8 @@ class PortconWrapper(Wrapper): """Wrap portcon statements for diff purposes.""" + __slots__ = ("protocol", "low", "high") + def __init__(self, ocon): self.origin = ocon self.protocol = ocon.protocol diff --git a/setools/diff/rbacrules.py b/setools/diff/rbacrules.py index 95b15c4..2ab1687 100644 --- a/setools/diff/rbacrules.py +++ b/setools/diff/rbacrules.py @@ -123,6 +123,8 @@ class RoleAllowWrapper(Wrapper): """Wrap role allow rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype @@ -146,6 +148,8 @@ class RoleTransitionWrapper(Wrapper): """Wrap role_transition rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target", "tclass") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype diff --git a/setools/diff/terules.py b/setools/diff/terules.py index 85c2230..282b7ff 100644 --- a/setools/diff/terules.py +++ b/setools/diff/terules.py @@ -297,6 +297,8 @@ class AVRuleWrapper(Wrapper): """Wrap access vector rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target", "tclass", "conditional", "conditional_block") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype @@ -332,6 +334,8 @@ class AVRuleXpermWrapper(Wrapper): """Wrap extended permission access vector rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target", "tclass", "xperm_type") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype @@ -360,6 +364,9 @@ class TERuleWrapper(Wrapper): """Wrap type_* rules to allow set operations.""" + __slots__ = ("ruletype", "source", "target", "tclass", "conditional", "conditional_block", + "filename") + def __init__(self, rule): self.origin = rule self.ruletype = rule.ruletype