Skip to content

Commit 313f7a5

Browse files
[py] moved all getters in fedcm/account.py into descriptor object. (#14858)
1 parent a3af929 commit 313f7a5

File tree

1 file changed

+21
-36
lines changed

1 file changed

+21
-36
lines changed

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

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,33 @@ 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("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
"""
3344

45+
account_id = _AccountDescriptor("accountId")
46+
email = _AccountDescriptor("email")
47+
name = _AccountDescriptor("name")
48+
given_name = _AccountDescriptor("givenName")
49+
picture_url = _AccountDescriptor("pictureUrl")
50+
idp_config_url = _AccountDescriptor("idpConfigUrl")
51+
terms_of_service_url = _AccountDescriptor("termsOfServiceUrl")
52+
privacy_policy_url = _AccountDescriptor("privacyPolicyUrl")
53+
login_state = _AccountDescriptor("loginState")
54+
3455
def __init__(self, account_data):
3556
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)