|
1 | 1 | """ |
2 | 2 | pyexcel_text.ndjsonr |
3 | | - ~~~~~~~~~~~~~~~~~~~ |
| 3 | + ~~~~~~~~~~~~~~~~~~~~~~ |
4 | 4 |
|
5 | 5 | Render newline delimited json input |
6 | 6 |
|
7 | | - :copyright: (c) 2014-2016 by C. W. |
| 7 | + :copyright: (c) 2014-2017 by C. W. |
8 | 8 | :license: New BSD |
9 | 9 | """ |
| 10 | +import json |
| 11 | +import itertools |
| 12 | +import pyexcel._compact as compact |
10 | 13 | import pyexcel.constants as constants |
11 | 14 | from pyexcel.parser import AbstractParser |
12 | | -from pyexcel._compact import StringIO |
13 | 15 | from pyexcel.plugins.sources.pydata.common import ( |
14 | 16 | ArrayReader, RecordsReader) |
15 | | -import json |
16 | | -import itertools |
17 | 17 |
|
18 | 18 |
|
19 | 19 | AUTO_DETECT = 'AD' |
@@ -43,6 +43,9 @@ def row_iterator(self): |
43 | 43 |
|
44 | 44 |
|
45 | 45 | class NDJsonParser(AbstractParser): |
| 46 | + """ |
| 47 | + parse ndjson |
| 48 | + """ |
46 | 49 | def parse_file(self, file_name, on_demand=False, **keywords): |
47 | 50 | if on_demand: |
48 | 51 | file_handle = open(file_name, 'r') |
@@ -74,15 +77,21 @@ def parse_file_stream(self, file_stream, struct=AUTO_DETECT, |
74 | 77 |
|
75 | 78 | def parse_file_content(self, file_content, **keywords): |
76 | 79 | return self.parse_file_stream( |
77 | | - StringIO(file_content), **keywords) |
| 80 | + compact.StringIO(file_content), **keywords) |
78 | 81 |
|
79 | 82 |
|
80 | 83 | def json_loads(file_stream): |
| 84 | + """ |
| 85 | + Simple load each line as json |
| 86 | + """ |
81 | 87 | for raw_row in file_stream: |
82 | 88 | yield json.loads(raw_row) |
83 | 89 |
|
84 | 90 |
|
85 | 91 | def detect_format(content_generator): |
| 92 | + """ |
| 93 | + This function need to make sheet.ndjson to work |
| 94 | + """ |
86 | 95 | struct = AUTO_DETECT |
87 | 96 | first_line = next(content_generator) |
88 | 97 | if isinstance(first_line, list): |
|
0 commit comments