Re: [Zope] How do I write to a text file from Python?

2008-09-02 Thread Dieter Maurer
Jakob Schou Jensen wrote at 2008-9-2 09:25 +0200:
>By file object I meant the "OFS.Image.File" kind. I had two problems
>creating and modifying the file (at least). The first was that the
>manage_addFile() function that you mention seemed to insist on a os-file
>like object for the "file" parameter.

It is ready to accept a string or a "file" like object
(usually, it gets a "ZPublisher.HTTPRequest.FileUpload" instance).

>Appart from that I got a security error when I called the File.update_data()
>function.

This is internal. The corresponding "official" method
is "manage_upload".

> ...
>Well ... it works ... there may be a simpler way as you suggest. If you have
>some sample code I would like to see it. I am using zope 2.4.something.

In an interactive Python session (under *nix: "bin/zopectl debug"):

>>> app.manage_addProduct['OFSP'].manage_addFile('test_file', 'test_content')
>>> tf=app.test_file
>>> str(tf)
'test_content'

The example shows you, that a string is accepted as "file" value.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How do I write to a text file from Python?

2008-09-02 Thread Jakob Schou Jensen
Hi Dieter

By file object I meant the "OFS.Image.File" kind. I had two problems
creating and modifying the file (at least). The first was that the
manage_addFile() function that you mention seemed to insist on a os-file
like object for the "file" parameter. I got some kind of seek error when
trying to supply a string. But I might have done something else wrong.
Appart from that I got a security error when I called the File.update_data()
function. Using external methods I could call update_data() and import the
StringIO python module that allows creating of string based file which I
could in turn pass on to manage_addFile().

Well ... it works ... there may be a simpler way as you suggest. If you have
some sample code I would like to see it. I am using zope 2.4.something.

Thanks,

Jakob
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )