+mailing list On Mon, Feb 22, 2016 at 1:07 AM, Kshitij Gupta <[email protected]> wrote:
> Hello, > > On Sun, Dec 27, 2015 at 8:34 PM, Christian Boltz <[email protected]> > wrote: > >> Hello, >> >> some dbus rule conditionals come with optional parenthesis. Instead of >> making the regex even more complicated, use a small function to strip >> those parenthesis. >> >> Also add some tests for strip_parenthesis() to test-regex.py. >> >> >> [ 53-add-strip_parenthesis.diff ] >> >> === modified file ./utils/apparmor/regex.py >> --- utils/apparmor/regex.py 2015-12-21 00:13:57.207799592 +0100 >> +++ utils/apparmor/regex.py 2015-12-24 01:19:47.916978461 +0100 >> @@ -128,6 +128,15 @@ >> >> return matches.group('magicpath') >> >> +def strip_parenthesis(data): >> + '''strips parenthesis from the given string and returns the >> strip()ped result. >> + The parenthesis must be the first and last char, otherwise they >> won't be removed. >> + Even if no parenthesis get removed, the result will be strip()ped. >> + ''' >> + if data[0] + data[-1] == '()': >> + return data[1:-1].strip() >> + else: >> + return data.strip() >> > Might be useful to do the data.strip() before the "data[0] + data[-1] == > '()'" check, that way you don't miss on something like '(hey) '. > This is because there doesn't seem to be a strong assumption that the data > will already be stripped coz we return data.strip() > Also, I don't see any harm in having the .strip before the check. > >> >> def strip_quotes(data): >> if data[0] + data[-1] == '""': >> === modified file ./utils/test/test-regex_matches.py >> --- utils/test/test-regex_matches.py 2015-12-21 00:13:57.207799592 >> +0100 >> +++ utils/test/test-regex_matches.py 2015-12-24 00:56:50.382751188 >> +0100 >> @@ -14,7 +14,7 @@ >> from common_test import AATest, setup_all_loops >> from apparmor.common import AppArmorBug, AppArmorException >> >> -from apparmor.regex import strip_quotes, parse_profile_start_line, >> re_match_include, RE_PROFILE_START, RE_PROFILE_CAP, RE_PROFILE_PTRACE, >> RE_PROFILE_SIGNAL >> +from apparmor.regex import strip_parenthesis, strip_quotes, >> parse_profile_start_line, re_match_include, RE_PROFILE_START, >> RE_PROFILE_CAP, RE_PROFILE_PTRACE, RE_PROFILE_SIGNAL >> >> >> class AARegexTest(AATest): >> @@ -501,6 +501,24 @@ >> re_match_include(params) >> >> >> +class TestStripParenthesis(AATest): >> + tests = [ >> + ('foo', 'foo' ), >> + ('(foo)', 'foo' ), >> + ('( foo )', 'foo' ), >> + ('(foo', '(foo' ), >> + ('foo )', 'foo )' ), >> + ('foo ()', 'foo ()' ), >> + ('()', '' ), >> + ('( )', '' ), >> + ('(())', '()' ), >> + (' (foo)', '(foo)' ), # parenthesis not first char, >> whitespace stripped nevertheless >> + ('(foo) ', '(foo)' ), # parenthesis not last char, >> whitespace stripped nevertheless >> + ] >> + >> + def _run_test(self, params, expected): >> + self.assertEqual(strip_parenthesis(params), expected) >> + >> class TestStripQuotes(AATest): >> def test_strip_quotes_01(self): >> self.assertEqual('foo', strip_quotes('foo')) >> >> >> Regards, >> >> Christian Boltz >> -- >> > Und fuer die Jahre-Hiersein finde ich die zwei Ergebnisse >> > (unechte Mini-FAQ und Etikette) recht duenn!!!!!!!! >> Ich glaub es hackt. Du kannst ja das Geld zurück verlangen, wenn es Dir >> nicht paßt. [> toRBEN pOLLmann und Bernd Brodesser in suse-linux] >> >> -- >> AppArmor mailing list >> [email protected] >> Modify settings or unsubscribe at: >> https://lists.ubuntu.com/mailman/listinfo/apparmor >> >> > > > -- > Regards, > > Kshitij Gupta > -- Regards, Kshitij Gupta
-- AppArmor mailing list [email protected] Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/apparmor
