aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--klippy/configfile.py8
-rw-r--r--klippy/extras/save_variables.py2
-rw-r--r--klippy/extras/statistics.py2
-rw-r--r--klippy/queuelogger.py2
-rw-r--r--klippy/reactor.py2
-rw-r--r--klippy/util.py21
6 files changed, 29 insertions, 8 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py
index 0c4f8ba7..71f5ca60 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 as configparser, StringIO
+import os, glob, re, time, logging, configparser, io
error = configparser.Error
@@ -211,7 +211,7 @@ class PrinterConfig:
return
data = '\n'.join(buffer)
del buffer[:]
- sbuffer = StringIO.StringIO(data)
+ sbuffer = io.StringIO(data)
fileconfig.readfp(sbuffer, filename)
def _resolve_include(self, source_filename, include_spec, fileconfig,
visited):
@@ -255,11 +255,11 @@ class PrinterConfig:
self._parse_config_buffer(buffer, filename, fileconfig)
visited.remove(path)
def _build_config_wrapper(self, data, filename):
- fileconfig = configparser.RawConfigParser()
+ fileconfig = configparser.RawConfigParser(strict=False)
self._parse_config(data, filename, fileconfig, set())
return ConfigWrapper(self.printer, fileconfig, {}, 'printer')
def _build_config_string(self, config):
- sfile = StringIO.StringIO()
+ sfile = io.StringIO()
config.fileconfig.write(sfile)
return sfile.getvalue().strip()
def read_config(self, filename):
diff --git a/klippy/extras/save_variables.py b/klippy/extras/save_variables.py
index f15dbc11..3765a1ae 100644
--- a/klippy/extras/save_variables.py
+++ b/klippy/extras/save_variables.py
@@ -4,7 +4,7 @@
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import os, logging, ast, ConfigParser as configparser
+import os, logging, ast, configparser
class SaveVariables:
def __init__(self, config):
diff --git a/klippy/extras/statistics.py b/klippy/extras/statistics.py
index 641396a3..d9c0a367 100644
--- a/klippy/extras/statistics.py
+++ b/klippy/extras/statistics.py
@@ -23,7 +23,7 @@ class PrinterSysStats:
self.mem_file = None
def stats(self, eventtime):
# Get core usage stats
- ptime = time.clock()
+ ptime = time.process_time()
pdiff = ptime - self.last_process_time
self.last_process_time = ptime
if pdiff > 0.:
diff --git a/klippy/queuelogger.py b/klippy/queuelogger.py
index 8fa98a6b..c6447f8e 100644
--- a/klippy/queuelogger.py
+++ b/klippy/queuelogger.py
@@ -3,7 +3,7 @@
# Copyright (C) 2016-2019 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import logging, logging.handlers, threading, Queue as queue, time
+import logging, logging.handlers, threading, queue, time
# Class to forward all messages through a queue to a background thread
class QueueHandler(logging.Handler):
diff --git a/klippy/reactor.py b/klippy/reactor.py
index dd083a07..69eedcbd 100644
--- a/klippy/reactor.py
+++ b/klippy/reactor.py
@@ -3,7 +3,7 @@
# Copyright (C) 2016-2020 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import os, gc, select, math, time, logging, Queue as queue
+import os, gc, select, math, time, logging, queue
import greenlet
import chelper, util
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
######################################################################