scratchattach 2.1.8__py3-none-any.whl → 2.1.10a0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- scratchattach/__init__.py +28 -25
- scratchattach/cloud/__init__.py +2 -0
- scratchattach/cloud/_base.py +454 -282
- scratchattach/cloud/cloud.py +171 -168
- scratchattach/editor/__init__.py +21 -0
- scratchattach/editor/asset.py +199 -0
- scratchattach/editor/backpack_json.py +117 -0
- scratchattach/editor/base.py +142 -0
- scratchattach/editor/block.py +507 -0
- scratchattach/editor/blockshape.py +353 -0
- scratchattach/editor/build_defaulting.py +47 -0
- scratchattach/editor/comment.py +74 -0
- scratchattach/editor/commons.py +243 -0
- scratchattach/editor/extension.py +43 -0
- scratchattach/editor/field.py +90 -0
- scratchattach/editor/inputs.py +132 -0
- scratchattach/editor/meta.py +106 -0
- scratchattach/editor/monitor.py +175 -0
- scratchattach/editor/mutation.py +317 -0
- scratchattach/editor/pallete.py +91 -0
- scratchattach/editor/prim.py +170 -0
- scratchattach/editor/project.py +273 -0
- scratchattach/editor/sbuild.py +2837 -0
- scratchattach/editor/sprite.py +586 -0
- scratchattach/editor/twconfig.py +113 -0
- scratchattach/editor/vlb.py +134 -0
- scratchattach/eventhandlers/_base.py +99 -92
- scratchattach/eventhandlers/cloud_events.py +110 -103
- scratchattach/eventhandlers/cloud_recorder.py +26 -21
- scratchattach/eventhandlers/cloud_requests.py +460 -452
- scratchattach/eventhandlers/cloud_server.py +246 -244
- scratchattach/eventhandlers/cloud_storage.py +135 -134
- scratchattach/eventhandlers/combine.py +29 -27
- scratchattach/eventhandlers/filterbot.py +160 -159
- scratchattach/eventhandlers/message_events.py +41 -40
- scratchattach/other/other_apis.py +284 -212
- scratchattach/other/project_json_capabilities.py +475 -546
- scratchattach/site/_base.py +64 -46
- scratchattach/site/activity.py +414 -122
- scratchattach/site/backpack_asset.py +118 -84
- scratchattach/site/classroom.py +430 -142
- scratchattach/site/cloud_activity.py +107 -103
- scratchattach/site/comment.py +220 -190
- scratchattach/site/forum.py +400 -399
- scratchattach/site/project.py +806 -787
- scratchattach/site/session.py +1134 -867
- scratchattach/site/studio.py +611 -609
- scratchattach/site/user.py +835 -837
- scratchattach/utils/commons.py +243 -148
- scratchattach/utils/encoder.py +157 -156
- scratchattach/utils/enums.py +197 -190
- scratchattach/utils/exceptions.py +233 -206
- scratchattach/utils/requests.py +67 -59
- {scratchattach-2.1.8.dist-info → scratchattach-2.1.10a0.dist-info}/LICENSE +21 -21
- {scratchattach-2.1.8.dist-info → scratchattach-2.1.10a0.dist-info}/METADATA +154 -146
- scratchattach-2.1.10a0.dist-info/RECORD +62 -0
- {scratchattach-2.1.8.dist-info → scratchattach-2.1.10a0.dist-info}/WHEEL +1 -1
- scratchattach-2.1.8.dist-info/RECORD +0 -40
- {scratchattach-2.1.8.dist-info → scratchattach-2.1.10a0.dist-info}/top_level.txt +0 -0
|
@@ -1,84 +1,118 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
try:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
try:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import time
|
|
5
|
+
import logging
|
|
6
|
+
|
|
7
|
+
from ._base import BaseSiteComponent
|
|
8
|
+
from ..utils import exceptions
|
|
9
|
+
from ..utils.requests import Requests as requests
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class BackpackAsset(BaseSiteComponent):
|
|
14
|
+
"""
|
|
15
|
+
Represents an asset from the backpack.
|
|
16
|
+
|
|
17
|
+
Attributes:
|
|
18
|
+
|
|
19
|
+
:.id:
|
|
20
|
+
|
|
21
|
+
:.type: The asset type (costume, script etc.)
|
|
22
|
+
|
|
23
|
+
:.mime: The format in which the content of the backpack asset is saved
|
|
24
|
+
|
|
25
|
+
:.name: The name of the backpack asset
|
|
26
|
+
|
|
27
|
+
:.filename: Filename of the file containing the content of the backpack asset
|
|
28
|
+
|
|
29
|
+
:.thumbnail_url: Link that leads to the asset's thumbnail (the image shown in the backpack UI)
|
|
30
|
+
|
|
31
|
+
:.download_url: Link that leads to a file containing the content of the backpack asset
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
def __init__(self, **entries):
|
|
35
|
+
# Set attributes every BackpackAsset object needs to have:
|
|
36
|
+
self._session = None
|
|
37
|
+
|
|
38
|
+
# Update attributes from entries dict:
|
|
39
|
+
self.__dict__.update(entries)
|
|
40
|
+
|
|
41
|
+
def update(self):
|
|
42
|
+
print("Warning: BackpackAsset objects can't be updated")
|
|
43
|
+
return False # Objects of this type cannot be updated
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _update_from_dict(self, data) -> bool:
|
|
47
|
+
try:
|
|
48
|
+
self.id = data["id"]
|
|
49
|
+
except Exception:
|
|
50
|
+
pass
|
|
51
|
+
try:
|
|
52
|
+
self.type = data["type"]
|
|
53
|
+
except Exception:
|
|
54
|
+
pass
|
|
55
|
+
try:
|
|
56
|
+
self.mime = data["mime"]
|
|
57
|
+
except Exception:
|
|
58
|
+
pass
|
|
59
|
+
try:
|
|
60
|
+
self.name = data["name"]
|
|
61
|
+
except Exception:
|
|
62
|
+
pass
|
|
63
|
+
try:
|
|
64
|
+
self.filename = data["body"]
|
|
65
|
+
except Exception:
|
|
66
|
+
pass
|
|
67
|
+
try:
|
|
68
|
+
self.thumbnail_url = "https://backpack.scratch.mit.edu/" + data["thumbnail"]
|
|
69
|
+
except Exception:
|
|
70
|
+
pass
|
|
71
|
+
try:
|
|
72
|
+
self.download_url = "https://backpack.scratch.mit.edu/" + data["body"]
|
|
73
|
+
except Exception:
|
|
74
|
+
pass
|
|
75
|
+
return True
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def _data_bytes(self) -> bytes:
|
|
79
|
+
try:
|
|
80
|
+
return requests.get(self.download_url).content
|
|
81
|
+
except Exception as e:
|
|
82
|
+
raise exceptions.FetchError(f"Failed to download asset: {e}")
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def file_ext(self):
|
|
86
|
+
return self.filename.split(".")[-1]
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def is_json(self):
|
|
90
|
+
return self.file_ext == "json"
|
|
91
|
+
|
|
92
|
+
@property
|
|
93
|
+
def data(self) -> dict | list | int | None | str | bytes | float:
|
|
94
|
+
if self.is_json:
|
|
95
|
+
return json.loads(self._data_bytes)
|
|
96
|
+
else:
|
|
97
|
+
# It's either a zip
|
|
98
|
+
return self._data_bytes
|
|
99
|
+
|
|
100
|
+
def download(self, *, fp: str = ''):
|
|
101
|
+
"""
|
|
102
|
+
Downloads the asset content to the given directory. The given filename is equal to the value saved in the .filename attribute.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
fp (str): The path of the directory the file will be saved in.
|
|
106
|
+
"""
|
|
107
|
+
if not (fp.endswith("/") or fp.endswith("\\")):
|
|
108
|
+
fp = fp + "/"
|
|
109
|
+
open(f"{fp}{self.filename}", "wb").write(self._data_bytes)
|
|
110
|
+
|
|
111
|
+
def delete(self):
|
|
112
|
+
self._assert_auth()
|
|
113
|
+
|
|
114
|
+
return requests.delete(
|
|
115
|
+
f"https://backpack.scratch.mit.edu/{self._session.username}/{self.id}",
|
|
116
|
+
headers=self._session._headers,
|
|
117
|
+
timeout=10,
|
|
118
|
+
).json()
|