diff options
| -rw-r--r-- | passlib/tests/test_utils.py | 8 | ||||
| -rw-r--r-- | passlib/utils/__init__.py | 25 |
2 files changed, 30 insertions, 3 deletions
diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index 4c3a6d2..678ae06 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -241,7 +241,13 @@ class MiscTest(TestCase): def test_saslprep(self): "test saslprep() unicode normalizer" - from passlib.utils import saslprep as sp + from passlib.utils import saslprep as sp, _ipy_missing_stringprep + + if IRONPYTHON: + self.assertTrue(_ipy_missing_stringprep, + "alert passlib author that IPY has stringprep support!") + self.assertRaises(NotImplementedError, sp, u('abc')) + raise self.skipTest("stringprep missing under IPY") # invalid types self.assertRaises(TypeError, sp, None) diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index e0b9e75..a283299 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -1,5 +1,13 @@ """passlib.utils -- helpers for writing password hashes""" #============================================================================= +# Python VM identification +#============================================================================= +import sys +PYPY = hasattr(sys, "pypy_version_info") +JYTHON = sys.platform.startswith('java') +IRONPYTHON = 'IronPython' in sys.version + +#============================================================================= #imports #============================================================================= #core @@ -9,9 +17,15 @@ from functools import update_wrapper import logging; log = logging.getLogger(__name__) import math import os -import sys import random -import stringprep +_ipy_missing_stringprep = False +if IRONPYTHON: + try: + import stringprep + except ImportError: + _ipy_missing_stringprep = True +else: + import stringprep import time import unicodedata from warnings import warn @@ -431,6 +445,13 @@ def saslprep(source, errname="value"): return data +# implement stub for ironpython +if _ipy_missing_stringprep: + def saslprep(source, errname="value"): + "ironpython stub for saslprep()" + raise NotImplementedError("saslprep() requires the stdlib 'stringprep' " + "module, which is not available under IronPython") + #============================================================================= # bytes helpers #============================================================================= |
