Skip to content

Commit 9c91638

Browse files
committed
Fix more basestring py3k issues
basestring has been removed from python 3.
1 parent 3db1cb2 commit 9c91638

File tree

13 files changed

+36
-22
lines changed

13 files changed

+36
-22
lines changed

src/idp_test/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import types
77
import argparse
88
import sys
9+
import six
910

1011
import logging
1112
import imp
@@ -356,7 +357,7 @@ def list_operations(self):
356357
item = {"id": key, "name": val["name"]}
357358
try:
358359
_desc = val["descr"]
359-
if isinstance(_desc, basestring):
360+
if isinstance(_desc, six.string_types):
360361
item["descr"] = _desc
361362
else:
362363
item["descr"] = "\n".join(_desc)
@@ -377,7 +378,7 @@ def list_operations(self):
377378
item = {"id": key, "name": val["name"]}
378379
try:
379380
_desc = val["descr"]
380-
if isinstance(_desc, basestring):
381+
if isinstance(_desc, six.string_types):
381382
item["descr"] = _desc
382383
else:
383384
item["descr"] = "\n".join(_desc)

src/idp_test/interaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
import six
56

67
from urlparse import urlparse
78
from bs4 import BeautifulSoup
@@ -34,7 +35,8 @@ def pick_interaction(interactions, _base="", content="", req=None):
3435
_match += 1
3536
else:
3637
_c = _bs.title.contents
37-
if isinstance(_c, list) and not isinstance(_c, basestring):
38+
if isinstance(_c, list) and not isinstance(
39+
_c, six.string_types):
3840
for _line in _c:
3941
if val in _line:
4042
_match += 1
@@ -165,7 +167,7 @@ def pick_form(response, url=None, **kwargs):
165167
_default = _ava["value"]
166168
try:
167169
orig_val = form[prop]
168-
if isinstance(orig_val, basestring):
170+
if isinstance(orig_val, six.string_types):
169171
if orig_val == _default:
170172
_form = form
171173
elif _default in orig_val:

