diff options
author | bbangert <devnull@localhost> | 2009-02-09 05:51:05 +0000 |
---|---|---|
committer | bbangert <devnull@localhost> | 2009-02-09 05:51:05 +0000 |
commit | ed1e385e7da5524dca0a8e47806d2a33f6619e35 (patch) | |
tree | efeb2f1a394075e3388fa0d2a95897b2ac72624b /paste/registry.py | |
parent | 244509d7d4ce21b51d44becaab853b8b522ca92a (diff) | |
download | paste-ed1e385e7da5524dca0a8e47806d2a33f6619e35.tar.gz |
Adding multiple registry function
Diffstat (limited to 'paste/registry.py')
-rw-r--r-- | paste/registry.py | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/paste/registry.py b/paste/registry.py index 1b40255..f7b9c2e 100644 --- a/paste/registry.py +++ b/paste/registry.py @@ -181,7 +181,10 @@ class StackedObjectProxy(object): provided will be used. Otherwise, a TypeError will be raised. """ - objects = getattr(self.____local__, 'objects', None) + try: + objects = self.____local__.objects + except AttributeError: + objects = None if objects: return objects[-1] else: @@ -224,11 +227,10 @@ class StackedObjectProxy(object): """ try: popped = self.____local__.objects.pop() - if obj: - if popped is not obj: - raise AssertionError( - 'The object popped (%s) is not the same as the object ' - 'expected (%s)' % (popped, obj)) + if obj and popped is not obj: + raise AssertionError( + 'The object popped (%s) is not the same as the object ' + 'expected (%s)' % (popped, obj)) except AttributeError: raise AssertionError('No object has been registered for this thread') @@ -313,6 +315,26 @@ class Registry(object): stacked._push_object(obj) myreglist[stacked_id] = (stacked, obj) + def multiregister(self, stacklist): + """Register a list of tuples + + Similar call semantics as register, except this registers + multiple objects at once. + + Example:: + + registry.multiregister([(sop, obj), (anothersop, anotherobj)]) + + """ + myreglist = self.reglist[-1] + for stacked, obj in stacklist: + stacked_id = id(stacked) + if stacked_id in myreglist: + stacked._pop_object(myreglist[stacked_id][1]) + del myreglist[stacked_id] + stacked._push_object(obj) + myreglist[stacked_id] = (stacked, obj) + # Replace now does the same thing as register replace = register |