how to zip a StringIO object?

N

Nagy Viktor

Hi,

I try to run the following code:

def generate_zip(object_list, template):
result = StringIO.StringIO()
zipped = zipfile.ZipFile(result, "w")
for object in object_list:
pdf = generate_pdf(object, template)
if not pdf:
raise IOError("Problem with generating invoice %d" %
object.pk)
zipped.writestr("invoice-%d.pdf" % object.pk, pdf)
zipped.close()
return result.getvalue()

where generate_pdf returns a valid pdf file's string content, more
precisely it returns a StringIO.getvalue() call containing the pdf
"string".

When I add this string to the zip file, I get a problem. Namely, the
zipped files are chmoded to non-readable when extracted. How can I
change this?

thanks,
V
 
D

Dave Angel

Nagy said:
Hi,

I try to run the following code:

def generate_zip(object_list, template):
result = StringIO.StringIO()
zipped = zipfile.ZipFile(result, "w")
for object in object_list:
pdf = generate_pdf(object, template)
if not pdf:
raise IOError("Problem with generating invoice %d" %
object.pk)
zipped.writestr("invoice-%d.pdf" % object.pk, pdf)
zipped.close()
return result.getvalue()

where generate_pdf returns a valid pdf file's string content, more
precisely it returns a StringIO.getvalue() call containing the pdf
"string".

When I add this string to the zip file, I get a problem. Namely, the
zipped files are chmoded to non-readable when extracted. How can I
change this?

thanks,
V
You don't tell us the version of Python, nor the OS environment, nor
what utility you're using to extract these files.

When I supply the missing imports, shortcircuit the missing classes and
functions, and add some mainline code, I can run this with no problem.
Are you also running on Windows XP, using 2.6.2, using the same missing
code as I, and extracting with Winzip 11.2?

DaveA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top