➕ Use immutabledict instead of frozendict on Py3
frozendict appears to be unmaintained and is incompatible to Python 3.10+ As discussed in #4043
This commit is contained in:
1 parent
84a6b2bfe1
commit
849cea15c1
4 files changed
+38
-16
No files matched your search
@@ -58,7 +58,6 @@ INSTALL_REQUIRES = [
|
||||
"websocket-client>=0.57,<1",
|
||||
"wrapt>=1.12.1,<2",
|
||||
"emoji>=0.5.4,<1",
|
||||
"frozendict>=1.2,<2",
|
||||
"sentry-sdk>=0.15.1,<1",
|
||||
"filetype>=1.0.7,<2",
|
||||
"zipstream-new>=1.1.8,<1.2",
|
||||
@@ -76,10 +75,15 @@ INSTALL_REQUIRES_PYTHON2 = [
|
||||
"chainmap>=1.0.3,<2",
|
||||
"typing>=3.7.4.1,<4",
|
||||
"enum34>=1.1.10,<1.2",
|
||||
"frozendict>=1.2,<2",
|
||||
]
|
||||
|
||||
# Python 3 specific requirements
|
||||
INSTALL_REQUIRES_PYTHON3 = ["feedparser>=6.0.2,<7", "zeroconf>=0.24,<0.25"]
|
||||
INSTALL_REQUIRES_PYTHON3 = [
|
||||
"feedparser>=6.0.2,<7",
|
||||
"zeroconf>=0.24,<0.25",
|
||||
"immutabledict>=1.2.0,<2",
|
||||
]
|
||||
|
||||
# OSX specific requirements
|
||||
INSTALL_REQUIRES_OSX = [
|
||||
|
||||
@@ -15,7 +15,12 @@ import os
|
||||
import threading
|
||||
import time
|
||||
|
||||
from frozendict import frozendict
|
||||
try:
|
||||
from immutabledict import immutabledict
|
||||
except ImportError:
|
||||
# Python 2
|
||||
from frozendict import frozendict as immutabledict
|
||||
|
||||
from past.builtins import basestring, long
|
||||
|
||||
import octoprint.util.json
|
||||
@@ -51,7 +56,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
self._logger_job = logging.getLogger("{}.job".format(__name__))
|
||||
|
||||
self._dict = (
|
||||
frozendict
|
||||
immutabledict
|
||||
if settings().getBoolean(["devel", "useFrozenDictForPrinterState"])
|
||||
else dict
|
||||
)
|
||||
@@ -194,7 +199,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
|
||||
@property
|
||||
def firmware_info(self):
|
||||
return frozendict(self._firmware_info) if self._firmware_info else None
|
||||
return immutabledict(self._firmware_info) if self._firmware_info else None
|
||||
|
||||
# ~~ handling of PrinterCallbacks
|
||||
|
||||
@@ -820,11 +825,11 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
||||
return self._comm.getErrorString()
|
||||
|
||||
def get_current_data(self, *args, **kwargs):
|
||||
return util.thaw_frozendict(self._stateMonitor.get_current_data())
|
||||
return util.thaw_immutabledict(self._stateMonitor.get_current_data())
|
||||
|
||||
def get_current_job(self, *args, **kwargs):
|
||||
currentData = self._stateMonitor.get_current_data()
|
||||
return util.thaw_frozendict(currentData["job"])
|
||||
return util.thaw_immutabledict(currentData["job"])
|
||||
|
||||
def get_current_temperatures(self, *args, **kwargs):
|
||||
if self._comm is not None:
|
||||
|
||||
@@ -27,13 +27,17 @@ from functools import wraps
|
||||
from typing import Union
|
||||
|
||||
try:
|
||||
# Python 3.4+
|
||||
from collections.abc import Iterable, MutableMapping, Set
|
||||
except ImportError:
|
||||
# Python 2.7
|
||||
from collections import Iterable, MutableMapping, Set
|
||||
|
||||
import frozendict
|
||||
try:
|
||||
from immutabledict import immutabledict
|
||||
except ImportError:
|
||||
# Python 2
|
||||
from frozendict import frozendict as immutabledict
|
||||
|
||||
import past.builtins
|
||||
|
||||
try:
|
||||
@@ -1367,20 +1371,25 @@ except ImportError:
|
||||
monotonic_time = time.time
|
||||
|
||||
|
||||
def thaw_frozendict(obj):
|
||||
if not isinstance(obj, (dict, frozendict.frozendict)):
|
||||
raise ValueError("obj must be a dict or frozendict instance")
|
||||
def thaw_immutabledict(obj):
|
||||
if not isinstance(obj, (dict, immutabledict)):
|
||||
raise ValueError("obj must be a dict or immutabledict instance")
|
||||
|
||||
# only true love can thaw a frozen dict
|
||||
letitgo = {}
|
||||
for key, value in obj.items():
|
||||
if isinstance(value, (dict, frozendict.frozendict)):
|
||||
letitgo[key] = thaw_frozendict(value)
|
||||
if isinstance(value, (dict, immutabledict)):
|
||||
letitgo[key] = thaw_immutabledict(value)
|
||||
else:
|
||||
letitgo[key] = copy.deepcopy(value)
|
||||
return letitgo
|
||||
|
||||
|
||||
thaw_frozendict = deprecated(
|
||||
"thaw_frozendict has been renamed to thaw_immutabledict", since="1.6.0"
|
||||
)(thaw_immutabledict)
|
||||
|
||||
|
||||
def utmify(link, source=None, medium=None, name=None, term=None, content=None):
|
||||
if source is None:
|
||||
return link
|
||||
|
||||
@@ -8,7 +8,11 @@ __copyright__ = "Copyright (C) 2018 The OctoPrint Project - Released under terms
|
||||
import collections
|
||||
import json
|
||||
|
||||
import frozendict
|
||||
try:
|
||||
from immutabledict import immutabledict
|
||||
except ImportError:
|
||||
# Python 2
|
||||
from frozendict import frozendict as immutabledict
|
||||
|
||||
from octoprint.util import to_unicode
|
||||
|
||||
@@ -45,5 +49,5 @@ class JsonEncoding(object):
|
||||
raise TypeError
|
||||
|
||||
|
||||
JsonEncoding.add_encoder(frozendict.frozendict, lambda obj: dict(obj))
|
||||
JsonEncoding.add_encoder(immutabledict, lambda obj: dict(obj))
|
||||
JsonEncoding.add_encoder(bytes, lambda obj: to_unicode(obj))
|
||||
Reference in new issue
Block a user