From f810a141f631a7bd59e166d653f84b939069aa71 Mon Sep 17 00:00:00 2001 From: A-UNDERSCORE-D Date: Tue, 21 Feb 2017 23:02:08 +0200 Subject: [PATCH 1/2] Added format check for descriptions --- mcstatus/pinger.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mcstatus/pinger.py b/mcstatus/pinger.py index 818ad56..3f55979 100644 --- a/mcstatus/pinger.py +++ b/mcstatus/pinger.py @@ -139,8 +139,18 @@ def __init__(self, raw): if "description" not in raw: raise ValueError("Invalid status object (no 'description' value)") - self.description = raw["description"] - self.description_clean = re.sub(r'\u00A7.', '', raw["description"]) + # for newer versions of minecraft + + if type(raw["description"]) is str: + self.description = raw["description"] + self.description_clean = re.sub(r'\u00A7.', '', raw["description"]) + + elif type(raw["description"]) is dict: + self.description = raw["description"]["text"] + self.description_clean = re.sub(r'\u00A7.', '', raw["description"]["text"]) + + else: + raise ValueError("Invalid status object (unknown 'description' type)") if "favicon" in raw: self.favicon = raw["favicon"] From 36e9d1a955fca8a0529175693d4dbd1aae1f3995 Mon Sep 17 00:00:00 2001 From: A_D Date: Wed, 10 May 2017 08:29:18 +0200 Subject: [PATCH 2/2] Now using isinstance() rather than type() and using string_types over str for compatability --- mcstatus/pinger.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mcstatus/pinger.py b/mcstatus/pinger.py index 3f55979..58b362d 100644 --- a/mcstatus/pinger.py +++ b/mcstatus/pinger.py @@ -141,16 +141,18 @@ def __init__(self, raw): raise ValueError("Invalid status object (no 'description' value)") # for newer versions of minecraft - if type(raw["description"]) is str: + if isinstance(raw["description"], string_types): self.description = raw["description"] self.description_clean = re.sub(r'\u00A7.', '', raw["description"]) - elif type(raw["description"]) is dict: + elif isinstance(raw["description"], dict): self.description = raw["description"]["text"] - self.description_clean = re.sub(r'\u00A7.', '', raw["description"]["text"]) + self.description_clean = re.sub(r'\u00A7.', '', + raw["description"]["text"]) else: - raise ValueError("Invalid status object (unknown 'description' type)") + raise ValueError("Invalid status object " + "(unknown 'description' type)") if "favicon" in raw: self.favicon = raw["favicon"]