'Takes a cursor, and writes results to a local file.
:return: A dictionary where keys are filenames to be used as object
names in GCS, and values are file handles to local files that
contain the data for the GCS objects.'

def _write_local_data_files(self, cursor):

    schema = map((lambda schema_tuple: schema_tuple[0]), cursor.description)
    file_no = 0
    tmp_file_handle = NamedTemporaryFile(delete=True)
    tmp_file_handles = {self.filename.format(file_no): tmp_file_handle}
    for row in cursor:
        row = map(self.convert_types, row)
        row_dict = dict(zip(schema, row))
        json.dump(row_dict, tmp_file_handle)
        tmp_file_handle.write('\n')
        if (tmp_file_handle.tell() >= self.approx_max_file_size_bytes):
            file_no += 1
            tmp_file_handle = NamedTemporaryFile(delete=True)
            tmp_file_handles[self.filename.format(file_no)] = tmp_file_handle
    return tmp_file_handles
