Skip to content

Commit 307a36d

Browse files
committed
Update for pydantic v2 compatibility
1 parent 398320c commit 307a36d

File tree

26 files changed

+372
-371
lines changed

26 files changed

+372
-371
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,17 @@ async def async_main():
100100
with open(tokens_file) as f:
101101
tokens = f.read()
102102
# Assign gathered tokens
103-
auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
103+
auth_mgr.oauth = OAuth2TokenResponse.model_validate_json(tokens)
104104
except FileNotFoundError as e:
105105
print(
106106
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
107107
)
108-
sys.exit(-1)
108+
print("Authorizing via OAUTH")
109+
url = auth_mgr.generate_authorization_url()
110+
print(f"Auth via URL: {url}")
111+
authorization_code = input("Enter authorization code> ")
112+
tokens = await auth_mgr.request_oauth_token(authorization_code)
113+
auth_mgr.oauth = tokens
109114

110115
"""
111116
Refresh tokens, just in case

readme_example.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ async def async_main():
3939
with open(tokens_file) as f:
4040
tokens = f.read()
4141
# Assign gathered tokens
42-
auth_mgr.oauth = OAuth2TokenResponse.parse_raw(tokens)
42+
auth_mgr.oauth = OAuth2TokenResponse.model_validate_json(tokens)
4343
except FileNotFoundError as e:
4444
print(
4545
f"File {tokens_file} isn`t found or it doesn`t contain tokens! err={e}"
4646
)
47-
sys.exit(-1)
47+
print("Authorizing via OAUTH")
48+
url = auth_mgr.generate_authorization_url()
49+
print(f"Auth via URL: {url}")
50+
authorization_code = input("Enter authorization code> ")
51+
tokens = await auth_mgr.request_oauth_token(authorization_code)
52+
auth_mgr.oauth = tokens
4853

4954
"""
5055
Refresh tokens, just in case

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ httpx
33
appdirs
44
ecdsa
55
ms_cv
6-
pydantic
6+
pydantic==2.*
77

88
# Dev
99
pytest

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, UTC
22
import uuid
33

44
from ecdsa.keys import SigningKey, VerifyingKey
@@ -29,9 +29,9 @@
2929
async def auth_mgr(event_loop):
3030
session = SignedSession()
3131
mgr = AuthenticationManager(session, "abc", "123", "http://localhost")
32-
mgr.oauth = OAuth2TokenResponse.parse_raw(get_response("auth_oauth2_token"))
33-
mgr.user_token = XAUResponse.parse_raw(get_response("auth_user_token"))
34-
mgr.xsts_token = XSTSResponse.parse_raw(get_response("auth_xsts_token"))
32+
mgr.oauth = OAuth2TokenResponse.model_validate_json(get_response("auth_oauth2_token"))
33+
mgr.user_token = XAUResponse.model_validate_json(get_response("auth_user_token"))
34+
mgr.xsts_token = XSTSResponse.model_validate_json(get_response("auth_xsts_token"))
3535
yield mgr
3636
await session.aclose()
3737

@@ -77,4 +77,4 @@ def synthetic_request_signer(ecdsa_signing_key) -> RequestSigner:
7777

7878
@pytest.fixture(scope="session")
7979
def synthetic_timestamp() -> datetime:
80-
return datetime.utcfromtimestamp(1586999965)
80+
return datetime.fromtimestamp(1586999965, UTC)

xbox/webapi/api/provider/achievements/models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class PagingInfo(CamelCaseModel):
10-
continuation_token: Optional[str]
10+
continuation_token: Optional[str] = None
1111
total_records: int
1212

1313

@@ -62,7 +62,7 @@ class TitleAssociation(BaseModel):
6262

6363
class Requirement(CamelCaseModel):
6464
id: str
65-
current: Optional[str]
65+
current: Optional[str] = None
6666
target: str
6767
operation_type: str
6868
value_type: str
@@ -81,11 +81,11 @@ class MediaAsset(BaseModel):
8181

8282

8383
class Reward(CamelCaseModel):
84-
name: Any
85-
description: Any
84+
name: Any = None
85+
description: Any = None
8686
value: str
8787
type: str
88-
media_asset: Any
88+
media_asset: Any = None
8989
value_type: str
9090

9191

@@ -104,10 +104,10 @@ class Achievement(CamelCaseModel):
104104
product_id: str
105105
achievement_type: str
106106
participation_type: str
107-
time_window: Any
107+
time_window: Any = None
108108
rewards: List[Reward]
109109
estimated_time: time
110-
deeplink: Any
110+
deeplink: Any = None
111111
is_revoked: bool
112112

113113

0 commit comments

Comments
 (0)