[Zope] small python problem

Robert Rottermann robert@redcor.ch
Wed, 5 Dec 2001 23:53:16 +0100


Dieter,
this could answer a former question of mine. Is this the reason why in CMF
Metadata and Fileupload is always separated?

Robert
----- Original Message -----
From: "Dieter Maurer" <dieter@handshake.de>
To: "sanjeev c s" <sanju22_us@yahoo.com>
Cc: <zope@zope.org>
Sent: Wednesday, December 05, 2001 11:04 PM
Subject: Re: [Zope] small python problem


> sanjeev c s writes:
>  > i have a form which uploads a file.
>  > and it calls a method which pass parameter to a python
>  > script. this python script creates a 'file object'.
>  > ....
>  > if picture:
>  >   container.foldername.manage_addImage(id=id,
>  > file=picture)
>  >
>  > but still even if the file is not uploaded the 'file
>  > object' is created. what is the problem ??
> The reason is easy:
>
>   Even if no file is uploaded, you get a "FileUpload" object.
>
>   Unfortunately, the "FileUpload" class does not define senseful
>   "__len__" or "__nonzero__" methods (this is a
>   bug --> <http:collector.zope.org>) and therefore, all such
>   objects are considered Python true values.
>
> Your options:
>
>   *  Fix "ZPublisher.HTTPRequest.FileUpload" such that it
>      defines a "__nonzero__" method. Post your patch to
>      the collector (see above). This way, you help improve
>      Zope
>
>   *  Work around the problem in your application code.
>      You can use:
>
> "if picture.filename:" in place of "if picture:"
>
>
> Dieter
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>