Skip to content

Commit

Permalink
added descriptor object to Account class
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsuryaprasad committed Dec 5, 2024
1 parent c286473 commit ab400cc
Showing 1 changed file with 20 additions and 36 deletions.
56 changes: 20 additions & 36 deletions py/selenium/webdriver/common/fedcm/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,32 @@ class LoginState(Enum):
SIGN_UP = "SignUp"


class _AccountDescriptor:
def __init__(self, name):
self.name = name

def __get__(self, obj, cls) -> Optional[str]:
return obj._account_data.get(self.name)

def __set__(self, obj, value) -> None:
raise AttributeError(f"Cannot set readonly attribute")


class Account:
"""Represents an account displayed in a FedCM account list.
See: https://w3c-fedid.github.io/FedCM/#dictdef-identityprovideraccount
https://w3c-fedid.github.io/FedCM/#webdriver-accountlist
"""
account_id = _AccountDescriptor("accountId")
email = _AccountDescriptor("email")
name = _AccountDescriptor("name")
given_name = _AccountDescriptor("givenName")
picture_url = _AccountDescriptor("pictureUrl")
idp_config_url = _AccountDescriptor("idpConfigUrl")
terms_of_service_url = _AccountDescriptor("termsOfServiceUrl")
privacy_policy_url = _AccountDescriptor("privacyPolicyUrl")
login_state = _AccountDescriptor("loginState")

def __init__(self, account_data):
self._account_data = account_data

@property
def account_id(self) -> Optional[str]:
return self._account_data.get("accountId")

@property
def email(self) -> Optional[str]:
return self._account_data.get("email")

@property
def name(self) -> Optional[str]:
return self._account_data.get("name")

@property
def given_name(self) -> Optional[str]:
return self._account_data.get("givenName")

@property
def picture_url(self) -> Optional[str]:
return self._account_data.get("pictureUrl")

@property
def idp_config_url(self) -> Optional[str]:
return self._account_data.get("idpConfigUrl")

@property
def terms_of_service_url(self) -> Optional[str]:
return self._account_data.get("termsOfServiceUrl")

@property
def privacy_policy_url(self) -> Optional[str]:
return self._account_data.get("privacyPolicyUrl")

@property
def login_state(self) -> Optional[str]:
return self._account_data.get("loginState")

0 comments on commit ab400cc

Please sign in to comment.