diff --git a/src/idp_test/__init__.py b/src/idp_test/__init__.py index 61381c5..a061511 100644 --- a/src/idp_test/__init__.py +++ b/src/idp_test/__init__.py @@ -6,6 +6,7 @@ import pprint import types import argparse import sys +import six import logging import imp @@ -356,7 +357,7 @@ class SAML2client(object): item = {"id": key, "name": val["name"]} try: _desc = val["descr"] - if isinstance(_desc, basestring): + if isinstance(_desc, six.string_types): item["descr"] = _desc else: item["descr"] = "\n".join(_desc) @@ -377,7 +378,7 @@ class SAML2client(object): item = {"id": key, "name": val["name"]} try: _desc = val["descr"] - if isinstance(_desc, basestring): + if isinstance(_desc, six.string_types): item["descr"] = _desc else: item["descr"] = "\n".join(_desc) diff --git a/src/idp_test/interaction.py b/src/idp_test/interaction.py index 03da9c2..2fbc46b 100644 --- a/src/idp_test/interaction.py +++ b/src/idp_test/interaction.py @@ -2,6 +2,7 @@ __author__ = 'rohe0002' import json import logging +import six from urlparse import urlparse from bs4 import BeautifulSoup @@ -34,7 +35,8 @@ def pick_interaction(interactions, _base="", content="", req=None): _match += 1 else: _c = _bs.title.contents - if isinstance(_c, list) and not isinstance(_c, basestring): + if isinstance(_c, list) and not isinstance( + _c, six.string_types): for _line in _c: if val in _line: _match += 1 @@ -165,7 +167,7 @@ def pick_form(response, url=None, **kwargs): _default = _ava["value"] try: orig_val = form[prop] - if isinstance(orig_val, basestring): + if isinstance(orig_val, six.string_types): if orig_val == _default: _form = form elif _default in orig_val: diff --git a/src/saml2/entity.py b/src/saml2/entity.py index 6eed861..34b3e90 100644 --- a/src/saml2/entity.py +++ b/src/saml2/entity.py @@ -4,6 +4,7 @@ import logging from hashlib import sha1 from Crypto.PublicKey import RSA import requests +import six from saml2.metadata import ENDPOINTS from saml2.profile import paos, ecp from saml2.soap import parse_soap_enveloped_saml_artifact_resolve @@ -156,7 +157,7 @@ class Entity(HTTPBase): self.sec = security_context(self.config) if virtual_organization: - if isinstance(virtual_organization, basestring): + if isinstance(virtual_organization, six.string_types): self.vorg = self.config.vorg[virtual_organization] elif isinstance(virtual_organization, VirtualOrg): self.vorg = virtual_organization diff --git a/src/saml2/httpbase.py b/src/saml2/httpbase.py index 79d4ba0..2da045f 100644 --- a/src/saml2/httpbase.py +++ b/src/saml2/httpbase.py @@ -1,4 +1,5 @@ import calendar +import six from six.moves import http_cookiejar import copy import re @@ -260,7 +261,7 @@ class HTTPBase(object): :param typ: Whether a Request, Response or Artifact :return: dictionary """ - if not isinstance(message, basestring): + if not isinstance(message, six.string_types): message = "%s" % (message,) return http_form_post_message(message, destination, relay_state, typ) @@ -375,7 +376,7 @@ class HTTPBase(object): :param key: Key to use for signing :return: dictionary """ - if not isinstance(message, basestring): + if not isinstance(message, six.string_types): message = "%s" % (message,) return http_redirect_message(message, destination, relay_state, typ, diff --git a/src/saml2/ident.py b/src/saml2/ident.py index 0420747..c7090bc 100644 --- a/src/saml2/ident.py +++ b/src/saml2/ident.py @@ -1,6 +1,7 @@ import copy import shelve import logging +import six from hashlib import sha256 from urllib import quote @@ -66,7 +67,7 @@ class IdentDB(object): Keeps a list of all nameIDs returned per SP """ def __init__(self, db, domain="", name_qualifier=""): - if isinstance(db, basestring): + if isinstance(db, six.string_types): self.db = shelve.open(db) else: self.db = db @@ -94,7 +95,7 @@ class IdentDB(object): :param ident: user identifier :param name_id: NameID instance """ - if isinstance(ident, unicode): + if isinstance(ident, six.string_types): ident = ident.encode("utf-8") # One user may have more than one NameID defined diff --git a/src/saml2/pack.py b/src/saml2/pack.py index f045c7a..7c6b957 100644 --- a/src/saml2/pack.py +++ b/src/saml2/pack.py @@ -20,6 +20,7 @@ import logging from saml2.sigver import REQ_ORDER from saml2.sigver import RESP_ORDER from saml2.sigver import SIGNER_ALGS +import six logger = logging.getLogger(__name__) @@ -57,7 +58,7 @@ def http_form_post_message(message, location, relay_state="", """ response = ["", """SAML 2.0 POST""", ""] - if not isinstance(message, basestring): + if not isinstance(message, six.string_types): message = "%s" % (message,) if typ == "SAMLRequest" or typ == "SAMLResponse": @@ -94,7 +95,7 @@ def http_redirect_message(message, location, relay_state="", typ="SAMLRequest", :return: A tuple containing header information and a HTML message. """ - if not isinstance(message, basestring): + if not isinstance(message, six.string_types): message = "%s" % (message,) _order = None @@ -163,7 +164,7 @@ def make_soap_enveloped_saml_thingy(thingy, header_parts=None): body.tag = '{%s}Body' % NAMESPACE envelope.append(body) - if isinstance(thingy, basestring): + if isinstance(thingy, six.string_types): # remove the first XML version/encoding line logger.debug("thingy0: %s" % thingy) _part = thingy.split("\n") diff --git a/src/saml2/s2repoze/plugins/sp.py b/src/saml2/s2repoze/plugins/sp.py index bd05a06..2088a5f 100644 --- a/src/saml2/s2repoze/plugins/sp.py +++ b/src/saml2/s2repoze/plugins/sp.py @@ -12,6 +12,7 @@ import platform import shelve import traceback import saml2 +import six from urlparse import parse_qs, urlparse from saml2.md import Extensions from saml2 import xmldsig as ds @@ -555,7 +556,7 @@ class SAML2Plugin(object): def add_metadata(self, environ, identity): """ Add information to the knowledge I have about the user """ name_id = identity['repoze.who.userid'] - if isinstance(name_id, basestring): + if isinstance(name_id, six.string_types): try: # Make sure that userids authenticated by another plugin # don't cause problems here. diff --git a/src/saml2/sigver.py b/src/saml2/sigver.py index cbeec97..2ff13fc 100644 --- a/src/saml2/sigver.py +++ b/src/saml2/sigver.py @@ -15,6 +15,7 @@ import urllib from time import mktime from binascii import hexlify +import six from Crypto.PublicKey.RSA import importKey from Crypto.Signature import PKCS1_v1_5 @@ -728,7 +729,7 @@ class CryptoBackendXmlSec1(CryptoBackend): def __init__(self, xmlsec_binary, **kwargs): CryptoBackend.__init__(self, **kwargs) - assert (isinstance(xmlsec_binary, basestring)) + assert (isinstance(xmlsec_binary, six.string_types)) self.xmlsec = xmlsec_binary if os.environ.get('PYSAML2_KEEP_XMLSEC_TMP', None): self._xmlsec_delete_tmpfiles = False @@ -1353,7 +1354,7 @@ class SecurityContext(object): _certs = [] certs = [] for cert in _certs: - if isinstance(cert, basestring): + if isinstance(cert, six.string_types): certs.append(make_temp(pem_format(cert), suffix=".pem", decode=False, delete=self._xmlsec_delete_tmpfiles)) diff --git a/src/saml2test/check.py b/src/saml2test/check.py index 2433e31..7109371 100644 --- a/src/saml2test/check.py +++ b/src/saml2test/check.py @@ -1,5 +1,6 @@ import inspect import json +import six __author__ = 'rolandh' @@ -91,7 +92,7 @@ class ResponseInfo(Information): self._status = self.status _msg = conv.last_content - if isinstance(_msg, basestring): + if isinstance(_msg, six.string_types): self._message = _msg else: self._message = _msg.to_dict() diff --git a/src/saml2test/interaction.py b/src/saml2test/interaction.py index 0121fbc..ddfbeac 100644 --- a/src/saml2test/interaction.py +++ b/src/saml2test/interaction.py @@ -2,6 +2,7 @@ __author__ = 'rohe0002' import json import logging +import six from urlparse import urlparse from bs4 import BeautifulSoup @@ -125,8 +126,8 @@ class Interaction(object): _match += 1 else: _c = _bs.title.contents - if isinstance(_c, list) and not isinstance(_c, - basestring): + if isinstance(_c, list) and not isinstance( + _c, six.string_types): for _line in _c: if val in _line: _match += 1 @@ -186,7 +187,7 @@ class Interaction(object): _default = _ava["value"] try: orig_val = form[prop] - if isinstance(orig_val, basestring): + if isinstance(orig_val, six.string_types): if orig_val == _default: _form = form elif _default in orig_val: diff --git a/src/saml2test/opfunc.py b/src/saml2test/opfunc.py index 2f88c70..2d612ed 100644 --- a/src/saml2test/opfunc.py +++ b/src/saml2test/opfunc.py @@ -1,5 +1,6 @@ import logging import json +import six from urlparse import urlparse @@ -163,7 +164,7 @@ def pick_form(response, content, url=None, **kwargs): _default = _ava["value"] try: orig_val = form[prop] - if isinstance(orig_val, basestring): + if isinstance(orig_val, six.string_types): if orig_val == _default: _form = form elif _default in orig_val: diff --git a/src/saml2test/tool.py b/src/saml2test/tool.py index 6071408..d911359 100644 --- a/src/saml2test/tool.py +++ b/src/saml2test/tool.py @@ -3,6 +3,7 @@ import sys import traceback import logging from urlparse import parse_qs +import six from saml2test.opfunc import Operation from saml2test import CheckError, FatalError @@ -64,7 +65,7 @@ class Conversation(object): raise CheckError def do_check(self, test, **kwargs): - if isinstance(test, basestring): + if isinstance(test, six.string_types): chk = self.check_factory(test)(**kwargs) else: chk = test(**kwargs) diff --git a/src/sp_test/base.py b/src/sp_test/base.py index eaea070..1ed778c 100644 --- a/src/sp_test/base.py +++ b/src/sp_test/base.py @@ -5,6 +5,7 @@ import os import traceback import urllib import sys +import six from urlparse import parse_qs from saml2 import BINDING_HTTP_REDIRECT, class_name @@ -93,7 +94,7 @@ class Conversation(): raise CheckError def do_check(self, test, **kwargs): - if isinstance(test, basestring): + if isinstance(test, six.string_types): chk = self.check_factory(test)(**kwargs) else: chk = test(**kwargs)