← Back to team overview

launchpad-dev team mailing list archive

Re: zope class registry

 

On Dec 2, 2009, at 12:21 PM, Muharem Hrnjadovic wrote:

> Gary Poster wrote:
>> On Dec 2, 2009, at 11:41 AM, Muharem Hrnjadovic wrote:
>> 
>>> Gary Poster wrote:
>>>> On Dec 2, 2009, at 10:41 AM, Muharem Hrnjadovic wrote:
>>>> 
>>>>> Quick question:
>>>>> 
>>>>> do we use the zope class registry anywhere?
>>>> I doubt it.
>>>> 
>>>>> Is it safe to use within
>>>>> Launchpad?
>>>> I'd prefer to use utility registration if that can work with your use case.
>>> Sorry for not being precise enough. In my particular case a number of
>>> classes would implement the interface in question (IBuildFarmJob).
>>> 
>>> I understood the utility registration mechanism requires that there is
>>> exactly one class that implements a particular interface in which case I
>>> could not use it for the interface/purpose at hand.
>> 
>> The class registry you showed had keys and values.
>> 
>> You can register different utilities for the same interface by
>> providing a different name for each one (I think of this as a
>> namespace).
> Sorry for pestering you with daft questions but I have never dealt with
> this before. How does one "register different utilities for the same
> interface by providing a different name"?

Sorry, I should have explained that too.

If you are doing it in Python, and greet is an instance that provides IGreeter, and you want to register it for the name 'robert,' then this is an example from the docs:

component.provideUtility(greet, IGreeter, 'robert')

(``component`` is again the object you got back from ``zope.component.getSiteManager()``)

Or if greet provides only one interface then we can omit the provided interface from the call to provideUtility:

component.provideUtility(greet, name='ted')

http://pypi.python.org/pypi/zope.component#utilities

In zcml, you use the "name" attribute.

<utlity component="example.greet" name="robert" />

http://apidoc.zope.org/++apidoc++/ZCML/http_co__sl__sl_namespaces.zope.org_sl_zope/utility/index.html

...

>> 
>> Is that sufficient?
> This is *very* helpful. Thank you!

Cool. :-) You are welcome.

Gary




References