Skip to content

Commit 05195ff

Browse files
committed
Remove the python-future module and use six
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent a73239c commit 05195ff

File tree

7 files changed

+32
-41
lines changed

7 files changed

+32
-41
lines changed

setup.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ scripts =
5050
install_requires =
5151
cryptography >= 1.4
5252
defusedxml
53-
future
5453
pyOpenSSL
5554
python-dateutil
5655
pytz

src/saml2/discovery.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from future.backports.urllib.parse import parse_qs
2-
from future.backports.urllib.parse import urlencode
3-
from future.backports.urllib.parse import urlparse
1+
from six.moves.urllib import parse
42

53
from saml2.entity import Entity
64
from saml2.response import VerificationError
@@ -17,10 +15,10 @@ def __init__(self, config=None, config_file=""):
1715

1816
def parse_discovery_service_request(self, url="", query=""):
1917
if url:
20-
part = urlparse(url)
21-
dsr = parse_qs(part[4])
18+
part = parse.urlparse(url)
19+
dsr = parse.parse_qs(part[4])
2220
elif query:
23-
dsr = parse_qs(query)
21+
dsr = parse.parse_qs(query)
2422
else:
2523
dsr = {}
2624

@@ -35,9 +33,9 @@ def parse_discovery_service_request(self, url="", query=""):
3533
pass
3634

