diff --git a/datapackage/resource.py b/datapackage/resource.py index 8a30be1..c8daa60 100644 --- a/datapackage/resource.py +++ b/datapackage/resource.py @@ -7,6 +7,7 @@ import os import json import six +import warnings import six.moves.urllib as urllib import tabulator import jsontableschema @@ -271,19 +272,24 @@ def iter(self): inline_data = self._parse_inline_data() result = iter(inline_data) elif data_path_or_url: + encoding=self.descriptor.get('encoding') dialect = self.descriptor.get('dialect', {}) - parser_options = {} + options = {} + if dialect: + options['format'] = 'csv' if 'delimiter' in dialect: - parser_options['delimiter'] = dialect['delimiter'] + options['delimiter'] = dialect['delimiter'] if 'lineTerminator' in dialect: - parser_options['lineterminator'] = dialect['lineTerminator'] - if len(dialect) > 0: - parser_options['constructor'] = tabulator.parsers.CSV - + # https://github.com/frictionlessdata/datapackage-py/issues/58 + # tabulator doesn't support lineTerminator because + # it's not supported by Python builtin csv parser + lineterm = dialect['lineTerminator'] + if lineterm not in ['\r\n', '\r', '\n']: + message = 'Line terminator "%s" is not supported' % lineterm + warnings.warn(message, UserWarning) try: - table = tabulator.Stream(data_path_or_url, headers=1, - encoding=self.descriptor.get('encoding'), - parser_options=parser_options).open() + table = tabulator.Stream(data_path_or_url, + headers=1, encoding=encoding, **options).open() result = self._iter_from_tabulator(table, self.descriptor.get('schema')) except tabulator.exceptions.TabulatorException as e: msg = 'Data at \'{0}\' isn\'t in a known tabular data format' diff --git a/setup.py b/setup.py index 068e08d..6721b31 100644 --- a/setup.py +++ b/setup.py @@ -73,6 +73,6 @@ def recursive_glob(path, patterns): 'jsonschema>=2.5,<3.0a', 'unicodecsv>=0.14,<1.0a', 'jsontableschema>=0.7,<1.0a', - 'tabulator>=0.7,<1.0a', + 'tabulator>=0.8,<1.0a', ], )