diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-09-21 00:51:04 +0300 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2022-10-01 18:19:13 +0300 |
commit | cbc37ce7fe4dce33af71ca7a1a6f2395b270a001 (patch) | |
tree | 8a8778f5f32cce6fa4f754526faa0a2ace199976 | |
parent | c280a912057a3caa82d0ec3b64bb9d208a28677e (diff) | |
download | pysaml2-cbc37ce7fe4dce33af71ca7a1a6f2395b270a001.tar.gz |
Fix flake8 warnings
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
32 files changed, 88 insertions, 130 deletions
diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py index 89105003..34272fe8 100644 --- a/src/saml2/__init__.py +++ b/src/saml2/__init__.py @@ -636,8 +636,8 @@ class SamlBase(ExtensionContainer): # fixup all elements in the tree memo = {} - for elem in elem.iter(): - self.fixup_element_prefixes(elem, uri_map, memo) + for element in elem.iter(): + self.fixup_element_prefixes(element, uri_map, memo) def fixup_element_prefixes(self, elem, uri_map, memo): def fixup(name): @@ -739,18 +739,15 @@ class SamlBase(ExtensionContainer): # print("set_text: %s" % (val,)) if isinstance(val, bool): - if val: - setattr(self, "text", "true") - else: - setattr(self, "text", "false") + self.text = "true" if val else "false" elif isinstance(val, int): - setattr(self, "text", "%d" % val) + self.text = str(val) elif isinstance(val, six.string_types): - setattr(self, "text", val) + self.text = val elif val is None: pass else: - raise ValueError("Type shouldn't be '%s'" % (val,)) + raise ValueError("Type shouldn't be '%s'" % val) return self diff --git a/src/saml2/authn_context/__init__.py b/src/saml2/authn_context/__init__.py index 0dd4d5fb..8209f7df 100644 --- a/src/saml2/authn_context/__init__.py +++ b/src/saml2/authn_context/__init__.py @@ -1,13 +1,14 @@ +from saml2 import extension_elements_to_elements +from saml2.authn_context import ippword +from saml2.authn_context import mobiletwofactor +from saml2.authn_context import ppt +from saml2.authn_context import pword +from saml2.authn_context import sslcert from saml2.saml import AuthnContext from saml2.saml import AuthnContextClassRef from saml2.samlp import RequestedAuthnContext -__author__ = "rolandh" - -from saml2 import extension_elements_to_elements - - UNSPECIFIED = "urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified" INTERNETPROTOCOLPASSWORD = "urn:oasis:names:tc:SAML:2.0:ac:classes:InternetProtocolPassword" @@ -22,13 +23,6 @@ AL2 = "http://idmanagement.gov/icam/2009/12/saml_2.0_profile/assurancelevel2" AL3 = "http://idmanagement.gov/icam/2009/12/saml_2.0_profile/assurancelevel3" AL4 = "http://idmanagement.gov/icam/2009/12/saml_2.0_profile/assurancelevel4" -from saml2.authn_context import ippword -from saml2.authn_context import mobiletwofactor -from saml2.authn_context import ppt -from saml2.authn_context import pword -from saml2.authn_context import sslcert - - CMP_TYPE = ["exact", "minimum", "maximum", "better"] diff --git a/src/saml2/cert.py b/src/saml2/cert.py index 395c8e06..2354a714 100644 --- a/src/saml2/cert.py +++ b/src/saml2/cert.py @@ -122,11 +122,11 @@ class OpenSSLWrapper(object): key_file = "%s.key" % cn try: remove(cert_file) - except: + except Exception: pass try: remove(key_file) - except: + except Exception: pass c_f = join(cert_dir, cert_file) k_f = join(cert_dir, key_file) @@ -146,7 +146,7 @@ class OpenSSLWrapper(object): cert.get_subject().C = cert_info["country_code"] cert.get_subject().ST = cert_info["state"] cert.get_subject().L = cert_info["city"] - cert.get_subject().O = cert_info["organization"] + cert.get_subject().O = cert_info["organization"] # noqa: E741 cert.get_subject().OU = cert_info["organization_unit"] cert.get_subject().CN = cn if not request: @@ -333,7 +333,7 @@ class OpenSSLWrapper(object): crypto.verify(ca_cert, cert_crypto.signature, cert_crypto.tbs_certificate_bytes, cert_algorithm) return True, "Signed certificate is valid and correctly signed by CA certificate." except crypto.Error as e: - return False, "Certificate is incorrectly signed." + return False, "Certificate is incorrectly signed: %s" % str(e) except Exception as e: return False, "Certificate is not valid for an unknown reason. %s" % str(e) diff --git a/src/saml2/client_base.py b/src/saml2/client_base.py index 6719b3a8..69f1b3af 100644 --- a/src/saml2/client_base.py +++ b/src/saml2/client_base.py @@ -54,8 +54,6 @@ from saml2.samlp import Extensions from saml2.samlp import NameIDMappingRequest from saml2.samlp import RequestedAuthnContext from saml2.soap import make_soap_enveloped_saml_thingy -from saml2.xmldsig import DIGEST_ALLOWED_ALG -from saml2.xmldsig import SIG_ALLOWED_ALG logger = logging.getLogger(__name__) @@ -445,7 +443,7 @@ class Base(Entity): args.update(_args) args.pop("id", None) - client_crt = kwargs.get("client_crt") + # client_crt = kwargs.get("client_crt") nsprefix = kwargs.get("nsprefix") msg = self._message( @@ -797,12 +795,12 @@ class Base(Entity): try: resp = self._parse_response(xmlstr, AuthnResponse, "assertion_consumer_service", binding, **kwargs) except StatusError as err: - logger.error("SAML status error: %s", err) + logger.error("SAML status error: %s", str(err)) raise except UnravelError: return None except Exception as err: - logger.error("XML parse error: %s", err) + logger.error("XML parse error: %s", str(err)) raise if not isinstance(resp, AuthnResponse): diff --git a/src/saml2/cryptography/asymmetric.py b/src/saml2/cryptography/asymmetric.py index 1c8ee519..e52a68e2 100644 --- a/src/saml2/cryptography/asymmetric.py +++ b/src/saml2/cryptography/asymmetric.py @@ -26,7 +26,7 @@ def key_verify(rsakey, signature, message, digest): try: rsakey.verify(signature, message, padding, digest) - except Exception as e: + except Exception: return False else: return True diff --git a/src/saml2/ecp.py b/src/saml2/ecp.py index d6105321..676544c4 100644 --- a/src/saml2/ecp.py +++ b/src/saml2/ecp.py @@ -200,4 +200,4 @@ class ECPServer(Server): soap_envelope = soapenv.Envelope(header=header, body=body) - return "%s" % soap_envelope + return str(soap_envelope) diff --git a/src/saml2/ecp_client.py b/src/saml2/ecp_client.py index e28f16a2..8286ccea 100644 --- a/src/saml2/ecp_client.py +++ b/src/saml2/ecp_client.py @@ -298,7 +298,7 @@ class Client(Entity): opargs["headers"] = self.add_paos_headers(opargs["headers"]) response = self.send(sp_url, op, **opargs) - logger.debug("[Op] SP response: %s" % response) + logger.debug("[Op] SP response", extra={"response": response}) print(response.text) if response.status_code != 200: diff --git a/src/saml2/entity.py b/src/saml2/entity.py index 78499c47..57daa0ec 100644 --- a/src/saml2/entity.py +++ b/src/saml2/entity.py @@ -215,7 +215,7 @@ class Entity(HTTPBase): try: self.metadata.reload(metadata_conf) except Exception as ex: - logger.error("Loading metadata failed", exc_info=ex) + logger.error("Loading metadata failed; reason: %s" % str(ex)) return False self.sourceid = self.metadata.construct_source_id() @@ -884,7 +884,7 @@ class Entity(HTTPBase): if encrypt_assertion_self_contained: try: assertion_tag = response.assertion._to_element_tree().tag - except: + except Exception: assertion_tag = response.assertion[0]._to_element_tree().tag response = pre_encrypt_assertion(response) response = response.get_xml_string_with_self_contained_assertion_within_encrypted_assertion( @@ -995,7 +995,7 @@ class Entity(HTTPBase): :return: A request instance """ - _log_info = logger.info + # _log_info = logger.info _log_debug = logger.debug # The addresses I should receive messages like this on @@ -1430,7 +1430,7 @@ class Entity(HTTPBase): try: response = response_cls(self.sec, **kwargs) except Exception as exc: - logger.info("%s", exc) + logger.info(str(exc)) raise xmlstr = self.unravel(xmlstr, binding, response_cls.msgtype) @@ -1449,7 +1449,7 @@ class Entity(HTTPBase): response = response.loads(xmlstr, False, origxml=xmlstr) except SigverError as err: if require_response_signature: - logger.error("Signature Error: %s", err) + logger.error("Signature Error: %s", str(err)) raise else: # The response is not signed but a signature is not required @@ -1501,7 +1501,7 @@ class Entity(HTTPBase): response.verify(keys) except SignatureError as err: if require_signature: - logger.error("Signature Error: %s", err) + logger.error("Signature Error: %s", str(err)) raise else: response.require_signature = require_signature diff --git a/src/saml2/httpbase.py b/src/saml2/httpbase.py index cb51a919..08b5aea6 100644 --- a/src/saml2/httpbase.py +++ b/src/saml2/httpbase.py @@ -5,7 +5,6 @@ import re import time import requests -import six from six.moves import http_cookiejar from six.moves.http_cookies import SimpleCookie from six.moves.urllib.parse import urlencode @@ -13,7 +12,6 @@ from six.moves.urllib.parse import urlparse from saml2 import SAMLError from saml2 import class_name -from saml2.pack import http_post_message from saml2.pack import make_soap_enveloped_saml_thingy from saml2.time_util import utc_now @@ -321,7 +319,7 @@ class HTTPBase(object): args["headers"] = dict(args["headers"]) response = self.send(**args) except Exception as exc: - logger.info("HTTPClient exception: %s", exc) + logger.info("HTTPClient exception: %s", str(exc)) raise if response.status_code == 200: diff --git a/src/saml2/httputil.py b/src/saml2/httputil.py index 374875ba..2e5e7c27 100644 --- a/src/saml2/httputil.py +++ b/src/saml2/httputil.py @@ -167,6 +167,7 @@ class HttpParameters(object): signature = None sigalg = None # Relaystate and SAML message are stored elsewhere + def __init__(self, dict): try: self.signature = dict["Signature"][0] diff --git a/src/saml2/ident.py b/src/saml2/ident.py index dd0d382c..d52051d1 100644 --- a/src/saml2/ident.py +++ b/src/saml2/ident.py @@ -68,7 +68,7 @@ def decode(txt): i, val = part.split("=") try: setattr(_nid, ATTR[int(i)], unquote(val)) - except: + except Exception: pass return _nid @@ -160,7 +160,7 @@ class IdentDB(object): if nformat == NAMEID_FORMAT_PERSISTENT: nameid = self.match_local_id(userid, sp_name_qualifier, name_qualifier) if nameid: - logger.debug("Found existing persistent NameId {nid} for user {uid}".format(nid=nameid, uid=userid)) + logger.debug("Found existing persistent NameId %s for user %s" % (nameid, userid)) return nameid _id = self.create_id(nformat, name_qualifier, sp_name_qualifier) diff --git a/src/saml2/mdstore.py b/src/saml2/mdstore.py index 44ddd8fe..19dbf3b8 100644 --- a/src/saml2/mdstore.py +++ b/src/saml2/mdstore.py @@ -738,7 +738,7 @@ class InMemoryMetaData(MetaData): def try_verify_signature(node_name): try: self.security.verify_signature(txt, node_name=node_name, cert_file=self.cert) - except SignatureError as e: + except SignatureError: return False else: return True @@ -798,7 +798,7 @@ class MetaDataLoader(MetaDataFile): @staticmethod def get_metadata_loader(func): - if hasattr(func, "__call__"): + if callable(func): return func i = func.rfind(".") @@ -813,7 +813,7 @@ class MetaDataLoader(MetaDataFile): except AttributeError: raise RuntimeError('Module "%s" does not define a "%s" metadata loader' % (module, attr)) - if not hasattr(metadata_loader, "__call__"): + if not callable(metadata_loader): raise RuntimeError("Metadata loader %s.%s must be callable" % (module, attr)) return metadata_loader @@ -957,7 +957,7 @@ class MetaDataMDX(InMemoryMetaData): _txt = response.content if not self.parse_and_check_signature(_txt): - error_msg = "Fething {item}: invalid signature".format(item=item, status=response.status_code) + error_msg = "Fething {item}: invalid signature".format(item=item) logger.info(error_msg) raise KeyError(error_msg) @@ -974,7 +974,7 @@ class MetaDataMDX(InMemoryMetaData): elif not self._is_metadata_fresh(item): msg = "Metadata for {} have expired; refreshing metadata".format(item) logger.info(msg) - old_entity = self.entity.pop(item) + _ = self.entity.pop(item) entity = self._fetch_metadata(item) else: entity = self.entity[item] diff --git a/src/saml2/metadata.py b/src/saml2/metadata.py index c5066ba9..f8aa2c9c 100644 --- a/src/saml2/metadata.py +++ b/src/saml2/metadata.py @@ -373,7 +373,7 @@ def _do_nameid_format(cls, conf, typ): name_id_format = [name_id_format] formats = [md.NameIDFormat(text=format) for format in name_id_format] - setattr(cls, "name_id_format", formats) + cls.name_id_format = formats def do_endpoints(conf, endpoints): diff --git a/src/saml2/mongo_store.py b/src/saml2/mongo_store.py index 143dd571..cfadd1c3 100644 --- a/src/saml2/mongo_store.py +++ b/src/saml2/mongo_store.py @@ -267,7 +267,7 @@ def _mdb_get_database(uri, **kwargs): :params database: name as string or (uri, name) :returns: pymongo database object """ - if not "tz_aware" in kwargs: + if "tz_aware" not in kwargs: # default, but not forced kwargs["tz_aware"] = True diff --git a/src/saml2/pack.py b/src/saml2/pack.py index ea76d7af..c065d2d3 100644 --- a/src/saml2/pack.py +++ b/src/saml2/pack.py @@ -12,7 +12,7 @@ import base64 try: import html -except: +except Exception: import cgi as html import logging diff --git a/src/saml2/response.py b/src/saml2/response.py index 8b739b56..941a5f55 100644 --- a/src/saml2/response.py +++ b/src/saml2/response.py @@ -220,9 +220,7 @@ def for_me(conditions, myself): if audience.text and audience.text.strip() == myself: return True else: - logger.debug( - "AudienceRestriction - One condition not satisfied: {} != {}".format(audience.text, myself) - ) + logger.debug("AudienceRestriction - One condition not satisfied: %s != %s" % (audience.text, myself)) logger.debug("AudienceRestrictions not satisfied!") return False @@ -375,11 +373,9 @@ class StatusResponse(object): except SignatureError: raise except Exception as excp: - logger.exception("EXCEPTION: %s", excp) + logger.exception("EXCEPTION: %s", str(excp)) raise - # print("<", self.response) - return self._postamble() def status_ok(self): @@ -608,7 +604,7 @@ class AuthnResponse(StatusResponse): if conditions.not_before: validate_before(conditions.not_before, self.timeslack) except Exception as excp: - logger.error("Exception on conditions: %s", excp) + logger.error("Exception on conditions: %s", str(excp)) if not lax: raise else: @@ -939,7 +935,7 @@ class AuthnResponse(StatusResponse): decr_text_old = decr_text try: decr_text = self.sec.decrypt_keys(decr_text, keys=keys) - except DecryptError as e: + except DecryptError: continue else: resp = samlp.response_from_string(decr_text) @@ -959,7 +955,7 @@ class AuthnResponse(StatusResponse): decr_text_old = decr_text try: decr_text = self.sec.decrypt_keys(decr_text, keys=keys) - except DecryptError as e: + except DecryptError: continue else: resp = samlp.response_from_string(decr_text) @@ -1009,7 +1005,7 @@ class AuthnResponse(StatusResponse): if self.context == "AuthnReq" or self.context == "AttrQuery": self.ava = self.get_identity() - logger.debug("--- AVA: {0}".format(self.ava)) + logger.debug("--- AVA: %s" % self.ava) return True @@ -1024,7 +1020,7 @@ class AuthnResponse(StatusResponse): try: res = self._verify() except AssertionError as err: - logger.error("Verification error on the response: %s", err) + logger.error("Verification error on the response: %s", str(err)) raise else: if not res: @@ -1393,7 +1389,7 @@ class AssertionIDResponse(object): except SignatureError: raise except Exception as excp: - logger.exception("EXCEPTION: %s", excp) + logger.exception("EXCEPTION: %s", str(excp)) raise # print("<", self.response) diff --git a/src/saml2/s2repoze/plugins/challenge_decider.py b/src/saml2/s2repoze/plugins/challenge_decider.py index ae56a03f..141f0349 100644 --- a/src/saml2/s2repoze/plugins/challenge_decider.py +++ b/src/saml2/s2repoze/plugins/challenge_decider.py @@ -65,7 +65,7 @@ class MyChallengeDecider: if status.startswith("401 "): return True else: - if environ.has_key("samlsp.pending"): + if "samlsp.pending" in environ: return True uri = environ.get("REQUEST_URI", None) @@ -80,7 +80,7 @@ class MyChallengeDecider: # If the user is already authent, whatever happens(except logout), # don't make a challenge - if environ.has_key("repoze.who.identity"): + if "repoze.who.identity" in environ: return False # require a challenge for login diff --git a/src/saml2/s2repoze/plugins/sp.py b/src/saml2/s2repoze/plugins/sp.py index c0d37373..ea3cd388 100644 --- a/src/saml2/s2repoze/plugins/sp.py +++ b/src/saml2/s2repoze/plugins/sp.py @@ -26,7 +26,6 @@ from six import StringIO from six.moves.urllib import parse from zope.interface import implementer -import saml2 from saml2 import BINDING_HTTP_POST from saml2 import BINDING_HTTP_REDIRECT from saml2 import ecp @@ -125,12 +124,12 @@ class SAML2Plugin(object): rememberer = environ["repoze.who.plugins"][self.rememberer_name] return rememberer - #### IIdentifier #### + # #### IIdentifier #### def remember(self, environ, identity): rememberer = self._get_rememberer(environ) return rememberer.remember(environ, identity) - #### IIdentifier #### + # #### IIdentifier #### def forget(self, environ, identity): rememberer = self._get_rememberer(environ) return rememberer.forget(environ, identity) @@ -260,7 +259,7 @@ class SAML2Plugin(object): logger.info("Chosen IdP: '%s'", idp_entity_id) return 0, idp_entity_id - #### IChallenger #### + # #### IChallenger #### # noinspection PyUnusedLocal def challenge(self, environ, _status, _app_headers, _forget_headers): _cli = self.saml_client @@ -269,7 +268,6 @@ class SAML2Plugin(object): name_id = decode(environ["REMOTE_USER"]) _cli = self.saml_client - path_info = environ["PATH_INFO"] if "samlsp.logout" in environ: responses = _cli.global_logout(name_id) @@ -363,16 +361,17 @@ class SAML2Plugin(object): logger.debug("ht_args: %s", ht_args) except Exception as exc: - logger.exception(exc) + logger.exception("Failed to construct the AuthnRequest: %s" % str(exc)) raise Exception("Failed to construct the AuthnRequest: %s" % exc) try: + path_info = environ.get("PATH_INFO") ret = _cli.config.getattr("endpoints", "sp")["discovery_response"][0][0] - if (environ["PATH_INFO"]) in ret and ret.split(environ["PATH_INFO"])[1] == "": + if path_info in ret and ret.split(path_info)[1] == "": query = parse.parse_qs(environ["QUERY_STRING"]) result_sid = query["sid"][0] came_from = self.outstanding_queries[result_sid] - except: + except Exception: pass # remember the request self.outstanding_queries[_sid] = came_from @@ -439,7 +438,7 @@ class SAML2Plugin(object): return session_info - #### IIdentifier #### + # #### IIdentifier #### def identify(self, environ): """ Tries to do the identification @@ -492,7 +491,7 @@ class SAML2Plugin(object): ) environ["samlsp.pending"] = self._handle_logout(response) return {} - except: + except Exception: import traceback traceback.print_exc() @@ -559,7 +558,7 @@ class SAML2Plugin(object): # Make sure that userids authenticated by another plugin # don't cause problems here. name_id = decode(name_id) - except: + except Exception: pass _cli = self.saml_client @@ -606,7 +605,7 @@ class SAML2Plugin(object): url = construct_url(environ) return url - #### IAuthenticatorPlugin #### + # #### IAuthenticatorPlugin #### # noinspection PyUnusedLocal def authenticate(self, environ, identity=None): if identity: diff --git a/src/saml2/schema/soapenv.py b/src/saml2/schema/soapenv.py index a7985926..8b541670 100644 --- a/src/saml2/schema/soapenv.py +++ b/src/saml2/schema/soapenv.py @@ -292,14 +292,14 @@ ELEMENT_FROM_STRING = { } ELEMENT_BY_TAG = { - "Envelope": Envelope, + # "Envelope": Envelope, "Envelope": Envelope_, - "Header": Header, + # "Header": Header, "Header": Header_, - "Body": Body, + # "Body": Body, "Body": Body_, "encodingStyle": EncodingStyle_, - "Fault": Fault, + # "Fault": Fault, "Fault": Fault_, "detail": Detail_, "faultcode": Fault_faultcode, diff --git a/src/saml2/schema/wsdl.py b/src/saml2/schema/wsdl.py index 8b41ef1b..54e377e2 100644 --- a/src/saml2/schema/wsdl.py +++ b/src/saml2/schema/wsdl.py @@ -1,5 +1,3 @@ -#!!!! 'NoneType' object has no attribute 'py_class' -#!!!! 'NoneType' object has no attribute 'py_class' #!/usr/bin/env python # diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py index 63e67ab3..b8004ce4 100644 --- a/src/saml2/sigver.py +++ b/src/saml2/sigver.py @@ -782,7 +782,7 @@ class CryptoBackendXmlSec1(CryptoBackend): try: (stdout, stderr, output) = self._run_xmlsec(com_list, [tmp.name]) except XmlsecError as e: - raise SignatureError(com_list) + raise SignatureError(com_list) from e # this does not work if --store-signatures is used if output: @@ -1011,7 +1011,7 @@ def encrypt_cert_from_item(item): try: try: _elem = extension_elements_to_elements(item.extensions.extension_elements, [pefim, ds]) - except: + except Exception: _elem = extension_elements_to_elements(item.extension_elements[0].children, [pefim, ds]) for _tmp_elem in _elem: @@ -1020,7 +1020,7 @@ def encrypt_cert_from_item(item): if _tmp_key_info.x509_data is not None and len(_tmp_key_info.x509_data) > 0: _encrypt_cert = _tmp_key_info.x509_data[0].x509_certificate.text break - except Exception as _exception: + except Exception: pass if _encrypt_cert is not None: @@ -1296,12 +1296,8 @@ class SecurityContext(object): key_files = list(make_temp(key, decode=False, delete_tmpfiles=self.delete_tmpfiles) for key in keys_encoded) key_file_names = list(tmp.name for tmp in key_files) - try: - dectext = self.decrypt(enctext, key_file=key_file_names) - except DecryptError as e: - raise - else: - return dectext + dectext = self.decrypt(enctext, key_file=key_file_names) + return dectext def decrypt(self, enctext, key_file=None): """Decrypting an encrypted text by the use of a private key. @@ -1316,7 +1312,7 @@ class SecurityContext(object): for key_file in key_files: try: dectext = self.crypto.decrypt(enctext, key_file) - except XmlsecError as e: + except XmlsecError: continue else: if dectext: @@ -1501,10 +1497,10 @@ class SecurityContext(object): verified = True break except XmlsecError as exc: - logger.error("check_sig: %s", exc) + logger.error("check_sig: %s", str(exc)) pass except Exception as exc: - logger.error("check_sig: %s", exc) + logger.error("check_sig: %s", str(exc)) raise if verified or only_valid_cert: diff --git a/src/saml2/tools/make_metadata.py b/src/saml2/tools/make_metadata.py index 40425d1a..ffb65301 100644 --- a/src/saml2/tools/make_metadata.py +++ b/src/saml2/tools/make_metadata.py @@ -35,7 +35,7 @@ def main(): valid_for = 0 nspair = {"xs": "http://www.w3.org/2001/XMLSchema"} - paths = [".", "/opt/local/bin"] + # paths = [".", "/opt/local/bin"] if args.valid: # translate into hours diff --git a/src/saml2/tools/mdexport.py b/src/saml2/tools/mdexport.py index 80633f7d..247a2a2d 100644 --- a/src/saml2/tools/mdexport.py +++ b/src/saml2/tools/mdexport.py @@ -1,15 +1,10 @@ #!/usr/bin/env python import argparse -from saml2 import md -from saml2 import saml -from saml2 import xmldsig -from saml2 import xmlenc from saml2.attribute_converter import ac_factory from saml2.httpbase import HTTPBase from saml2.mdstore import MetaDataExtern from saml2.mdstore import MetaDataFile -from saml2.mdstore import load_extensions from saml2.sigver import SecurityContext from saml2.sigver import _get_xmlsec_cryptobackend diff --git a/src/saml2/tools/merge_metadata.py b/src/saml2/tools/merge_metadata.py index d31361a3..79f88d4b 100644 --- a/src/saml2/tools/merge_metadata.py +++ b/src/saml2/tools/merge_metadata.py @@ -67,10 +67,7 @@ def main(): metad = MetaDataExtern(ATTRCONV, spec[1], sc, cert=spec[2], http=httpc, **kwargs) if metad is not None: - try: - metad.load() - except: - raise + metad.load() mds.metadata[spec[1]] = metad diff --git a/src/saml2/tools/parse_xsd2.py b/src/saml2/tools/parse_xsd2.py index e08089cb..db775548 100644 --- a/src/saml2/tools/parse_xsd2.py +++ b/src/saml2/tools/parse_xsd2.py @@ -2177,7 +2177,7 @@ def main(): elif opt in ("-I", "--ignore"): ignore.append(arg) else: - assert False, "unhandled option" + raise Exception("unhandled option %s" % opt) if not args: print("No XSD-file specified") diff --git a/src/saml2/tools/verify_metadata.py b/src/saml2/tools/verify_metadata.py index aefffe40..7e3ef970 100644 --- a/src/saml2/tools/verify_metadata.py +++ b/src/saml2/tools/verify_metadata.py @@ -51,12 +51,8 @@ def main(): metad = MetaDataExtern(ATTRCONV, args.url, sc, cert=args.cert, http=httpc, **kwargs) if metad: - try: - metad.load() - except: - raise - else: - print("OK") + metad.load() + print("OK") if __name__ == "__main__": diff --git a/src/saml2/ws/wspol.py b/src/saml2/ws/wspol.py index 3ef49a6e..7f26795b 100644 --- a/src/saml2/ws/wspol.py +++ b/src/saml2/ws/wspol.py @@ -6,8 +6,6 @@ import saml2 from saml2 import SamlBase -from saml2.ws import wssec as wsse -from saml2.ws import wsutil as wsu NAMESPACE = "http://schemas.xmlsoap.org/ws/2004/09/policy" diff --git a/src/saml2/ws/wssec.py b/src/saml2/ws/wssec.py index 4b057fd9..ac27385c 100644 --- a/src/saml2/ws/wssec.py +++ b/src/saml2/ws/wssec.py @@ -6,9 +6,6 @@ import saml2 from saml2 import SamlBase -from saml2 import xmldsig as ds -from saml2.schema import soapenv -from saml2.ws import wsutil as wsu NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" diff --git a/src/saml2/ws/wstrust.py b/src/saml2/ws/wstrust.py index 81402cdf..7152a5d7 100644 --- a/src/saml2/ws/wstrust.py +++ b/src/saml2/ws/wstrust.py @@ -7,7 +7,6 @@ import saml2 from saml2 import SamlBase from saml2.ws import wsaddr as wsa -from saml2.ws import wspol as wsp from saml2.ws import wssec as wsse from saml2.ws import wsutil as wsu diff --git a/src/saml2test/check.py b/src/saml2test/check.py index c797f11c..7ef51279 100644 --- a/src/saml2test/check.py +++ b/src/saml2test/check.py @@ -131,7 +131,7 @@ class VerifyBadRequestResponse(ExpectedError): def _func(self, conv): _response = conv.last_response - _content = conv.last_content + # _content = conv.last_content res = {} if _response.status_code == 400: pass @@ -202,7 +202,7 @@ class CheckSpHttpResponseOK(Error): def _func(self, conv): _response = conv.last_response - _content = conv.last_response.content + # _content = conv.last_response.content res = {} if _response.status_code >= 400: @@ -225,7 +225,7 @@ class CheckSpHttpResponse500(Error): def _func(self, conv): _response = conv.last_response - _content = conv.last_response.content + # _content = conv.last_response.content res = {} if _response.status_code < 500: diff --git a/src/saml2test/tool.py b/src/saml2test/tool.py index b373f608..f87f0e2a 100644 --- a/src/saml2test/tool.py +++ b/src/saml2test/tool.py @@ -312,11 +312,11 @@ class Conversation(object): } ) break - except (FatalError, OperationError): - raise - except Exception as err: - # self.err_check("exception", err) - raise + # except (FatalError, OperationError): + # raise + # except Exception as err: + # self.err_check("exception", err) + # raise try: self.test_sequence(oper["tests"]["post"]) diff --git a/src/utility/metadata.py b/src/utility/metadata.py index 5ee15978..ab6d30f2 100644 --- a/src/utility/metadata.py +++ b/src/utility/metadata.py @@ -1,6 +1,5 @@ import logging import os.path -import sys import time from time import strftime import urllib @@ -37,5 +36,5 @@ def fetch_metadata(url, path, maxage=600): try: f.retrieve(url, path) logger.debug("downloaded metadata from %s into %s", url, path) - except: - logger.debug("downloaded metadata from %s failed: %s", url, sys.exc_info()[0]) + except Exception as e: + logger.debug("downloaded metadata from %s failed: %s", url, str(e)) |