diff --git a/os_apply_config/apply_config.py b/os_apply_config/apply_config.py index 697c22c..b14e1f8 100644 --- a/os_apply_config/apply_config.py +++ b/os_apply_config/apply_config.py @@ -113,7 +113,7 @@ def print_key( return else: raise exc.ConfigException( - 'key %s does not exist in %s' % (key, config_path)) + 'key {} does not exist in {}'.format(key, config_path)) value_types.ensure_type(str(config), type_name) if isinstance(config, (dict, list, bool)): print(json.dumps(config)) @@ -349,8 +349,8 @@ def main(argv=sys.argv): opts.metadata = os.environ['OS_CONFIG_FILES'].split(':') else: opts.metadata = load_list_from_json(opts.os_config_files) - if ((not opts.metadata and opts.os_config_files == - OS_CONFIG_FILES_PATH)): + if (not opts.metadata and opts.os_config_files == + OS_CONFIG_FILES_PATH): logger.warning('DEPRECATED: falling back to %s' % OS_CONFIG_FILES_PATH_OLD) opts.metadata = load_list_from_json(OS_CONFIG_FILES_PATH_OLD) diff --git a/os_apply_config/collect_config.py b/os_apply_config/collect_config.py index 35136ba..d58ae0b 100644 --- a/os_apply_config/collect_config.py +++ b/os_apply_config/collect_config.py @@ -27,7 +27,7 @@ def read_configs(config_files): try: with open(input_path) as input_file: yield (input_file.read(), input_path) - except IOError as e: + except OSError as e: raise exc.ConfigException('Could not open %s for reading. %s' % (input_path, e)) diff --git a/os_apply_config/oac_file.py b/os_apply_config/oac_file.py index f341d97..1ea22b7 100644 --- a/os_apply_config/oac_file.py +++ b/os_apply_config/oac_file.py @@ -19,7 +19,7 @@ import pwd from os_apply_config import config_exception as exc -class OacFile(object): +class OacFile: DEFAULTS = { 'allow_empty': True, 'mode': None, @@ -28,7 +28,7 @@ class OacFile(object): } def __init__(self, body, **kwargs): - super(OacFile, self).__init__() + super().__init__() self.body = body for k, v in self.DEFAULTS.items(): @@ -53,7 +53,7 @@ class OacFile(object): for key, default in self.DEFAULTS.items(): value = getattr(self, key) if value != default: - a.append("%s=%s" % (key, repr(value))) + a.append("{}={}".format(key, repr(value))) return ", ".join(a) + ")" def set(self, key, value): diff --git a/os_apply_config/renderers.py b/os_apply_config/renderers.py index 5170870..5d630ac 100644 --- a/os_apply_config/renderers.py +++ b/os_apply_config/renderers.py @@ -33,11 +33,11 @@ class JsonRenderer(pystache.Renderer): return u if escape is None: escape = escape_noop - return super(JsonRenderer, self).__init__(file_encoding, - string_encoding, - decode_errors, search_dirs, - file_extension, escape, - partials, missing_tags) + return super().__init__(file_encoding, + string_encoding, + decode_errors, search_dirs, + file_extension, escape, + partials, missing_tags) def str_coerce(self, val): if val is None: diff --git a/os_apply_config/tests/test_apply_config.py b/os_apply_config/tests/test_apply_config.py index 5a1c5d7..e4b9110 100644 --- a/os_apply_config/tests/test_apply_config.py +++ b/os_apply_config/tests/test_apply_config.py @@ -86,7 +86,7 @@ class TestRunOSConfigApplier(testtools.TestCase): """Tests the commandline options.""" def setUp(self): - super(TestRunOSConfigApplier, self).setUp() + super().setUp() self.useFixture(fixtures.NestedTempfile()) self.stdout = self.useFixture(fixtures.StringStream('stdout')).stream self.useFixture(fixtures.MonkeyPatch('sys.stdout', self.stdout)) @@ -234,7 +234,7 @@ class TestRunOSConfigApplier(testtools.TestCase): class OSConfigApplierTestCase(testtools.TestCase): def setUp(self): - super(OSConfigApplierTestCase, self).setUp() + super().setUp() self.logger = self.useFixture(fixtures.FakeLogger('os-apply-config')) self.useFixture(fixtures.NestedTempfile()) @@ -329,7 +329,7 @@ class OSConfigApplierTestCase(testtools.TestCase): apply_config.render_moustache("ab{{x.a}}cd", {"x": {"a": "123"}})) def test_render_moustache_bad_key(self): - self.assertEqual(u'', apply_config.render_moustache("{{badkey}}", {})) + self.assertEqual('', apply_config.render_moustache("{{badkey}}", {})) def test_render_moustache_none(self): self.assertEqual('foo: ', diff --git a/os_apply_config/tests/test_json_renderer.py b/os_apply_config/tests/test_json_renderer.py index 2b34218..6ebfbdb 100644 --- a/os_apply_config/tests/test_json_renderer.py +++ b/os_apply_config/tests/test_json_renderer.py @@ -35,4 +35,4 @@ class JsonRendererTestCase(testtools.TestCase): self.assertEqual(desire_structure, result_structure) result = x.render('{{a.c}}', context) self.addDetail('result', content.text_content(result)) - self.assertEqual(u'the quick brown fox', result) + self.assertEqual('the quick brown fox', result) diff --git a/os_apply_config/value_types.py b/os_apply_config/value_types.py index 9f9cb90..7d2595d 100644 --- a/os_apply_config/value_types.py +++ b/os_apply_config/value_types.py @@ -39,6 +39,6 @@ def ensure_type(string_value, type_name='default'): "requested validation of unknown type: %s" % type_name) if not re.match(TYPES[type_name], string_value): exception = config_exception.ConfigException - raise exception("cannot interpret value '%s' as type %s" % ( + raise exception("cannot interpret value '{}' as type {}".format( string_value, type_name)) return string_value