From ed1e385e7da5524dca0a8e47806d2a33f6619e35 Mon Sep 17 00:00:00 2001 From: bbangert Date: Mon, 9 Feb 2009 05:51:05 +0000 Subject: Adding multiple registry function --- paste/registry.py | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'paste/registry.py') 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 -- cgit v1.2.1