Use cStringIO to open zip files in python 2.5

This commit is contained in:
John Garland 2010-01-07 15:27:05 +00:00
parent 4dbc93b1fa
commit 8175b2af58
1 changed files with 7 additions and 1 deletions

View File

@ -39,7 +39,13 @@ def Zipped(reader):
"""Blocklist reader for zipped blocklists""" """Blocklist reader for zipped blocklists"""
def open(self): def open(self):
z = zipfile.ZipFile(self.file) z = zipfile.ZipFile(self.file)
return z.open(z.namelist()[0]) if hasattr(z, 'open'):
f = z.open(z.namelist()[0])
else:
# Handle python 2.5
import cStringIO
f = cStringIO.StringIO(z.read(z.namelist()[0]))
return f
reader.open = open reader.open = open
return reader return reader