Re: unzipping a zipx file

2013-04-20 Thread Serhiy Storchaka

19.04.13 20:59, b_erickson1 написав(ла):

I have python 2.6.2 and I trying to get it to unzip a file made with winzip 
pro.  The file extension is zipx.  This is on a windows machine where I have to 
send them all that files necessary to run.  I am packaging this with py2exe.  I 
can open the file with
zFile = zipfile.ZipFile(fullPathName,'r')
and I can look through all the file in the archive
for filename in zFile.namelist():
but when I write the file out with this code:
 ozFile = open(filename,'w')
 ozFile.write(zFile.read(filename))
 ozFile.close()
that file still looks encrypted.


AFAIK some archivers use zipx extension for zip files which contains 
files compressed with advanced compression methods (bzip2, lzma, etc). 
Python supports bzip2 and lzma compression in zip files since 3.3.



No errors are thrown.


Python 2.7 and 3.2 should raise an exception (this bug was fixed several 
months ago). 2.6 is too old and this fix was not backported to it.


 What am I missing?

Use Python 3.3 or at least 2.7.

--
http://mail.python.org/mailman/listinfo/python-list


unzipping a zipx file

2013-04-19 Thread b_erickson1
I have python 2.6.2 and I trying to get it to unzip a file made with winzip 
pro.  The file extension is zipx.  This is on a windows machine where I have to 
send them all that files necessary to run.  I am packaging this with py2exe.  I 
can open the file with 
zFile = zipfile.ZipFile(fullPathName,'r')
and I can look through all the file in the archive 
for filename in zFile.namelist():
but when I write the file out with this code:
ozFile = open(filename,'w')
ozFile.write(zFile.read(filename))
ozFile.close()
that file still looks encrypted.  No errors are thrown.  The file is just a 
text file not a jpeg or anything else.  I can open the file with 7zip and 
extract the text file out just fine.  


What am I missing?

Thanks 

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread John Gordon
In mailman.834.1366394500.3114.python-l...@python.org b_erickson1 
br...@dashley.net writes:

 ozFile = open(filename,'w')
 ozFile.write(zFile.read(filename))
 ozFile.close()

Perhaps you want to use zFile.extract() instead of zFile.read()?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread John Gordon
In kks2mi$54d$1...@reader1.panix.com John Gordon gor...@panix.com writes:

 In mailman.834.1366394500.3114.python-l...@python.org b_erickson1 
 br...@dashley.net writes:

  ozFile = open(filename,'w')
  ozFile.write(zFile.read(filename))
  ozFile.close()

 Perhaps you want to use zFile.extract() instead of zFile.read()?

No, that's not it.  Your code should work.

You said the output file 'looks encrypted'.  Is the source zip file
encrypted?

Is the source text file something other than plain ASCII?

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, The Gashlycrumb Tinies

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread Dave Angel

On 04/19/2013 01:59 PM, b_erickson1 wrote:

I have python 2.6.2 and I trying to get it to unzip a file made with winzip 
pro.  The file extension is zipx.  This is on a windows machine where I have to 
send them all that files necessary to run.  I am packaging this with py2exe.  I 
can open the file with
zFile = zipfile.ZipFile(fullPathName,'r')
and I can look through all the file in the archive
for filename in zFile.namelist():
but when I write the file out with this code:
 ozFile = open(filename,'w')
 ozFile.write(zFile.read(filename))
 ozFile.close()
that file still looks encrypted.  No errors are thrown.  The file is just a 
text file not a jpeg or anything else.  I can open the file with 7zip and 
extract the text file out just fine.


What am I missing?

Thanks



The second parameter to ZipFile() probably should be 'rb' not 'r'

Likewise, I'd suggest using 'wb' on the output file, though that's not 
your problem here.


--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread Tim Chase
On 2013-04-19 16:29, Dave Angel wrote:
  zFile = zipfile.ZipFile(fullPathName,'r')
 
 The second parameter to ZipFile() probably should be 'rb' not 'r'

Just for the record, the zipfile.ZipFile.__init__ maps r to open the
file with rb, so that's not the issue.

Your suggestion about opening the file to write in binary mode is a
good one, but I'd just suggest using ZipFile.extract(...) which is
built in and takes care of writing the file for you. :-)

-tkc


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread Steven D'Aprano
On Fri, 19 Apr 2013 17:59:26 +, b_erickson1 wrote:

 I have python 2.6.2 and I trying to get it to unzip a file made with
 winzip pro.  The file extension is zipx.  This is on a windows machine
 where I have to send them all that files necessary to run.  I am
 packaging this with py2exe.  I can open the file with zFile =
 zipfile.ZipFile(fullPathName,'r') and I can look through all the file in
 the archive for filename in zFile.namelist():
 but when I write the file out with this code:
 ozFile = open(filename,'w')
 ozFile.write(zFile.read(filename))
 ozFile.close()
 that file still looks encrypted.  No errors are thrown.  The file is
 just a text file not a jpeg or anything else.  I can open the file with
 7zip and extract the text file out just fine.
 
 
 What am I missing?


You are missing that zipx is not the same as zip, and Python very likely 
does not support the zipx compression algorithm.

http://kb.winzip.com/kb/entry/7/

My guess is that the zipx header is similar enough to zip that Python can 
retrieve the file names, but it cannot decompress the files. 
Unfortunately, instead of getting a nice error, it is fooled into 
thinking that it decompressed when in fact you just got junk.


I suggest that you start with a simple example: create a plain text file 
with just a few words. Compress this single file to .zipx, then try to 
decompress it using Python. If it still fails, you will have a simple 
example that you could post here and see if others have more success.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: unzipping a zipx file

2013-04-19 Thread Dave Angel

On 04/19/2013 08:24 PM, Steven D'Aprano wrote:




SNIP


You are missing that zipx is not the same as zip, and Python very likely
does not support the zipx compression algorithm.

http://kb.winzip.com/kb/entry/7/

My guess is that the zipx header is similar enough to zip that Python can
retrieve the file names, but it cannot decompress the files.
Unfortunately, instead of getting a nice error, it is fooled into
thinking that it decompressed when in fact you just got junk.



The zip header includes a 32bit CRC for each file.  Do you know whether 
the zip module checks that CRC ?


I suggest that you start with a simple example: create a plain text file
with just a few words. Compress this single file to .zipx, then try to
decompress it using Python. If it still fails, you will have a simple
example that you could post here and see if others have more success.






--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list