import sys
import optparse
import xml.parsers.expat
+import gzip
ELEMENT_START, ELEMENT_END, CHARACTER_DATA, EOF = range(4)
self.index = 0
data = self.fp.read(size)
self.final = len(data) < size
+ data = data.rstrip('\0')
try:
self.parser.Parse(data, self.final)
except xml.parsers.expat.ExpatError, e:
return data
+class GzipFile(gzip.GzipFile):
+
+ def _read_eof(self):
+ # Ignore incomplete files
+ try:
+ gzip.GzipFile._read_eof(self)
+ except IOError:
+ pass
+
+
class Formatter:
def function(self, name):
if args:
for arg in args:
if arg.endswith('.gz'):
- from gzip import GzipFile
stream = GzipFile(arg, 'rt')
elif arg.endswith('.bz2'):
from bz2 import BZ2File