Skip to content

Commit c76eaf7

Browse files
committed
Fix more renamed modules/functions for py3
In doing so it was discovered that the 'implements' function has been replaced by a class decorator, which must be used in python3. Also commented out method arguments seem to expose internal py.test problems in python3. Removing them seems fine since we can look in revision history if we need to find the exact way it was used before.
1 parent ed5d617 commit c76eaf7

File tree

11 files changed

+26
-54
lines changed

11 files changed

+26
-54
lines changed

src/saml2/discovery.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from urllib import urlencode
2-
from urlparse import parse_qs
3-
from urlparse import urlparse
1+
from six.moves.urllib.parse import urlencode, parse_qs, urlparse
42
from saml2.entity import Entity
53
from saml2.response import VerificationError
64

src/saml2/ecp_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
programs.
88
"""
99

10-
import cookielib
10+
from six.moves import http_cookiejar as cookielib
1111
import logging
1212

1313
from saml2 import soap

src/saml2/httputil.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import cgi
66
import six
77

8-
from urllib import quote
9-
from urlparse import parse_qs
10-
from Cookie import SimpleCookie
8+
from six.moves.urllib.parse import quote, parse_qs
9+
from six.moves.http_cookies import SimpleCookie
1110

1211
from saml2 import BINDING_HTTP_ARTIFACT, SAMLError
1312
from saml2 import BINDING_HTTP_REDIRECT

src/saml2/pack.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
- how to package the information
1111
- which protocol to use
1212
"""
13-
from six.moves.urllib.parse import urlparse
13+
from six.moves.urllib.parse import urlparse, urlencode
1414
import saml2
1515
import base64
16-
import urllib
1716
from saml2.s_utils import deflate_and_base64_encode
1817
from saml2.s_utils import Unsupported
1918
import logging
@@ -126,12 +125,12 @@ def http_redirect_message(message, location, relay_state="", typ="SAMLRequest",
126125
except:
127126
raise Unsupported("Signing algorithm")
128127
else:
129-
string = "&".join([urllib.urlencode({k: args[k]})
128+
string = "&".join([urlencode({k: args[k]})
130129
for k in _order if k in args])
131130
args["Signature"] = base64.b64encode(signer.sign(string, key))
132-
string = urllib.urlencode(args)
131+
string = urlencode(args)
133132
else:
134-
string = urllib.urlencode(args)
133+
string = urlencode(args)
135134

136135
glue_char = "&" if urlparse(location).query else "?"
137136
login_url = glue_char.join([location, string])

src/saml2/s2repoze/plugins/sp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import traceback
1414
import saml2
1515
import six
16-
from urlparse import parse_qs, urlparse
16+
from six.moves.urllib.parse import parse_qs, urlparse
1717
from saml2.samlp import Extensions
1818
from saml2 import xmldsig as ds
1919

20-
from StringIO import StringIO
20+
from six import StringIO
2121

2222
from paste.httpexceptions import HTTPSeeOther, HTTPRedirection
2323
from paste.httpexceptions import HTTPNotImplemented
@@ -27,7 +27,7 @@
2727
from saml2.extension.pefim import SPCertEnc
2828
from saml2.httputil import SeeOther
2929
from saml2.client_base import ECP_SERVICE
30-
from zope.interface import implements
30+
from zope.interface import implementer
3131

3232
from repoze.who.interfaces import IChallenger, IIdentifier, IAuthenticator
3333
from repoze.who.interfaces import IMetadataProvider
@@ -80,8 +80,8 @@ def __call__(self, environ, start_response):
8080
return [self.content]
8181

8282

83+
@implementer(IChallenger, IIdentifier, IAuthenticator, IMetadataProvider)
8384
class SAML2Plugin(object):
84-
implements(IChallenger, IIdentifier, IAuthenticator, IMetadataProvider)
8585

8686
def __init__(self, rememberer_name, config, saml_client, wayf, cache,
8787
sid_store=None, discovery="", idp_query_param="",

tests/fakeIDP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from urlparse import parse_qs
1+
from six.moves.urllib.parse import parse_qs
22
from saml2.authn_context import INTERNETPROTOCOLPASSWORD
33
from saml2.samlp import attribute_query_from_string, logout_request_from_string
44
from saml2 import BINDING_HTTP_REDIRECT, pack

tests/test_50_server.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import base64
44
import os
55
from contextlib import closing
6-
from urlparse import parse_qs
6+
from six.moves.urllib.parse import parse_qs
77
import uuid
88

99
from saml2.cert import OpenSSLWrapper
@@ -540,7 +540,6 @@ def test_encrypted_signed_response_1(self):
540540
encrypt_assertion=False,
541541
encrypt_assertion_self_contained=True,
542542
pefim=True,
543-
#encrypted_advice_attributes=True,
544543
encrypt_cert_advice=cert_str,
545544
)
546545

@@ -680,7 +679,6 @@ def test_encrypted_signed_response_4(self):
680679
sign_assertion=True,
681680
encrypt_assertion=True,
682681
encrypt_assertion_self_contained=True,
683-
#encrypted_advice_attributes=True,
684682
pefim=True,
685683
encrypt_cert_advice=cert_str,
686684
)
@@ -741,7 +739,6 @@ def test_encrypted_response_1(self):
741739
sign_assertion=False,
742740
encrypt_assertion=False,
743741
encrypt_assertion_self_contained=True,
744-
#encrypted_advice_attributes=True,
745742
pefim=True,
746743
encrypt_cert_advice=cert_str_advice,
747744
)
@@ -774,7 +771,6 @@ def test_encrypted_response_2(self):
774771
sign_assertion=False,
775772
encrypt_assertion=True,
776773
encrypt_assertion_self_contained=True,
777-
#encrypted_advice_attributes=True,
778774
pefim=True,
779775
encrypt_cert_advice=cert_str_advice,
780776
)
@@ -867,7 +863,6 @@ def test_encrypted_response_5(self):
867863
sign_assertion=False,
868864
encrypt_assertion=False,
869865
encrypt_assertion_self_contained=True,
870-
#encrypted_advice_attributes=True,
871866
pefim=True
872867
)
873868