3735
if "return" in dsr:
38-
part = urlparse(dsr["return"])
36+
part = parse.urlparse(dsr["return"])
3937
if part.query:
40-
qp = parse_qs(part.query)
38+
qp = parse.parse_qs(part.query)
4139
if "returnIDParam" in dsr:
4240
assert dsr["returnIDParam"] not in qp.keys()
4341
else:
@@ -74,9 +72,9 @@ def create_discovery_service_response(return_url=None,
7472
return_url = kwargs["return"]
7573

7674
if entity_id:
77-
qp = urlencode({returnIDParam: entity_id})
75+
qp = parse.urlencode({returnIDParam: entity_id})
7876

79-
part = urlparse(return_url)
77+
part = parse.urlparse(return_url)
8078
if part.query:
8179
# Iff there is a query part add the new info at the end
8280
return_url = "%s&%s" % (return_url, qp)

src/saml2/response.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
#
4-
from future.utils import python_2_unicode_compatible
54
import calendar
65
import logging
76
import six
@@ -468,7 +467,6 @@ def __init__(self, sec_context, return_addrs=None, timeslack=0,
468467

469468
# ----------------------------------------------------------------------------
470469

471-
@python_2_unicode_compatible
472470
class AuthnResponse(StatusResponse):
473471
""" This is where all the profile compliance is checked.
474472
This one does saml2int compliance. """

src/saml2/s2repoze/plugins/sp.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
from saml2.samlp import Extensions
1616
from saml2 import xmldsig as ds
1717

18-
from future.backports.urllib.parse import parse_qs
19-
from future.backports.urllib.parse import urlparse
20-
2118
from six import StringIO
19+
from six.moves.urllib import parse
2220

2321
from paste.httpexceptions import HTTPSeeOther, HTTPRedirection
2422
from paste.httpexceptions import HTTPNotImplemented
@@ -104,7 +102,7 @@ def __init__(
104102
self.discosrv = discovery
105103
self.idp_query_param = idp_query_param
106104
self.logout_endpoints = [
107-
urlparse(ep)[2] for ep in config.endpoint("single_logout_service")
105+
parse.urlparse(ep)[2] for ep in config.endpoint("single_logout_service")
108106
]
109107
try:
110108
self.metadata = self.conf.metadata
@@ -158,7 +156,7 @@ def _get_post(self, environ):
158156
environ["wsgi.input"] = StringIO(body) # restore the request body
159157
# as a stream so that everything seems untouched
160158

161-
post = parse_qs(body) # parse the POST fields into a dict
159+
post = parse.parse_qs(body) # parse the POST fields into a dict
162160

163161
logger.debug("identify post: %s", post)
164162

@@ -218,7 +216,7 @@ def _pick_idp(self, environ, came_from):
218216
query = environ.get(key)
219217
if query:
220218
try:
221-
_idp_entity_id = dict(parse_qs(query))[self.idp_query_param][0]
219+
_idp_entity_id = dict(parse.parse_qs(query))[self.idp_query_param][0]
222220
if _idp_entity_id in idps:
223221
idp_entity_id = _idp_entity_id
224222
break
@@ -239,7 +237,7 @@ def _pick_idp(self, environ, came_from):
239237
if self.wayf:
240238
if query:
241239
try:
242-
wayf_selected = dict(parse_qs(query))["wayf_selected"][0]
240+
wayf_selected = dict(parse.parse_qs(query))["wayf_selected"][0]
243241
except KeyError:
244242
return self._wayf_redirect(came_from)
245243
idp_entity_id = wayf_selected
@@ -385,7 +383,7 @@ def challenge(self, environ, _status, _app_headers, _forget_headers):
385383
if (environ["PATH_INFO"]) in ret and ret.split(environ["PATH_INFO"])[
386384
1
387385
] == "":
388-
query = parse_qs(environ["QUERY_STRING"])
386+
query = parse.parse_qs(environ["QUERY_STRING"])
389387
sid = query["sid"][0]
390388
came_from = self.outstanding_queries[sid]
391389
except:

src/saml2/sigver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from time import mktime
1414
from binascii import hexlify
1515

16-
from future.backports.urllib.parse import urlencode
16+
from six.moves.urllib import parse
1717

1818
import saml2.cryptography.asymmetric
1919
import saml2.cryptography.pki
@@ -578,7 +578,7 @@ def verify_redirect_signature(saml_msg, crypto, cert=None, sigkey=None):
578578
_args = saml_msg.copy()
579579
del _args['Signature'] # everything but the signature
580580
string = '&'.join(
581-
[urlencode({k: _args[k]}) for k in _order if k in
581+
[parse.urlencode({k: _args[k]}) for k in _order if k in
582582
_args]).encode('ascii')
583583

584584
if cert:

tests/test_30_mdstore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import re
55
from collections import OrderedDict
66

7-
from future.backports.urllib.parse import quote_plus
7+
from six.moves.urllib import parse
88

99
from saml2.config import Config
1010
from saml2.mdstore import MetadataStore, MetaDataExtern
@@ -299,7 +299,7 @@ def test_mdx_service():
299299
entity_id = "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
300300

301301
url = "http://mdx.example.com/entities/{}".format(
302-
quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
302+
parse.quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
303303
responses.add(responses.GET, url, body=TEST_METADATA_STRING, status=200,
304304
content_type=SAML_METADATA_CONTENT_TYPE)
305305

@@ -315,7 +315,7 @@ def test_mdx_single_sign_on_service():
315315
entity_id = "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
316316

317317
url = "http://mdx.example.com/entities/{}".format(
318-
quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
318+
parse.quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
319319
responses.add(responses.GET, url, body=TEST_METADATA_STRING, status=200,
320320
content_type=SAML_METADATA_CONTENT_TYPE)
321321

tests/test_51_client.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import base64
55
import uuid
66
import six
7-
from future.backports.urllib.parse import parse_qs
8-
from future.backports.urllib.parse import urlencode
9-
from future.backports.urllib.parse import urlparse
7+
from six.moves.urllib import parse
108
from pytest import raises
119

1210
from saml2.argtree import add_path
@@ -1378,7 +1376,7 @@ def test_signed_redirect(self):
13781376
relay_state="relay2", sign=True, sigalg=SIG_RSA_SHA256)
13791377

13801378
loc = info["headers"][0][1]
1381-
qs = parse_qs(loc[1:])
1379+
qs = parse.parse_qs(loc[1:])
13821380
assert _leq(qs.keys(),
13831381
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
13841382

@@ -1417,8 +1415,8 @@ def test_do_logout_signed_redirect(self):
14171415
assert binding == BINDING_HTTP_REDIRECT
14181416

14191417
loc = info["headers"][0][1]
1420-
_, _, _, _, qs, _ = urlparse(loc)
1421-
qs = parse_qs(qs)
1418+
_, _, _, _, qs, _ = parse.urlparse(loc)
1419+
qs = parse.parse_qs(qs)
14221420
assert _leq(qs.keys(),
14231421
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
14241422

@@ -2940,7 +2938,7 @@ def test_signed_redirect(self):
29402938
relay_state="relay2", sign=True, sigalg=SIG_RSA_SHA256)
29412939

29422940
loc = info["headers"][0][1]
2943-
qs = parse_qs(loc[1:])
2941+
qs = parse.parse_qs(loc[1:])
29442942
assert _leq(qs.keys(),
29452943
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
29462944

@@ -2979,8 +2977,8 @@ def test_do_logout_signed_redirect(self):
29792977
assert binding == BINDING_HTTP_REDIRECT
29802978

29812979
loc = info["headers"][0][1]
2982-
_, _, _, _, qs, _ = urlparse(loc)
2983-
qs = parse_qs(qs)
2980+
_, _, _, _, qs, _ = parse.urlparse(loc)
2981+
qs = parse.parse_qs(qs)
29842982
assert _leq(qs.keys(),
29852983
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
29862984

@@ -3076,8 +3074,8 @@ def test_do_authn(self):
30763074
assert http_args["headers"][0][0] == "Location"
30773075
assert http_args["data"] == []
30783076
redirect_url = http_args["headers"][0][1]
3079-
_, _, _, _, qs, _ = urlparse(redirect_url)
3080-
qs_dict = parse_qs(qs)
3077+
_, _, _, _, qs, _ = parse.urlparse(redirect_url)
3078+
qs_dict = parse.parse_qs(qs)
30813079
req = self.server.parse_authn_request(qs_dict["SAMLRequest"][0],
30823080
binding)
30833081
resp_args = self.server.response_args(req.message, [response_binding])
@@ -3097,8 +3095,8 @@ def test_do_negotiated_authn(self):
30973095
assert http_args["headers"][0][0] == "Location"
30983096
assert http_args["data"] == []
30993097
redirect_url = http_args["headers"][0][1]
3100-
_, _, _, _, qs, _ = urlparse(redirect_url)
3101-
qs_dict = parse_qs(qs)
3098+
_, _, _, _, qs, _ = parse.urlparse(redirect_url)
3099+
qs_dict = parse.parse_qs(qs)
31023100
req = self.server.parse_authn_request(qs_dict["SAMLRequest"][0],
31033101
binding)
31043102
resp_args = self.server.response_args(req.message, [response_binding])
@@ -3152,7 +3150,7 @@ def test_post_sso(self):
31523150
# Here I fake what the client will do
31533151
# create the form post
31543152

3155-
http_args["data"] = urlencode(_dic)
3153+
http_args["data"] = parse.urlencode(_dic)
31563154
http_args["method"] = "POST"
31573155
http_args["dummy"] = _dic["SAMLRequest"]
31583156
http_args["headers"] = [('Content-type',
@@ -3188,7 +3186,7 @@ def test_negotiated_post_sso(self):
31883186
# Here I fake what the client will do
31893187
# create the form post
31903188

3191-
http_args["data"] = urlencode(_dic)
3189+
http_args["data"] = parse.urlencode(_dic)
31923190
http_args["method"] = "POST"
31933191
http_args["dummy"] = _dic["SAMLRequest"]
31943192
http_args["headers"] = [('Content-type',

0 commit comments

Comments
 (0)