[Zope3-dev] Re: help with directlyProvides

2006-05-09 Thread luis

Hi again,

>> 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)
>>   [...]
>>
[...]
> 

well... I'm not sure but it seems not to be a bug in ContainedProxy, but
just a "display bug" in the  @@introspector.html...

I couldn't trace into the ContainedProxy, but put some debug messages and
got something interesting

I put this code in a pacage called "dprovide"

###
### dprovide/__init__.py
from zope import interface
from zope import schema
from zope.formlib import form
from zope.app.file import File
from zope.app.folder import Folder
from zope.location import ILocation

class IMarker(interface.Interface):
""" test marker interface for directlyProvides """

class ITestSchema(interface.Interface):
""" test schema for directlyprovides """
file  = schema.Bool( 
title = u'Create File and directlyProvide IMarker' )
file2= schema.Bool( 
title = u'Create File and directlyProvide ILocation and IMarker' )
folder = schema.Bool( 
title = u'Create Folder and directlyProvide IMarker' )

class DirectlyProvidesTest(form.AddForm):
form_fields = form.Fields( ITestSchema )

def create( self, data ):
r = {}
if data['file']:
f = File()
interface.directlyProvides( f, IMarker )
r['file'] = f
if not IMarker.providedBy( r['file'] ):
raise Error
if data['file2']:
f = File()
f.__name__ = ''
f.__parent__ = ''
interface.directlyProvides( f, ILocation, IMarker )
r['file2'] = f
if not IMarker.providedBy( r['file2'] ):
raise Error
if data['folder']:
f = Folder()
interface.directlyProvides(f, IMarker)
r['folder'] = f
if not IMarker.providedBy( r['folder'] ):
raise Error
return r

def add( self, r ):
if r.has_key('file'):
self.context.add( r['file'] )
if r.has_key('file2'):
self.context.add( r['file2'] )
if r.has_key('folder'):
self.context.add( r['folder'] )
self._finished_add = True
###
and in dprovide/configure.zcml


and I "patched" zope.app.container.contained @ 325 to look like this:

if not IContained.providedBy(object):
if ILocation.providedBy(object):
zope.interface.directlyProvides(
object, IContained,
zope.interface.directlyProvidedBy(object))
else:
print_provides = False
if object.__class__.__name__ == 'File' or\
   object.__class__.__name__ == 'Folder':
   from dprovide import IMarker
   print "! BEFORE ContainedProxy: ",
object.__provides__
   print " IMarker.providedBy = ",
IMarker.providedBy(object)
   print_provides = True
object = ContainedProxy(object)
if print_provides:
print "### AFTER ContainedProxy: ",
object.__provides__
print " IMarker.providedBy = ", IMarker.providedBy(object)

###

now.. after adding a File (without) ILocation, I see the output
! BEFORE ContainedProxy:  
 IMarker.providedBy =  True
### AFTER ContainedProxy:  
 IMarker.providedBy =  True

so, the IMarker is provided by the file, but in a "different" way.. so I
think the introspector is just not showing it correctly...
if I add a File w/ ILocation, it doesnt go into the ContainedProxy and the
introspector shows the directlyProvided intefaces correctly...


regards.
luis


ps. if you want to try that... you have to add the files "one by one".. if
you select two checkboxes at once you get a "dupplicate names" error.. not
sure why.


___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



Re: [Zope3-dev] Re: help with directlyProvides

2006-05-07 Thread Jean-Marc Orliaguet




luis wrote:

  Jean-Marc Orliaguet wrote:

  
  
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

  
  
nop. that's not it... I still havn't figured it out, but it seems very
strange to me. it seems like folder-like objects work, but content-like
objects don't..

for example

folder = Folder()
interface.directlyProvides( folder, IMarker )
file = File()
interface.directlyProvides( file, IMarker )
root['folder'] = folder
root['file'] = file

would leave "folder" directly providing the "IMarker" interface, but "file"
directly providing nothing.
the other strange thing is that the interface seems to be added to the
provided-list, but then it is removed again later...so when you look at the
introspector tab in the zmi, it's gone.

regards.luis

  


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

>>> import zope.interface
>>> class IMarker(zope.interface.Interface):
...  """Marker interface"""
... 
>>> zope.interface.directlyProvides(f, IMarker)
>>> list(zope.interface.directlyProvidedBy(f))
[]
>>> IMarker.providedBy(f)
True

hope it helps
/JM




___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com



[Zope3-dev] Re: help with directlyProvides

2006-05-07 Thread luis

Jean-Marc Orliaguet wrote:

> 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

nop. that's not it... I still havn't figured it out, but it seems very
strange to me. it seems like folder-like objects work, but content-like
objects don't..

for example

folder = Folder()
interface.directlyProvides( folder, IMarker )
file = File()
interface.directlyProvides( file, IMarker )
root['folder'] = folder
root['file'] = file

would leave "folder" directly providing the "IMarker" interface, but "file"
directly providing nothing.
the other strange thing is that the interface seems to be added to the
provided-list, but then it is removed again later...so when you look at the
introspector tab in the zmi, it's gone.

regards.luis


___
Zope3-dev mailing list
Zope3-dev@zope.org
Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com