aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/util.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-10-01 19:30:48 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-10-04 14:36:08 -0400
commitf1747b51182cbe4d77c991492b55fd2df12b4c18 (patch)
tree3da8d0349dbc0af81b25ce9c713cb3508cf75aff /klippy/util.py
parentb8c91914b75c23bae05b29c9c0ebf2bff35a9b4a (diff)
downloadkutter-f1747b51182cbe4d77c991492b55fd2df12b4c18.tar.gz
kutter-f1747b51182cbe4d77c991492b55fd2df12b4c18.tar.xz
kutter-f1747b51182cbe4d77c991492b55fd2df12b4c18.zip
klippy: Add Python2 module wrappers and use Python3 module naming
Add wrappers for some common Python modules so that the code can run on both Python2 and Python3. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/util.py')
-rw-r--r--klippy/util.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/klippy/util.py b/klippy/util.py
index 0321014e..6d110e47 100644
--- a/klippy/util.py
+++ b/klippy/util.py
@@ -91,6 +91,27 @@ def dump_mcu_build():
######################################################################
+# Python2 wrapper hacks
+######################################################################
+
+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, ConfigParser, time
+ sys.modules["queue"] = Queue
+ io.StringIO = StringIO.StringIO
+ time.process_time = time.clock
+ sys.modules["configparser"] = ConfigParser
+ OrigRawConfigParser = ConfigParser.RawConfigParser
+ def RCP(strict=False, *args, **kwargs):
+ return OrigRawConfigParser(*args, **kwargs)
+ RCP.SECTCRE = OrigRawConfigParser.SECTCRE
+ ConfigParser.RawConfigParser = RCP
+setup_python2_wrappers()
+
+
+######################################################################
# General system and software information
######################################################################