[Zope3-dev] Re: ObjectHub

Casey Duncan casey@zope.com
Sat, 7 Dec 2002 17:56:02 -0500


Do you care what the hubid is if the object was already registered?

Perhaps to make register and unregister behave symmetrically, you should
have register return the hubid only if the object was a new register and
None if not. Unregister would return a bool. Then the code code be:

register_count = 0
for ob in objects:
    hubid = objecthub.register(ob)
    if hubid is not None:
        register_count += 1

I dunno. Does it really matter to the application if register does any work?
When is that important? If not then I say it should just always return the
hubid.

-Casey


----- Original Message -----
From: "Steve Alexander" <steve@cat-box.net>
To: "Gary Poster" <gary@zope.com>
Cc: <guido@python.org>; <zope3-dev@zope.org>
Sent: Saturday, December 07, 2002 7:56 AM
Subject: [Zope3-dev] Re: ObjectHub


> Gary Poster wrote:
> > Guido wrote in comments to ObjectHub:
> >
> >            # XXX It would be more convenient if register() returned
> >            #     a bool indicating whether the object is already
> >            #     registered, rather than raising an exception.
> >            #     Then a more useful distinction between real errors
> >            #     and this (common) condition could be made.
> >
> > To which my reply is: +1.  I can do this, or you, Steve.  I'm working in
> > the vicinity now so would be happy to if you agree and noone else
> > disagrees.
>
> I was working alongside Guido when we added that comment.
>
> Now that I think about it more carefully, we can't do exactly what is
> suggested there. The 'register' method of IObjectHub is supposed to
> return the hubid of the newly registered object. This is meaningful
> information, and it is useful information for many clients of the
> ObjectHub: you want to know the hubid of the object you just
> successfully registered.
>
> So, here are my requirements for the 'register' method:
>
> * Postcondition: the given object's location is registered
>
> * If the postcondition cannot be met, you get an exception
>
>    Otherwise...
>
> * You want to know the hubid of the registration
>
> * You want to know whether registration did any work
>
>
> So, I propose that 'register' return a tuple of
>
>    (hubid, is_new_registration)
>
> For example:
>
>  >>> print hub.register('/foo/bar/baz')
> (23, True)
>  >>> print hub.register('/foo/bar/baz')
> (23, False)
>  >>> print hub.register('/foo/bar/baz')
> (23, False)
>
> For another example:
>
>    newly_registered_count = 0
>    for wrapped_object in iteratorOfSomeObjectHierarchy():
>        hubid, isregistered = hub.register(wrapped_object)
>        newly_registered_count += isregistered  # True == 1, False == 0
>    print "I registered %s additional objects" % newly_registered_count
>
>
> There's a similar issue with 'unregister': it raises a NotFoundError if
> the object/location is not registered.
>
> We can change 'unregister' to return a bool. This is fine, as it
> currently does not return anything meaningful.
>
> --
> Steve Alexander
>
>
> _______________________________________________
> Zope3-dev mailing list
> Zope3-dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope3-dev
>