diff --git a/pyproject.toml b/pyproject.toml index 8901704..9a6e34a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -48,7 +48,7 @@ line-length = 88 target-version = "py311" [tool.ruff.lint] -select = ["E4", "E7", "E9", "F", "UP", "S", "ANN", "C4", "I", "RUF", "SIM", "PLR", "ERA"] +select = ["E4", "E7", "E9", "F", "UP", "S", "ANN", "C4", "I", "RUF", "SIM", "PLR", "ERA", "RET"] # select = ["ALL"] ignore = ["ANN003", "ANN401", "D", "COM"] diff --git a/src/pythonxbox/api/provider/ratelimitedprovider.py b/src/pythonxbox/api/provider/ratelimitedprovider.py index 979ba87..808f691 100644 --- a/src/pythonxbox/api/provider/ratelimitedprovider.py +++ b/src/pythonxbox/api/provider/ratelimitedprovider.py @@ -69,12 +69,11 @@ def __parse_rate_limit_key( if isinstance(key, int) and not isinstance(key, bool): # bool is a subclass of int, hence the explicit check return ParsedRateLimit(read=key, write=key, period=period) - elif isinstance(key, dict): + if isinstance(key, dict): # TODO: schema here? # Since the key-value pairs match we can just pass the dict to the model return ParsedRateLimit(**key, period=period) - else: - raise XboxException( - "RATE_LIMITS value types not recognised. Must be one of 'int, 'dict'." - ) + raise XboxException( + "RATE_LIMITS value types not recognised. Must be one of 'int, 'dict'." + ) diff --git a/src/pythonxbox/authentication/xal.py b/src/pythonxbox/authentication/xal.py index 654c663..9e7d1b7 100644 --- a/src/pythonxbox/authentication/xal.py +++ b/src/pythonxbox/authentication/xal.py @@ -112,9 +112,7 @@ def _generate_code_verifier() -> str: def _get_code_challenge_from_code_verifier(code_verifier: str) -> str: code_challenge = hashlib.sha256(code_verifier.encode()).digest() # Base64 urlsafe encoding WITH stripping trailing '=' - code_challenge = base64.urlsafe_b64encode(code_challenge).decode().rstrip("=") - - return code_challenge + return base64.urlsafe_b64encode(code_challenge).decode().rstrip("=") @staticmethod def _generate_random_state() -> str: @@ -345,8 +343,6 @@ async def auth_flow( ) # Do Sisu authorization - sisu_authorization = await self.do_sisu_authorization( + return await self.do_sisu_authorization( sisu_session_id, tokens.access_token, device_token_resp.token ) - - return sisu_authorization diff --git a/src/pythonxbox/common/filetimes.py b/src/pythonxbox/common/filetimes.py index f06a3fe..a72dee3 100644 --- a/src/pythonxbox/common/filetimes.py +++ b/src/pythonxbox/common/filetimes.py @@ -77,5 +77,4 @@ def filetime_to_dt(ft: int) -> datetime: # Convert to datetime object dt = datetime.fromtimestamp(s, UTC) # Add remainder in as microseconds. Python 3.2 requires an integer - dt = dt.replace(microsecond=(ns100 // 10)) - return dt + return dt.replace(microsecond=(ns100 // 10)) diff --git a/src/pythonxbox/common/request_signer.py b/src/pythonxbox/common/request_signer.py index 531a04f..bb58fd7 100644 --- a/src/pythonxbox/common/request_signer.py +++ b/src/pythonxbox/common/request_signer.py @@ -179,11 +179,13 @@ def _concat_data_to_sign( # noqa: PLR0913 @staticmethod def __base64_escaped(binary: bytes) -> str: - encoded = base64.b64encode(binary).decode("ascii") - encoded = encoded.rstrip("=") - encoded = encoded.replace("+", "-") - encoded = encoded.replace("/", "_") - return encoded + return ( + base64.b64encode(binary) + .decode("ascii") + .rstrip("=") + .replace("+", "-") + .replace("/", "_") + ) @staticmethod def __encode_ec_coord(coord: int) -> str: diff --git a/src/pythonxbox/scripts/xal.py b/src/pythonxbox/scripts/xal.py index 2a0b767..3e1651e 100644 --- a/src/pythonxbox/scripts/xal.py +++ b/src/pythonxbox/scripts/xal.py @@ -42,12 +42,11 @@ def user_prompt_authentication(auth_url: str) -> str: Takes the redirect URL from stdin """ - redirect_url = input( + return input( f"Continue auth with the following URL:\n\n" f"URL: {auth_url}\n\n" f"Provide redirect URI: " ) - return redirect_url async def do_auth(device_id: uuid.UUID, token_filepath: str) -> None: