From cc9cf967b279f81d3d225dc5d9cf4ff3a7a71999 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Wed, 28 Oct 2015 22:52:07 +0100 Subject: [PATCH] Add (abstract) get_clean() method to baserule Also add a test to ensure it raises an AppArmorBug. Acked-by: Kshitij Gupta --- utils/apparmor/rule/__init__.py | 5 +++++ utils/test/test-baserule.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/utils/apparmor/rule/__init__.py b/utils/apparmor/rule/__init__.py index 3150600dd..27cd4b35b 100644 --- a/utils/apparmor/rule/__init__.py +++ b/utils/apparmor/rule/__init__.py @@ -81,6 +81,11 @@ class BaseRule(object): required to be implemented by subclasses; raise exception if not''' raise AppArmorBug("'%s' needs to implement _parse(), but didn't" % (str(cls))) + # @abstractmethod FIXME - uncomment when python3 only + def get_clean(self, depth=0): + '''return clean rule (with default formatting, and leading whitespace as specified in the depth parameter)''' + raise AppArmorBug("'%s' needs to implement get_clean(), but didn't" % (str(self.__class__))) + def get_raw(self, depth=0): '''return raw rule (with original formatting, and leading whitespace in the depth parameter)''' if self.raw_rule: diff --git a/utils/test/test-baserule.py b/utils/test/test-baserule.py index 74fd4a195..b5b3ba66f 100644 --- a/utils/test/test-baserule.py +++ b/utils/test/test-baserule.py @@ -35,6 +35,11 @@ class TestBaserule(AATest): with self.assertRaises(AppArmorBug): BaseRule.match('foo') + def test_abstract_get_clean(self): + obj = BaseRule() + with self.assertRaises(AppArmorBug): + obj.get_clean() + def test_is_equal_localvars(self): obj = BaseRule() with self.assertRaises(AppArmorBug):