[Zope] Upload, read() and a rather unexpected persistence

Casey Duncan casey@zope.com
Fri, 5 Jul 2002 10:25:58 -0400


This is normal behavior of Python fileish objects and has nothing to do w=
ith=20
persistence. To rewind a file back to the beginning, use the seek method:

file.seek(0)

AFAICT FileUpload objects should support seek.

hth,

Casey

On Friday 05 July 2002 10:07 am, Milos Prudek wrote:
> Hi,
>=20
> I just found out that it is impossible to use File.read(20000) twice=20
> even in separate scripts, because Zope remembers the file position.
>=20
> Therefore data must be saved in the same Python Script that checks for=20
> validity and the data distilled from File.read must be saved elsewhere,=
=20
> if the saving procedure would use File.read again.
>=20
> Details:
>=20
> HTTP upload files may be checked via simple routine:
>=20
> fault=3D[]
> for F in files:
>     Ft =3D context.filetype(F.file.read(20000))
>     # filetype is External method that calls UNIX's file command
>     if Ft.find('GIF image data')=3D=3D-1:
>        fault.append('Not an image'.)
>=20
> But it is impossible to use F.file.read(20000) in a second script whose=
=20
> execution follows, because Zope remembers the 20000 position and will=20
> start reading at position 20001.
>=20
> Is this a feature (persistence), or a bug?
>=20
>=20
> --=20
> Milos Prudek