Skip to content

Commit 5c63aa6

Browse files
author
Dan Sully
committed
Remove (undeclared dependency) usage of backports.test.support. This was
pulling in `unittest2` as a runtime dependency instead of a test dependency. It's also really not needed, as the functionality that it provides was not being called. Just use importlib instead. Remove unused functions in s_utils.py
1 parent ccb842d commit 5c63aa6

File tree

3 files changed

+19
-90
lines changed

3 files changed

+19
-90
lines changed

src/saml2/config.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env python
2+
23
import copy
3-
import sys
4-
import os
5-
import re
4+
import importlib
65
import logging
76
import logging.handlers
8-
import six
7+
import os
8+
import re
9+
import sys
910

10-
from future.backports.test.support import import_module
11+
import six
1112

1213
from saml2 import root_logger, BINDING_URI, SAMLError
1314
from saml2 import BINDING_SOAP
@@ -359,7 +360,7 @@ def _load(self, fil):
359360
else:
360361
sys.path.insert(0, head)
361362

362-
return import_module(tail)
363+
return importlib.import_module(tail)
363364

364365
def load_file(self, config_file, metadata_construction=False):
365366
if config_file.endswith(".py"):

src/saml2/mdstore.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
from __future__ import print_function
22
import hashlib
3+
import importlib
4+
import json
35
import logging
46
import os
57
import sys
6-
import json
7-
import requests
8-
import six
98

109
from hashlib import sha1
1110
from os.path import isfile
1211
from os.path import join
1312

14-
from future.backports.test.support import import_module
13+
import requests
14+
import six
1515

1616
from saml2 import md
1717
from saml2 import saml
@@ -694,7 +694,7 @@ def get_metadata_loader(func):
694694
i = func.rfind('.')
695695
module, attr = func[:i], func[i + 1:]
696696
try:
697-
mod = import_module(module)
697+
mod = importlib.import_module(module)
698698
except Exception as e:
699699
raise RuntimeError(
700700
'Cannot find metadata provider function %s: "%s"' % (func, e))

src/saml2/s_utils.py

+7-79
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
11
#!/usr/bin/env python
2-
import logging
3-
import random
42

5-
import time
63
import base64
7-
import six
8-
import sys
4+
import hashlib
95
import hmac
10-
import string
11-
12-
# from python 2.5
13-
import imp
6+
import logging
7+
import random
8+
import sys
9+
import time
1410
import traceback
11+
import zlib
1512

16-
if sys.version_info >= (2, 5):
17-
import hashlib
18-
else: # before python 2.5
19-
import sha
13+
import six
2014

2115
from saml2 import saml
2216
from saml2 import samlp
2317
from saml2 import VERSION
2418
from saml2.time_util import instant
2519

26-
try:
27-
from hashlib import md5
28-
except ImportError:
29-
from md5 import md5
30-
import zlib
3120

3221
logger = logging.getLogger(__name__)
3322

@@ -407,67 +396,6 @@ def verify_signature(secret, parts):
407396
return False
408397

409398

410-
FTICKS_FORMAT = "F-TICKS/SWAMID/2.0%s#"
411-
412-
413-
def fticks_log(sp, logf, idp_entity_id, user_id, secret, assertion):
414-
"""
415-
'F-TICKS/' federationIdentifier '/' version *('#' attribute '=' value) '#'
416-
Allowed attributes:
417-
TS the login time stamp
418-
RP the relying party entityID
419-
AP the asserting party entityID (typcially the IdP)
420-
PN a sha256-hash of the local principal name and a unique key
421-
AM the authentication method URN
422-
423-
:param sp: Client instance
424-
:param logf: The log function to use
425-
:param idp_entity_id: IdP entity ID
426-
:param user_id: The user identifier
427-
:param secret: A salt to make the hash more secure
428-
:param assertion: A SAML Assertion instance gotten from the IdP
429-
"""
430-
csum = hmac.new(secret, digestmod=hashlib.sha1)
431-
csum.update(user_id)
432-
ac = assertion.AuthnStatement[0].AuthnContext[0]
433-
434-
info = {
435-
"TS": time.time(),
436-
"RP": sp.entity_id,
437-
"AP": idp_entity_id,
438-
"PN": csum.hexdigest(),
439-
"AM": ac.AuthnContextClassRef.text
440-
}
441-
logf.info(FTICKS_FORMAT % "#".join(["%s=%s" % (a, v) for a, v in info]))
442-
443-
444-
def dynamic_importer(name, class_name=None):
445-
"""
446-
Dynamically imports modules / classes
447-
"""
448-
try:
449-
fp, pathname, description = imp.find_module(name)
450-
except ImportError:
451-
print("unable to locate module: " + name)
452-
return None, None
453-
454-
try:
455-
package = imp.load_module(name, fp, pathname, description)
456-
except Exception:
457-
raise
458-
459-
if class_name:
460-
try:
461-
_class = imp.load_module("%s.%s" % (name, class_name), fp,
462-
pathname, description)
463-
except Exception:
464-
raise
465-
466-
return package, _class
467-
else:
468-
return package, None
469-
470-
471399
def exception_trace(exc):
472400
message = traceback.format_exception(*sys.exc_info())
473401

0 commit comments

Comments
 (0)