[Zope3-dev] Need help with JobBoardEx

Gary Poster gary@modernsongs.com
06 Aug 2002 19:57:13 -0400


I looked into this a bit.  A few notes and thoughts.

---------------

1) the IFactory interface almost certainly should not have the
getInterfaces method requirement.  This is cruft (that I think I added
way back when) from the old factoryFromClass and Addables stuff, and
probably should be removed.

2) the IFactory interface apparently should not have the __call__ method
requirement.  What we really want is an interface specifying that
calling the factory will return a new object, whether the factory is a
class or any other kind of object.  However, requiring __call__ does not
accomplish this, and I can't think of anything that would, so removing
it seems the right course.  This would leave the IFactory interface to
be a marker interface, with no attributes or methods: is this even
useful, or can we just remove any kind of error checking here?

3) Note this interesting interactive Python output:

>>> verifyObject(IFactory, Image)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/home/gposter/Zope3/lib/python/Interface/Verify.py", line 72, in
verifyObject
    return _verify(iface, candidate, tentative, vtype='o')
  File "/home/gposter/Zope3/lib/python/Interface/Verify.py", line 44, in
_verify    raise DoesNotImplement(iface)
Interface.Exceptions.DoesNotImplement: An object does not implement
interface <Interface Zope.ComponentArchitecture.IFactory.IFactory at
4022edac>

That is, Image in fact creates the same exception that JobList does. 
This might imply that the built-in factories are not running through the
full verification process to which JobList was (correctly) submitted.

---------------

In any case, if I make IFactory into a simple "class
IFactory(Interface): pass" statement, the JobList is on my add content
list, which is as far as I went.  I believe this is in fact the correct
resolution.  However, I'm not checking this in, because this is just my
take on things.

Gary

On Tue, 2002-08-06 at 16:08, Guido van Rossum wrote:
> I haven't made much progress with this problem, except to rule out a
> bunch of things.
> 
> The JobBoard code itself still works; however the configuration parser
> doesn't want to believe that the JobBoard class is a factory.  Here's
> the ZCML (slightly different from CVS, but it doesn't make a
> difference):
> 
> <content class=".JobList.">
>   <factory
>       id="JobList"
>       permission="Zope.ManageContent"
>       title="Job List"
>       description="A Job List" />
>   <allow interface=".IJobList." />
>   <implements interface="Zope.App.OFS.Container.IContainer.IItemContainer" />
> </content>
> 
> It appears that the <factory> directive invokes the provideFactory()
> method of the GlobalFactoryService class (in
> Zope/ComponentArchitecture/GlobalFactoryService.py):
> 
>     def provideFactory(self, name, factory):
>         """See IGlobalFactoryService interface"""
>         verifyObject(IFactory, factory)
>         self.__factories[name] = factory
> 
> If I comment out the call to verifyObject() everything works as
> expected.  Adding some print statements (and a call to
> trustedRemoveSecurityProxy) show that the factory object that causes
> the failure is a security proxy for a ClassFactory instance whose
> _class attribute is the JobList class.
> 
> But here's the mystery: look at the way the class
> Zope.App.OFS.Content.Image.Image.Image is configured; it's very similar:
> 
>   <content class=".Image.">
>     <factory
>         id="Image"
>         permission="Zope.ManageContent"
>         title="Image"
>         description="An Image" />
>     <require
>         permission="Zope.View"
>         interface="Zope.App.OFS.Content.File.IFile.IReadFile" />
>     <require
>         permission="Zope.View"
>         interface=".Image.IImage" />
>     <require
>         permission="Zope.ManageContent"
>         interface="Zope.App.OFS.Content.File.IFile.IWriteFile" />
>   </content>
> 
> The <factory> statement is almost identical.  I tried removing the
> other differences in the <content> directive; these don't seem to make
> a difference.
> 
> Looking in the Image class in the Image module, I see no further
> clues.  I checked all the base classes and interfaces, and none of
> them asserts the IFactory interface (or implements __call__); and even
> if I add
> 
>     __class_implements__ = IFactory
> 
> to the JobList class, I still get the same error.
> 
> HEEEEEEEEEEEEEEEEEEEEEEEEEEELP!!!!!
> 
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> 
> _______________________________________________
> Zope3-dev mailing list
> Zope3-dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope3-dev
> 
>