|
16 | 16 | from contextlib import contextmanager |
17 | 17 | from threading import local |
18 | 18 |
|
19 | | -# import secrets |
20 | | -# import zipfile |
21 | | -# from typing import Type |
22 | 19 | Type = type |
23 | 20 |
|
24 | 21 | if TYPE_CHECKING: |
@@ -910,6 +907,7 @@ def connect_user_by_id(self, user_id: int) -> user.User: |
910 | 907 | Returns: |
911 | 908 | scratchattach.user.User: An object that represents the requested user and allows you to perform actions on the user (like user.follow) |
912 | 909 | """ |
| 910 | + # noinspection PyDeprecation |
913 | 911 | return self._make_linked_object("username", self.find_username_from_id(user_id), user.User, |
914 | 912 | exceptions.UserNotFound) |
915 | 913 |
|
@@ -1131,21 +1129,18 @@ def login_by_id(session_id: str, *, username: Optional[str] = None, password: Op |
1131 | 1129 | scratchattach.session.Session: An object that represents the created login / session |
1132 | 1130 | """ |
1133 | 1131 | # Generate session_string (a scratchattach-specific authentication method) |
| 1132 | + # should this be changed to a @property? |
1134 | 1133 | issue_login_warning() |
1135 | 1134 | if password is not None: |
1136 | 1135 | session_data = dict(id=session_id, username=username, password=password) |
1137 | 1136 | session_string = base64.b64encode(json.dumps(session_data).encode()).decode() |
1138 | 1137 | else: |
1139 | 1138 | session_string = None |
1140 | 1139 |
|
1141 | | - if xtoken is not None: |
1142 | | - # todo: consider removing the xtoken parameter? |
1143 | | - warnings.warn("xtoken is redundant because it is retrieved by decoding the session id.") |
1144 | | - |
1145 | 1140 | _session = Session(id=session_id, username=username, session_string=session_string) |
1146 | | - |
1147 | | - # xtoken is decoded from sessid, so don't use sess.update |
1148 | | - # but this will cause incompatibilities, warranting a change in the 2nd (semver) version number |
| 1141 | + if xtoken is not None: |
| 1142 | + # xtoken is retrievable from session id, so the most we can do is assert equality |
| 1143 | + assert xtoken == _session.xtoken |
1149 | 1144 |
|
1150 | 1145 | return _session |
1151 | 1146 |
|
@@ -1176,7 +1171,6 @@ def login(username, password, *, timeout=10) -> Session: |
1176 | 1171 | with requests.no_error_handling(): |
1177 | 1172 | request = requests.post( |
1178 | 1173 | "https://scratch.mit.edu/login/", json={"username": username, "password": password}, headers=_headers, |
1179 | | - |
1180 | 1174 | timeout=timeout |
1181 | 1175 | ) |
1182 | 1176 | try: |
|
0 commit comments