Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions scratchattach/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
# 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
from .site.comment import Comment, CommentSource
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
Expand Down
16 changes: 14 additions & 2 deletions scratchattach/site/classroom.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,13 @@ 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\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)


Expand All @@ -415,7 +421,13 @@ 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.filterwarnings('ignore', category=ClassroomAuthenticationWarning). "
"To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use "
"warnings.filterwarnings('ignore', category=GetAuthenticationWarning).",
exceptions.ClassroomAuthenticationWarning
)
return commons._get_object("classtoken", class_token, Classroom, exceptions.ClassroomNotFound)


Expand Down
10 changes: 9 additions & 1 deletion scratchattach/site/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random
import base64
import time
import warnings
import zipfile
from io import BytesIO
from typing import Callable
Expand Down Expand Up @@ -933,7 +934,14 @@ 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.\n"
"If you want to remove this warning, "
"use `warnings.filterwarnings('ignore', category=scratchattach.ProjectAuthenticationWarning)`.\n"
"To ignore all warnings of the type GetAuthenticationWarning, which includes this warning, use "
"`warnings.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.",
exceptions.ProjectAuthenticationWarning
)
return commons._get_object("id", project_id, Project, exceptions.ProjectNotFound)


Expand Down
9 changes: 8 additions & 1 deletion scratchattach/site/studio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Studio class"""
from __future__ import annotations

import warnings
import json
import random
from . import user, comment, project, activity
Expand Down Expand Up @@ -592,7 +593,13 @@ 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.\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.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.",
exceptions.StudioAuthenticationWarning
)
return commons._get_object("id", studio_id, Studio, exceptions.StudioNotFound)

def search_studios(*, query="", mode="trending", language="en", limit=40, offset=0):
Expand Down
8 changes: 7 additions & 1 deletion scratchattach/site/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,5 +990,11 @@ 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.\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.filterwarnings('ignore', category=scratchattach.GetAuthenticationWarning)`.",
exceptions.UserAuthenticationWarning
)
return commons._get_object("username", username, User, exceptions.UserNotFound)
29 changes: 29 additions & 0 deletions scratchattach/utils/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,32 @@ class InvalidUpdateWarning(UserWarning):
"""
Warns you that something cannot be updated.
"""

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(GetAuthenticationWarning):
"""
Warns you to use session.connect_project instead of project.get_project
for actions that require authentication.
"""

class StudioAuthenticationWarning(GetAuthenticationWarning):
"""
Warns you to use session.connect_studio instead of studio.get_studio
for actions that require authentication.
"""

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.
"""