From 571239a8d7905207594ec0e4924ad35e19525767 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 8 Dec 2025 19:06:11 -0600 Subject: [PATCH 1/6] Support chunked transfers in wget --- adafruit_portalbase/network.py | 47 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index b500dc2..d590f6e 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -333,27 +333,40 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None): if self._debug: print(response.headers) - if "content-length" in headers: - content_length = int(headers["content-length"]) - else: - raise RuntimeError("Content-Length missing from headers") - remaining = content_length + if "content-length" not in headers and "transfer-encoding" not in headers and headers["transfer-encoding"] == "chunked": + raise RuntimeError("Invalid headers in response") + print("Saving data to ", filename) stamp = time.monotonic() with open(filename, "wb") as file: - for i in response.iter_content(min(remaining, chunk_size)): # huge chunks! - self.neo_status(STATUS_DOWNLOADING) - remaining -= len(i) - file.write(i) - if self._debug: - print("Read %d bytes, %d remaining" % (content_length - remaining, remaining)) - else: - print(".", end="") - if not remaining: - break - self.neo_status(STATUS_FETCHING) + if "content-length" in headers: + content_length = int(headers["content-length"]) + remaining = content_length + for i in response.iter_content(min(remaining, chunk_size)): # huge chunks! + self.neo_status(STATUS_DOWNLOADING) + remaining -= len(i) + file.write(i) + if self._debug: + print("Read %d bytes, %d remaining" % (content_length - remaining, remaining)) + else: + print(".", end="") + if not remaining: + break + self.neo_status(STATUS_FETCHING) + response.close() + elif "transfer-encoding" in headers and headers["transfer-encoding"] == "chunked": + content_length = 0 + for i in response.iter_content(chunk_size): + self.neo_status(STATUS_DOWNLOADING) + content_length += len(i) + file.write(i) + if self._debug: + print("Read %d bytes, %d total" % (len(i), content_length)) + else: + print(".", end="") + self.neo_status(STATUS_FETCHING) + response.close() - response.close() stamp = time.monotonic() - stamp print("Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp)) self.neo_status(STATUS_OFF) From cf1ec95a7ba22140cd56dede5ab1748af0bd8c20 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 8 Dec 2025 19:10:23 -0600 Subject: [PATCH 2/6] Fix encoding check --- adafruit_portalbase/network.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index d590f6e..4545e8a 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -333,7 +333,7 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None): if self._debug: print(response.headers) - if "content-length" not in headers and "transfer-encoding" not in headers and headers["transfer-encoding"] == "chunked": + if "content-length" not in headers and "transfer-encoding" not in headers and headers["transfer-encoding"] != "chunked": raise RuntimeError("Invalid headers in response") print("Saving data to ", filename) From f790b713cfe4dde4891e20ccf6f54943b1938639 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Mon, 8 Dec 2025 19:25:15 -0600 Subject: [PATCH 3/6] Fix formatting errors --- adafruit_portalbase/network.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 4545e8a..168255e 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -333,7 +333,11 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None): if self._debug: print(response.headers) - if "content-length" not in headers and "transfer-encoding" not in headers and headers["transfer-encoding"] != "chunked": + if ( + "content-length" not in headers + and "transfer-encoding" not in headers + and headers["transfer-encoding"] != "chunked" + ): raise RuntimeError("Invalid headers in response") print("Saving data to ", filename) @@ -347,7 +351,9 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None): remaining -= len(i) file.write(i) if self._debug: - print("Read %d bytes, %d remaining" % (content_length - remaining, remaining)) + print( + "Read %d bytes, %d remaining" % (content_length - remaining, remaining) + ) else: print(".", end="") if not remaining: From c30a11159cb7815cdbd43302f810dc53787419ec Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 9 Dec 2025 10:26:34 -0600 Subject: [PATCH 4/6] Merge standard and chunked download process to avoid PLR0915 --- adafruit_portalbase/network.py | 53 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/adafruit_portalbase/network.py b/adafruit_portalbase/network.py index 168255e..0cfdc03 100755 --- a/adafruit_portalbase/network.py +++ b/adafruit_portalbase/network.py @@ -333,45 +333,40 @@ def wget(self, url, filename, *, chunk_size=12000, headers=None): if self._debug: print(response.headers) - if ( + + chunked = ( "content-length" not in headers - and "transfer-encoding" not in headers - and headers["transfer-encoding"] != "chunked" - ): + and "transfer-encoding" in headers + and headers["transfer-encoding"] == "chunked" + ) + if "content-length" not in headers and not chunked: raise RuntimeError("Invalid headers in response") print("Saving data to ", filename) stamp = time.monotonic() with open(filename, "wb") as file: - if "content-length" in headers: - content_length = int(headers["content-length"]) - remaining = content_length - for i in response.iter_content(min(remaining, chunk_size)): # huge chunks! - self.neo_status(STATUS_DOWNLOADING) + content_length = int(headers["content-length"]) if "content-length" in headers else 0 + remaining = chunk_size if chunked else content_length + for i in response.iter_content(min(remaining, chunk_size)): # huge chunks! + self.neo_status(STATUS_DOWNLOADING) + if chunked: + content_length += len(i) + else: remaining -= len(i) - file.write(i) - if self._debug: + file.write(i) + if self._debug: + if chunked: + print("Read %d bytes, %d total" % (len(i), content_length)) + else: print( "Read %d bytes, %d remaining" % (content_length - remaining, remaining) ) - else: - print(".", end="") - if not remaining: - break - self.neo_status(STATUS_FETCHING) - response.close() - elif "transfer-encoding" in headers and headers["transfer-encoding"] == "chunked": - content_length = 0 - for i in response.iter_content(chunk_size): - self.neo_status(STATUS_DOWNLOADING) - content_length += len(i) - file.write(i) - if self._debug: - print("Read %d bytes, %d total" % (len(i), content_length)) - else: - print(".", end="") - self.neo_status(STATUS_FETCHING) - response.close() + else: + print(".", end="") + if not chunked and not remaining: + break + self.neo_status(STATUS_FETCHING) + response.close() stamp = time.monotonic() - stamp print("Created file of %d bytes in %0.1f seconds" % (os.stat(filename)[6], stamp)) From dc7ecff7794435053cc4ab2076978a9b35149009 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 9 Dec 2025 10:50:41 -0600 Subject: [PATCH 5/6] Fix `OutlinedLabel` deprecation error --- adafruit_portalbase/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_portalbase/__init__.py b/adafruit_portalbase/__init__.py index e0ca19f..3c46fdc 100644 --- a/adafruit_portalbase/__init__.py +++ b/adafruit_portalbase/__init__.py @@ -28,7 +28,6 @@ from adafruit_bitmap_font import bitmap_font from adafruit_display_text import wrap_text_to_lines from adafruit_display_text.bitmap_label import Label -from adafruit_display_text.outlined_label import OutlinedLabel __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git" @@ -291,7 +290,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches scale=self._text[index]["scale"], ) else: - self._text[index]["label"] = OutlinedLabel( + self._text[index]["label"] = Label( self._fonts[self._text[index]["font"]], text=string, scale=self._text[index]["scale"], From cdbce86cb78ad9211b752c6462415724f74dcf00 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 9 Dec 2025 11:33:03 -0600 Subject: [PATCH 6/6] Compatibility with frozen adafruit_display_text module --- adafruit_portalbase/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/adafruit_portalbase/__init__.py b/adafruit_portalbase/__init__.py index 3c46fdc..89a63b2 100644 --- a/adafruit_portalbase/__init__.py +++ b/adafruit_portalbase/__init__.py @@ -29,6 +29,11 @@ from adafruit_display_text import wrap_text_to_lines from adafruit_display_text.bitmap_label import Label +try: + from adafruit_display_text.outlined_label import OutlinedLabel +except ImportError: + OutlinedLabel = Label + __version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PortalBase.git" @@ -290,7 +295,7 @@ def set_text(self, val, index=0): # noqa: PLR0912 Too many branches scale=self._text[index]["scale"], ) else: - self._text[index]["label"] = Label( + self._text[index]["label"] = OutlinedLabel( self._fonts[self._text[index]["font"]], text=string, scale=self._text[index]["scale"],