# Path: djenga/csv/unicode_csv_writer.py
# class UnicodeCsvWriter:
#     def __init__(self, f, dialect=csv.excel, **kwds):
#         self.queue = StringIO()
#         self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
#         self.stream = f
# 
#     def writerow(self, row):
#         """
#         writerow(unicode) -> None
#         This function takes a Unicode string and encodes it to the output.
#         """
#         data = []
#         basestring_type = six.string_types[0]
#         for value in row:
#             if not isinstance(value, basestring_type):
#                 value = '%s' % (value,)
#             data.append(value.encode('utf-8'))
#         self.writer.writerow(data)
#         data = self.queue.getvalue()
#         data = data.decode('utf-8')
#         self.stream.write(data)
#         self.queue.truncate(0)
# 
#     def writerows(self, rows):
#         for row in rows:
#             self.writerow(row)


from ...csv import UnicodeCsvWriter
        self.csv_writer = None
        """@type: UnicodeCsvWriter"""
        self.file_handle = None
        """@type: stream"""

    def add_arguments(self, parser):
        """
        Adds the output file argument to the list of
        arguments accepted by the command
        :type parser: argparse.ArgumentParser
        """
        super(CsvMixin, self).add_arguments(parser)
        parser.add_argument(
            '-o', '--output',
            dest='output_file',
            help='The /path/to/output-file.csv of the output CSV.'
                 '  If no output file is specified, the command'
                 ' will output the CSV contents to stdout.')

    def get_csv_writer(self):
        """
        Returns an initialized CSV writer
        :rtype: UnicodeCsvWriter
        """
        if not self.csv_writer:
            if self.output_file:
                self.file_handle = open(
                    self.output_file, 'w', encoding='utf-8')
            else:
                self.file_handle = self.stdout

# Path: djenga/csv/unicode_csv_writer.py
# class UnicodeCsvWriter:
#     def __init__(self, f, dialect=csv.excel, **kwds):
#         self.queue = StringIO()
#         self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
#         self.stream = f
# 
#     def writerow(self, row):
#         """
#         writerow(unicode) -> None
#         This function takes a Unicode string and encodes it to the output.
#         """
#         data = []
#         basestring_type = six.string_types[0]
#         for value in row:
#             if not isinstance(value, basestring_type):
#                 value = '%s' % (value,)
#             data.append(value.encode('utf-8'))
#         self.writer.writerow(data)
#         data = self.queue.getvalue()
#         data = data.decode('utf-8')
#         self.stream.write(data)
#         self.queue.truncate(0)
# 
#     def writerows(self, rows):
#         for row in rows:
#             self.writerow(row)


# Path: djenga/management/commands/csvmixin.py
from ...csv import UnicodeCsvWriter

        self.csv_writer = None
        """@type: UnicodeCsvWriter"""
        self.file_handle = None
        """@type: stream"""

    def add_arguments(self, parser):
        """
        Adds the output file argument to the list of
        arguments accepted by the command
        :type parser: argparse.ArgumentParser
        """
        super(CsvMixin, self).add_arguments(parser)
        parser.add_argument(
            '-o', '--output',
            dest='output_file',
            help='The /path/to/output-file.csv of the output CSV.'
                 '  If no output file is specified, the command'
                 ' will output the CSV contents to stdout.')

    def get_csv_writer(self):
        """
        Returns an initialized CSV writer
        :rtype: UnicodeCsvWriter
        """
        if not self.csv_writer:
            if self.output_file:
                self.file_handle = open(
                    self.output_file, 'w', encoding='utf-8')
            else:
                self.file_handle = self.stdout

            self.csv_writer = UnicodeCsvWriter(self.file_handle)