Skip to content

Commit

Permalink
updated to tabulator-v0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Oct 26, 2016
1 parent e255e25 commit 645c8f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions datapackage/resource.py
Expand Up @@ -7,6 +7,7 @@
import os
import json
import six
import warnings
import six.moves.urllib as urllib
import tabulator
import jsontableschema
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
],
)

0 comments on commit 645c8f1

Please sign in to comment.