Re: [Zope] Using page templates to generate large XML files

2008-09-06 Thread Andreas Jung



--On 6. September 2008 20:34:21 +0200 Dieter Maurer <[EMAIL PROTECTED]> 
wrote:



Marco Bizzarri wrote at 2008-9-6 08:26 +0200:

I need to generate a large XML file inside a Zope application; the
file is for backup purposes, so it is stored on the server and can be
downloaded later with whatever suitable tool.

The data are taken from a database, and then they are used to create
the XML. I assume there will be between 40.000 and 100.000 rows to be
dumped.

I thought i could use page template for this purpose, but I'm not sure
if it is possible to send the output from a pt to a file, directly.


I fear, this is not a supported usecase:

  The standard page template implementation writes to a
  "StringIO" object (thus its internal infrastructure is prepared
  for incremental output generation)
  but the file to be written to it not controllable from outside.


Of course you can write the rendered result to a file. However the 
construction will occur in memory and might require lots of memory.

No idea about the structure and the complexity of the XML document
generating it through Python is very likely faster and will requires less 
resources.


-aj

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


Re: [Zope] Using page templates to generate large XML files

2008-09-06 Thread Dieter Maurer
Marco Bizzarri wrote at 2008-9-6 08:26 +0200:
>I need to generate a large XML file inside a Zope application; the
>file is for backup purposes, so it is stored on the server and can be
>downloaded later with whatever suitable tool.
>
>The data are taken from a database, and then they are used to create
>the XML. I assume there will be between 40.000 and 100.000 rows to be
>dumped.
>
>I thought i could use page template for this purpose, but I'm not sure
>if it is possible to send the output from a pt to a file, directly.

I fear, this is not a supported usecase:

  The standard page template implementation writes to a
  "StringIO" object (thus its internal infrastructure is prepared
  for incremental output generation)
  but the file to be written to it not controllable from outside.

If your XML is not too complex, I would directly generate it
(and not go through a PageTemplate).



-- 
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] Using page templates to generate large XML files

2008-09-06 Thread Andreas Jung



--On 6. September 2008 09:15:37 +0200 Marco Bizzarri 
<[EMAIL PROTECTED]> wrote:



On Sat, Sep 6, 2008 at 8:36 AM, Andreas Jung <[EMAIL PROTECTED]> wrote:



--On 6. September 2008 08:26:17 +0200 Marco Bizzarri
<[EMAIL PROTECTED]> wrote:


Hi all.

I need to generate a large XML file inside a Zope application; the
file is for backup purposes, so it is stored on the server and can be
downloaded later with whatever suitable tool.

The data are taken from a database, and then they are used to create
the XML. I assume there will be between 40.000 and 100.000 rows to be
dumped.

I thought i could use page template for this purpose, but I'm not sure
if it is possible to send the output from a pt to a file, directly. Of
course, this is a problem which can be easily solved.


If you're using Zope 2.10 or higher, you can either use the "native"  ZPT
implementation from Zope 3 (see zope.pagetemplate module) or you use the
Zope 2 implementation (which is basically only a wrapper around the Z3
implementation). In this case you might look at the unittests in
testZopePageTemplates.py or otherwise you check the doctests of
zope.pagetemplate.

-aj


Thanks, Andreas. I'm using Zope 2.8, here (yes, I know it is old
software; yes, I know, I should switch; yes, I will do soon, I promise
:-) ))


In Zope 2.8 you could use the ZopePageTemplate class. Something like


pt = ZopePageTemplate()
pt.pt_edit(zpt_source_code)
xml = pt.pt_render(...)

should work. The unit tests (or the code) should show you how to specify 
text/xml as mime-type and how to pass the options/parameters to the 
template.


-aj


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


Re: [Zope] Using page templates to generate large XML files

2008-09-06 Thread Marco Bizzarri
On Sat, Sep 6, 2008 at 8:36 AM, Andreas Jung <[EMAIL PROTECTED]> wrote:
>
>
> --On 6. September 2008 08:26:17 +0200 Marco Bizzarri
> <[EMAIL PROTECTED]> wrote:
>
>> Hi all.
>>
>> I need to generate a large XML file inside a Zope application; the
>> file is for backup purposes, so it is stored on the server and can be
>> downloaded later with whatever suitable tool.
>>
>> The data are taken from a database, and then they are used to create
>> the XML. I assume there will be between 40.000 and 100.000 rows to be
>> dumped.
>>
>> I thought i could use page template for this purpose, but I'm not sure
>> if it is possible to send the output from a pt to a file, directly. Of
>> course, this is a problem which can be easily solved.
>
> If you're using Zope 2.10 or higher, you can either use the "native"  ZPT
> implementation from Zope 3 (see zope.pagetemplate module) or you use the
> Zope 2 implementation (which is basically only a wrapper around the Z3
> implementation). In this case you might look at the unittests in
> testZopePageTemplates.py or otherwise you check the doctests of
> zope.pagetemplate.
>
> -aj

Thanks, Andreas. I'm using Zope 2.8, here (yes, I know it is old
software; yes, I know, I should switch; yes, I will do soon, I promise
:-) ))

I will see what I can accomplish with what I have.

Regards
Marco


-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.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] Using page templates to generate large XML files

2008-09-05 Thread Andreas Jung



--On 6. September 2008 08:26:17 +0200 Marco Bizzarri 
<[EMAIL PROTECTED]> wrote:



Hi all.

I need to generate a large XML file inside a Zope application; the
file is for backup purposes, so it is stored on the server and can be
downloaded later with whatever suitable tool.

The data are taken from a database, and then they are used to create
the XML. I assume there will be between 40.000 and 100.000 rows to be
dumped.

I thought i could use page template for this purpose, but I'm not sure
if it is possible to send the output from a pt to a file, directly. Of
course, this is a problem which can be easily solved.


If you're using Zope 2.10 or higher, you can either use the "native"  ZPT 
implementation from Zope 3 (see zope.pagetemplate module) or you use the 
Zope 2 implementation (which is basically only a wrapper around the Z3 
implementation). In this case you might look at the unittests in 
testZopePageTemplates.py or otherwise you check the doctests of 
zope.pagetemplate.


-aj

pgpEhj49tLVzg.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] Using page templates to generate large XML files

2008-09-05 Thread Marco Bizzarri
Hi all.

I need to generate a large XML file inside a Zope application; the
file is for backup purposes, so it is stored on the server and can be
downloaded later with whatever suitable tool.

The data are taken from a database, and then they are used to create
the XML. I assume there will be between 40.000 and 100.000 rows to be
dumped.

I thought i could use page template for this purpose, but I'm not sure
if it is possible to send the output from a pt to a file, directly. Of
course, this is a problem which can be easily solved.

I wonder however if the PT has to generate the whole XML in just one
step; in that case, maybe I should resort to use PT on one row at
time, and write the data to different files.

Thanks for your time.

Regards
Marco

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.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 )