Creates a session / log in to the Scratch website with the specified session id. Structured similarly to Session._connect_object method. Args: session_id (str) Keyword arguments: username (str) password (str) xtoken (str) Returns: scrat
(session_id: str, *, username: Optional[str] = None, password: Optional[str] = None, xtoken=None)
| 1365 | |
| 1366 | |
| 1367 | def login_by_id(session_id: str, *, username: Optional[str] = None, password: Optional[str] = None, xtoken=None) -> Session: |
| 1368 | """ |
| 1369 | Creates a session / log in to the Scratch website with the specified session id. |
| 1370 | Structured similarly to Session._connect_object method. |
| 1371 | |
| 1372 | Args: |
| 1373 | session_id (str) |
| 1374 | |
| 1375 | Keyword arguments: |
| 1376 | username (str) |
| 1377 | password (str) |
| 1378 | xtoken (str) |
| 1379 | |
| 1380 | Returns: |
| 1381 | scratchattach.session.Session: An object that represents the created login / session |
| 1382 | """ |
| 1383 | # Generate session_string (a scratchattach-specific authentication method) |
| 1384 | # should this be changed to a @property? |
| 1385 | issue_login_warning() |
| 1386 | if password is not None: |
| 1387 | session_data = dict(id=session_id, username=username, password=password) |
| 1388 | session_string = base64.b64encode(json.dumps(session_data).encode()).decode() |
| 1389 | else: |
| 1390 | session_string = None |
| 1391 | |
| 1392 | _session = Session(id=session_id, username=username or "", session_string=session_string) |
| 1393 | if xtoken is not None: |
| 1394 | # xtoken is retrievable from session id, so the most we can do is assert equality |
| 1395 | assert xtoken == _session.xtoken |
| 1396 | |
| 1397 | return _session |
| 1398 | |
| 1399 | |
| 1400 | def login(username, password, *, timeout=10) -> Session: |
no test coverage detected