diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2012-03-12 22:41:12 -0400 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2012-03-12 22:41:12 -0400 |
| commit | ca830cd76a655f20488aebd082aba1a320e230d0 (patch) | |
| tree | e06a21086d82987bb33da82ec7c3038153e66610 /passlib | |
| parent | 4307162072d9b1c65f41990752b39ad4483c0a00 (diff) | |
| download | passlib-ca830cd76a655f20488aebd082aba1a320e230d0.tar.gz | |
updated passlib.ext.django; made some notes about django 1.4
(may not support django 1.4 until passlib 1.7)
Diffstat (limited to 'passlib')
| -rw-r--r-- | passlib/ext/django/__init__.py | 3 | ||||
| -rw-r--r-- | passlib/ext/django/models.py | 14 | ||||
| -rw-r--r-- | passlib/ext/django/utils.py | 26 | ||||
| -rw-r--r-- | passlib/tests/test_ext_django.py | 9 |
4 files changed, 35 insertions, 17 deletions
diff --git a/passlib/ext/django/__init__.py b/passlib/ext/django/__init__.py index b4fcb2c..a9e019b 100644 --- a/passlib/ext/django/__init__.py +++ b/passlib/ext/django/__init__.py @@ -2,8 +2,7 @@ .. warning:: - This code is experimental and subject to change, - and not officially documented in Passlib just yet + This code is experimental and subject to change (though it should work). see the Passlib documentation for details on how to use this app diff --git a/passlib/ext/django/models.py b/passlib/ext/django/models.py index 9ae17b7..2b3dd16 100644 --- a/passlib/ext/django/models.py +++ b/passlib/ext/django/models.py @@ -2,8 +2,7 @@ .. warning:: - This code is experimental and subject to change, - and not officially documented in Passlib just yet + This code is experimental and subject to change (though it should work). see the Passlib documentation for details on how to use this app @@ -29,18 +28,17 @@ def patch(): catfunc = getattr(settings, "PASSLIB_GET_CATEGORY", get_category) #parse & validate input value - if not ctx: + if ctx == "disabled": # remove any patching that was already set, just in case. set_django_password_context(None) return if ctx == "passlib-default": ctx = DEFAULT_CTX - if isinstance(ctx, sb_types): - ctx = CryptPolicy.from_string(ctx) - if isinstance(ctx, CryptPolicy): - ctx = CryptContext(policy=ctx) + if isinstance(ctx, str): + ctx = CryptContext(policy=CryptPolicy.from_string(ctx)) if not is_crypt_context(ctx): - raise TypeError("django settings.PASSLIB_CONTEXT must be CryptContext instance or config string: %r" % (ctx,)) + raise TypeError("django settings.PASSLIB_CONTEXT must be CryptContext " + "instance or configuration string: %r" % (ctx,)) #monkeypatch django.contrib.auth.models:User set_django_password_context(ctx, get_category=catfunc) diff --git a/passlib/ext/django/utils.py b/passlib/ext/django/utils.py index be8771c..32aa96c 100644 --- a/passlib/ext/django/utils.py +++ b/passlib/ext/django/utils.py @@ -2,9 +2,21 @@ .. warning:: - This code is experimental and subject to change, - and not officially documented in Passlib just yet + This code is experimental and subject to change (though it should work). + +Django 1.4 Notes +================ +they isolated the hashing code into auth.hashers. +public interface is check_password(), make_password(), is_password_unusable() +make_password(None) should return unusable. +User object uses these stubs. +will need to refactor monkeypatching quite a bit. +and their new hashers framework might not require passlib anymore anyways. + +as opposed to pre-1.4, which had everything in auth.models - +a check_password(), and User.set_password / check_password / set_unusable methods. +so if there is utility for this, will need to rethink. """ #=================================================================== #imports @@ -26,14 +38,20 @@ __all__ = [ #=================================================================== _has_django0 = None # old 0.9 django - lacks unusable_password support +_has_django14 = None # new django 1.4 with auth.hashers _dam = None #django.contrib.auth.models reference def _import_django(): - global _dam, _has_django0 + global _dam, _has_django0, _has_django4 if _dam is None: import django.contrib.auth.models as _dam from django import VERSION _has_django0 = VERSION < (1,0) + _has_django14 = VERISON >= (1,4) + if _has_django14: + # django 1.4 had a large rewrite that adds new stronger schemes, + # but changes how things work. our monkeypatching may not jive. + warn("passlib.ext.django may not work correctly with django >= 1.4") return _dam #=================================================================== @@ -58,7 +76,6 @@ DEFAULT_CTX = """ [passlib] schemes = sha512_crypt, - pbkdf2_sha256, django_salted_sha1, django_salted_md5, django_des_crypt, hex_md5, django_disabled @@ -66,7 +83,6 @@ schemes = default = sha512_crypt deprecated = - pbkdf2_sha256, django_salted_sha1, django_salted_md5, django_des_crypt, hex_md5 diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py index 13085fc..96de69e 100644 --- a/passlib/tests/test_ext_django.py +++ b/passlib/tests/test_ext_django.py @@ -30,13 +30,16 @@ except ImportError: settings = None has_django = False -has_django0 = False #are we using django 0.9 release? -has_django1 = False #inverse - are we using django >= 1.0 +has_django0 = False # are we using django 0.9? +has_django1 = False # are we using django >= 1.0? +has_django14 = False # are we using django >= 1.4? if has_django: from django import VERSION + log.debug("found django %r installation", VERSION) has_django0 = (VERSION < (1,0)) has_django1 = (VERSION >= (1,0)) + has_django14 = (VERSION >= (1,4)) if not isinstance(settings, LazySettings): #this could mean django has been configured somehow, @@ -51,6 +54,8 @@ if has_django: else: if not settings.configured: settings.configure() +else: + log.debug("django installation not found") _NOTSET = object() |
