Skip to content

Commit ab400cc

Browse files
added descriptor object to Account class
1 parent c286473 commit ab400cc

File tree

1 file changed

+20
-36
lines changed

1 file changed

+20
-36
lines changed

py/selenium/webdriver/common/fedcm/account.py

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,32 @@ class LoginState(Enum):
2424
SIGN_UP = "SignUp"
2525

2626

27+
class _AccountDescriptor:
28+
def __init__(self, name):
29+
self.name = name
30+
31+
def __get__(self, obj, cls) -> Optional[str]:
32+
return obj._account_data.get(self.name)
33+
34+
def __set__(self, obj, value) -> None:
35+
raise AttributeError(f"Cannot set readonly attribute")
36+
37+
2738
class Account:
2839
"""Represents an account displayed in a FedCM account list.
2940
3041
See: https://w3c-fedid.github.io/FedCM/#dictdef-identityprovideraccount
3142
https://w3c-fedid.github.io/FedCM/#webdriver-accountlist
3243
"""
44+
account_id = _AccountDescriptor("accountId")
45+
email = _AccountDescriptor("email")
46+
name = _AccountDescriptor("name")
47+
given_name = _AccountDescriptor("givenName")
48+
picture_url = _AccountDescriptor("pictureUrl")
49+
idp_config_url = _AccountDescriptor("idpConfigUrl")
50+
terms_of_service_url = _AccountDescriptor("termsOfServiceUrl")
51+
privacy_policy_url = _AccountDescriptor("privacyPolicyUrl")
52+
login_state = _AccountDescriptor("loginState")
3353

3454
def __init__(self, account_data):
3555
self._account_data = account_data
36-
37-
@property
38-
def account_id(self) -> Optional[str]:
39-
return self._account_data.get("accountId")
40-
41-
@property
42-
def email(self) -> Optional[str]:
43-
return self._account_data.get("email")
44-
45-
@property
46-
def name(self) -> Optional[str]:
47-
return self._account_data.get("name")
48-
49-
@property
50-
def given_name(self) -> Optional[str]:
51-
return self._account_data.get("givenName")
52-
53-
@property
54-
def picture_url(self) -> Optional[str]:
55-
return self._account_data.get("pictureUrl")
56-
57-
@property
58-
def idp_config_url(self) -> Optional[str]:
59-
return self._account_data.get("idpConfigUrl")
60-
61-
@property
62-
def terms_of_service_url(self) -> Optional[str]:
63-
return self._account_data.get("termsOfServiceUrl")
64-
65-
@property
66-
def privacy_policy_url(self) -> Optional[str]:
67-
return self._account_data.get("privacyPolicyUrl")
68-
69-
@property
70-
def login_state(self) -> Optional[str]:
71-
return self._account_data.get("loginState")

0 commit comments

Comments
 (0)