Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Rebased on ijson@2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
roll committed Sep 21, 2019
1 parent 9ca5425 commit 16af3de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def read(*paths):
# Format: csv
'unicodecsv>=0.14',
# Format: json
'ijson>=2.0',
'ijson>=2.5',
# Format: ndjson
'jsonlines>=1.1',
# Format: sql
Expand Down
14 changes: 7 additions & 7 deletions tabulator/parsers/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ def __init__(self, loader, force_parse=False, property=None):
self.__force_parse = force_parse
self.__extended_rows = None
self.__encoding = None
self.__chars = None
self.__bytes = None

@property
def closed(self):
return self.__chars is None or self.__chars.closed
return self.__bytes is None or self.__bytes.closed

def open(self, source, encoding=None):
self.close()
self.__chars = self.__loader.load(source, encoding=encoding)
self.__encoding = getattr(self.__chars, 'encoding', encoding)
self.__encoding = encoding
self.__bytes = self.__loader.load(source, mode='b', encoding=encoding)
if self.__encoding:
self.__encoding.lower()
self.reset()

def close(self):
if not self.closed:
self.__chars.close()
self.__bytes.close()

def reset(self):
helpers.reset_stream(self.__chars)
helpers.reset_stream(self.__bytes)
self.__extended_rows = self.__iter_extended_rows()

@property
Expand All @@ -64,7 +64,7 @@ def __iter_extended_rows(self):
path = 'item'
if self.__property is not None:
path = '%s.item' % self.__property
items = ijson.items(self.__chars, path)
items = ijson.items(self.__bytes, path)
for row_number, item in enumerate(items, start=1):
if isinstance(item, (tuple, list)):
yield (row_number, None, list(item))
Expand Down

0 comments on commit 16af3de

Please sign in to comment.