Fix more basestring py3k issues

basestring has been removed from python 3.
This commit is contained in:
Clint Byrum
2015-05-20 23:31:17 -07:00
parent 3db1cb25d8
commit 9c91638891
13 changed files with 36 additions and 22 deletions

View File

@@ -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)

View File

@@ -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:

View File

@@ -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

View File

@@ -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,

View File

@@ -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

View File

@@ -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 = ["<head>", """<title>SAML 2.0 POST</title>""", "</head><body>"]
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")

View File

@@ -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.

View File

@@ -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))

View File

@@ -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()

View File

@@ -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:

View File

@@ -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:

View File

@@ -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)

View File

@@ -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)