@@ -900,7 +895,6 @@ def test_encrypted_response_6(self):
900895
sign_assertion=False,
901896
encrypt_assertion=True,
902897
encrypt_assertion_self_contained=True,
903-
#encrypted_advice_attributes=True,
904898
pefim=True,
905899
encrypt_cert_advice=cert_str_advice,
906900
encrypt_cert_assertion=cert_str_assertion
@@ -935,7 +929,6 @@ def test_encrypted_response_7(self):
935929
sign_assertion=False,
936930
encrypt_assertion=True,
937931
encrypt_assertion_self_contained=True,
938-
#encrypted_advice_attributes=True,
939932
pefim=True
940933
)
941934

@@ -965,7 +958,6 @@ def test_encrypted_response_8(self):
965958
sign_assertion=False,
966959
encrypt_assertion=True,
967960
encrypt_assertion_self_contained=True,
968-
#encrypted_advice_attributes=True,
969961
pefim=True,
970962
encrypt_cert_advice="whatever",
971963
encrypt_cert_assertion="whatever"
@@ -987,7 +979,6 @@ def test_encrypted_response_8(self):
987979
sign_assertion=False,
988980
encrypt_assertion=False,
989981
encrypt_assertion_self_contained=True,
990-
#encrypted_advice_attributes=True,
991982
pefim=True,
992983
encrypt_cert_advice="whatever",
993984
)
@@ -1030,7 +1021,6 @@ def test_encrypted_response_8(self):
10301021
sign_assertion=False,
10311022
encrypt_assertion=True,
10321023
encrypt_assertion_self_contained=True,
1033-
#encrypted_advice_attributes=True,
10341024
pefim=True,
10351025
encrypt_cert_advice="whatever",
10361026
encrypt_cert_assertion="whatever"
@@ -1052,7 +1042,6 @@ def test_encrypted_response_8(self):
10521042
sign_assertion=False,
10531043
encrypt_assertion=False,
10541044
encrypt_assertion_self_contained=True,
1055-
#encrypted_advice_attributes=True,
10561045
pefim=True,
10571046
encrypt_cert_advice="whatever",
10581047
)
@@ -1095,7 +1084,6 @@ def test_encrypted_response_9(self):
10951084
sign_assertion=False,
10961085
encrypt_assertion=True,
10971086
encrypt_assertion_self_contained=True,
1098-
#encrypted_advice_attributes=True,
10991087
pefim=True,
11001088
)
11011089

