diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-04-17 21:58:54 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-04-17 21:58:54 -0400 |
| commit | 2ad8463a456796300df5340a2bc511e290e62072 (patch) | |
| tree | 116a85776ae75ecde4c72c29b12c13d777b53c0f /passlib/utils | |
| parent | ceb7a00ddae502624d609bc63a9048f0de9f1b23 (diff) | |
| download | passlib-2ad8463a456796300df5340a2bc511e290e62072.tar.gz | |
disabling saslprep() support under Jython - it lacks the stringprep module
Diffstat (limited to 'passlib/utils')
| -rw-r--r-- | passlib/utils/__init__.py | 31 | ||||
| -rw-r--r-- | passlib/utils/compat.py | 6 |
2 files changed, 31 insertions, 6 deletions
diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index d2fe9a5..dc89e4d 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -2,6 +2,7 @@ #============================================================================= #imports #============================================================================= +from passlib.utils.compat import PYPY, JYTHON #core from base64 import b64encode, b64decode from codecs import lookup as _lookup_codec @@ -11,9 +12,19 @@ import math import os import sys import random -import stringprep +if JYTHON: + # Jython 2.5.2 lacks stringprep module - + # see http://bugs.jython.org/issue1758320 + try: + import stringprep + except ImportError: + stringprep = None + _stringprep_missing_reason = "not present under Jython" +else: + import stringprep import time -import unicodedata +if stringprep: + import unicodedata from warnings import warn #site #pkg @@ -79,10 +90,6 @@ __all__ = [ # constants #================================================================================= -# Python VM identification -PYPY = hasattr(sys, "pypy_version_info") -JYTHON = sys.platform.startswith('java') - # bitsize of system architecture (32 or 64) sys_bits = int(math.log(sys.maxsize if PY3 else sys.maxint, 2) + 1.5) @@ -371,6 +378,11 @@ def saslprep(source, errname="value"): :returns: normalized unicode string + + .. note:: + + Due to a missing :mod:`!stringprep` module, this feature + is not available on Jython. """ # saslprep - http://tools.ietf.org/html/rfc4013 # stringprep - http://tools.ietf.org/html/rfc3454 @@ -460,6 +472,13 @@ def saslprep(source, errname="value"): return data +# replace saslprep() with stub when stringprep is missing +if stringprep is None: + def saslprep(source, errname="value"): + "stub for saslprep()" + raise NotImplementedError("saslprep() support requires the 'stringprep' " + "module, which is " + _stringprep_missing_reason) + #============================================================================= # bytes helpers #============================================================================= diff --git a/passlib/utils/compat.py b/passlib/utils/compat.py index 77f9c3c..1d88f75 100644 --- a/passlib/utils/compat.py +++ b/passlib/utils/compat.py @@ -10,6 +10,12 @@ PY27 = sys.version_info[:2] == (2,7) # supports last 2.x release PY_MIN_32 = sys.version_info >= (3,2) # py 3.2 or later #============================================================================= +# figure out what VM we're running +#============================================================================= +PYPY = hasattr(sys, "pypy_version_info") +JYTHON = sys.platform.startswith('java') + +#============================================================================= # common imports #============================================================================= import logging; log = logging.getLogger(__name__) |
