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

2008-09-09 Thread Dieter Maurer
Jakob Schou Jensen wrote at 2008-9-9 08:27 +0200:
>Where is the 'manage_upload' function documented?

In the source ("OFS.Image.File.manage_upload").

def manage_upload(self,file='',REQUEST=None):
"""
Replaces the current contents of the File or Image object with file.

The file or images contents are replaced with the contents of 'file'.
"""

You are right when you point out:

  Why does the integrated online help documents (the private) "update_data"
  but not (the official) "manage_upload"?

I do not know.


I know that "manage_upload" is "official" because it has an
associated permission (and because it is used in the ZMI).


If you use "DocFinder" (or even "DocFinderTab"), then you can
easily see which methods are available in the various contexts.



-- 
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-08 Thread Jakob Schou Jensen
Hi Dieter,

Where is the 'manage_upload' function documented?

The problem that I had with manage_addFile seems to because I passed it a
unicode object rather than a string. The error message was "*'unicode'
object has no attribute 'seek'*" which led me to think a file-like object
was needed.

Thanks,

Jakob

2008/9/2 Dieter Maurer <[EMAIL PROTECTED]>

> 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 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 )


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

2008-08-30 Thread Dieter Maurer
Jakob Schou Jensen wrote at 2008-8-29 20:11 +0200:
>I would like to create a File object in the and store some text in it from a
>Python script.

It depends what you mean by "File object".

If you mean a Python "file", sitting somewhere on your file system,
then Andreas' advice is helpful.

If you mean a Zope "File" object (an "OFS.Image.File"), then
you would create the object in the standard way for creation
of Zope objects, that is:

   destination.manage_addProducts[].().

For a "File" object, "" is "OFSP" ("Object File System Product"),
"constructor" is "manage_addFile" and the arguments are
"id, file='', title='', precondition='', content_type=''".

"file" is in fact the content that should be stored in your
"File" object. It can be a string or a "file" like object.


-- 
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-08-29 Thread Israel Saeta Pérez
On Fri, Aug 29, 2008 at 8:14 PM, Andreas Jung <[EMAIL PROTECTED]> wrote:
>
>
> --On 29. August 2008 20:11:53 +0200 Jakob Schou Jensen
> <[EMAIL PROTECTED]> wrote:
>
>> I would like to create a File object in the and store some text in it
>> from a Python script. Everything I try seems to end up in a security
>> restriction of some kind. Is there some obvious way that I have
>> overlooked?
>
>
> Use an external method or the modern way: a Z3 browser view.

Some starting pointers about zope 3 browser views:
 * http://plone.org/documentation/how-to/creating-a-minimalistic-zope-3-view
 * "Web Component Development with Zope 3", by Philipp von Weiterhausen


-- 
Israel Saeta Pérez
http://dukebody.com
___
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-08-29 Thread Andreas Jung



--On 29. August 2008 20:11:53 +0200 Jakob Schou Jensen 
<[EMAIL PROTECTED]> wrote:



I would like to create a File object in the and store some text in it
from a Python script. Everything I try seems to end up in a security
restriction of some kind. Is there some obvious way that I have
overlooked?



Use an external method or the modern way: a Z3 browser view.

-aj

pgp7gj5BtrLlW.pgp
Description: PGP signature
___
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 )


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

2008-08-29 Thread Jakob Schou Jensen
I would like to create a File object in the and store some text in it from a
Python script. Everything I try seems to end up in a security restriction of
some kind. Is there some obvious way that I have overlooked?

Thanks,

Jakob Schou Jensen
___
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 )