From c0552d9d644a1dfa1e2111b1afe78fadc55af045 Mon Sep 17 00:00:00 2001 From: Mickey Yawn Date: Mon, 20 Nov 2023 09:48:51 -0500 Subject: [PATCH 1/2] removed old method. oops. removed old method. oops. --- polygon/websocket/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/polygon/websocket/__init__.py b/polygon/websocket/__init__.py index 4875a1ac..c86d0d7d 100644 --- a/polygon/websocket/__init__.py +++ b/polygon/websocket/__init__.py @@ -197,15 +197,26 @@ async def _unsubscribe(self, topics: Union[List[str], Set[str]]): self.json.dumps({"action": "unsubscribe", "params": subs}) ) + @staticmethod def _parse_subscription(s: str): s = s.strip() split = s.split(".") - if len(split) != 2: - logger.warning("invalid subscription:", s) - return [None, None] + length = len(split) + + match length: + case _ if length < 2: + logger.warning("invalid subscription:", s) + return [None, None] + case 3: + return split[0], split[1] + "." + split[2] + case _ if length > 3: + logger.warning("invalid subscription:", s) + return [None, None] + case _: + return split[0], split[1] + - return split def subscribe(self, *subscriptions: str): """ From 4b79944bd8973f31209471f4a71be2071c0d219a Mon Sep 17 00:00:00 2001 From: Mickey Yawn Date: Mon, 20 Nov 2023 10:10:29 -0500 Subject: [PATCH 2/2] moved from case to if statement not sure if our linter/parser was happy with the case statement so moved it back to an if statement --- polygon/websocket/__init__.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/polygon/websocket/__init__.py b/polygon/websocket/__init__.py index c86d0d7d..6d00d907 100644 --- a/polygon/websocket/__init__.py +++ b/polygon/websocket/__init__.py @@ -204,18 +204,16 @@ def _parse_subscription(s: str): split = s.split(".") length = len(split) - match length: - case _ if length < 2: - logger.warning("invalid subscription:", s) - return [None, None] - case 3: - return split[0], split[1] + "." + split[2] - case _ if length > 3: - logger.warning("invalid subscription:", s) - return [None, None] - case _: - return split[0], split[1] - + if length < 2: + logger.warning("invalid subscription:", s) + return [None, None] + if length == 2: + return split[0], split[1] + if length == 3: + return split[0], split[1] + "." + split[2] + if length > 3: + logger.warning("invalid subscription:", s) + return [None, None] def subscribe(self, *subscriptions: str):