Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 502e875

Browse files
committedNov 11, 2022
flake8: fix unused local variables (F841)
1 parent d5de976 commit 502e875

File tree

10 files changed

+18
-28
lines changed

10 files changed

+18
-28
lines changed
 

‎src/satosa/backends/apple.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def response_endpoint(self, context, *args):
210210
try:
211211
userdata = context.request.get("user", "{}")
212212
userinfo = json.load(userdata)
213-
except Exception as e:
213+
except Exception:
214214
userinfo = {}
215215

216216
authn_resp = self.client.parse_response(

‎src/satosa/backends/oauth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def user_information(self, access_token):
259259
try:
260260
picture_url = data["picture"]["data"]["url"]
261261
data["picture"] = picture_url
262-
except KeyError as e:
262+
except KeyError:
263263
pass
264264
return data
265265

‎src/satosa/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _load_state(self, context):
200200
self.config["COOKIE_STATE_NAME"],
201201
self.config["STATE_ENCRYPTION_KEY"],
202202
)
203-
except SATOSAStateError as e:
203+
except SATOSAStateError:
204204
state = State()
205205
finally:
206206
context.state = state

‎src/satosa/frontends/saml2.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ def _validate_config(self, config):
173173
raise ValueError("No configuration given")
174174

175175
for key in required_keys:
176-
try:
177-
_val = config[key]
178-
except KeyError as e:
179-
raise ValueError("Missing configuration key: %s" % key) from e
176+
if key not in config:
177+
raise ValueError("Missing configuration key: %s" % key)
180178

181179
def _handle_authn_request(self, context, binding_in, idp):
182180
"""
@@ -630,7 +628,7 @@ def _get_sp_display_name(self, idp, entity_id):
630628

631629
try:
632630
return extensions[0]["display_name"]
633-
except (IndexError, KeyError) as e:
631+
except (IndexError, KeyError):
634632
pass
635633

636634
return None

‎src/satosa/micro_services/consent.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _handle_consent_response(self, context):
6666
except ConnectionError as e:
6767
msg = "Consent service is not reachable, no consent given."
6868
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
69-
logger.error(logline)
69+
logger.error(logline, exc_info=e)
7070
# Send an internal_response without any attributes
7171
consent_attributes = None
7272

@@ -136,7 +136,7 @@ def process(self, context, internal_response):
136136
except requests.exceptions.ConnectionError as e:
137137
msg = "Consent service is not reachable, no consent is given."
138138
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
139-
logger.error(logline)
139+
logger.error(logline, exc_info=e)
140140
# Send an internal_response without any attributes
141141
internal_response.attributes = {}
142142
return self._end_consent(context, internal_response)

‎src/satosa/micro_services/custom_logging.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def process(self, context, data):
3939
try:
4040
spEntityID = context.state.state_dict['SATOSA_BASE']['requester']
4141
idpEntityID = data.auth_info.issuer
42-
except KeyError as err:
42+
except KeyError:
4343
msg = "{} Unable to determine the entityID's for the IdP or SP".format(logprefix)
4444
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
4545
logger.error(logline)
@@ -71,8 +71,6 @@ def process(self, context, data):
7171
logger.error(logline)
7272
return super().process(context, data)
7373

74-
record = None
75-
7674
try:
7775
msg = "{} Using context {}".format(logprefix, context)
7876
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)

‎src/satosa/micro_services/primary_identifier.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def process(self, context, data):
138138
# Find the entityID for the SP that initiated the flow
139139
try:
140140
spEntityID = context.state.state_dict['SATOSA_BASE']['requester']
141-
except KeyError as err:
141+
except KeyError:
142142
msg = "{} Unable to determine the entityID for the SP requester".format(logprefix)
143143
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
144144
logger.error(logline)
@@ -151,7 +151,7 @@ def process(self, context, data):
151151
# Find the entityID for the IdP that issued the assertion
152152
try:
153153
idpEntityID = data.auth_info.issuer
154-
except KeyError as err:
154+
except KeyError:
155155
msg = "{} Unable to determine the entityID for the IdP issuer".format(logprefix)
156156
logline = lu.LOG_FMT.format(id=lu.get_session_id(context.state), message=msg)
157157
logger.error(logline)

‎tests/satosa/frontends/test_openid_connect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def test_full_flow(self, context, frontend_with_extra_scopes):
557557
frontend_with_extra_scopes.auth_req_callback_func = mock_callback
558558
# discovery
559559
http_response = frontend_with_extra_scopes.provider_config(context)
560-
provider_config = ProviderConfigurationResponse().deserialize(http_response.message, "json")
560+
_ = ProviderConfigurationResponse().deserialize(http_response.message, "json")
561561

562562
# client registration
563563
registration_request = RegistrationRequest(redirect_uris=[redirect_uri], response_types=[response_type])

‎tests/satosa/micro_services/test_attribute_authorization.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from satosa.internal import AuthenticationInformation
23
from satosa.internal import InternalData
34
from satosa.micro_services.attribute_authorization import AttributeAuthorization
@@ -25,7 +26,7 @@ def test_authz_allow_success(self):
2526
ctx = Context()
2627
ctx.state = dict()
2728
authz_service.process(ctx, resp)
28-
except SATOSAAuthenticationError as ex:
29+
except SATOSAAuthenticationError:
2930
assert False
3031

3132
def test_authz_allow_fail(self):
@@ -38,13 +39,10 @@ def test_authz_allow_fail(self):
3839
resp.attributes = {
3940
"a0": ["bar"],
4041
}
41-
try:
42+
with pytest.raises(SATOSAAuthenticationError):
4243
ctx = Context()
4344
ctx.state = dict()
4445
authz_service.process(ctx, resp)
45-
assert False
46-
except SATOSAAuthenticationError as ex:
47-
assert True
4846

4947
def test_authz_allow_second(self):
5048
attribute_allow = {
@@ -60,7 +58,7 @@ def test_authz_allow_second(self):
6058
ctx = Context()
6159
ctx.state = dict()
6260
authz_service.process(ctx, resp)
63-
except SATOSAAuthenticationError as ex:
61+
except SATOSAAuthenticationError:
6462
assert False
6563

6664
def test_authz_deny_success(self):
@@ -73,13 +71,10 @@ def test_authz_deny_success(self):
7371
resp.attributes = {
7472
"a0": ["foo2"],
7573
}
76-
try:
74+
with pytest.raises(SATOSAAuthenticationError):
7775
ctx = Context()
7876
ctx.state = dict()
7977
authz_service.process(ctx, resp)
80-
assert False
81-
except SATOSAAuthenticationError as ex:
82-
assert True
8378

8479
def test_authz_deny_fail(self):
8580
attribute_deny = {
@@ -95,5 +90,5 @@ def test_authz_deny_fail(self):
9590
ctx = Context()
9691
ctx.state = dict()
9792
authz_service.process(ctx, resp)
98-
except SATOSAAuthenticationError as ex:
93+
except SATOSAAuthenticationError:
9994
assert False

‎tox.ini

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ ignore =
4646
E302
4747
E303
4848
E703
49-
F841
5049
W291
5150
W292
5251
W293

0 commit comments

Comments
 (0)
Please sign in to comment.