[issue6090] zipfile: Bad error message when zipping a file with timestamp before 1980

2017-08-15 Thread Craig McQueen

Craig McQueen added the comment:

One ongoing weakness I see with this situation is that it's difficult to code a 
suitable work-around if a user wants to zip files that have a date < 1980 (e.g. 
to zip it with a datestamp of 1-Jan-1980).
https://stackoverflow.com/q/45703747/60075

I am trying to create a zip file with Python 3.5.2 zipfile, on Linux. Some of 
the files I'm trying to add have timestamps of 1-Jan-1970 (embedded system 
without a real-time clock module). So zipfile gives an exception:

ValueError: ZIP does not support timestamps before 1980

My goal then is to implement a work-around to add these files to the zip file 
with a timestamp of 1-Jan-1980. However, I am finding it difficult to find a 
suitable work-around.

At first I thought I can do this:

def zinfo_from_file(fullname, arcname):
st = os.stat(fullname)
mtime = time.localtime(st.st_mtime)
date_time = mtime[0:6]
if date_time[0] < 1980:
date_time = (1980, 1, 1, 0, 0, 0)
zinfo = zipfile.ZipInfo(arcname, date_time)
return zinfo

...
zinfo = zinfo_from_file(fullname, arcname)
chunksize=512
with open(fullname, 'rb') as src, myzipfile.open(zinfo, 'w') as dest:
while True:
data = src.read(chunksize)
if not data:
break
dest.write(data)
...

However, it turns out that myzipfile.open(zinfo, 'w') is not supported until 
Python 3.6. (I'm using Yocto to build embedded Linux, which currently only 
supports Python 3.5.x.)

I guess I could try doing myzipfile.writestr(...), although then it appears 
that I have to load the entire file data into memory.

--
nosy: +cmcqueen1975

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6090] zipfile: Bad error message when zipping a file with timestamp before 1980

2011-10-19 Thread Roundup Robot

Roundup Robot devn...@psf.upfronthosting.co.za added the comment:

New changeset 649ac338203f by Senthil Kumaran in branch '2.7':
Fix closes Issue6090 - Raise a ValueError, instead of failing with unrelated
http://hg.python.org/cpython/rev/649ac338203f

New changeset 12f3e86e9041 by Senthil Kumaran in branch '3.2':
3.2 - Fix closes Issue6090 - Raise a ValueError, instead of failing with 
unrelated
http://hg.python.org/cpython/rev/12f3e86e9041

New changeset 55318658e1be by Senthil Kumaran in branch 'default':
default - Fix closes Issue6090 - Raise a ValueError, instead of failing with 
unrelated
http://hg.python.org/cpython/rev/55318658e1be

--
nosy: +python-dev
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6090
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6090] zipfile: Bad error message when zipping a file with timestamp before 1980

2011-10-19 Thread Senthil Kumaran

Senthil Kumaran sent...@uthcode.com added the comment:

Fixed in all active branches. Thanks for the patch, Petri. 
Mark, for this issue, raising ValueError from zipfile was seemingly a  right 
thing to do, the previous error from struct for a side effect of sending a 
value lower than 1980.

--
nosy: +orsenthil

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6090
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue6090] zipfile: Bad error message when zipping a file with timestamp before 1980

2011-07-06 Thread Petri Lehtinen

Changes by Petri Lehtinen pe...@digip.org:


--
title: zipfile: Bad error message when zipping a with timestamp before 1980 - 
zipfile: Bad error message when zipping a file with timestamp before 1980

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue6090
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com