diff options
author | Eli Collins <elic@assurancetechnologies.com> | 2013-12-22 15:25:02 -0500 |
---|---|---|
committer | Eli Collins <elic@assurancetechnologies.com> | 2013-12-22 15:25:02 -0500 |
commit | bffea42e623aa7229311f9b59144f600a8093815 (patch) | |
tree | 5d1f92c84cb84e5390f24282271255862f159f4d /passlib/ext | |
parent | d48644569397bfe529bc05a68ecd21d031550fa6 (diff) | |
download | passlib-bffea42e623aa7229311f9b59144f600a8093815.tar.gz |
django compatibility part 2
* added implementation of django 1.6's bcrypt_sha256 hasher, and UTs
* added django16 premade context to passlib.apps, made it default django_context
* test_ext_django now makes use of django16_context
* passlib.ext.django.utils.get_preset_config() now uses django16_context
* tox 'django' and 'django-py3' now test bcrypt integration
Diffstat (limited to 'passlib/ext')
-rw-r--r-- | passlib/ext/django/utils.py | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/passlib/ext/django/utils.py b/passlib/ext/django/utils.py index ab10b6f..161212b 100644 --- a/passlib/ext/django/utils.py +++ b/passlib/ext/django/utils.py @@ -28,6 +28,15 @@ __all__ = [ #============================================================================= # default policies #============================================================================= + +# map preset names -> passlib.app attrs +_preset_map = { + "django-1.0": "django10_context", + "django-1.4": "django14_context", + "django-1.6": "django16_context", + "django-latest": "django_context", +} + def get_preset_config(name): """Returns configuration string for one of the preset strings supported by the ``PASSLIB_CONFIG`` setting. @@ -35,36 +44,41 @@ def get_preset_config(name): * ``"passlib-default"`` - default config used by this release of passlib. * ``"django-default"`` - config matching currently installed django version. - * ``"django-latest"`` - config matching newest django version (currently same as ``"django-1.4"``). + * ``"django-latest"`` - config matching newest django version (currently same as ``"django-1.6"``). * ``"django-1.0"`` - config used by stock Django 1.0 - 1.3 installs - * ``"django-1.4"`` -config used by stock Django 1.4 installs + * ``"django-1.4"`` - config used by stock Django 1.4 installs + * ``"django-1.6"`` - config used by stock Django 1.6 installs """ # TODO: add preset which includes HASHERS + PREFERRED_HASHERS, - # after having imported any custom hashers. "django-current" + # after having imported any custom hashers. e.g. "django-current" if name == "django-default": - if (0,0) < DJANGO_VERSION < (1,4): + if not DJANGO_VERSION: + raise ValueError("can't resolve django-default preset, " + "django not installed") + if DJANGO_VERSION < (1,4): name = "django-1.0" - else: + elif DJANGO_VERSION < (1,6): name = "django-1.4" - if name == "django-1.0": - from passlib.apps import django10_context - return django10_context.to_string() - if name == "django-1.4" or name == "django-latest": - from passlib.apps import django14_context - return django14_context.to_string() + else: + name = "django-1.6" if name == "passlib-default": return PASSLIB_DEFAULT - raise ValueError("unknown preset config name: %r" % name) + try: + attr = _preset_map[name] + except KeyError: + raise ValueError("unknown preset config name: %r" % name) + import passlib.apps + return getattr(passlib.apps, attr).to_string() # default context used by passlib 1.6 PASSLIB_DEFAULT = """ [passlib] ; list of schemes supported by configuration -; currently all django 1.4 hashes, django 1.0 hashes, +; currently all django 1.6, 1.4, and 1.0 hashes, ; and three common modular crypt format hashes. schemes = - django_pbkdf2_sha256, django_pbkdf2_sha1, django_bcrypt, + django_pbkdf2_sha256, django_pbkdf2_sha1, django_bcrypt, django_bcrypt_sha256, django_salted_sha1, django_salted_md5, django_des_crypt, hex_md5, sha512_crypt, bcrypt, phpass |