Re: [Zope3-dev] help with directlyProvides
luis wrote: Jean-Marc Orliaguet wrote: luis wrote: are you sure? I tried with: [EMAIL PROTECTED] ~/Zope3/src $ python2.4 Python 2.4.2 (#1, Dec 4 2005, 15:28:38) Type help, copyright, credits or license for more information. from zope.app.file import file f = file.File() f zope.app.file.file.File object at 0xb7cbad2c import zope.interface class IMarker(zope.interface.Interface): ... Marker interface ... zope.interface.directlyProvides(f, IMarker) list(zope.interface.directlyProvidedBy(f)) [InterfaceClass __main__.IMarker] IMarker.providedBy(f) True yes.. that's why I say that it seems very strange... the call to directlyProvides works as you show with your example, ... *but*, after you add your file to a folder, something removes the IMarker interface (or it doesn't get saved for some reason ) directlyProvides( f, IMarker ) if not IMarker.providedBy( f ): raise Error myfolder['f'] = f if you put something like that in an Adding-Form, no exception is raised and the object f is added to the container. so the directlyProvides does work...but then, if you take a look at the object f in the zmi introspector, you will see something like: DirectlyProvided interfaces nothing so what I'm saying is not that directlyProvides doesnt work, but that provided-list gets lost somewhere on the way into the database... (but if f is a Folder, then the provided-list is kept ) luis If there is a bug in the container framework my assumption would be that that the following part of code causes your problem. The regular container asserts IContained either by the directlyProvides mechanism if the item provides ILocation or else by a ContainedProxy. zope.app.container.contained line 325: [...] if not IContained.providedBy(object): if ILocation.providedBy(object): zope.interface.directlyProvides( object, IContained, zope.interface.directlyProvidedBy(object)) else: object = ContainedProxy(object) [...] First try to provide IContained to your File implementation using the following zcml entry: class class=.to.your.File implements =.zope.app.container.interfaces.IContained / /class That should solve the problem. If yes, could you track down if the problem: Is it caused by the directlyProvided mechanism or by the ContainedProxy? (If no, perhaps a persistency problem?) Regards, Dominik ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/dominik.huber%40perse.ch ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] help with directlyProvides
Dominik Huber wrote: luis wrote: Jean-Marc Orliaguet wrote: luis wrote: are you sure? I tried with: [EMAIL PROTECTED] ~/Zope3/src $ python2.4 Python 2.4.2 (#1, Dec 4 2005, 15:28:38) Type help, copyright, credits or license for more information. from zope.app.file import file f = file.File() f zope.app.file.file.File object at 0xb7cbad2c import zope.interface class IMarker(zope.interface.Interface): ... Marker interface ... zope.interface.directlyProvides(f, IMarker) list(zope.interface.directlyProvidedBy(f)) [InterfaceClass __main__.IMarker] IMarker.providedBy(f) True yes.. that's why I say that it seems very strange... the call to directlyProvides works as you show with your example, ... *but*, after you add your file to a folder, something removes the IMarker interface (or it doesn't get saved for some reason ) directlyProvides( f, IMarker ) if not IMarker.providedBy( f ): raise Error myfolder['f'] = f if you put something like that in an Adding-Form, no exception is raised and the object f is added to the container. so the directlyProvides does work...but then, if you take a look at the object f in the zmi introspector, you will see something like: DirectlyProvided interfaces nothing so what I'm saying is not that directlyProvides doesnt work, but that provided-list gets lost somewhere on the way into the database... (but if f is a Folder, then the provided-list is kept ) luis If there is a bug in the container framework my assumption would be that that the following part of code causes your problem. The regular container asserts IContained either by the directlyProvides mechanism if the item provides ILocation or else by a ContainedProxy. zope.app.container.contained line 325: [...] if not IContained.providedBy(object): if ILocation.providedBy(object): zope.interface.directlyProvides( object, IContained, zope.interface.directlyProvidedBy(object)) else: object = ContainedProxy(object) [...] First try to provide IContained to your File implementation using the following zcml entry: class class=.to.your.File implements =.zope.app.container.interfaces.IContained / /class That should solve the problem. If yes, could you track down if the problem: Is it caused by the directlyProvided mechanism or by the ContainedProxy? (If no, perhaps a persistency problem?) Regards, Dominik by what I can tell, it's the ContainedProxy line: object = ContainedProxy(object) that removes all directly provided interfaces on all types of objects not just files. With folders ContainedProxy() is not called. /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] help with directlyProvides
luis wrote: Hi all, I asked this a while ago in the zope3.user list but had no luck, so I'll try it here now.. I'm having problems getting interface.directlyProvides to work... does anyone know why the following code doesn't work (file is created, but it doesnt provide the IMarker interface...) thanks and regards, luis ### class IMarker(interface.Interface): marker test interface Hi, shouldn't it be, instead: from zope.interface.interfaces import IInterface class IMarker(IInterface): ... /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] help with directlyProvides
Jean-Marc Orliaguet wrote: luis wrote: Hi all, I asked this a while ago in the zope3.user list but had no luck, so I'll try it here now.. I'm having problems getting interface.directlyProvides to work... does anyone know why the following code doesn't work (file is created, but it doesnt provide the IMarker interface...) thanks and regards, luis ### class IMarker(interface.Interface): marker test interface Hi, shouldn't it be, instead: from zope.interface.interfaces import IInterface class IMarker(IInterface): ... /JM sorry I thought you wanted to do something else.. maybe you want to use 'alsoProvides' if it is to set a marker, to avoid removing other interfaces that the file might provide? /JM ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com