diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2012-04-30 21:17:18 -0400 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2012-04-30 21:17:18 -0400 |
commit | d3650f5a8458d84c4ef7886aced7e99ef3935bfd (patch) | |
tree | b4d687940a6eeda95d9139edb10a60f180750a3a | |
parent | dc0450fdb6a1d8e53b159a1061cc64c6c71fb43e (diff) | |
download | passlib-d3650f5a8458d84c4ef7886aced7e99ef3935bfd.tar.gz |
splitcomma won't die
-rw-r--r-- | passlib/context.py | 17 | ||||
-rw-r--r-- | passlib/handlers/scram.py | 4 | ||||
-rw-r--r-- | passlib/tests/test_utils.py | 9 | ||||
-rw-r--r-- | passlib/utils/__init__.py | 16 |
4 files changed, 23 insertions, 23 deletions
diff --git a/passlib/context.py b/passlib/context.py index 8fb8006..d32a5cd 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -18,8 +18,8 @@ from warnings import warn #libs from passlib.exc import PasslibConfigWarning, ExpectedStringError, ExpectedTypeError from passlib.registry import get_crypt_handler, _validate_handler_name -from passlib.utils import is_crypt_handler, rng, tick, to_bytes, \ - to_unicode +from passlib.utils import rng, tick, to_bytes, \ + to_unicode, splitcomma from passlib.utils.compat import bytes, iteritems, num_types, \ PY3, PY_MIN_32, unicode, SafeConfigParser, \ NativeStringIO, BytesIO, base_string_types @@ -62,15 +62,6 @@ _coerce_scheme_options = dict( salt_size=int, ) -def _splitcomma(source): - "split comma-separated string into list of strings" - source = source.strip() - if source.endswith(","): - source = source[:-1] - if not source: - return [] - return [ elem.strip() for elem in source.split(",") ] - def _is_handler_registered(handler): """detect if handler is registered or a custom handler""" return get_crypt_handler(handler.name, None) is handler @@ -1411,7 +1402,7 @@ class CryptContext(object): schemes = [] data = source.get((None,None,"schemes")) if isinstance(data, str): - data = _splitcomma(data) + data = splitcomma(data) for elem in data or (): # resolve elem -> handler & scheme if hasattr(elem, "name"): @@ -1488,7 +1479,7 @@ class CryptContext(object): self._default_schemes[cat] = value elif key == "deprecated": if isinstance(value, str): - value = _splitcomma(value) + value = splitcomma(value) elif not isinstance(value, (list,tuple)): raise ExpectedTypeError(value, "str or seq", "deprecated") if schemes: diff --git a/passlib/handlers/scram.py b/passlib/handlers/scram.py index 3797514..e423a1c 100644 --- a/passlib/handlers/scram.py +++ b/passlib/handlers/scram.py @@ -13,7 +13,7 @@ from warnings import warn #libs from passlib.exc import PasslibHashWarning from passlib.utils import ab64_decode, ab64_encode, consteq, saslprep, \ - to_native_str, xor_bytes + to_native_str, xor_bytes, splitcomma from passlib.utils.compat import b, bytes, bascii_to_str, iteritems, \ itervalues, PY3, u, unicode from passlib.utils.pbkdf2 import pbkdf2, get_prf, norm_hash_name @@ -324,7 +324,7 @@ class scram(uh.HasRounds, uh.HasRawSalt, uh.HasRawChecksum, uh.GenericHandler): # parse args value if isinstance(algs, str): - algs = algs.split(",") + algs = splitcomma(algs) algs = sorted(norm_hash_name(alg, 'iana') for alg in algs) if any(len(alg)>9 for alg in algs): raise ValueError("SCRAM limits alg names to max of 9 characters") diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index a468ecf..4b03b0c 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -372,6 +372,15 @@ class MiscTest(TestCase): self.assertRaises(ValueError, sp, u("\u0627\u0031")) self.assertEqual(sp(u("\u0627\u0031\u0628")), u("\u0627\u0031\u0628")) + def test_splitcomma(self): + from passlib.utils import splitcomma + self.assertEqual(splitcomma(""), []) + self.assertEqual(splitcomma(","), []) + self.assertEqual(splitcomma("a"), ['a']) + self.assertEqual(splitcomma(" a , "), ['a']) + self.assertEqual(splitcomma(" a , b"), ['a', 'b']) + self.assertEqual(splitcomma(" a, b, "), ['a', 'b']) + #========================================================= #byte/unicode helpers #========================================================= diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 450da38..fc90055 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -344,16 +344,16 @@ def consteq(left, right): result |= ord(l) ^ ord(r) return result == 0 -@deprecated_function(deprecated="1.6", removed="1.8") -def splitcomma(source, sep=","): # pragma: no cover +def splitcomma(source, sep=","): """split comma-separated string into list of elements, - stripping whitespace and discarding empty elements. + stripping whitespace. """ - return [ - elem.strip() - for elem in source.split(sep) - if elem.strip() - ] + source = source.strip() + if source.endswith(sep): + source = source[:-1] + if not source: + return [] + return [ elem.strip() for elem in source.split(sep) ] def saslprep(source, param="value"): """normalizes unicode string using SASLPrep stringprep profile. |