From f7d76ca4dbd538f60a7d7c98c45fd4ab3de39398 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 28 Nov 2023 00:23:20 +0100 Subject: [PATCH 1/4] Set `enforces_secure_chat` to `None` if not provided --- mcstatus/status_response.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mcstatus/status_response.py b/mcstatus/status_response.py index ae5ef768..2295e154 100644 --- a/mcstatus/status_response.py +++ b/mcstatus/status_response.py @@ -109,7 +109,7 @@ class JavaStatusResponse(BaseStatusResponse): """ players: JavaStatusPlayers version: JavaStatusVersion - enforces_secure_chat: bool + enforces_secure_chat: bool | None icon: str | None """The icon of the server. In `Base64 `_ encoded PNG image format. @@ -133,7 +133,7 @@ def build(cls, raw: RawJavaResponse, latency: float = 0) -> Self: players=JavaStatusPlayers.build(raw["players"]), version=JavaStatusVersion.build(raw["version"]), motd=Motd.parse(raw["description"], bedrock=False), - enforces_secure_chat=raw.get("enforcesSecureChat", False), + enforces_secure_chat=raw.get("enforcesSecureChat"), icon=raw.get("favicon"), latency=latency, ) From 7146e53e20dda01766d42746289cbf9886aefc69 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 28 Nov 2023 00:25:32 +0100 Subject: [PATCH 2/4] Improve tests for `enforces_secure_chat` We should use consistent style across tests. --- tests/status_response/test_java.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tests/status_response/test_java.py b/tests/status_response/test_java.py index 7632faef..6eb8743a 100644 --- a/tests/status_response/test_java.py +++ b/tests/status_response/test_java.py @@ -11,6 +11,7 @@ class TestJavaStatusResponse(BaseStatusResponseTest): "players": {"max": 20, "online": 0}, "version": {"name": "1.8-pre1", "protocol": 44}, "description": "A Minecraft Server", + "enforcesSecureChat": True, "favicon": "data:image/png;base64,foo", } @@ -19,13 +20,15 @@ class TestJavaStatusResponse(BaseStatusResponseTest): ("version", JavaStatusVersion("1.8-pre1", 44)), ("motd", Motd.parse("A Minecraft Server", bedrock=False)), ("latency", 0), + ("enforces_secure_chat", True), ("icon", "data:image/png;base64,foo"), ("raw", RAW), ] - OPTIONAL_FIELDS = [("favicon", "icon")], { + OPTIONAL_FIELDS = [("favicon", "icon"), ("enforcesSecureChat", "enforces_secure_chat")], { "players": {"max": 20, "online": 0}, "version": {"name": "1.8-pre1", "protocol": 44}, "description": "A Minecraft Server", + "enforcesSecureChat": True, "favicon": "data:image/png;base64,foo", } @@ -33,12 +36,6 @@ class TestJavaStatusResponse(BaseStatusResponseTest): def build(self): return JavaStatusResponse.build(self.RAW) # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict - @pytest.mark.parametrize("value", (True, False, object())) - def test_enforces_secure_chat(self, value): - raw = self.RAW.copy() - raw["enforcesSecureChat"] = value - assert JavaStatusResponse.build(raw, 0).enforces_secure_chat is value # type: ignore # dict[str, Unknown] cannot be assigned to TypedDict - @BaseStatusResponseTest.construct class TestJavaStatusPlayers(BaseStatusResponseTest): From 1a68631dbe63bdbb1a312af78d22550e5ca61f86 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 28 Nov 2023 00:31:00 +0100 Subject: [PATCH 3/4] Add docstring --- mcstatus/status_response.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mcstatus/status_response.py b/mcstatus/status_response.py index 2295e154..c695c20a 100644 --- a/mcstatus/status_response.py +++ b/mcstatus/status_response.py @@ -110,6 +110,14 @@ class JavaStatusResponse(BaseStatusResponse): players: JavaStatusPlayers version: JavaStatusVersion enforces_secure_chat: bool | None + """Whether the server enforces secure chat (every message is signed up with a key). + + .. seealso:: + `Signed Chat explanation `_, + `22w17a changelog, where this was added `_. + + .. versionadded:: 11.1.0 + """ icon: str | None """The icon of the server. In `Base64 `_ encoded PNG image format. From a63cc1467f13f1c43910855614400249175a7661 Mon Sep 17 00:00:00 2001 From: PerchunPak Date: Tue, 28 Nov 2023 00:42:38 +0100 Subject: [PATCH 4/4] Remove trailing whitespaces --- mcstatus/status_response.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mcstatus/status_response.py b/mcstatus/status_response.py index c695c20a..acaac9c2 100644 --- a/mcstatus/status_response.py +++ b/mcstatus/status_response.py @@ -111,12 +111,12 @@ class JavaStatusResponse(BaseStatusResponse): version: JavaStatusVersion enforces_secure_chat: bool | None """Whether the server enforces secure chat (every message is signed up with a key). - + .. seealso:: `Signed Chat explanation `_, `22w17a changelog, where this was added `_. - - .. versionadded:: 11.1.0 + + .. versionadded:: 11.1.0 """ icon: str | None """The icon of the server. In `Base64 `_ encoded PNG image format.