diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2021-10-09 19:34:08 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2021-10-09 19:37:48 -0400 |
commit | c56c34fa1c4c8bf7e10448804604edf600fdefa0 (patch) | |
tree | cf34580b682881732564682a765b679dc2ac2228 | |
parent | 21d5a34d220e0d609cc89414d120e8c375d7e394 (diff) | |
download | kutter-c56c34fa1c4c8bf7e10448804604edf600fdefa0.tar.gz kutter-c56c34fa1c4c8bf7e10448804604edf600fdefa0.tar.xz kutter-c56c34fa1c4c8bf7e10448804604edf600fdefa0.zip |
configfile: Use Python2's ConfigParser when running on Python2
The backport of Python3's configparser causes issues when there is
unicode characters in the config file. To avoid introducing new
errors, go back to using the Python2 version of ConfigParser when
running on Python2.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | klippy/configfile.py | 10 | ||||
-rw-r--r-- | klippy/util.py | 3 | ||||
-rw-r--r-- | scripts/klippy-requirements.txt | 1 |
3 files changed, 8 insertions, 6 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py index 518b574b..165e9320 100644 --- a/klippy/configfile.py +++ b/klippy/configfile.py @@ -3,7 +3,7 @@ # Copyright (C) 2016-2021 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. -import os, glob, re, time, logging, configparser, io +import sys, os, glob, re, time, logging, configparser, io error = configparser.Error @@ -255,9 +255,11 @@ class PrinterConfig: self._parse_config_buffer(buffer, filename, fileconfig) visited.remove(path) def _build_config_wrapper(self, data, filename): - cp = (';', '#') - fileconfig = configparser.RawConfigParser( - strict=False, comment_prefixes=cp, inline_comment_prefixes=cp) + if sys.version_info.major >= 3: + fileconfig = configparser.RawConfigParser( + strict=False, inline_comment_prefixes=(';', '#')) + else: + fileconfig = configparser.RawConfigParser() self._parse_config(data, filename, fileconfig, set()) return ConfigWrapper(self.printer, fileconfig, {}, 'printer') def _build_config_string(self, config): diff --git a/klippy/util.py b/klippy/util.py index eabd2263..4f018b0f 100644 --- a/klippy/util.py +++ b/klippy/util.py @@ -98,7 +98,8 @@ def setup_python2_wrappers(): if sys.version_info.major >= 3: return # Add module hacks so that common Python3 module imports work in Python2 - import Queue, io, StringIO, time + import ConfigParser, Queue, io, StringIO, time + sys.modules["configparser"] = ConfigParser sys.modules["queue"] = Queue io.StringIO = StringIO.StringIO time.process_time = time.clock diff --git a/scripts/klippy-requirements.txt b/scripts/klippy-requirements.txt index bdc431ed..77c2b8ef 100644 --- a/scripts/klippy-requirements.txt +++ b/scripts/klippy-requirements.txt @@ -7,4 +7,3 @@ pyserial==3.4 greenlet==1.1.2 Jinja2==2.11.3 python-can==3.3.4 -configparser==4.0.2 |