From 7e40d176ae58803c7fe209c6d2a6cd7f29eb9af6 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:19:03 -0500 Subject: [PATCH 01/19] Add note when encountering WebSocketBadStatusException Encountering a WebSocketBadStatusException most likely means that Scratch's cloud is down. Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/cloud/_base.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scratchattach/cloud/_base.py b/scratchattach/cloud/_base.py index ed71c9b5..8e3575aa 100644 --- a/scratchattach/cloud/_base.py +++ b/scratchattach/cloud/_base.py @@ -335,20 +335,22 @@ def _handshake(self): self._send_packet(packet) def connect(self): - self.websocket = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE}) - self.websocket.connect( - self.cloud_host, - cookie=self.cookie, - origin=self.origin, - enable_multithread=True, - timeout=self.ws_timeout, - header=self.header - ) - self._handshake() - self.active_connection = True - if self.print_connect_message: - print("Connected to cloud server ", self.cloud_host) - + try: + self.websocket = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE}) + self.websocket.connect( + self.cloud_host, + cookie=self.cookie, + origin=self.origin, + enable_multithread=True, + timeout=self.ws_timeout, + header=self.header + ) + self._handshake() + self.active_connection = True + if self.print_connect_message: + print("Connected to cloud server ", self.cloud_host) + except WebSocketBadStatusException as e: + print(f"Error: {e} --- Scratch's Cloud system may be down. Please try again later.") def disconnect(self): self.active_connection = False if self.recorder is not None: From ab5fa4eb9c27c31275e626e7a01048ecc1595820 Mon Sep 17 00:00:00 2001 From: retek <107722825+faretek1@users.noreply.github.com> Date: Sat, 27 Sep 2025 21:56:20 +0100 Subject: [PATCH 02/19] Apply suggestions from code review Signed-off-by: retek <107722825+faretek1@users.noreply.github.com> --- scratchattach/cloud/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scratchattach/cloud/_base.py b/scratchattach/cloud/_base.py index 8e3575aa..88e1ed44 100644 --- a/scratchattach/cloud/_base.py +++ b/scratchattach/cloud/_base.py @@ -350,7 +350,7 @@ def connect(self): if self.print_connect_message: print("Connected to cloud server ", self.cloud_host) except WebSocketBadStatusException as e: - print(f"Error: {e} --- Scratch's Cloud system may be down. Please try again later.") + raise WebSocketBadStatusException(f"Error: Scratch's Cloud system may be down. Please try again later.") from e def disconnect(self): self.active_connection = False if self.recorder is not None: From 0efb5070fa7bcf5e194fada531a78909b9b53234 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sat, 27 Sep 2025 18:40:06 -0500 Subject: [PATCH 03/19] Update cloud.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/cloud/cloud.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scratchattach/cloud/cloud.py b/scratchattach/cloud/cloud.py index 05d04169..419ae632 100644 --- a/scratchattach/cloud/cloud.py +++ b/scratchattach/cloud/cloud.py @@ -26,7 +26,10 @@ def __init__(self, *, project_id, _session=None): def connect(self): self._assert_auth() # Connecting to Scratch's cloud websocket requires a login to the Scratch website - super().connect() + try: + super().connect() + except WebSocketBadStatusException as e: + raise WebSocketBadStatusException(f"Error: Scratch's Cloud system may be down. Please try again later.") from e def set_var(self, variable, value): self._assert_auth() # Setting a cloud var requires a login to the Scratch website From 44f48052d095ca2b1a1ff057382290b66d0bf5ad Mon Sep 17 00:00:00 2001 From: TheCommCraft <79996518+TheCommCraft@users.noreply.github.com> Date: Sun, 28 Sep 2025 10:30:31 +0200 Subject: [PATCH 04/19] Only warn if scratch cloud is used Signed-off-by: TheCommCraft <79996518+TheCommCraft@users.noreply.github.com> --- scratchattach/cloud/_base.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/scratchattach/cloud/_base.py b/scratchattach/cloud/_base.py index 88e1ed44..ed71c9b5 100644 --- a/scratchattach/cloud/_base.py +++ b/scratchattach/cloud/_base.py @@ -335,22 +335,20 @@ def _handshake(self): self._send_packet(packet) def connect(self): - try: - self.websocket = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE}) - self.websocket.connect( - self.cloud_host, - cookie=self.cookie, - origin=self.origin, - enable_multithread=True, - timeout=self.ws_timeout, - header=self.header - ) - self._handshake() - self.active_connection = True - if self.print_connect_message: - print("Connected to cloud server ", self.cloud_host) - except WebSocketBadStatusException as e: - raise WebSocketBadStatusException(f"Error: Scratch's Cloud system may be down. Please try again later.") from e + self.websocket = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE}) + self.websocket.connect( + self.cloud_host, + cookie=self.cookie, + origin=self.origin, + enable_multithread=True, + timeout=self.ws_timeout, + header=self.header + ) + self._handshake() + self.active_connection = True + if self.print_connect_message: + print("Connected to cloud server ", self.cloud_host) + def disconnect(self): self.active_connection = False if self.recorder is not None: From 7f01c365a3f7cd012b9f8cd4720231e52f605d0b Mon Sep 17 00:00:00 2001 From: faretek Date: Sun, 28 Sep 2025 09:45:19 +0100 Subject: [PATCH 05/19] fix: import exception It seems like the scratch cloud variables are up again, so it can't really be tested anymore. On that note, we should test if new scratchers and banned accounts can still set cloud vars. --- scratchattach/cloud/cloud.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scratchattach/cloud/cloud.py b/scratchattach/cloud/cloud.py index 419ae632..b9070b7d 100644 --- a/scratchattach/cloud/cloud.py +++ b/scratchattach/cloud/cloud.py @@ -8,6 +8,7 @@ from scratchattach.utils import exceptions, commons from scratchattach.site import cloud_activity +from websocket import WebSocketBadStatusException class ScratchCloud(BaseCloud): def __init__(self, *, project_id, _session=None): From 5be290239ec1f68883d00354b5c2cfa6d872e1bc Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:03:24 -0500 Subject: [PATCH 06/19] Update user.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/user.py b/scratchattach/site/user.py index e7b9c81f..47a76db4 100644 --- a/scratchattach/site/user.py +++ b/scratchattach/site/user.py @@ -990,5 +990,9 @@ def get_user(username) -> User: If you want to use these, get the user with :meth:`scratchattach.session.Session.connect_user` instead. """ - print("Warning: For methods that require authentication, use session.connect_user instead of get_user") + warnings.warn( + "Warning: For methods that require authentication, use session.connect_user instead of get_user. " + "To ignore this warning, use warnings.filterwarning('ignore', category=UserAuthenticationWarning)", + exceptions.UserAuthenticationWarning + ) return commons._get_object("username", username, User, exceptions.UserNotFound) From e56a124de18dae75e9aadc93938cd8617268f07e Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:06:34 -0500 Subject: [PATCH 07/19] Update exceptions.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/utils/exceptions.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scratchattach/utils/exceptions.py b/scratchattach/utils/exceptions.py index e33d2a85..63774041 100644 --- a/scratchattach/utils/exceptions.py +++ b/scratchattach/utils/exceptions.py @@ -236,3 +236,15 @@ class InvalidUpdateWarning(UserWarning): """ Warns you that something cannot be updated. """ + +class UserAuthenticationWarning(UserWarning): + """ + Warns you to use seesion.commect_user instead of session.get_user + for actions that require authentication. + """ + +class ProjectAuthenticationWarning(UserWarning): + """ + Warns you to use session.connect_project instead of seesion.get_project + for actions that require authentication. + """ From 42ab8ab6b4842e034247675bd989cb733cb0087c Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:08:56 -0500 Subject: [PATCH 08/19] Update project.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/project.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index ae44c69b..280845ab 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -933,7 +933,12 @@ def get_project(project_id) -> Project: If you want to use these methods, get the project with :meth:`scratchattach.session.Session.connect_project` instead. """ - print("Warning: For methods that require authentication, use session.connect_project instead of get_project") + warnings.warn( + "Warning: For methods that require authentication, use session.connect_project instead of get_project. " + "If you want to remove this warning, " + "use `warnings.filterwarnings('ignore', category=scratchattach.LoginDataWarning)`", + exceptions.ProjectAuthenticationWarning + ) return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound) From 6012b20b92789788fcc10d3a5e0e774df610c41e Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:14:47 -0500 Subject: [PATCH 09/19] Update exceptions.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/utils/exceptions.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scratchattach/utils/exceptions.py b/scratchattach/utils/exceptions.py index 63774041..0be13feb 100644 --- a/scratchattach/utils/exceptions.py +++ b/scratchattach/utils/exceptions.py @@ -239,12 +239,24 @@ class InvalidUpdateWarning(UserWarning): class UserAuthenticationWarning(UserWarning): """ - Warns you to use seesion.commect_user instead of session.get_user + Warns you to use session.connect_user instead of user.get_user for actions that require authentication. """ class ProjectAuthenticationWarning(UserWarning): """ - Warns you to use session.connect_project instead of seesion.get_project + Warns you to use session.connect_project instead of project.get_project + for actions that require authentication. + """ + +class StudioAuthenticationWarning(UserWarning): + """ + Warns you to use session.connect_studio instead of studio.get_studio + for actions that require authentication. + """ + +class ClassroomAuthenticationWarning(UserWarning): + """ + Warns you to use session.connect_classroom or session.connect_classroom_from_token instead of classroom.get_classroom for actions that require authentication. """ From 32a9c19fd2ec17db23fa13478d6e52f4ec806c03 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:16:43 -0500 Subject: [PATCH 10/19] Update classroom.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/classroom.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scratchattach/site/classroom.py b/scratchattach/site/classroom.py index 3262ee9c..da17cb34 100644 --- a/scratchattach/site/classroom.py +++ b/scratchattach/site/classroom.py @@ -396,7 +396,11 @@ def get_classroom(class_id: str) -> Classroom: If you want to use these, get the user with :meth:`scratchattach.session.Session.connect_classroom` instead. """ - warnings.warn("For methods that require authentication, use session.connect_classroom instead of get_classroom") + warnings.warn( + "For methods that require authentication, use session.connect_classroom instead of get_classroom" + "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning)", + exceptions.ClassroomAuthenticationWarning + ) return commons._get_object("id", class_id, Classroom, exceptions.ClassroomNotFound) @@ -415,7 +419,11 @@ def get_classroom_from_token(class_token) -> Classroom: If you want to use these, get the user with :meth:`scratchattach.session.Session.connect_classroom` instead. """ - warnings.warn("For methods that require authentication, use session.connect_classroom instead of get_classroom") + warnings.warn( + "For methods that require authentication, use session.connect_classroom instead of get_classroom. " + "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning)", + exceptions.ClassroomAuthenticationWarning + ) return commons._get_object("classtoken", class_token, Classroom, exceptions.ClassroomNotFound) From cf1198bb01551de7c683239f1f22145d75291f27 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:18:31 -0500 Subject: [PATCH 11/19] Update studio.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/studio.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/studio.py b/scratchattach/site/studio.py index 4d254bc0..6eeb6def 100644 --- a/scratchattach/site/studio.py +++ b/scratchattach/site/studio.py @@ -592,7 +592,11 @@ def get_studio(studio_id) -> Studio: If you want to use these, get the studio with :meth:`scratchattach.session.Session.connect_studio` instead. """ - print("Warning: For methods that require authentication, use session.connect_studio instead of get_studio") + warnings.warn( + "Warning: For methods that require authentication, use session.connect_studio instead of get_studio." + "If you want to remove this warning, use warnings.filterwarning('ignore', category=StudioAuthenticationWarning)", + exceptions.StudioAuthenticationWarning + ) return commons._get_object("id", studio_id, Studio, exceptions.StudioNotFound) def search_studios(*, query="", mode="trending", language="en", limit=40, offset=0): From 0c3e7ea62e2c50eaf87036e06a716934b18bb4a7 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:53:13 -0500 Subject: [PATCH 12/19] import warnings Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index 280845ab..4b456ee5 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -6,6 +6,7 @@ import random import base64 import time +import warnings import zipfile from io import BytesIO from typing import Callable From e996ca92e5192d60146b6f5e1092c5cdb5a618fd Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 07:15:04 -0500 Subject: [PATCH 13/19] fix project authentication message Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index 4b456ee5..272fafd5 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -937,7 +937,7 @@ def get_project(project_id) -> Project: warnings.warn( "Warning: For methods that require authentication, use session.connect_project instead of get_project. " "If you want to remove this warning, " - "use `warnings.filterwarnings('ignore', category=scratchattach.LoginDataWarning)`", + "use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`", exceptions.ProjectAuthenticationWarning ) return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound) From 30ab713f838834df2e22e5368e0d0a980a75c031 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:18:10 -0500 Subject: [PATCH 14/19] subclass all warnings Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/utils/exceptions.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scratchattach/utils/exceptions.py b/scratchattach/utils/exceptions.py index 0be13feb..3ed22106 100644 --- a/scratchattach/utils/exceptions.py +++ b/scratchattach/utils/exceptions.py @@ -236,26 +236,31 @@ class InvalidUpdateWarning(UserWarning): """ Warns you that something cannot be updated. """ - -class UserAuthenticationWarning(UserWarning): + +class GetAuthenticationWarning(UserWarning): + """ + All authentication warnings. + """ + +class UserAuthenticationWarning(GetAuthenticationWarning): """ Warns you to use session.connect_user instead of user.get_user for actions that require authentication. """ -class ProjectAuthenticationWarning(UserWarning): +class ProjectAuthenticationWarning(GetAuthenticationWarning): """ Warns you to use session.connect_project instead of project.get_project for actions that require authentication. """ -class StudioAuthenticationWarning(UserWarning): +class StudioAuthenticationWarning(GetAuthenticationWarning): """ Warns you to use session.connect_studio instead of studio.get_studio for actions that require authentication. """ -class ClassroomAuthenticationWarning(UserWarning): +class ClassroomAuthenticationWarning(GetAuthenticationWarning): """ Warns you to use session.connect_classroom or session.connect_classroom_from_token instead of classroom.get_classroom for actions that require authentication. From e897958bf467bdda8cb190729f099dc0dcc94649 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:21:08 -0500 Subject: [PATCH 15/19] Update user.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/user.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/user.py b/scratchattach/site/user.py index 47a76db4..21a4f678 100644 --- a/scratchattach/site/user.py +++ b/scratchattach/site/user.py @@ -992,7 +992,9 @@ def get_user(username) -> User: """ warnings.warn( "Warning: For methods that require authentication, use session.connect_user instead of get_user. " - "To ignore this warning, use warnings.filterwarning('ignore', category=UserAuthenticationWarning)", + "To ignore this warning, use warnings.filterwarning('ignore', category=UserAuthenticationWarning). " + "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " + "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", exceptions.UserAuthenticationWarning ) return commons._get_object("username", username, User, exceptions.UserNotFound) From 7e9b798a2045dc5d80aa4483c35c6f5f88ae8cb1 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:21:32 -0500 Subject: [PATCH 16/19] Update studio.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/studio.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/studio.py b/scratchattach/site/studio.py index 6eeb6def..a75240ed 100644 --- a/scratchattach/site/studio.py +++ b/scratchattach/site/studio.py @@ -594,7 +594,9 @@ def get_studio(studio_id) -> Studio: """ warnings.warn( "Warning: For methods that require authentication, use session.connect_studio instead of get_studio." - "If you want to remove this warning, use warnings.filterwarning('ignore', category=StudioAuthenticationWarning)", + "If you want to remove this warning, use warnings.filterwarning('ignore', category=StudioAuthenticationWarning). " + "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " + "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", exceptions.StudioAuthenticationWarning ) return commons._get_object("id", studio_id, Studio, exceptions.StudioNotFound) From 005d7f366e450b7000000b4b6987d190a472e694 Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:22:04 -0500 Subject: [PATCH 17/19] Update project.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/project.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index 272fafd5..2849ceac 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -937,7 +937,9 @@ def get_project(project_id) -> Project: warnings.warn( "Warning: For methods that require authentication, use session.connect_project instead of get_project. " "If you want to remove this warning, " - "use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`", + "use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`. " + "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " + "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", exceptions.ProjectAuthenticationWarning ) return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound) From ba0a358b88e65a8e9d51b2d994f040f62b10018d Mon Sep 17 00:00:00 2001 From: Boss-1s <95505913+Boss-1s@users.noreply.github.com> Date: Mon, 29 Sep 2025 15:22:30 -0500 Subject: [PATCH 18/19] Update classroom.py Signed-off-by: Boss-1s <95505913+Boss-1s@users.noreply.github.com> --- scratchattach/site/classroom.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scratchattach/site/classroom.py b/scratchattach/site/classroom.py index da17cb34..f7e4acb5 100644 --- a/scratchattach/site/classroom.py +++ b/scratchattach/site/classroom.py @@ -421,7 +421,9 @@ def get_classroom_from_token(class_token) -> Classroom: """ warnings.warn( "For methods that require authentication, use session.connect_classroom instead of get_classroom. " - "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning)", + "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning). " + "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " + "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", exceptions.ClassroomAuthenticationWarning ) return commons._get_object("classtoken", class_token, Classroom, exceptions.ClassroomNotFound) From 6b34f790e9d36a9bed3a70f8d947521367a42178 Mon Sep 17 00:00:00 2001 From: faretek Date: Mon, 29 Sep 2025 22:26:42 +0100 Subject: [PATCH 19/19] fix: amendments to make it work: - import warnings in `__init__.py` - add 's' to filterwarning - use newlines in warning message - use 'scratchattach.' as a prefix - add the note about getauthentication warning to classroom - import warnings in studio.py Closes 486 --- scratchattach/__init__.py | 11 +++++++++-- scratchattach/site/classroom.py | 10 ++++++---- scratchattach/site/project.py | 6 +++--- scratchattach/site/studio.py | 7 ++++--- scratchattach/site/user.py | 6 +++--- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/scratchattach/__init__.py b/scratchattach/__init__.py index f10ae38b..63a9c59f 100644 --- a/scratchattach/__init__.py +++ b/scratchattach/__init__.py @@ -11,7 +11,13 @@ # from .other.project_json_capabilities import ProjectBody, get_empty_project_pb, get_pb_from_dict, read_sb3_file, download_asset from .utils.encoder import Encoding from .utils.enums import Languages, TTSVoices -from .utils.exceptions import LoginDataWarning +from .utils.exceptions import ( + LoginDataWarning, + GetAuthenticationWarning, + StudioAuthenticationWarning, + ClassroomAuthenticationWarning, + ProjectAuthenticationWarning, + UserAuthenticationWarning) from .site.activity import Activity, ActvityTypes from .site.backpack_asset import BackpackAsset @@ -19,7 +25,8 @@ from .site.cloud_activity import CloudActivity from .site.forum import ForumPost, ForumTopic, get_topic, get_topic_list, youtube_link_to_scratch from .site.project import Project, get_project, search_projects, explore_projects -from .site.session import Session, login, login_by_id, login_by_session_string, login_by_io, login_by_file, login_from_browser +from .site.session import Session, login, login_by_id, login_by_session_string, login_by_io, login_by_file, \ + login_from_browser from .site.studio import Studio, get_studio, search_studios, explore_studios from .site.classroom import Classroom, get_classroom from .site.user import User, get_user, Rank diff --git a/scratchattach/site/classroom.py b/scratchattach/site/classroom.py index f7e4acb5..4eacac89 100644 --- a/scratchattach/site/classroom.py +++ b/scratchattach/site/classroom.py @@ -397,8 +397,10 @@ def get_classroom(class_id: str) -> Classroom: If you want to use these, get the user with :meth:`scratchattach.session.Session.connect_classroom` instead. """ warnings.warn( - "For methods that require authentication, use session.connect_classroom instead of get_classroom" - "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning)", + "For methods that require authentication, use session.connect_classroom instead of get_classroom\n" + "If you want to remove this warning, use warnings.filterwarnings('ignore', category=scratchattach.ClassroomAuthenticationWarning)\n" + "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " + "`warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.", exceptions.ClassroomAuthenticationWarning ) return commons._get_object("id", class_id, Classroom, exceptions.ClassroomNotFound) @@ -421,9 +423,9 @@ def get_classroom_from_token(class_token) -> Classroom: """ warnings.warn( "For methods that require authentication, use session.connect_classroom instead of get_classroom. " - "If you want to remove this warning, use warnings.filterwarning('ignore', category=ClassroomAuthenticationWarning). " + "If you want to remove this warning, use warnings.filterwarnings('ignore', category=ClassroomAuthenticationWarning). " "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " - "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", + "warnings.filterwarnings('ignore', category=GetAuthenticationWarning).", exceptions.ClassroomAuthenticationWarning ) return commons._get_object("classtoken", class_token, Classroom, exceptions.ClassroomNotFound) diff --git a/scratchattach/site/project.py b/scratchattach/site/project.py index 2849ceac..891e1a12 100644 --- a/scratchattach/site/project.py +++ b/scratchattach/site/project.py @@ -935,11 +935,11 @@ def get_project(project_id) -> Project: If you want to use these methods, get the project with :meth:`scratchattach.session.Session.connect_project` instead. """ warnings.warn( - "Warning: For methods that require authentication, use session.connect_project instead of get_project. " + "Warning: For methods that require authentication, use session.connect_project instead of get_project.\n" "If you want to remove this warning, " - "use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`. " + "use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`.\n" "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " - "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", + "`warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.", exceptions.ProjectAuthenticationWarning ) return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound) diff --git a/scratchattach/site/studio.py b/scratchattach/site/studio.py index a75240ed..a9eaf93f 100644 --- a/scratchattach/site/studio.py +++ b/scratchattach/site/studio.py @@ -1,6 +1,7 @@ """Studio class""" from __future__ import annotations +import warnings import json import random from . import user, comment, project, activity @@ -593,10 +594,10 @@ def get_studio(studio_id) -> Studio: If you want to use these, get the studio with :meth:`scratchattach.session.Session.connect_studio` instead. """ warnings.warn( - "Warning: For methods that require authentication, use session.connect_studio instead of get_studio." - "If you want to remove this warning, use warnings.filterwarning('ignore', category=StudioAuthenticationWarning). " + "Warning: For methods that require authentication, use session.connect_studio instead of get_studio.\n" + "If you want to remove this warning, use warnings.filterwarnings('ignore', category=scratchattach.StudioAuthenticationWarning).\n" "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " - "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", + "`warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.", exceptions.StudioAuthenticationWarning ) return commons._get_object("id", studio_id, Studio, exceptions.StudioNotFound) diff --git a/scratchattach/site/user.py b/scratchattach/site/user.py index 21a4f678..a9b35d1e 100644 --- a/scratchattach/site/user.py +++ b/scratchattach/site/user.py @@ -991,10 +991,10 @@ def get_user(username) -> User: If you want to use these, get the user with :meth:`scratchattach.session.Session.connect_user` instead. """ warnings.warn( - "Warning: For methods that require authentication, use session.connect_user instead of get_user. " - "To ignore this warning, use warnings.filterwarning('ignore', category=UserAuthenticationWarning). " + "Warning: For methods that require authentication, use session.connect_user instead of get_user.\n" + "To ignore this warning, use warnings.filterwarnings('ignore', category=scratchattach.UserAuthenticationWarning).\n" "To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use " - "warnings.filterwarning('ignore', category=GetAuthenticationWarning).", + "`warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.", exceptions.UserAuthenticationWarning ) return commons._get_object("username", username, User, exceptions.UserNotFound)