Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1Origin: https://github.com/mikeperry-tor/vanguards/pull/105/commits/183d24775521feb3ed61b681088347279c3fc84c
2From: Dave Jones <dave@waveform.org.uk>
3Date: Wed, 28 Aug 2024 12:54:24 +0100
4Subject: [PATCH] Python 3.12 compatibility
5
6Python 3.12 removes the deprecated `SafeConfigParser` class. This patch
7switches the code to using ConfigParser and read_file from Python 3.x,
8and patches 2.7's SafeConfigParser to a compatible definition.
9---
10 src/vanguards/config.py | 11 +++++++----
11 1 file changed, 7 insertions(+), 4 deletions(-)
12
13diff --git a/src/vanguards/config.py b/src/vanguards/config.py
14index 1c33391..b8e3f9c 100644
15--- a/src/vanguards/config.py
16+++ b/src/vanguards/config.py
17@@ -16,9 +16,12 @@
18 from .logger import plog
19
20 try:
21- from configparser import SafeConfigParser, Error
22+ from configparser import ConfigParser, Error
23 except ImportError:
24 from ConfigParser import SafeConfigParser, Error
25+ class ConfigParser(SafeConfigParser):
26+ def read_file(self, f, source=None):
27+ return self.readfp(f, source)
28
29 ################# Global options ##################
30
31@@ -209,7 +212,7 @@ def set_options_from_module(config, module, section):
32 config.set(section, param, str(val))
33
34 def generate_config():
35- config = SafeConfigParser(allow_no_value=True)
36+ config = ConfigParser(allow_no_value=True)
37 set_options_from_module(config, sys.modules[__name__], "Global")
38 set_options_from_module(config, vanguards, "Vanguards")
39 set_options_from_module(config, bandguards, "Bandguards")
40@@ -219,9 +222,9 @@ def generate_config():
41 return config
42
43 def apply_config(config_file):
44- config = SafeConfigParser(allow_no_value=True)
45+ config = ConfigParser(allow_no_value=True)
46
47- config.readfp(open(config_file, "r"))
48+ config.read_file(open(config_file, "r"))
49
50 get_options_for_module(config, sys.modules[__name__], "Global")
51 get_options_for_module(config, vanguards, "Vanguards")