diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-02-08 23:25:45 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-02-08 23:25:45 -0500 |
| commit | 4712bcd50e12e8ed2e8c135d88ed49951dd45bdf (patch) | |
| tree | ba00b4a8b0f6fb28c8659c26dab94880dc93cc65 | |
| parent | bf927985d1fe8df1b6a1cb9db4c314bf4c4c13af (diff) | |
| download | passlib-4712bcd50e12e8ed2e8c135d88ed49951dd45bdf.tar.gz | |
renamed passlib.exc warning classes
| -rw-r--r-- | admin/benchmarks.py | 8 | ||||
| -rw-r--r-- | docs/lib/passlib.exc.rst | 4 | ||||
| -rw-r--r-- | docs/password_hash_api.rst | 2 | ||||
| -rw-r--r-- | passlib/context.py | 12 | ||||
| -rw-r--r-- | passlib/exc.py | 4 | ||||
| -rw-r--r-- | passlib/handlers/bcrypt.py | 6 | ||||
| -rw-r--r-- | passlib/handlers/scram.py | 2 | ||||
| -rw-r--r-- | passlib/tests/test_context.py | 16 | ||||
| -rw-r--r-- | passlib/tests/test_utils_handlers.py | 10 | ||||
| -rw-r--r-- | passlib/tests/utils.py | 4 | ||||
| -rw-r--r-- | passlib/utils/handlers.py | 8 |
11 files changed, 38 insertions, 38 deletions
diff --git a/admin/benchmarks.py b/admin/benchmarks.py index 0976569..2dd44cd 100644 --- a/admin/benchmarks.py +++ b/admin/benchmarks.py @@ -19,9 +19,9 @@ import warnings # site # pkg try: - from passlib.exc import PasslibContextWarning + from passlib.exc import PasslibConfigWarning except ImportError: - PasslibContextWarning = None + PasslibConfigWarning = None import passlib.utils.handlers as uh from passlib.utils.compat import u, print_, unicode # local @@ -101,8 +101,8 @@ def setup_context(): yield test_context_init ctx = test_context_init() -# if PasslibContextWarning: -# warnings.filterwarnings("ignore", category=PasslibContextWarning) +# if PasslibConfigWarning: +# warnings.filterwarnings("ignore", category=PasslibConfigWarning) def test_context_calls(): hash = ctx.encrypt(secret, rounds=2001) ctx.verify(secret, hash) diff --git a/docs/lib/passlib.exc.rst b/docs/lib/passlib.exc.rst index 8be1b0a..ed4413e 100644 --- a/docs/lib/passlib.exc.rst +++ b/docs/lib/passlib.exc.rst @@ -15,6 +15,6 @@ Exceptions Warnings ======== .. autoexception:: PasslibWarning -.. autoexception:: PasslibContextWarning -.. autoexception:: PasslibHandlerWarning +.. autoexception:: PasslibConfigWarning +.. autoexception:: PasslibHashWarning .. autoexception:: PasslibRuntimeWarning diff --git a/docs/password_hash_api.rst b/docs/password_hash_api.rst index 5e59f83..15d4a72 100644 --- a/docs/password_hash_api.rst +++ b/docs/password_hash_api.rst @@ -147,7 +147,7 @@ Required Attributes If supported, ``relaxed=True`` will cause the handler to be more forgiving about invalid input. Instead of immediately throwing a :exc:`ValueError`, it will first attempt to correct the input, - and issue a :exc:`~passlib.exc.PasslibHandlerWarning` if successful. + and issue a :exc:`~passlib.exc.PasslibHashWarning` if successful. This includes actions like clamping out-of-range rounds values, and truncating salts that are too long. diff --git a/passlib/context.py b/passlib/context.py index da9e1dd..7471e76 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -21,7 +21,7 @@ except ImportError: #not available eg: under GAE resource_string = None #libs -from passlib.exc import PasslibContextWarning +from passlib.exc import PasslibConfigWarning from passlib.registry import get_crypt_handler, _validate_handler_name from passlib.utils import is_crypt_handler, rng, saslprep, tick, to_bytes, \ to_unicode @@ -853,10 +853,10 @@ class _CryptRecord(object): "issue warnings if value outside of handler limits" if hmn is not None and value < hmn: warn("%s: %s value is below handler minimum %d: %d" % - (self._ident, name, hmn, value), PasslibContextWarning) + (self._ident, name, hmn, value), PasslibConfigWarning) if hmx is not None and value > hmx: warn("%s: %s value is above handler maximum %d: %d" % - (self._ident, name, hmx, value), PasslibContextWarning) + (self._ident, name, hmx, value), PasslibConfigWarning) def clip(value): "clip value to policy & handler limits" @@ -1008,12 +1008,12 @@ class _CryptRecord(object): mn = self._min_rounds if mn is not None and rounds < mn: warn("%s requires rounds >= %d, increasing value from %d" % - (self._ident, mn, rounds), PasslibContextWarning, 4) + (self._ident, mn, rounds), PasslibConfigWarning, 4) rounds = mn mx = self._max_rounds if mx and rounds > mx: warn("%s requires rounds <= %d, decreasing value from %d" % - (self._ident, mx, rounds), PasslibContextWarning, 4) + (self._ident, mx, rounds), PasslibConfigWarning, 4) rounds = mx kwds['rounds'] = rounds @@ -1042,7 +1042,7 @@ class _CryptRecord(object): #warn app they aren't being protected against timing attacks... warn("CryptContext: verify exceeded min_verify_time: " "scheme=%r min_verify_time=%r elapsed=%r" % - (self.scheme, mvt, end-start), PasslibContextWarning) + (self.scheme, mvt, end-start), PasslibConfigWarning) return ok #================================================================ diff --git a/passlib/exc.py b/passlib/exc.py index 8e60b90..29813cd 100644 --- a/passlib/exc.py +++ b/passlib/exc.py @@ -20,7 +20,7 @@ class MissingBackendError(RuntimeError): class PasslibWarning(UserWarning): """base class for Passlib's user warnings""" -class PasslibContextWarning(PasslibWarning): +class PasslibConfigWarning(PasslibWarning): """Warning issued when non-fatal issue is found related to the configuration of a :class:`~passlib.context.CryptContext` instance. @@ -35,7 +35,7 @@ class PasslibContextWarning(PasslibWarning): but the warning is issued as a sign the configuration may need updating. """ -class PasslibHandlerWarning(PasslibWarning): +class PasslibHashWarning(PasslibWarning): """Warning issued when non-fatal issue is found with parameters or hash string passed to a passlib hash class. diff --git a/passlib/handlers/bcrypt.py b/passlib/handlers/bcrypt.py index 440e39c..5f89b66 100644 --- a/passlib/handlers/bcrypt.py +++ b/passlib/handlers/bcrypt.py @@ -26,7 +26,7 @@ try: except ImportError: #pragma: no cover - though should run whole suite w/o bcryptor installed bcryptor_engine = None #libs -from passlib.exc import PasslibHandlerWarning +from passlib.exc import PasslibHashWarning from passlib.utils import BCRYPT_CHARS as BCHARS, safe_crypt, \ classproperty, rng, getrandstr, test_crypt from passlib.utils.compat import bytes, u, uascii_to_str, unicode @@ -188,7 +188,7 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh. "encountered a bcrypt hash with incorrectly set padding bits; " "you may want to use bcrypt.normhash() " "to fix this; see Passlib 1.5.3 changelog.", - PasslibHandlerWarning) + PasslibHashWarning) return salt def _norm_checksum(self, checksum): @@ -200,7 +200,7 @@ class bcrypt(uh.HasManyIdents, uh.HasRounds, uh.HasSalt, uh.HasManyBackends, uh. "encountered a bcrypt hash with incorrectly set padding bits; " "you may want to use bcrypt.normhash() " "to fix this; see Passlib 1.5.3 changelog.", - PasslibHandlerWarning) + PasslibHashWarning) return checksum #========================================================= diff --git a/passlib/handlers/scram.py b/passlib/handlers/scram.py index 7024dd6..ce972e5 100644 --- a/passlib/handlers/scram.py +++ b/passlib/handlers/scram.py @@ -23,7 +23,7 @@ import logging; log = logging.getLogger(__name__) from warnings import warn #site #libs -from passlib.exc import PasslibHandlerWarning +from passlib.exc import PasslibHashWarning from passlib.utils import ab64_decode, ab64_encode, consteq, saslprep, \ to_native_str, xor_bytes from passlib.utils.compat import b, bytes, bascii_to_str, iteritems, \ diff --git a/passlib/tests/test_context.py b/passlib/tests/test_context.py index 2ee966a..9d96a0f 100644 --- a/passlib/tests/test_context.py +++ b/passlib/tests/test_context.py @@ -18,7 +18,7 @@ except ImportError: #pkg from passlib import hash from passlib.context import CryptContext, CryptPolicy, LazyCryptContext -from passlib.exc import PasslibContextWarning +from passlib.exc import PasslibConfigWarning from passlib.utils import tick, to_bytes, to_unicode from passlib.utils.compat import irange, u import passlib.utils.handlers as uh @@ -622,8 +622,8 @@ class CryptContextTest(TestCase): # set below handler min c2 = cc.replace(all__min_rounds=500, all__max_rounds=None, all__default_rounds=500) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) self.assertEqual(c2.genconfig(salt="nacl"), "$5$rounds=1000$nacl$") self.assertNoWarnings(wlog) @@ -632,7 +632,7 @@ class CryptContextTest(TestCase): cc.genconfig(rounds=1999, salt="nacl"), '$5$rounds=2000$nacl$', ) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) self.assertNoWarnings(wlog) # equal @@ -654,8 +654,8 @@ class CryptContextTest(TestCase): # set above handler max c2 = cc.replace(all__max_rounds=int(1e9)+500, all__min_rounds=None, all__default_rounds=int(1e9)+500) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) self.assertEqual(c2.genconfig(salt="nacl"), "$5$rounds=999999999$nacl$") self.assertNoWarnings(wlog) @@ -665,7 +665,7 @@ class CryptContextTest(TestCase): cc.genconfig(rounds=3001, salt="nacl"), '$5$rounds=3000$nacl$' ) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) self.assertNoWarnings(wlog) # equal @@ -818,7 +818,7 @@ class CryptContextTest(TestCase): cc.encrypt("password", rounds=1999, salt="nacl"), '$5$rounds=2000$nacl$9/lTZ5nrfPuz8vphznnmHuDGFuvjSNvOEDsGmGfsS97', ) - self.assertWarningMatches(wlog.pop(), category=PasslibContextWarning) + self.assertWarningMatches(wlog.pop(), category=PasslibConfigWarning) self.assertFalse(wlog) self.assertEqual( diff --git a/passlib/tests/test_utils_handlers.py b/passlib/tests/test_utils_handlers.py index def6d3e..148228b 100644 --- a/passlib/tests/test_utils_handlers.py +++ b/passlib/tests/test_utils_handlers.py @@ -13,7 +13,7 @@ import warnings from passlib.hash import ldap_md5, sha256_crypt from passlib.registry import _unload_handler_name as unload_handler_name, \ register_crypt_handler, get_crypt_handler -from passlib.exc import MissingBackendError, PasslibHandlerWarning +from passlib.exc import MissingBackendError, PasslibHashWarning from passlib.utils import getrandstr, JYTHON, rng, to_unicode from passlib.utils.compat import b, bytes, bascii_to_str, str_to_uascii, \ uascii_to_str, unicode, PY_MAX_25 @@ -191,7 +191,7 @@ class SkeletonTest(TestCase): self.assertNoWarnings(wlog) self.assertEqual(norm_salt(salt='aaaabb', relaxed=True), 'aaaa') - self.assertWarningMatches(wlog.pop(0), category=PasslibHandlerWarning) + self.assertWarningMatches(wlog.pop(0), category=PasslibHashWarning) self.assertNoWarnings(wlog) #check generated salts @@ -213,7 +213,7 @@ class SkeletonTest(TestCase): self.assertNoWarnings(wlog) self.assertIn(gen_salt(5, relaxed=True), salts4) - self.assertWarningMatches(wlog.pop(0), category=PasslibHandlerWarning) + self.assertWarningMatches(wlog.pop(0), category=PasslibHashWarning) self.assertNoWarnings(wlog) # test with max_salt_size=None @@ -248,7 +248,7 @@ class SkeletonTest(TestCase): self.assertNoWarnings(wlog) self.assertEqual(norm_rounds(rounds=0, relaxed=True), 1) - self.assertWarningMatches(wlog.pop(0), category=PasslibHandlerWarning) + self.assertWarningMatches(wlog.pop(0), category=PasslibHashWarning) self.assertNoWarnings(wlog) # just right @@ -262,7 +262,7 @@ class SkeletonTest(TestCase): self.assertNoWarnings(wlog) self.assertEqual(norm_rounds(rounds=4, relaxed=True), 3) - self.assertWarningMatches(wlog.pop(0), category=PasslibHandlerWarning) + self.assertWarningMatches(wlog.pop(0), category=PasslibHashWarning) self.assertNoWarnings(wlog) # check no default rounds diff --git a/passlib/tests/utils.py b/passlib/tests/utils.py index 5a29203..c4019ab 100644 --- a/passlib/tests/utils.py +++ b/passlib/tests/utils.py @@ -10,7 +10,7 @@ import re import os import sys import tempfile -from passlib.exc import PasslibHandlerWarning +from passlib.exc import PasslibHashWarning from passlib.utils.compat import PY2, PY27, PY_MIN_32, PY3 try: @@ -922,7 +922,7 @@ class HandlerCase(TestCase): if fk: ctx = catch_warnings() ctx.__enter__() - warnings.filterwarnings("ignore", category=PasslibHandlerWarning) + warnings.filterwarnings("ignore", category=PasslibHashWarning) for config, secret, hash in self.known_correct_configs: result = self.do_genhash(secret, config) self.assertEqual(result, hash, "config=%r,secret=%r:" % (config,secret)) diff --git a/passlib/utils/handlers.py b/passlib/utils/handlers.py index 3bba10a..f404b47 100644 --- a/passlib/utils/handlers.py +++ b/passlib/utils/handlers.py @@ -13,7 +13,7 @@ import os from warnings import warn #site #libs -from passlib.exc import MissingBackendError, PasslibHandlerWarning, \ +from passlib.exc import MissingBackendError, PasslibHashWarning, \ PasslibRuntimeWarning from passlib.registry import get_crypt_handler from passlib.utils import is_crypt_handler @@ -867,7 +867,7 @@ class HasSalt(GenericHandler): msg = "salt too large (%s requires %s %d %s)" % (self.name, "exactly" if mx == mn else "<=", mx, self._salt_unit) if self.relaxed: - warn(msg, PasslibHandlerWarning) + warn(msg, PasslibHashWarning) salt = self._truncate_salt(salt, mx) else: raise ValueError(msg) @@ -1023,7 +1023,7 @@ class HasRounds(GenericHandler): if rounds < mn: msg = "rounds too low (%s requires >= %d rounds)" % (self.name, mn) if self.relaxed: - warn(msg, PasslibHandlerWarning) + warn(msg, PasslibHashWarning) rounds = mn else: raise ValueError(msg) @@ -1032,7 +1032,7 @@ class HasRounds(GenericHandler): if mx and rounds > mx: msg = "rounds too high (%s requires <= %d rounds)" % (self.name, mx) if self.relaxed: - warn(msg, PasslibHandlerWarning) + warn(msg, PasslibHashWarning) rounds = mx else: raise ValueError(msg) |
