class BlobIterator:
    """Because the python csv module doesn't like strange newline chars and
    the google blob reader cannot be told to open in universal mode, then
    we need to read blocks of the blob and 'fix' the newlines as we go"""

def __init__(self, blob_reader):
    self.blob_reader = blob_reader
self.last_line = ''
self.line_num = 0
self.lines = []
self.buffer = None

def __iter__(self):
    return self

def next(self):
    if not self.buffer or len(self.lines) == self.line_num + 1:
        self.buffer = self.blob_reader.read(1048576)
self.lines = self.buffer.splitlines()
self.line_num = 0
if self.buffer[-1:] == '\n' or self.buffer[-1:] == '\r':
    self.lines.append('')
if not self.buffer:
    raise StopIteration
if self.line_num == 0 and len(self.last_line) > 0:
    result = self.last_line + self.lines[self.line_num] + '\n'
else:
    result = self.lines[self.line_num] + '\n'
self.last_line = self.lines[self.line_num + 1]
self.line_num += 1
return result
Upload and parse csv file with "universal newline" in python on Google App Engine