Have a look at zope.interface.__init__.py -> alsoProvides


Frank Burkhardt wrote:

On Mon, May 29, 2006 at 01:31:03PM +0200, Lennart Regebro wrote:
On 5/29/06, Frank Burkhardt <[EMAIL PROTECTED]> wrote:
I'm going to write an alternative implementation of
zope.app.file.interfaces.IFile . This implementation will automatically
determine the mime type of the data it's containing.

I would like to add a method that determines (guesses), if the current file
object contains an image...

isimage=(mimetype(self.data).split('/')[0] == 'image')

... and I want to dynamically make the object implement another interface ...
Ehhh. Really? I must say that I find that a very suspiscious way of
handling that problem. Rather I would use a factory that generates the
correct type of object (image or file) from the data.

Different factories won't help because the user should be able to update
the file object's content after ist was created.

if isimage:

Unfortunately, there is no 'provide' method on interfaces :-( .
Of course, you don't want to make an interface dynamically be another
interface, that just doens't make any sense. You could probably do it
by making the OBJECT provide different interfaces dynamically.

OK - this was a bit confusing. One more try:

 I want to make an object provided one interface (IFile) always and one
 interface (IImage) "sometimes". Sometimes means "whenever libmagic thinks,
 the file is an Image". I don't want to modify any interface but only the
 object's list of provided interfaces.



Zope3-users mailing list

Reply via email to