mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 06:16:03 +00:00
Ensure all None comparisons use is
or is not
.
This commit is contained in:
@@ -100,7 +100,7 @@ if __name__ == "__main__":
|
||||
|
||||
apparmor.easyprof.print_files(files)
|
||||
sys.exit(0)
|
||||
elif binary == None and not options.profile_name and \
|
||||
elif binary is None and not options.profile_name and \
|
||||
not options.manifest:
|
||||
error("Must specify binary and/or profile name\n%s" % m)
|
||||
|
||||
|
@@ -340,7 +340,7 @@ class AppArmorEasyProfile:
|
||||
self.set_policygroup(opt.policy_groups)
|
||||
if opt.name:
|
||||
self.set_name(opt.name)
|
||||
elif self.binary != None:
|
||||
elif self.binary is not None:
|
||||
self.set_name(self.binary)
|
||||
|
||||
self.templates = []
|
||||
@@ -445,7 +445,7 @@ class AppArmorEasyProfile:
|
||||
elif inc_p is not None and os.path.exists(inc_p):
|
||||
p = inc_p
|
||||
|
||||
if self.policy_groups == None or not p in self.policy_groups:
|
||||
if self.policy_groups is None or not p in self.policy_groups:
|
||||
raise AppArmorException("Policy group '%s' does not exist" % p)
|
||||
with open(p) as f:
|
||||
return f.read()
|
||||
@@ -453,7 +453,7 @@ class AppArmorEasyProfile:
|
||||
def set_policygroup(self, policygroups):
|
||||
'''Set policygroups'''
|
||||
self.policy_groups = []
|
||||
if policygroups != None:
|
||||
if policygroups is not None:
|
||||
for p in policygroups.split(','):
|
||||
# If have abs path, just use it
|
||||
if p.startswith('/'):
|
||||
@@ -573,20 +573,20 @@ class AppArmorEasyProfile:
|
||||
policy = re.sub(r'###NAME###', name, policy)
|
||||
|
||||
# Fill-in various comment fields
|
||||
if comment != None:
|
||||
if comment is not None:
|
||||
policy = re.sub(r'###COMMENT###', "Comment: %s" % comment, policy)
|
||||
|
||||
if author != None:
|
||||
if author is not None:
|
||||
policy = re.sub(r'###AUTHOR###', "Author: %s" % author, policy)
|
||||
|
||||
if copyright != None:
|
||||
if copyright is not None:
|
||||
policy = re.sub(r'###COPYRIGHT###', "Copyright: %s" % copyright, policy)
|
||||
|
||||
# Fill-in rules and variables with proper indenting
|
||||
search = '###ABSTRACTIONS###'
|
||||
prefix = find_prefix(policy, search)
|
||||
s = "%s# No abstractions specified" % prefix
|
||||
if abstractions != None:
|
||||
if abstractions is not None:
|
||||
s = "%s# Specified abstractions" % (prefix)
|
||||
t = abstractions.split(',')
|
||||
t.sort()
|
||||
@@ -597,7 +597,7 @@ class AppArmorEasyProfile:
|
||||
search = '###POLICYGROUPS###'
|
||||
prefix = find_prefix(policy, search)
|
||||
s = "%s# No policy groups specified" % prefix
|
||||
if policy_groups != None:
|
||||
if policy_groups is not None:
|
||||
s = "%s# Rules specified via policy groups" % (prefix)
|
||||
t = policy_groups.split(',')
|
||||
t.sort()
|
||||
@@ -869,7 +869,7 @@ def parse_args(args=None, parser=None):
|
||||
'''Parse arguments'''
|
||||
global DEBUGGING
|
||||
|
||||
if parser == None:
|
||||
if parser is None:
|
||||
parser = optparse.OptionParser()
|
||||
|
||||
parser.add_option("-c", "--config-file",
|
||||
@@ -1102,11 +1102,11 @@ def verify_options(opt, strict=False):
|
||||
'''Make sure our options are valid'''
|
||||
if hasattr(opt, 'binary') and opt.binary and not valid_path(opt.binary):
|
||||
raise AppArmorException("Invalid binary '%s'" % opt.binary)
|
||||
if hasattr(opt, 'profile_name') and opt.profile_name != None and \
|
||||
if hasattr(opt, 'profile_name') and opt.profile_name is not None and \
|
||||
not valid_profile_name(opt.profile_name):
|
||||
raise AppArmorException("Invalid profile name '%s'" % opt.profile_name)
|
||||
if hasattr(opt, 'binary') and opt.binary and \
|
||||
hasattr(opt, 'profile_name') and opt.profile_name != None and \
|
||||
hasattr(opt, 'profile_name') and opt.profile_name is not None and \
|
||||
opt.profile_name.startswith('/'):
|
||||
raise AppArmorException("Profile name should not specify path with binary")
|
||||
if hasattr(opt, 'policy_vendor') and opt.policy_vendor and \
|
||||
|
@@ -73,7 +73,7 @@ class FileRule(BaseRule):
|
||||
perms, tmp_exec_perms = split_perms(perms, deny)
|
||||
if tmp_exec_perms:
|
||||
raise AppArmorBug('perms must not contain exec perms')
|
||||
elif perms == None:
|
||||
elif perms is None:
|
||||
perms = set()
|
||||
|
||||
if perms == {'subset'}:
|
||||
|
@@ -41,7 +41,7 @@ def check_requirements(binary):
|
||||
|
||||
def parse_args(args=None, parser=None):
|
||||
'''Parse arguments'''
|
||||
if parser == None:
|
||||
if parser is None:
|
||||
parser = optparse.OptionParser()
|
||||
|
||||
parser.add_option('-X', '--with-x',
|
||||
@@ -113,7 +113,7 @@ def set_environ(env):
|
||||
|
||||
def aa_exec(command, opt, environ={}, verify_rules=[]):
|
||||
'''Execute binary under specified policy'''
|
||||
if opt.profile != None:
|
||||
if opt.profile is not None:
|
||||
policy_name = opt.profile
|
||||
else:
|
||||
opt.ensure_value("template_var", None)
|
||||
@@ -390,7 +390,7 @@ class SandboxXpra(SandboxXserver):
|
||||
|
||||
xvfb_args = []
|
||||
|
||||
if self.driver == None:
|
||||
if self.driver is None:
|
||||
# The default from the man page, but be explicit in what we enable
|
||||
xvfb_args.append('--xvfb=Xvfb')
|
||||
xvfb_args.append('-screen 0 3840x2560x24+32')
|
||||
|
@@ -33,7 +33,7 @@ class Install(_install):
|
||||
super().run()
|
||||
|
||||
prefix = self.prefix
|
||||
if self.root != None:
|
||||
if self.root is not None:
|
||||
prefix = self.root
|
||||
|
||||
# Install scripts, configuration files and data
|
||||
|
@@ -282,7 +282,7 @@ TEMPLATES_DIR="%s/templates"
|
||||
# no fallback
|
||||
self.assertTrue(easyp.dirs['policygroups'] == rel, "Not using specified --policy-groups-dir\n" +
|
||||
"Specified dir: %s\nActual dir: %s" % (rel, str(easyp.dirs['policygroups'])))
|
||||
self.assertFalse(easyp.get_policy_groups() == None, "Could not find policy-groups")
|
||||
self.assertFalse(easyp.get_policy_groups() is None, "Could not find policy-groups")
|
||||
|
||||
def test_policygroups_dir_nonexistent(self):
|
||||
'''Test --policy-groups-dir (nonexistent DIR)'''
|
||||
@@ -298,7 +298,7 @@ TEMPLATES_DIR="%s/templates"
|
||||
self.assertFalse(easyp.dirs['policygroups'] == rel, "Using nonexistent --policy-groups-dir")
|
||||
|
||||
# test fallback
|
||||
self.assertTrue(easyp.get_policy_groups() != None, "Found policy-groups when shouldn't have")
|
||||
self.assertTrue(easyp.get_policy_groups() is not None, "Found policy-groups when shouldn't have")
|
||||
|
||||
def test_policygroups_dir_valid(self):
|
||||
'''Test --policy-groups-dir (valid DIR)'''
|
||||
@@ -314,7 +314,7 @@ TEMPLATES_DIR="%s/templates"
|
||||
|
||||
# no fallback
|
||||
self.assertTrue(easyp.dirs['policygroups'] == valid, "Not using specified --policy-groups-dir")
|
||||
self.assertFalse(easyp.get_policy_groups() == None, "Could not find policy-groups")
|
||||
self.assertFalse(easyp.get_policy_groups() is None, "Could not find policy-groups")
|
||||
|
||||
def test_policygroups_dir_valid_with_vendor(self):
|
||||
'''Test --policy-groups-dir (valid DIR with vendor)'''
|
||||
@@ -336,7 +336,7 @@ TEMPLATES_DIR="%s/templates"
|
||||
easyp = easyprof.AppArmorEasyProfile(self.binary, self.options)
|
||||
|
||||
self.assertTrue(easyp.dirs['policygroups'] == valid, "Not using specified --policy-groups-dir")
|
||||
self.assertFalse(easyp.get_policy_groups() == None, "Could not find policy-groups")
|
||||
self.assertFalse(easyp.get_policy_groups() is None, "Could not find policy-groups")
|
||||
for f in easyp.get_policy_groups():
|
||||
self.assertFalse(os.path.basename(f) == vendor, "Found '%s' in %s" % (vendor, f))
|
||||
|
||||
@@ -409,7 +409,7 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
# no fallback
|
||||
self.assertTrue(easyp.dirs['templates'] == rel, "Not using specified --template-dir\n" +
|
||||
"Specified dir: %s\nActual dir: %s" % (rel, str(easyp.dirs['templates'])))
|
||||
self.assertFalse(easyp.get_templates() == None, "Could not find templates")
|
||||
self.assertFalse(easyp.get_templates() is None, "Could not find templates")
|
||||
|
||||
def test_templates_dir_nonexistent(self):
|
||||
'''Test --templates-dir (nonexistent DIR)'''
|
||||
@@ -425,7 +425,7 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
self.assertFalse(easyp.dirs['templates'] == rel, "Using nonexistent --template-dir")
|
||||
|
||||
# test fallback
|
||||
self.assertTrue(easyp.get_templates() != None, "Found templates when shouldn't have")
|
||||
self.assertTrue(easyp.get_templates() is not None, "Found templates when shouldn't have")
|
||||
|
||||
def test_templates_dir_valid(self):
|
||||
'''Test --templates-dir (valid DIR)'''
|
||||
@@ -441,7 +441,7 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
|
||||
# no fallback
|
||||
self.assertTrue(easyp.dirs['templates'] == valid, "Not using specified --template-dir")
|
||||
self.assertFalse(easyp.get_templates() == None, "Could not find templates")
|
||||
self.assertFalse(easyp.get_templates() is None, "Could not find templates")
|
||||
|
||||
def test_templates_dir_valid_with_vendor(self):
|
||||
'''Test --templates-dir (valid DIR with vendor)'''
|
||||
@@ -463,7 +463,7 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
easyp = easyprof.AppArmorEasyProfile(self.binary, self.options)
|
||||
|
||||
self.assertTrue(easyp.dirs['templates'] == valid, "Not using specified --template-dir")
|
||||
self.assertFalse(easyp.get_templates() == None, "Could not find templates")
|
||||
self.assertFalse(easyp.get_templates() is None, "Could not find templates")
|
||||
for f in easyp.get_templates():
|
||||
self.assertFalse(os.path.basename(f) == vendor, "Found '%s' in %s" % (vendor, f))
|
||||
|
||||
@@ -772,12 +772,12 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
# Build up our args
|
||||
args = self.full_args
|
||||
|
||||
if template == None:
|
||||
if template is None:
|
||||
args.append('--template=%s' % self.test_template)
|
||||
else:
|
||||
args.append('--template=%s' % template)
|
||||
|
||||
if name != None:
|
||||
if name is not None:
|
||||
args.append('--name=%s' % name)
|
||||
|
||||
if len(extra_args) > 0:
|
||||
@@ -793,10 +793,10 @@ POLICYGROUPS_DIR="%s/templates"
|
||||
|
||||
# We always need to check for these
|
||||
search_terms = [self.binary]
|
||||
if name != None:
|
||||
if name is not None:
|
||||
search_terms.append(name)
|
||||
|
||||
if template == None:
|
||||
if template is None:
|
||||
search_terms.append(self.test_template)
|
||||
|
||||
for s in search_terms:
|
||||
|
Reference in New Issue
Block a user