From b41bc2fe22cdeec2cc7c60f982417ce5b083a6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Mon, 6 Jan 2025 15:55:37 +0100 Subject: [PATCH] chore: use unpacking instead of manual concatenation This directly contructs the list instead of using an intermediate copy. --- social_core/actions.py | 15 +++++++++------ social_core/backends/mendeley.py | 3 ++- social_core/backends/oauth.py | 2 +- social_core/backends/odnoklassniki.py | 8 ++++++-- social_core/backends/professionali.py | 9 +++++++-- social_core/backends/vk.py | 3 ++- social_core/utils.py | 2 +- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/social_core/actions.py b/social_core/actions.py index 4ac2b43ab..e9a0d0afc 100644 --- a/social_core/actions.py +++ b/social_core/actions.py @@ -24,8 +24,9 @@ def do_auth(backend, redirect_name="next"): # Check and sanitize a user-defined GET/POST next field value redirect_uri = data[redirect_name] if backend.setting("SANITIZE_REDIRECTS", True): - allowed_hosts = backend.setting("ALLOWED_REDIRECT_HOSTS", []) + [ - backend.strategy.request_host() + allowed_hosts = [ + *backend.setting("ALLOWED_REDIRECT_HOSTS", []), + backend.strategy.request_host(), ] redirect_uri = sanitize_redirect(allowed_hosts, redirect_uri) backend.strategy.session_set( @@ -105,8 +106,9 @@ def do_complete(backend, login, user=None, redirect_name="next", *args, **kwargs url += ("&" if "?" in url else "?") + f"{redirect_name}={redirect_value}" if backend.setting("SANITIZE_REDIRECTS", True): - allowed_hosts = backend.setting("ALLOWED_REDIRECT_HOSTS", []) + [ - backend.strategy.request_host() + allowed_hosts = [ + *backend.setting("ALLOWED_REDIRECT_HOSTS", []), + backend.strategy.request_host(), ] url = sanitize_redirect(allowed_hosts, url) or backend.setting( "LOGIN_REDIRECT_URL" @@ -136,8 +138,9 @@ def do_disconnect( or backend.setting("LOGIN_REDIRECT_URL") ) if backend.setting("SANITIZE_REDIRECTS", True): - allowed_hosts = backend.setting("ALLOWED_REDIRECT_HOSTS", []) + [ - backend.strategy.request_host() + allowed_hosts = [ + *backend.setting("ALLOWED_REDIRECT_HOSTS", []), + backend.strategy.request_host(), ] url = ( sanitize_redirect(allowed_hosts, url) diff --git a/social_core/backends/mendeley.py b/social_core/backends/mendeley.py index 677351fba..b9e37641c 100644 --- a/social_core/backends/mendeley.py +++ b/social_core/backends/mendeley.py @@ -50,7 +50,8 @@ class MendeleyOAuth2(MendeleyMixin, BaseOAuth2): ACCESS_TOKEN_METHOD = "POST" DEFAULT_SCOPE = ["all"] REDIRECT_STATE = False - EXTRA_DATA = MendeleyMixin.EXTRA_DATA + [ + EXTRA_DATA = [ + *MendeleyMixin.EXTRA_DATA, ("refresh_token", "refresh_token"), ("expires_in", "expires_in"), ("token_type", "token_type"), diff --git a/social_core/backends/oauth.py b/social_core/backends/oauth.py index 4668a373e..4a15e69af 100644 --- a/social_core/backends/oauth.py +++ b/social_core/backends/oauth.py @@ -238,7 +238,7 @@ def get_unauthorized_token(self): def set_unauthorized_token(self): token = self.unauthorized_token() name = self.name + self.UNATHORIZED_TOKEN_SUFIX - tokens = self.strategy.session_get(name, []) + [token] + tokens = [*self.strategy.session_get(name, []), token] self.strategy.session_set(name, tokens) return token diff --git a/social_core/backends/odnoklassniki.py b/social_core/backends/odnoklassniki.py index e744689fb..dbc6611de 100644 --- a/social_core/backends/odnoklassniki.py +++ b/social_core/backends/odnoklassniki.py @@ -77,8 +77,12 @@ def get_user_details(self, response): def auth_complete(self, *args, **kwargs): self.verify_auth_sig() response = self.get_response() - fields = ("uid", "first_name", "last_name", "name") + self.setting( - "EXTRA_USER_DATA_LIST", () + fields = ( + "uid", + "first_name", + "last_name", + "name", + *self.setting("EXTRA_USER_DATA_LIST", ()), ) data = { "method": "users.getInfo", diff --git a/social_core/backends/professionali.py b/social_core/backends/professionali.py index 1ee10f35a..27ee01202 100644 --- a/social_core/backends/professionali.py +++ b/social_core/backends/professionali.py @@ -35,8 +35,13 @@ def user_data(self, access_token, response, *args, **kwargs): url = "https://api.professionali.ru/v6/users/get.json" fields = list( set( - ["firstname", "lastname", "avatar_big", "link"] - + self.setting("EXTRA_DATA", []) + [ + "firstname", + "lastname", + "avatar_big", + "link", + *self.setting("EXTRA_DATA", []), + ] ) ) params = { diff --git a/social_core/backends/vk.py b/social_core/backends/vk.py index 8eec688cb..4432e39a8 100644 --- a/social_core/backends/vk.py +++ b/social_core/backends/vk.py @@ -106,7 +106,8 @@ def user_data(self, access_token, *args, **kwargs): "screen_name", "nickname", "photo", - ] + self.setting("EXTRA_DATA", []) + *self.setting("EXTRA_DATA", []), + ] fields = ",".join(set(request_data)) data = vk_api( diff --git a/social_core/utils.py b/social_core/utils.py index 894e31274..1ea14a017 100644 --- a/social_core/utils.py +++ b/social_core/utils.py @@ -83,7 +83,7 @@ def to_setting_name(*names): def setting_name(*names): - return to_setting_name(*((SETTING_PREFIX,) + names)) + return to_setting_name(*((SETTING_PREFIX, *names))) def sanitize_redirect(hosts, redirect_to):