@@ -1111,7 +1099,6 @@ def test_encrypted_response_9(self):
11111099
sign_assertion=False,
11121100
encrypt_assertion=False,
11131101
encrypt_assertion_self_contained=True,
1114-
#encrypted_advice_attributes=True,
11151102
pefim=True
11161103
)
11171104

tests/test_51_client.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import uuid
66
import six
77
import urllib
8-
import urlparse
8+
from six.moves.urllib.parse import parse_qs
9+
from six.moves.urllib.parse import urlparse
910
from saml2.cert import OpenSSLWrapper
1011
from saml2.xmldsig import SIG_RSA_SHA256
1112
from saml2 import BINDING_HTTP_POST
@@ -415,15 +416,13 @@ def test_response_2(self):
415416
in_response_to="id1",
416417
destination="http://lingon.catalogix.se:8087/",
417418
sp_entity_id="urn:mace:example.com:saml:roland:sp",
418-
#name_id_policy=nameid_policy,
419419
name_id=self.name_id,
420420
421421
authn=AUTHN,
422422
sign_response=True,
423423
sign_assertion=True,
424424
encrypt_assertion=False,
425425
encrypt_assertion_self_contained=True,
426-
#encrypted_advice_attributes=True,
427426
pefim=True,
428427
encrypt_cert_advice=cert_str
429428
)
@@ -453,15 +452,13 @@ def test_response_3(self):
453452
in_response_to="id1",
454453
destination="http://lingon.catalogix.se:8087/",
455454
sp_entity_id="urn:mace:example.com:saml:roland:sp",
456-
#name_id_policy=nameid_policy,
457455
name_id=self.name_id,
458456
459457
authn=AUTHN,
460458
sign_response=True,
461459
sign_assertion=True,
462460
encrypt_assertion=False,
463461
encrypt_assertion_self_contained=True,
464-
#encrypted_advice_attributes=True,
465462
pefim=True,
466463
)
467464

@@ -490,15 +487,13 @@ def test_response_4(self):
490487
in_response_to="id1",
491488
destination="http://lingon.catalogix.se:8087/",
492489
sp_entity_id="urn:mace:example.com:saml:roland:sp",
493-
#name_id_policy=nameid_policy,
494490
name_id=self.name_id,
495491
496492
authn=AUTHN,
497493
sign_response=True,
498494
sign_assertion=True,
499495
encrypt_assertion=True,
500496
encrypt_assertion_self_contained=True,
501-
#encrypted_advice_attributes=True,
502497
pefim=True,
503498
)
504499

