aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2025-08-06 17:58:10 +0100
committerTomasz Kramkowski <tomasz@kramkow.ski>2025-08-06 18:42:41 +0100
commit8eab4299c93014613dbadfee6770535b99d48746 (patch)
tree25f2a82d41ec7f78724b4821040873a83c64f9ff
parent581208b2ffeeb2a2128aee0741fa3fd9e46358e2 (diff)
downloadkutter-8eab4299c93014613dbadfee6770535b99d48746.tar.gz
kutter-8eab4299c93014613dbadfee6770535b99d48746.tar.xz
kutter-8eab4299c93014613dbadfee6770535b99d48746.zip
Remove python2 support (first party)
-rw-r--r--klippy/configfile.py17
-rw-r--r--klippy/extras/virtual_sdcard.py7
-rw-r--r--klippy/util.py22
-rw-r--r--klippy/webhooks.py23
4 files changed, 9 insertions, 60 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py
index 3ddfe0d3..e8ede0c3 100644
--- a/klippy/configfile.py
+++ b/klippy/configfile.py
@@ -3,7 +3,7 @@
# Copyright (C) 2016-2024 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import sys, os, glob, re, time, logging, configparser, io
+import os, glob, re, time, logging, configparser, io
error = configparser.Error
@@ -263,19 +263,12 @@ class ConfigFileReader:
if pos >= 0:
lines[i] = line[:pos]
sbuffer = io.StringIO("\n".join(lines))
- if sys.version_info.major >= 3:
- fileconfig.read_file(sbuffer, filename)
- else:
- fileconfig.readfp(sbuffer, filename)
+ fileconfig.read_file(sbuffer, filename)
def _create_fileconfig(self):
- if sys.version_info.major >= 3:
- fileconfig = configparser.RawConfigParser(
- strict=False, inline_comment_prefixes=(";", "#")
- )
- else:
- fileconfig = configparser.RawConfigParser()
- return fileconfig
+ return configparser.RawConfigParser(
+ strict=False, inline_comment_prefixes=(";", "#")
+ )
def build_fileconfig(self, data, filename):
fileconfig = self._create_fileconfig()
diff --git a/klippy/extras/virtual_sdcard.py b/klippy/extras/virtual_sdcard.py
index aca257ea..85dd3616 100644
--- a/klippy/extras/virtual_sdcard.py
+++ b/klippy/extras/virtual_sdcard.py
@@ -3,7 +3,7 @@
# Copyright (C) 2018-2024 Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
-import os, sys, logging, io
+import os, logging, io
VALID_GCODE_EXTS = ["gcode", "g", "gco"]
@@ -305,10 +305,7 @@ class VirtualSD:
# Dispatch command
self.cmd_from_sd = True
line = lines.pop()
- if sys.version_info.major >= 3:
- next_file_position = self.file_position + len(line.encode()) + 1
- else:
- next_file_position = self.file_position + len(line) + 1
+ next_file_position = self.file_position + len(line.encode()) + 1
self.next_file_position = next_file_position
try:
self.gcode.run_script(line)
diff --git a/klippy/util.py b/klippy/util.py
index 43a2becc..b43a7f1c 100644
--- a/klippy/util.py
+++ b/klippy/util.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 sys, os, pty, fcntl, termios, signal, logging, json, time
+import os, pty, fcntl, termios, signal, logging, json, time
import subprocess, traceback, shlex
@@ -100,26 +100,6 @@ 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 ConfigParser, Queue, io, StringIO, time
-
- sys.modules["configparser"] = ConfigParser
- sys.modules["queue"] = Queue
- io.StringIO = StringIO.StringIO
- time.process_time = time.clock
-
-
-setup_python2_wrappers()
-
-
-######################################################################
# General system and software information
######################################################################
diff --git a/klippy/webhooks.py b/klippy/webhooks.py
index 1a471a93..64abe2b2 100644
--- a/klippy/webhooks.py
+++ b/klippy/webhooks.py
@@ -11,32 +11,11 @@ try:
except ImportError:
import json
- # Json decodes strings as unicode types in Python 2.x. This doesn't
- # play well with some parts of Klipper (particularly displays), so we
- # need to create an object hook. This solution borrowed from:
- #
- # https://stackoverflow.com/questions/956867/
- #
- json_loads_byteify = None
- if sys.version_info.major < 3:
-
- def json_loads_byteify(data, ignore_dicts=False):
- if isinstance(data, unicode):
- return data.encode("utf-8")
- if isinstance(data, list):
- return [json_loads_byteify(i, True) for i in data]
- if isinstance(data, dict) and not ignore_dicts:
- return {
- json_loads_byteify(k, True): json_loads_byteify(v, True)
- for k, v in data.items()
- }
- return data
-
def json_dumps(obj):
return json.dumps(obj, separators=(",", ":")).encode()
def json_loads(data):
- return json.loads(data, object_hook=json_loads_byteify)
+ return json.loads(data)
else:
json_dumps = msgspec.json.encode