diff options
| author | Eli Collins <elic@assurancetechnologies.com> | 2011-12-28 17:26:04 -0500 |
|---|---|---|
| committer | Eli Collins <elic@assurancetechnologies.com> | 2011-12-28 17:26:04 -0500 |
| commit | fec9d1c45fcd201eea26f5ce276825302f10dce0 (patch) | |
| tree | 4381eb3b2321d4dd8ac0814b9fff046864cfdbed /passlib | |
| parent | 9d1ca56acb757a034d66eb0b97acf0ca06245146 (diff) | |
| download | passlib-fec9d1c45fcd201eea26f5ce276825302f10dce0.tar.gz | |
removed Undef singleton, private _NOTSET singletons are cleaner.
Diffstat (limited to 'passlib')
| -rw-r--r-- | passlib/context.py | 2 | ||||
| -rw-r--r-- | passlib/registry.py | 8 | ||||
| -rw-r--r-- | passlib/tests/test_ext_django.py | 13 | ||||
| -rw-r--r-- | passlib/tests/test_utils.py | 12 | ||||
| -rw-r--r-- | passlib/utils/__init__.py | 21 |
5 files changed, 14 insertions, 42 deletions
diff --git a/passlib/context.py b/passlib/context.py index 97cb4cf..7e6e7fd 100644 --- a/passlib/context.py +++ b/passlib/context.py @@ -28,7 +28,7 @@ except ImportError: resource_string = None #libs from passlib.registry import get_crypt_handler, _validate_handler_name -from passlib.utils import to_bytes, to_unicode, bytes, Undef, \ +from passlib.utils import to_bytes, to_unicode, bytes, \ is_crypt_handler, rng, \ PasslibPolicyWarning from passlib.utils.compat import is_mapping, iteritems, num_types, \ diff --git a/passlib/registry.py b/passlib/registry.py index 31f5b74..06a70ee 100644 --- a/passlib/registry.py +++ b/passlib/registry.py @@ -9,7 +9,7 @@ import logging; log = logging.getLogger(__name__) from warnings import warn #site #libs -from passlib.utils import Undef, is_crypt_handler +from passlib.utils import is_crypt_handler #pkg #local __all__ = [ @@ -259,7 +259,9 @@ def register_crypt_handler(handler, force=False, name=None): _handlers[name] = handler log.info("registered crypt handler %r: %r", name, handler) -def get_crypt_handler(name, default=Undef): +_NOTSET = object() + +def get_crypt_handler(name, default=_NOTSET): """return handler for specified password hash scheme. this method looks up a handler for the specified scheme. @@ -314,7 +316,7 @@ def get_crypt_handler(name, default=Undef): return handler #fail! - if default is Undef: + if default is _NOTSET: raise KeyError("no crypt handler found for algorithm: %r" % (name,)) else: return default diff --git a/passlib/tests/test_ext_django.py b/passlib/tests/test_ext_django.py index 801f03e..008e397 100644 --- a/passlib/tests/test_ext_django.py +++ b/passlib/tests/test_ext_django.py @@ -15,7 +15,6 @@ from passlib.ext.django import utils from passlib.hash import sha256_crypt from passlib.tests.utils import TestCase, unittest, ut_version, catch_warnings import passlib.tests.test_drivers as td -from passlib.utils import Undef from passlib.utils.compat import iteritems, get_method_function, unicode from passlib.registry import get_crypt_handler #module @@ -53,9 +52,11 @@ if has_django: if not settings.configured: settings.configure() +_NOTSET = object() + def update_settings(**kwds): for k,v in iteritems(kwds): - if v is Undef: + if v is _NOTSET: if hasattr(settings, k): if has_django0: delattr(settings._target, k) @@ -147,7 +148,7 @@ class PatchTest(TestCase): self.assertEquals(func.__module__, "django.contrib.auth.models") self.assertFalse(hasattr(dam.User, "password_context")) - def assert_patched(self, context=Undef): + def assert_patched(self, context=_NOTSET): "helper to ensure django HAS been patched" state = utils._django_patch_state @@ -172,7 +173,7 @@ class PatchTest(TestCase): #make sure context matches obj = dam.User.password_context self.assertIs(obj, state['context']) - if context is not Undef: + if context is not _NOTSET: self.assertIs(obj, context) #make sure old methods were stored @@ -434,8 +435,8 @@ class PluginTest(TestCase): #ensure django settings are empty update_settings( - PASSLIB_CONTEXT=Undef, - PASSLIB_GET_CATEGORY=Undef, + PASSLIB_CONTEXT=_NOTSET, + PASSLIB_GET_CATEGORY=_NOTSET, ) #unload module so it's re-run diff --git a/passlib/tests/test_utils.py b/passlib/tests/test_utils.py index dfd5f39..340a5a2 100644 --- a/passlib/tests/test_utils.py +++ b/passlib/tests/test_utils.py @@ -13,7 +13,7 @@ import warnings #module from passlib.context import CryptContext from passlib import utils -from passlib.utils import h64, des, Undef, bytes, b, \ +from passlib.utils import h64, des, bytes, b, \ to_bytes, to_unicode, to_native_str, \ is_same_codec, is_ascii_safe, safe_os_crypt, md4 as md4_mod from passlib.utils.compat import unicode, PY3 @@ -32,16 +32,6 @@ class MiscTest(TestCase): #NOTE: could test xor_bytes(), but it's exercised well enough by pbkdf2 test - def test_undef(self): - "test Undef singleton" - self.assertEqual(repr(Undef), "<Undef>") - self.assertFalse(Undef==None,) - self.assertFalse(Undef==Undef,) - self.assertFalse(Undef==True,) - self.assertTrue(Undef!=None,) - self.assertTrue(Undef!=Undef,) - self.assertTrue(Undef!=True,) - def test_getrandbytes(self): "test getrandbytes()" def f(*a,**k): diff --git a/passlib/utils/__init__.py b/passlib/utils/__init__.py index 101afd3..604a476 100644 --- a/passlib/utils/__init__.py +++ b/passlib/utils/__init__.py @@ -86,27 +86,6 @@ if PY3: else: ALL_BYTE_VALUES = ''.join(chr(x) for x in irange(256)) -#NOTE: Undef is only used in *one* place now, could just remove it -class UndefType(object): - _undef = None - - def __new__(cls): - if cls._undef is None: - cls._undef = object.__new__(cls) - return cls._undef - - def __repr__(self): - return '<Undef>' - - def __eq__(self, other): - return False - - def __ne__(self, other): - return True - -#: singleton used as default kwd value in some functions, indicating "NO VALUE" -Undef = UndefType() - NoneType = type(None) class MissingBackendError(RuntimeError): |
