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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
9 changes: 4 additions & 5 deletions src/pythonxbox/api/provider/ratelimitedprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'."
)
8 changes: 2 additions & 6 deletions src/pythonxbox/authentication/xal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions src/pythonxbox/common/filetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
12 changes: 7 additions & 5 deletions src/pythonxbox/common/request_signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions src/pythonxbox/scripts/xal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading