+
+ {{ _('Use this to write a valid regular expression to hide notifications having the pattern defined in it. Chain multiple filters using "|". For more information, please see the Python docs on regular expressions')|format(tut_url="https://docs.python.org/3/library/re.html") }}
+
+
diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js
index 6acb249a2..32e1122ed 100644
--- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js
+++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js
@@ -357,21 +357,20 @@ var gCodeLineGenerator = async function* (fileURL) {
// the download failed.
if (!response.ok) return;
- // create a reader object that will read the incoming data
- const reader = response.body.getReader();
-
// we use these two variables to calculate the percentage.
var totalDownloadLength = response.headers.get("X-Original-Content-Length");
var currentDownloadLength = 0;
- // lets read a first data chunk
- let {value: chunk, done: readerDone} = await reader.read();
- chunk = chunk ? utf8Decoder.decode(chunk) : "";
-
// some init
const re = /\n|\r|\r\n/gm;
let startIndex = 0;
- let result;
+
+ // create a reader object that will read the incoming data
+ const reader = response.body.getReader();
+
+ // lets read a first data chunk
+ let {value: chunk, done: readerDone} = await reader.read();
+ chunk = chunk ? utf8Decoder.decode(chunk) : "";
// now continue until all the downloaded data is processed.
for (;;) {
@@ -386,7 +385,11 @@ var gCodeLineGenerator = async function* (fileURL) {
}
// lets read a new chunk
let remainder = chunk.substr(startIndex);
+
+ //console.log("reading chunk..."); // debug for #4879
({value: chunk, done: readerDone} = await reader.read());
+ //console.log("read chunk"); // debug for #4879
+
// concatenate with our leftovers from the previous chunk
chunk = remainder + (chunk ? utf8Decoder.decode(chunk) : "");
// reset the indexes
@@ -405,6 +408,7 @@ var gCodeLineGenerator = async function* (fileURL) {
// move to after the line we just returned
startIndex = re.lastIndex;
}
+
if (startIndex < chunk.length) {
// last line didn't end in a newline char
currentDownloadLength += chunk.length - startIndex;
diff --git a/src/octoprint/settings/__init__.py b/src/octoprint/settings/__init__.py
index 68ff2d290..c281d8969 100644
--- a/src/octoprint/settings/__init__.py
+++ b/src/octoprint/settings/__init__.py
@@ -253,10 +253,10 @@ class HierarchicalChainMap:
def _cached_prefixed_keys(self, prefix):
if prefix not in self._prefixed_keys:
- self._prefixed_keys[prefix] = [
- k for k in self._chainmap.keys() if k.startswith(prefix)
- ]
- return self._prefixed_keys[prefix]
+ keys = [k for k in self._chainmap.keys() if k.startswith(prefix)]
+ if keys:
+ self._prefixed_keys[prefix] = keys
+ return self._prefixed_keys.get(prefix, [])
def _invalidate_prefixed_keys(self, prefix):
seps = []
@@ -270,6 +270,10 @@ class HierarchicalChainMap:
except KeyError:
pass
+ to_delete = [key for key in self._prefixed_keys.keys() if key.startswith(prefix)]
+ for prefix in to_delete:
+ del self._prefixed_keys[prefix]
+
def deep_dict(self):
return self._unflatten(self._chainmap)
@@ -439,19 +443,13 @@ class HierarchicalChainMap:
def insert_map(self, pos, d):
flattened = self._flatten(d)
for k in flattened:
- if _CHAINMAP_SEP in k:
- self._invalidate_prefixed_keys(
- k.rsplit(_CHAINMAP_SEP, 1)[0] + _CHAINMAP_SEP
- )
+ self._invalidate_prefixed_keys(k + _CHAINMAP_SEP)
self._chainmap.maps.insert(pos, flattened)
def delete_map(self, pos):
flattened = self._chainmap.maps[pos]
for k in flattened:
- if _CHAINMAP_SEP in k:
- self._invalidate_prefixed_keys(
- k.rsplit(_CHAINMAP_SEP, 1)[0] + _CHAINMAP_SEP
- )
+ self._invalidate_prefixed_keys(k + _CHAINMAP_SEP)
del self._chainmap.maps[pos]
@property
diff --git a/src/octoprint/vendor/awesome_slugify/main.py b/src/octoprint/vendor/awesome_slugify/main.py
index dfb07b063..430642d28 100644
--- a/src/octoprint/vendor/awesome_slugify/main.py
+++ b/src/octoprint/vendor/awesome_slugify/main.py
@@ -41,7 +41,7 @@ def join_words(words, separator, max_length=None):
# uppercase letters to translate to uppercase letters, NOT camelcase
UPPER_TO_UPPER_LETTERS_RE = \
- u'''
+ r'''
(
\p{Uppercase_Letter} {2,} # 2 or more adjacent letters - UP always
|
@@ -95,7 +95,7 @@ class Slugify(object):
convert_dict[letter_upper] = translation.capitalize()
self.convert_dict = convert_dict
- PRETRANSLATE = re.compile(u'(\L)', options=convert_dict)
+ PRETRANSLATE = re.compile(r'(\L)', options=convert_dict)
# translate some letters before translating
return lambda text: PRETRANSLATE.sub(lambda m: convert_dict[m.group(1)], text)
@@ -137,11 +137,11 @@ class Slugify(object):
stop_words = property(fset=set_stop_words)
def calc_unwanted_chars_re(self):
- unwanted_chars_re = u'[^\p{{AlNum}}{safe_chars}]+'.format(safe_chars=re.escape(self._safe_chars or ''))
+ unwanted_chars_re = r'[^\p{{AlNum}}{safe_chars}]+'.format(safe_chars=re.escape(self._safe_chars or ''))
self.unwanted_chars_re = re.compile(unwanted_chars_re, re.IGNORECASE)
if self._stop_words:
- unwanted_chars_and_words_re = unwanted_chars_re + u'|(?)(?!\p{AlNum})'
+ unwanted_chars_and_words_re = unwanted_chars_re + r'|(?)(?!\p{AlNum})'
self.unwanted_chars_and_words_re = re.compile(unwanted_chars_and_words_re, re.IGNORECASE, stop_words=self._stop_words)
else:
self.unwanted_chars_and_words_re = None
diff --git a/tests/plugin/test_settings.py b/tests/plugin/test_settings.py
index 6d5a3d428..36f52182d 100644
--- a/tests/plugin/test_settings.py
+++ b/tests/plugin/test_settings.py
@@ -111,6 +111,7 @@ def test_deprecated_forwarded_getter(
called_method.__name__ = forwarded
called_method.__qualname__ = forwarded
called_method.__annotations__ = {}
+ called_method.__type_params__ = ()
method = getattr(plugin_settings, deprecated)
assert callable(method)
@@ -330,6 +331,7 @@ def test_deprecated_forwarded_setter(
called_method.__name__ = forwarded
called_method.__qualname__ = forwarded
called_method.__annotations__ = {}
+ called_method.__type_params__ = ()
method = getattr(plugin_settings, deprecated)
assert callable(method)
diff --git a/tests/settings/_files/config.yaml b/tests/settings/_files/config.yaml
index c6d98294a..c660f9a12 100644
--- a/tests/settings/_files/config.yaml
+++ b/tests/settings/_files/config.yaml
@@ -18,6 +18,14 @@ plugins:
a: 1
b: 2
c: 3
+ baz:
+ a: 1
+ b: 2
+ c: 3
+ d:
+ a: 1
+ b: 2
+ c: 3
server:
port: 8080
devel:
diff --git a/tests/settings/test_settings.py b/tests/settings/test_settings.py
index ce282d3bd..b19608956 100644
--- a/tests/settings/test_settings.py
+++ b/tests/settings/test_settings.py
@@ -772,6 +772,10 @@ def _key(*path):
return octoprint.settings._CHAINMAP_SEP.join(path)
+def _prefix(*path):
+ return _key(*path) + octoprint.settings._CHAINMAP_SEP
+
+
@ddt.ddt
class ChainmapTest(unittest.TestCase):
def setUp(self):
@@ -915,3 +919,66 @@ class ChainmapTest(unittest.TestCase):
self.assertEqual(
expected, octoprint.settings.HierarchicalChainMap._unflatten(value)
)
+
+ def test_prefix_caching_has_populates(self):
+ # this should populate the prefix cache
+ self.chainmap.has_path(["plugins", "foo"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 1)
+ self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys)
+
+ def test_prefix_caching_get_populates(self):
+ # this should populate the prefix cache
+ self.chainmap.get_by_path(["plugins", "foo"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 1)
+ self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys)
+
+ def test_prefix_caching_scalars_ignored(self):
+ # this shouldn't populate the prefix cache
+ self.chainmap.has_path(["api", "key"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 0)
+
+ def test_prefix_caching_set_invalidates(self):
+ # this should populate the prefix cache
+ self.chainmap.has_path(["plugins", "foo"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 1)
+ self.assertTrue(_prefix("plugins", "foo") in self.chainmap._prefixed_keys)
+
+ # this should extend the prefix cache
+ self.chainmap.get_by_path(["plugins", "foo", "bar"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 2)
+ self.chainmap.has_path(["plugins", "foo", "bar"])
+
+ # this should remove all plugins.foo keys in the prefix cache
+ self.chainmap.set_by_path(["plugins", "foo"], {})
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 0)
+
+ def test_prefix_caching_del_invalidates(self):
+ # this should populate the prefix cache
+ self.chainmap.has_path(["plugins", "baz", "d"])
+
+ # validate that
+ self.assertTrue(len(self.chainmap._prefixed_keys) == 1)
+ self.assertTrue(_prefix("plugins", "baz", "d") in self.chainmap._prefixed_keys)
+
+ # this should remove all plugins.baz keys in the prefix cache
+ self.chainmap.del_by_path(["plugins", "baz"])
+
+ # validate that
+ keys = [
+ key
+ for key in self.chainmap._prefixed_keys
+ if key.startswith(_prefix("plugins", "baz"))
+ ]
+ self.assertTrue(len(keys) == 0)
diff --git a/versioneer.py b/versioneer.py
index 63428fa14..f67734948 100644
--- a/versioneer.py
+++ b/versioneer.py
@@ -442,10 +442,14 @@ def get_config_from_root(root):
# the top of versioneer.py for instructions on writing your setup.cfg .
setup_cfg = os.path.join(root, "setup.cfg")
- # TODO: find a py2 compatible solution for the configparser deprecation issues
- parser = configparser.SafeConfigParser()
- with io.open(setup_cfg, "rt", encoding="utf-8") as f:
- parser.readfp(f)
+ try:
+ parser = configparser.SafeConfigParser()
+ with io.open(setup_cfg, "rt", encoding="utf-8") as f:
+ parser.readfp(f)
+ except AttributeError: # python 3.12 no longer has SafeConfigParser
+ parser = configparser.ConfigParser()
+ with io.open(setup_cfg, "rt", encoding="utf-8") as f:
+ parser.read_file(f)
VCS = parser.get("versioneer", "VCS") # mandatory