From 574edcf7206642115a68f390cfafc771deaefd97 Mon Sep 17 00:00:00 2001 From: Georgia Kokkinou Date: Thu, 13 Aug 2020 17:13:31 +0300 Subject: [PATCH] Fix configparser deprecation warnings Use config.read_file() to read configuration from a file instead of config.readfp(), which is deprecated. Also, use ConfigParser instead of SafeConfigParser, which is an alias that will be removed in future Python versions. --- publish2cloud.py | 2 +- tests/test_lists2safebrowsing.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/publish2cloud.py b/publish2cloud.py index 95e75de..8d7f1a4 100644 --- a/publish2cloud.py +++ b/publish2cloud.py @@ -22,7 +22,7 @@ ) from packaging import version as p_version -CONFIG = configparser.SafeConfigParser(os.environ) +CONFIG = configparser.ConfigParser(os.environ) CONFIG.read(['shavar_list_creation.ini']) try: REMOTE_SETTINGS_URL = '' diff --git a/tests/test_lists2safebrowsing.py b/tests/test_lists2safebrowsing.py index 4db6855..f35f366 100644 --- a/tests/test_lists2safebrowsing.py +++ b/tests/test_lists2safebrowsing.py @@ -554,7 +554,7 @@ def _get_entity_or_plugin_lists(chunknum, config, function, section, data): def test_get_entity_lists(chunknum, section, version, testcase): """Test creating an entity list from a configuration section.""" config = configparser.ConfigParser() - config.readfp(open("sample_shavar_list_creation.ini")) + config.read_file(open("sample_shavar_list_creation.ini")) if version: config.set(section, "version", version) @@ -587,7 +587,7 @@ def test_get_entity_lists(chunknum, section, version, testcase): def test_get_plugin_lists(chunknum): """Test creating a plugin blocklist from a configuration section.""" config = configparser.ConfigParser() - config.readfp(open("sample_shavar_list_creation.ini")) + config.read_file(open("sample_shavar_list_creation.ini")) section = "plugin-blocklist" domains = [d[1] for d in CANONICALIZE_TESTCASES[:2]] @@ -618,7 +618,7 @@ def test_get_plugin_lists(chunknum): def test_get_plugin_lists_empty_url(chunknum): """Test empty blocklist URL handling in get_plugin_lists.""" config = configparser.ConfigParser() - config.readfp(open("sample_shavar_list_creation.ini")) + config.read_file(open("sample_shavar_list_creation.ini")) section = "plugin-blocklist" config.set(section, "blocklist", "") @@ -635,7 +635,7 @@ def test_get_plugin_lists_empty_url(chunknum): def test_get_tracker_lists(parser, chunknum, section, domains, testcase): """Test creating a tracker blocklist from a configuration section.""" config = configparser.ConfigParser() - config.readfp(open("sample_shavar_list_creation.ini")) + config.read_file(open("sample_shavar_list_creation.ini")) version = None if testcase == "default":