diff options
author | ianb <devnull@localhost> | 2007-01-16 15:05:12 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2007-01-16 15:05:12 +0000 |
commit | eec15e69be44b502fc557886d48c3c8c3a846aeb (patch) | |
tree | 3d7d3fad683e072cfea90d8faba28b68dcaa6a6c /paste/registry.py | |
parent | 4c1d2311a4e2e67ea24bb9e5aed7c5576333ac6f (diff) | |
download | paste-eec15e69be44b502fc557886d48c3c8c3a846aeb.tar.gz |
Patch from Jason Kirtland to allow false defaults fro StackedObjectProxy, and to proxy bool()/__nonzero__
Diffstat (limited to 'paste/registry.py')
-rw-r--r-- | paste/registry.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/paste/registry.py b/paste/registry.py index 9e84bfb..bc30486 100644 --- a/paste/registry.py +++ b/paste/registry.py @@ -98,6 +98,8 @@ import paste.util.threadinglocal as threadinglocal __all__ = ['StackedObjectProxy', 'RegistryManager', 'StackedObjectRestorer', 'restorer'] +class NoDefault(object): pass + class StackedObjectProxy(object): """Track an object instance internally using a stack @@ -110,7 +112,7 @@ class StackedObjectProxy(object): objects can be removed with _pop_object. """ - def __init__(self, default=None, name="Default"): + def __init__(self, default=NoDefault, name="Default"): """Create a new StackedObjectProxy If a default is given, its used in every thread if no other object @@ -119,7 +121,7 @@ class StackedObjectProxy(object): """ self.__dict__['____name__'] = name self.__dict__['____local__'] = threadinglocal.local() - if default: + if default is not NoDefault: self.__dict__['____default_object__'] = default def __getattr__(self, attr): @@ -156,7 +158,10 @@ class StackedObjectProxy(object): def __contains__(self, key): return key in self._current_obj() - + + def __nonzero__(self): + return bool(self._current_obj()) + def current_obj(self): """ Deprecated (Aug 15 2006); moved to _current_obj. @@ -176,9 +181,9 @@ class StackedObjectProxy(object): if objects: return objects[-1] else: - object = self.__dict__.get('____default_object__') - if object: - return object + obj = self.__dict__.get('____default_object__', NoDefault) + if obj is not NoDefault: + return obj else: raise TypeError( 'No object (name: %s) has been registered for this ' |