import gzip
import csv

from django.core.files.storage import default_storage


def update_feed(feed):
    with default_storage.open(feed.file_path, 'w') as output_file:
        if feed.compression:
            output = gzip.GzipFile(fileobj=output_file)
        else:
            output = output_file

        writer = csv.DictWriter(output,feed.attributes,
                                delimiter=str("\t"))
        writer.writeheader()
        for item in feed.items():
            writer.writerow(feed.item_attributes(item))

        if feed.compression:
            output.close()

from __future__ import unicode_literals

import gzip
import csv

from django.core.files.storage import default_storage


def update_feed(feed):
    with default_storage.open(feed.file_path, 'wb') as output_file:
        if feed.compression:
            try:
                output = gzip.open(output_file, 'wt')
            except TypeError:
                output = gzip.GzipFile(fileobj=output_file, mode='w')
        else:
            output = output_file

        writer = csv.DictWriter(output, feed.attributes,
                                dialect=csv.excel_tab)
        writer.writeheader()
        for item in feed.items():
            writer.writerow(feed.item_attributes(item))

        if feed.compression:
            output.close()

Fix compressed feeds in python3
Fix compressed feeds in python3

+ from __future__ import unicode_literals
+ 
  import gzip
  import csv
  
  from django.core.files.storage import default_storage
  
  
  def update_feed(feed):
-     with default_storage.open(feed.file_path, 'w') as output_file:
+     with default_storage.open(feed.file_path, 'wb') as output_file:
          if feed.compression:
+             try:
+                 output = gzip.open(output_file, 'wt')
+             except TypeError:
-             output = gzip.GzipFile(fileobj=output_file)
+                 output = gzip.GzipFile(fileobj=output_file, mode='w')
          else:
              output = output_file
  
-         writer = csv.DictWriter(output,feed.attributes,
+         writer = csv.DictWriter(output, feed.attributes,
-                                 delimiter=str("\t"))
+                                 dialect=csv.excel_tab)
          writer.writeheader()
          for item in feed.items():
              writer.writerow(feed.item_attributes(item))
  
          if feed.compression:
              output.close()
  
Fix compressed feeds in python3
## Code Before:
import gzip
import csv

from django.core.files.storage import default_storage


def update_feed(feed):
    with default_storage.open(feed.file_path, 'w') as output_file:
        if feed.compression:
            output = gzip.GzipFile(fileobj=output_file)
        else:
            output = output_file

        writer = csv.DictWriter(output,feed.attributes,
                                delimiter=str("\t"))
        writer.writeheader()
        for item in feed.items():
            writer.writerow(feed.item_attributes(item))

        if feed.compression:
            output.close()

## Instruction:
Fix compressed feeds in python3
## Code After:
from __future__ import unicode_literals

import gzip
import csv

from django.core.files.storage import default_storage


def update_feed(feed):
    with default_storage.open(feed.file_path, 'wb') as output_file:
        if feed.compression:
            try:
                output = gzip.open(output_file, 'wt')
            except TypeError:
                output = gzip.GzipFile(fileobj=output_file, mode='w')
        else:
            output = output_file

        writer = csv.DictWriter(output, feed.attributes,
                                dialect=csv.excel_tab)
        writer.writeheader()
        for item in feed.items():
            writer.writerow(feed.item_attributes(item))

        if feed.compression:
            output.close()
