# Path: databuild/compat.py
# def _open(*args, **kwargs):
#     kwargs.pop('encoding', False)
#     return open(*args, **kwargs) 


    from StringIO import StringIO
    from io import StringIO
    from databuild.vendor import unicodecsv as csv
from databuild.compat import _open
import six
import json
import os
    import csv
        import_method = getattr(self, 'import_%s' % format, False)
        if import_method:
            return import_method(filename, sheet_name, *args, **kwargs)
        raise NotImplementedError()

    def import_csv(self, filename, sheet_name, headers=None, encoding='utf-8', replace=False, skip_first_lines=0, skip_last_lines=0, guess_types=True, **kwargs):
        with _open(filename, 'r', encoding=encoding) as f:
            if skip_last_lines:
                lines = f.readlines()[skip_first_lines:-skip_last_lines]
            else:
                lines = f.readlines()[skip_first_lines:]
        _buffer = StringIO('\n'.join(lines))
        _buffer.seek(0)

        reader = csv.DictReader(_buffer, **kwargs)
        if headers is None:
            headers = reader.fieldnames

        if not replace:
            sheet = self.workbook.get_or_create_sheet(sheet_name, headers)
        else:
            sheet = self.workbook.add_sheet(sheet_name, headers)
        sheet.headers = headers
        sheet.extend(reader)

        if guess_types:
            sheet.guess_column_types()
        return sheet

    def import_json(self, filename, sheet_name, headers=None, encoding='utf-8', replace=False, **kwargs):

# Path: databuild/compat.py
# def _open(*args, **kwargs):
#     kwargs.pop('encoding', False)
#     return open(*args, **kwargs) 


# Path: databuild/adapters/base/importer.py
    from StringIO import StringIO
    from io import StringIO
    from databuild.vendor import unicodecsv as csv
from databuild.compat import _open
import six
import json
import os
    import csv

        import_method = getattr(self, 'import_%s' % format, False)
        if import_method:
            return import_method(filename, sheet_name, *args, **kwargs)
        raise NotImplementedError()

    def import_csv(self, filename, sheet_name, headers=None, encoding='utf-8', replace=False, skip_first_lines=0, skip_last_lines=0, guess_types=True, **kwargs):
        with _open(filename, 'r', encoding=encoding) as f:
            if skip_last_lines:
                lines = f.readlines()[skip_first_lines:-skip_last_lines]
            else:
                lines = f.readlines()[skip_first_lines:]
        _buffer = StringIO('\n'.join(lines))
        _buffer.seek(0)

        reader = csv.DictReader(_buffer, **kwargs)
        if headers is None:
            headers = reader.fieldnames

        if not replace:
            sheet = self.workbook.get_or_create_sheet(sheet_name, headers)
        else:
            sheet = self.workbook.add_sheet(sheet_name, headers)
        sheet.headers = headers
        sheet.extend(reader)

        if guess_types:
            sheet.guess_column_types()
        return sheet

    def import_json(self, filename, sheet_name, headers=None, encoding='utf-8', replace=False, **kwargs):

        with _open(filename, 'r', encoding=encoding) as fh: