Skip to content

Commit

Permalink
Merge pull request #306 from OpenIDC/cleanup_variables
Browse files Browse the repository at this point in the history
Removed unused variables
  • Loading branch information
tpazderka authored Mar 28, 2017
2 parents 240a1ce + c6932e2 commit 5dd6fce
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 65 deletions.
4 changes: 2 additions & 2 deletions src/oic/extension/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def handle_provider_config(self, pcr, issuer, keys=True, endpoints=True):
_issuer = issuer

try:
_ = self.allow["issuer_mismatch"]
self.allow["issuer_mismatch"]
except KeyError:
try:
assert _issuer == _pcr_issuer
Expand Down Expand Up @@ -354,7 +354,7 @@ def handle_registration_info(self, response):
try:
resp.verify()
self.store_response(resp, response.text)
except Exception as err:
except Exception:
raise PyoidcError(
'Registration failed: {}'.format(response.text))

Expand Down
2 changes: 1 addition & 1 deletion src/oic/extension/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def verify(self, **kwargs):
pass
else:
# need to get the client keys before I can verify any signature
kj = kwargs['keyjar']
# kj = kwargs['keyjar']
# The case where jwks_uri is used
# try:
# kj.add(,self['jwks_uri'])
Expand Down
6 changes: 2 additions & 4 deletions src/oic/extension/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def providerinfo_endpoint(self, **kwargs):