src/saml2/entity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from hashlib import sha1
55
from Crypto.PublicKey import RSA
66
import requests
7+
import six
78
from saml2.metadata import ENDPOINTS
89
from saml2.profile import paos, ecp
910
from saml2.soap import parse_soap_enveloped_saml_artifact_resolve
@@ -156,7 +157,7 @@ def __init__(self, entity_type, config=None, config_file="",
156157
self.sec = security_context(self.config)
157158

158159
if virtual_organization:
159-
if isinstance(virtual_organization, basestring):
160+
if isinstance(virtual_organization, six.string_types):
160161
self.vorg = self.config.vorg[virtual_organization]
161162
elif isinstance(virtual_organization, VirtualOrg):
162163
self.vorg = virtual_organization

src/saml2/httpbase.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import calendar
2+
import six
23
from six.moves import http_cookiejar
34
import copy
45
import re
@@ -260,7 +261,7 @@ def use_http_form_post(message, destination, relay_state,
260261
:param typ: Whether a Request, Response or Artifact
261262
:return: dictionary
262263
"""
263-
if not isinstance(message, basestring):
264+
if not isinstance(message, six.string_types):
264265
message = "%s" % (message,)
265266

266267
return http_form_post_message(message, destination, relay_state, typ)
@@ -375,7 +376,7 @@ def use_http_get(message, destination, relay_state,
375376
:param key: Key to use for signing
376377
:return: dictionary
377378
"""
378-
if not isinstance(message, basestring):
379+
if not isinstance(message, six.string_types):
379380
message = "%s" % (message,)
380381

381382
return http_redirect_message(message, destination, relay_state, typ,

src/saml2/ident.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import shelve
33
import logging
4+
import six
45

56
from hashlib import sha256
67
from urllib import quote
@@ -66,7 +67,7 @@ class IdentDB(object):
6667
Keeps a list of all nameIDs returned per SP
6768
"""
6869
def __init__(self, db, domain="", name_qualifier=""):
69-
if isinstance(db, basestring):
70+
if isinstance(db, six.string_types):
7071
self.db = shelve.open(db)
7172
else:
7273
self.db = db
@@ -94,7 +95,7 @@ def store(self, ident, name_id):
9495
:param ident: user identifier
9596
:param name_id: NameID instance
9697
"""
97-
if isinstance(ident, unicode):
98+
if isinstance(ident, six.string_types):
9899
ident = ident.encode("utf-8")
99100

100101
# One user may have more than one NameID defined

src/saml2/pack.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from saml2.sigver import REQ_ORDER
2121
from saml2.sigver import RESP_ORDER
2222
from saml2.sigver import SIGNER_ALGS
23+
import six
2324

2425
logger = logging.getLogger(__name__)
2526

@@ -57,7 +58,7 @@ def http_form_post_message(message, location, relay_state="",
5758
"""
5859
response = ["<head>", """<title>SAML 2.0 POST</title>""", "</head><body>"]
5960

60-
if not isinstance(message, basestring):
61+
if not isinstance(message, six.string_types):
6162
message = "%s" % (message,)
6263

6364
if typ == "SAMLRequest" or typ == "SAMLResponse":
@@ -94,7 +95,7 @@ def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
9495
:return: A tuple containing header information and a HTML message.
9596
"""
9697

97-
if not isinstance(message, basestring):
98+
if not isinstance(message, six.string_types):
9899
message = "%s" % (message,)
99100

100101
_order = None
@@ -163,7 +164,7 @@ def make_soap_enveloped_saml_thingy(thingy, header_parts=None):
163164
body.tag = '{%s}Body' % NAMESPACE
164165
envelope.append(body)
165166

166-
if isinstance(thingy, basestring):
167+
if isinstance(thingy, six.string_types):
167168
# remove the first XML version/encoding line
168169
logger.debug("thingy0: %s" % thingy)
169170
_part = thingy.split("\n")

src/saml2/s2repoze/plugins/sp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import shelve
1313
import traceback
1414
import saml2
15+
import six
1516
from urlparse import parse_qs, urlparse
1617
from saml2.md import Extensions
1718
from saml2 import xmldsig as ds
@@ -555,7 +556,7 @@ def identify(self, environ):
555556
def add_metadata(self, environ, identity):
556557
""" Add information to the knowledge I have about the user """
557558
name_id = identity['repoze.who.userid']
558-
if isinstance(name_id, basestring):
559+
if isinstance(name_id, six.string_types):
559560
try:
560561
# Make sure that userids authenticated by another plugin
561562
# don't cause problems here.

src/saml2/sigver.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from time import mktime
1717
from binascii import hexlify
18+
import six
1819

1920
from Crypto.PublicKey.RSA import importKey
2021
from Crypto.Signature import PKCS1_v1_5
@@ -728,7 +729,7 @@ class CryptoBackendXmlSec1(CryptoBackend):
728729

729730
def __init__(self, xmlsec_binary, **kwargs):
730731
CryptoBackend.__init__(self, **kwargs)
731-
assert (isinstance(xmlsec_binary, basestring))
732+
assert (isinstance(xmlsec_binary, six.string_types))
732733
self.xmlsec = xmlsec_binary
733734
if os.environ.get('PYSAML2_KEEP_XMLSEC_TMP', None):
734735
self._xmlsec_delete_tmpfiles = False
@@ -1353,7 +1354,7 @@ def _check_signature(self, decoded_xml, item, node_name=NODE_NAME,
13531354
_certs = []
13541355
certs = []
13551356
for cert in _certs:
1356-
if isinstance(cert, basestring):
1357+
if isinstance(cert, six.string_types):
13571358
certs.append(make_temp(pem_format(cert), suffix=".pem",
13581359
decode=False,
13591360
delete=self._xmlsec_delete_tmpfiles))

src/saml2test/check.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import inspect
22
import json
3+
import six
34

45
__author__ = 'rolandh'
56

@@ -91,7 +92,7 @@ def _func(self, conv=None):
9192
self._status = self.status
9293
_msg = conv.last_content
9394

94-
if isinstance(_msg, basestring):
95+
if isinstance(_msg, six.string_types):
9596
self._message = _msg
9697
else:
9798
self._message = _msg.to_dict()

src/saml2test/interaction.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44
import logging
5+
import six
56

67
from urlparse import urlparse
78
from bs4 import BeautifulSoup
@@ -125,8 +126,8 @@ def pick_interaction(self, _base="", content="", req=None):
125126
_match += 1
126127
else:
127128
_c = _bs.title.contents
128-
if isinstance(_c, list) and not isinstance(_c,
129-
basestring):
129+
if isinstance(_c, list) and not isinstance(
130+
_c, six.string_types):
130131
for _line in _c:
131132
if val in _line:
132133
_match += 1
@@ -186,7 +187,7 @@ def pick_form(self, response, url=None, **kwargs):
186187
_default = _ava["value"]
187188
try:
188189
orig_val = form[prop]
189-
if isinstance(orig_val, basestring):
190+
if isinstance(orig_val, six.string_types):
190191
if orig_val == _default:
191192
_form = form
192193
elif _default in orig_val:

0 commit comments

Comments
 (0)