From f4b01833fd1b79dcdff4337bad1c4e0a60dfa8ea Mon Sep 17 00:00:00 2001 From: Battlefield Duck Date: Wed, 7 Feb 2024 23:16:56 +0800 Subject: [PATCH] Update docstring --- opengsq/responses/source/environment.py | 16 +++++++++++++++- opengsq/responses/source/server_type.py | 10 ++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/opengsq/responses/source/environment.py b/opengsq/responses/source/environment.py index 78fc6c2..53bb20d 100644 --- a/opengsq/responses/source/environment.py +++ b/opengsq/responses/source/environment.py @@ -17,4 +17,18 @@ class Environment(IntEnum): @staticmethod def parse(byte: int): - return Environment(ord(chr(byte).lower())) + """ + Parses the given byte to an Environment value. If the byte does not correspond to a valid + Environment value, it defaults to Environment.Mac. + + Args: + byte (int): The byte to parse. + + Returns: + Environment: The corresponding Environment value, or Environment.Mac if the byte is not valid. + """ + try: + return Environment(ord(chr(byte).lower())) + except ValueError: + # 'm' or 'o' for Mac (the code changed after L4D1) + return Environment.Mac diff --git a/opengsq/responses/source/server_type.py b/opengsq/responses/source/server_type.py index 115a17b..249c69e 100644 --- a/opengsq/responses/source/server_type.py +++ b/opengsq/responses/source/server_type.py @@ -17,4 +17,14 @@ class ServerType(IntEnum): @staticmethod def parse(byte: int): + """ + Parses the given byte to a ServerType value. If the byte does not correspond to a valid + ServerType value, a ValueError is raised. + + Args: + byte (int): The byte to parse. + + Returns: + ServerType: The corresponding ServerType value. + """ return ServerType(ord(chr(byte).lower()))