En Tue, 16 Dec 2008 12:28:00 -0200, Brendan <brendandetra...@yahoo.com>
escribió:
I would like zipfile.is_zipfile(), to operate on a cStringIO.StringIO
string buffer, but is seems only to accept file names as arguments.
Should it not be able to handle string buffers too?
A version of zipfile.is_zipfile() accepting both file names and file
objects:
def _check_zipfile(fp):
try:
if _EndRecData(fp):
return True # file has correct magic number
except IOError:
pass
return False
def is_zipfile(filename):
"""Quickly see if file is a ZIP file by checking the magic number."""
result = False
try:
if hasattr(filename, "read"):
result = _check_zipfile(fp=filename)
else:
with open(filename, "rb") as fp:
result = _check_zipfile(fp)
except IOError:
pass
return result
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list