resp = Response(_response.to_json(), content="application/json",
headers=headers)
except Exception as err:
except Exception:
message = traceback.format_exception(*sys.exc_info())
logger.error(message)
resp = Response(message, content="html/text")
Expand Down Expand Up @@ -747,16 +747,14 @@ def token_endpoint(self, authn="", **kwargs):
This is where clients come to get their access tokens
"""

_sdb = self.sdb

logger.debug("- token -")
body = kwargs["request"]
logger.debug("body: %s" % body)

areq = AccessTokenRequest().deserialize(body, "urlencoded")

try:
client_id = self.client_authn(self, areq, authn)
self.client_authn(self, areq, authn)
except FailedAuthentication as err:
logger.error(err)
err = TokenErrorResponse(error="unauthorized_client",
Expand Down
4 changes: 2 additions & 2 deletions src/oic/oauth2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ def parse_response(self, response, info="", sformat="json", state="",
resp = errmsg().deserialize(info, sformat)
resp.verify()
break
except Exception as aerr:
except Exception:
resp = None
except KeyError:
pass
Expand Down Expand Up @@ -913,7 +913,7 @@ def handle_provider_config(self, pcr, issuer, keys=True, endpoints=True):
_issuer = issuer

try:
_ = self.allow["issuer_mismatch"]
self.allow["issuer_mismatch"]
except KeyError:
try:
assert _issuer == _pcr_issuer
Expand Down
2 changes: 1 addition & 1 deletion src/oic/oauth2/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def serialize(self, method="urlencoded", lev=0, **kwargs):
def deserialize(self, info, method="urlencoded", **kwargs):
try:
func = getattr(self, "from_%s" % method)
except AttributeError as err:
except AttributeError:
raise FormatError("Unknown serialization method (%s)" % method)
else:
return func(info, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions src/oic/oauth2/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def _verify_redirect_uri(self, areq):
raise RedirectURIError("Doesn't match any registered uris")
# ignore query components that are not registered
return None
except Exception as err:
except Exception:
logger.error("Faulty redirect_uri: %s" % areq["redirect_uri"])
try:
_cinfo = self.cdb[str(areq["client_id"])]
Expand Down Expand Up @@ -775,7 +775,7 @@ def token_endpoint(self, authn="", **kwargs):
areq = AccessTokenRequest().deserialize(body, "urlencoded")

try:
client = self.client_authn(self, areq, authn)
self.client_authn(self, areq, authn)
except FailedAuthentication as err:
logger.error(err)
err = TokenErrorResponse(error="unauthorized_client",
Expand Down
4 changes: 2 additions & 2 deletions src/oic/oic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def handle_provider_config(self, pcr, issuer, keys=True, endpoints=True):
_issuer = issuer

try:
_ = self.allow["issuer_mismatch"]
self.allow["issuer_mismatch"]
except KeyError:
try:
assert _issuer == _pcr_issuer
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def handle_registration_info(self, response):
resp = RegistrationResponse().deserialize(response.text, "json")
# Some implementations sends back a 200 with an error message inside
try:
r = resp.verify()
resp.verify()
except Exception:
resp = ErrorResponse().deserialize(response.text, "json")
if resp.verify():
Expand Down
3 changes: 1 addition & 2 deletions src/oic/oic/claims_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,9 @@ def claims_endpoint(self, request, http_authz, *args):
_log_info("request: %s" % sanitize(ucreq))

try:
resp = self.client_authn(self, ucreq, http_authz)
self.client_authn(self, ucreq, http_authz)
except Exception as err:
_log_info("Failed to verify client due to: %s" % err)
resp = False

if "claims_names" in ucreq:
args = dict([(n, {"optional": True}) for n in
Expand Down
6 changes: 3 additions & 3 deletions src/oic/oic/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,13 +538,13 @@ def verify(self, **kwargs):
if "birthdate" in self:
# Either YYYY-MM-DD or just YYYY or 0000-MM-DD
try:
_ = time.strptime(self["birthdate"], "%Y-%m-%d")
time.strptime(self["birthdate"], "%Y-%m-%d")
except ValueError:
try:
_ = time.strptime(self["birthdate"], "%Y")
time.strptime(self["birthdate"], "%Y")
except ValueError:
try:
_ = time.strptime(self["birthdate"], "0000-%m-%d")
time.strptime(self["birthdate"], "0000-%m-%d")
except ValueError:
raise VerificationError("Birthdate format error", self)

Expand Down
12 changes: 2 additions & 10 deletions src/oic/oic/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,15 +851,12 @@ def encrypt(self, payload, client_info, cid, val_type="id_token", cty=""):

logger.debug("alg=%s, enc=%s, val_type=%s" % (alg, enc, val_type))
keys = self.keyjar.get_encrypt_key(owner=cid)
try:
_ckeys = self.keyjar[cid]
except KeyError:
if cid not in self.keyjar:
# Weird, but try to recuperate
logger.warning(
"Lost keys for {} trying to recuperate!!".format(cid))
self.keyjar.issuer_keys[cid] = []
self.keyjar.add(cid, client_info["jwks_uri"])
_ckeys = self.keyjar[cid]

kwargs = {"alg": alg, "enc": enc}
if cty:
Expand Down Expand Up @@ -1275,18 +1272,14 @@ def check_session_endpoint(self, request, **kwargs):
"""
"""
try:
_log_debug = kwargs["logger"].debug
_log_info = kwargs["logger"].info
except KeyError:
_log_debug = logger.debug
_log_info = logger.info

if not request:
_tok = kwargs["authn"]
if not _tok:
return error(error="invalid_request", descr="Illegal token")
else:
info = "id_token=%s" % _tok

if self.test_mode:
_log_info("check_session_request: %s" % sanitize(request))
Expand Down Expand Up @@ -1805,7 +1798,6 @@ def verify_capabilities(self, capabilities):

# noinspection PyUnusedLocal
def providerinfo_endpoint(self, handle="", **kwargs):
_log_debug = logger.debug
_log_info = logger.info

_log_info("@providerinfo_endpoint")
Expand All @@ -1826,7 +1818,7 @@ def providerinfo_endpoint(self, handle="", **kwargs):

resp = Response(_response.to_json(), content="application/json",
headers=headers)
except Exception as err:
except Exception:
message = traceback.format_exception(*sys.exc_info())
logger.error(message)
resp = error('service_error', message)
Expand Down
2 changes: 1 addition & 1 deletion src/oic/utils/authn/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def construct(self, cis, request_args=None, http_args=None, **kwargs):
cis["access_token"] = request_args["access_token"]
except KeyError:
try:
_ = kwargs["state"]
kwargs["state"]
except KeyError:
if not self.cli.state:
raise AuthnFailure("Missing state specification")
Expand Down
2 changes: 1 addition & 1 deletion src/oic/utils/authn/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def verify(self, request, **kwargs):

def done(self, areq):
try:
_ = areq[self.query_param]
areq[self.query_param]
return False
except KeyError:
return True
Expand Down
2 changes: 1 addition & 1 deletion src/oic/utils/client_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def load(self, filename):
_tmp[uris] = unpack_redirect_uri(_tmp[uris])
except KeyError:
pass
except Exception as err:
except Exception:
print("Faulty specification: {}".format(item))
else:
self.cdb[str(item["client_id"])] = item
Expand Down
2 changes: 1 addition & 1 deletion src/oic/utils/keyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def _parse_remote_response(self, response):
logger.debug("Loaded JWKS: %s from %s" % (response.text, self.source))
try:
return json.loads(response.text)
except ValueError as e:
except ValueError:
return None

def _uptodate(self):
Expand Down
14 changes: 7 additions & 7 deletions src/oic/utils/rp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,26 @@ def create_client(self, userid="", **kwargs):
# Find the service that provides information about the OP
issuer = client.wf.discovery_query(userid)
# Gather OP information
pcr = client.provider_config(issuer)
client.provider_config(issuer)
# register the client
client.register(client.provider_info["registration_endpoint"],
**kwargs["client_info"])
self.get_path(kwargs['client_info']['redirect_uris'], issuer)
elif _key_set == set(["client_info", "srv_discovery_url"]):
# Ship the webfinger part
# Gather OP information
_ = client.provider_config(kwargs["srv_discovery_url"])
client.provider_config(kwargs["srv_discovery_url"])
# register the client
_ = client.register(client.provider_info["registration_endpoint"],
**kwargs["client_info"])
client.register(client.provider_info["registration_endpoint"],
**kwargs["client_info"])
self.get_path(kwargs['client_info']['redirect_uris'],
kwargs["srv_discovery_url"])
elif _key_set == set(["provider_info", "client_info"]):
client.handle_provider_config(
ProviderConfigurationResponse(**kwargs["provider_info"]),
kwargs["provider_info"]["issuer"])
_ = client.register(client.provider_info["registration_endpoint"],
**kwargs["client_info"])
client.register(client.provider_info["registration_endpoint"],
**kwargs["client_info"])

self.get_path(kwargs['client_info']['redirect_uris'],
kwargs["provider_info"]["issuer"])
Expand All @@ -343,7 +343,7 @@ def create_client(self, userid="", **kwargs):
self.get_path(kwargs['client_info']['redirect_uris'],
kwargs["provider_info"]["issuer"])
elif _key_set == set(["srv_discovery_url", "client_registration"]):
_ = client.provider_config(kwargs["srv_discovery_url"])
client.provider_config(kwargs["srv_discovery_url"])
client.store_registration_info(RegistrationResponse(
**kwargs["client_registration"]))
self.get_path(kwargs['client_registration']['redirect_uris'],
Expand Down
2 changes: 1 addition & 1 deletion src/oic/utils/sdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def _get_token_type_and_key(self, item, order=None):
for key in order:
try:
return self.token_factory[key].type_and_key(item)
except Exception as err:
except Exception:
pass

logger.info("Unknown token format")
Expand Down
4 changes: 2 additions & 2 deletions tests/fakeoicsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def authorization_endpoint(self, query):
req = self.parse_authorization_request(query=query)
aevent = AuthnEvent("user", "salt", authn_info="acr")
sid = self.sdb.create_authz_session(aevent, areq=req)
_ = self.sdb.do_sub(sid, "client_salt")
self.sdb.do_sub(sid, "client_salt")
_info = self.sdb[sid]

if "code" in req["response_type"]:
Expand Down Expand Up @@ -181,7 +181,7 @@ def token_endpoint(self, data):

def userinfo_endpoint(self, data):

_ = self.parse_user_info_request(data)
self.parse_user_info_request(data)
_info = {
"sub": "melgar",
"name": "Melody Gardot",
Expand Down
6 changes: 3 additions & 3 deletions tests/mitmsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def authorization_endpoint(self, query):
req = self.parse_authorization_request(query=query)
aevent = AuthnEvent("user", "salt", authn_info="acr")
sid = self.sdb.create_authz_session(aevent, areq=req)
_ = self.sdb.do_sub(sid, 'client_salt')
self.sdb.do_sub(sid, 'client_salt')
_info = self.sdb[sid]

if "code" in req["response_type"]:
Expand Down Expand Up @@ -180,7 +180,7 @@ def token_endpoint(self, data):

def userinfo_endpoint(self, data):

_ = self.parse_user_info_request(data)
self.parse_user_info_request(data)
_info = {
"sub": "melgar",
"name": "Melody Gardot",
Expand Down Expand Up @@ -263,7 +263,7 @@ def check_session_endpoint(self, query):
# noinspection PyUnusedLocal
def refresh_session_endpoint(self, query):
try:
req = self.parse_refresh_session_request(query=query)
self.parse_refresh_session_request(query=query)
except Exception:
raise

Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def test_client_secret_jwt(self, client):
csj = ClientSecretJWT(client)
cis = AccessTokenRequest()

http_args = csj.construct(cis, algorithm="HS256",
authn_endpoint='token')
csj.construct(cis, algorithm="HS256",
authn_endpoint='token')
assert cis["client_assertion_type"] == JWT_BEARER
assert "client_assertion" in cis
cas = cis["client_assertion"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ def test_parse_error_resp(self):
jerr = err.to_json()
uerr = err.to_urlencoded()

_ = self.client.parse_response(AccessTokenResponse, info=jerr)
_ = self.client.parse_response(AccessTokenResponse, info=uerr,
sformat="urlencoded")
self.client.parse_response(AccessTokenResponse, info=jerr)
self.client.parse_response(AccessTokenResponse, info=uerr,
sformat="urlencoded")

with pytest.raises(ResponseError):
self.client.parse_response(AccessTokenResponse, info=jerr, sformat="urlencoded")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_oic_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def test_faulty_id_token(self):
# What if no verification key is given ?
# Should also result in an exception
with pytest.raises(MissingSigningKey):
_ = IdToken().from_jwt(_faulty_signed_jwt)
IdToken().from_jwt(_faulty_signed_jwt)

def test_faulty_id_token_in_access_token_response(self):
c = Consumer(None, None)
Expand Down
Loading

0 comments on commit 5dd6fce

Please sign in to comment.