changeset 5971:96ef8a8ecc80

improve some passlib related code using the 1.6.1-post-release doc updates catch all exceptions that might happen when creating CryptContext remove compatibility hack - as hash_needs_update removal was delayed to passlib 2.0, we can just use the deprecated method name to support older and current passlib versions.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 16 Mar 2013 21:47:54 +0100
parents 8b94e9a91753
children 35bf45b53714
files MoinMoin/config/multiconfig.py MoinMoin/user.py
diffstat 2 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Sat Mar 16 18:29:13 2013 +0100
+++ b/MoinMoin/config/multiconfig.py	Sat Mar 16 21:47:54 2013 +0100
@@ -433,13 +433,15 @@
         if self.passlib_support:
             try:
                 from passlib.context import CryptContext
+                from passlib.exc import UserWarning
             except ImportError, err:
                 raise error.ConfigurationError("Wiki is configured to use passlib, but importing passlib failed [%s]!" % str(err))
             try:
                 self.cache.pwd_context = CryptContext(**self.passlib_crypt_context)
-            except (ValueError, KeyError), err:
+            except (ValueError, KeyError, TypeError, UserWarning), err:
                 # ValueError: wrong configuration values
                 # KeyError: unsupported hash (seen with passlib 1.3)
+                # TypeError: configuration value has wrong type
                 raise error.ConfigurationError("passlib_crypt_context configuration is invalid [%s]." % str(err))
         elif self.password_scheme == '{PASSLIB}':
             raise error.ConfigurationError("passlib_support is switched off, thus you can't use password_scheme = '{PASSLIB}'.")
--- a/MoinMoin/user.py	Sat Mar 16 18:29:13 2013 +0100
+++ b/MoinMoin/user.py	Sat Mar 16 21:47:54 2013 +0100
@@ -596,10 +596,7 @@
                             # check if we need to recompute the hash. this is needed if either the
                             # passlib hash scheme / hash params changed or if we shall change to a
                             # builtin hash scheme (not recommended):
-                            if not hasattr(pwd_context, 'needs_update'):
-                                # older passlib versions (like 1.3.0) didn't have that method
-                                pwd_context.needs_update = pwd_context.hash_needs_update
-                            recompute_hash = pwd_context.needs_update(d) or wanted_scheme != '{PASSLIB}'
+                            recompute_hash = pwd_context.hash_needs_update(d) or wanted_scheme != '{PASSLIB}'
 
                 else:
                     # a password hash to be checked by legacy, builtin code