@@ -535,15 +530,13 @@ def test_response_5(self):
535530
in_response_to="id1",
536531
destination="http://lingon.catalogix.se:8087/",
537532
sp_entity_id="urn:mace:example.com:saml:roland:sp",
538-
#name_id_policy=nameid_policy,
539533
name_id=self.name_id,
540534
541535
authn=AUTHN,
542536
sign_response=True,
543537
sign_assertion=True,
544538
encrypt_assertion=True,
545539
encrypt_assertion_self_contained=True,
546-
#encrypted_advice_attributes=True,
547540
pefim=True,
548541
encrypt_cert_assertion=cert_str
549542
)
@@ -589,15 +582,13 @@ def test_response_6(self):
589582
in_response_to="id1",
590583
destination="http://lingon.catalogix.se:8087/",
591584
sp_entity_id="urn:mace:example.com:saml:roland:sp",
592-
#name_id_policy=nameid_policy,
593585
name_id=self.name_id,
594586
595587
authn=AUTHN,
596588
sign_response=True,
597589
sign_assertion=True,
598590
encrypt_assertion=True,
599591
encrypt_assertion_self_contained=True,
600-
#encrypted_advice_attributes=True,
601592
pefim=True,
602593
encrypt_cert_assertion=cert_assertion_str,
603594
encrypt_cert_advice=cert_advice_str
@@ -628,7 +619,6 @@ def test_response_7(self):
628619
in_response_to="id1",
629620
destination="http://lingon.catalogix.se:8087/",
630621
sp_entity_id="urn:mace:example.com:saml:roland:sp",
631-
#name_id_policy=nameid_policy,
632622
name_id=self.name_id,
633623
634624
authn=AUTHN,
@@ -672,7 +662,6 @@ def test_response_8(self):
672662
in_response_to="id1",
673663
destination="http://lingon.catalogix.se:8087/",
674664
sp_entity_id="urn:mace:example.com:saml:roland:sp",
675-
#name_id_policy=nameid_policy,
676665
name_id=self.name_id,
677666
678667
authn=AUTHN,
@@ -1177,7 +1166,7 @@ def test_signed_redirect(self):
11771166
relay_state="relay2", sigalg=SIG_RSA_SHA256, key=key)
11781167

11791168
loc = info["headers"][0][1]
1180-
qs = urlparse.parse_qs(loc[1:])
1169+
qs = parse_qs(loc[1:])
11811170
assert _leq(qs.keys(),
11821171
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
11831172

@@ -1214,8 +1203,8 @@ def test_do_authn(self):
12141203
assert http_args["headers"][0][0] == "Location"
12151204
assert http_args["data"] == []
12161205
redirect_url = http_args["headers"][0][1]
1217-
_, _, _, _, qs, _ = urlparse.urlparse(redirect_url)
1218-
qs_dict = urlparse.parse_qs(qs)
1206+
_, _, _, _, qs, _ = urlparse(redirect_url)
1207+
qs_dict = parse_qs(qs)
12191208
req = self.server.parse_authn_request(qs_dict["SAMLRequest"][0],
12201209
binding)
12211210
resp_args = self.server.response_args(req.message, [response_binding])
@@ -1234,8 +1223,8 @@ def test_do_negotiated_authn(self):
12341223
assert http_args["headers"][0][0] == "Location"
12351224
assert http_args["data"] == []
12361225
redirect_url = http_args["headers"][0][1]
1237-
_, _, _, _, qs, _ = urlparse.urlparse(redirect_url)
1238-
qs_dict = urlparse.parse_qs(qs)
1226+
_, _, _, _, qs, _ = urlparse(redirect_url)
1227+
qs_dict = parse_qs(qs)
12391228
req = self.server.parse_authn_request(qs_dict["SAMLRequest"][0],
12401229
binding)
12411230
resp_args = self.server.response_args(req.message, [response_binding])

tests/test_64_artifact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import base64
22
from contextlib import closing
33
from hashlib import sha1
4-
from urlparse import urlparse
5-
from urlparse import parse_qs
4+
from six.moves.urllib.parse import urlparse
5+
from six.moves.urllib.parse import parse_qs
66
from saml2 import BINDING_HTTP_ARTIFACT
77
from saml2 import BINDING_SOAP
88
from saml2 import BINDING_HTTP_POST

tests/test_65_authn_query.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from contextlib import closing
2-
from urlparse import urlparse, parse_qs
2+
from six.moves.urllib.parse import urlparse, parse_qs
33
from saml2 import BINDING_SOAP, BINDING_HTTP_POST
44

55
__author__ = 'rolandh'

0 commit comments

Comments
 (0)