json-stream 2.5.1__tar.gz → 2.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {json_stream-2.5.1/src/json_stream.egg-info → json_stream-2.5.2}/PKG-INFO +1 -1
- {json_stream-2.5.1 → json_stream-2.5.2}/pyproject.toml +1 -1
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/base.py +2 -2
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/loader.py +4 -1
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_load_many.py +12 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_loader.py +17 -3
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_visitor.py +22 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/visitor.py +4 -1
- {json_stream-2.5.1 → json_stream-2.5.2/src/json_stream.egg-info}/PKG-INFO +1 -1
- {json_stream-2.5.1 → json_stream-2.5.2}/LICENSE.txt +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/README.md +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/setup.cfg +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/dump/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/dump/tests/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/dump/tests/test_dump.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/dump/threading.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/httpx/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/httpx/tests/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/httpx/tests/test_httpx.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/iterators.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/requests/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/requests/tests/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/requests/tests/test_requests.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/select_tokenizer.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/__init__.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_binary_resumption.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_buffering.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_collection_abcs.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_iterators.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_tokenizer.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_tokenizer_integration.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_util.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_visit_many.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tests/test_writer.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/tokenizer.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/util.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream/writer.py +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream.egg-info/SOURCES.txt +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream.egg-info/dependency_links.txt +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream.egg-info/requires.txt +0 -0
- {json_stream-2.5.1 → json_stream-2.5.2}/src/json_stream.egg-info/top_level.txt +0 -0
|
@@ -81,10 +81,10 @@ class StreamingJSONBase(ABC):
|
|
|
81
81
|
raise NotImplementedError() # pragma: no cover
|
|
82
82
|
|
|
83
83
|
def __copy__(self):
|
|
84
|
-
raise copy.Error("Copying
|
|
84
|
+
raise copy.Error("Copying json_stream objects leads to a bad time")
|
|
85
85
|
|
|
86
86
|
def __deepcopy__(self, memo):
|
|
87
|
-
raise copy.Error("Copying
|
|
87
|
+
raise copy.Error("Copying json_stream objects leads to a bad time")
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
class PersistentStreamingJSONBase(StreamingJSONBase, ABC):
|
|
@@ -4,7 +4,10 @@ from json_stream.select_tokenizer import default_tokenizer
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def load(fp_or_iterable, persistent=False, tokenizer=default_tokenizer, **tokenizer_kwargs):
|
|
7
|
-
|
|
7
|
+
try:
|
|
8
|
+
return next(load_many(fp_or_iterable, persistent, tokenizer, **tokenizer_kwargs))
|
|
9
|
+
except StopIteration:
|
|
10
|
+
raise ValueError('No JSON value found') from None
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
def load_many(fp_or_iterable, persistent=False, tokenizer=default_tokenizer, **tokenizer_kwargs):
|
|
@@ -7,6 +7,18 @@ from json_stream import to_standard_types
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class TestLoadMany(TestCase):
|
|
10
|
+
def test_load_many_without_json_value(self):
|
|
11
|
+
for persistent in (False, True):
|
|
12
|
+
for text in ('', ' \t\r\n'):
|
|
13
|
+
sources = [
|
|
14
|
+
StringIO(text), BytesIO(text.encode()),
|
|
15
|
+
[text], [text.encode()],
|
|
16
|
+
list(text), [char.encode() for char in text],
|
|
17
|
+
]
|
|
18
|
+
for source in sources:
|
|
19
|
+
with self.subTest(persistent=persistent, text=text, source=source):
|
|
20
|
+
self.assertEqual(list(json_stream.load_many(source, persistent=persistent)), [])
|
|
21
|
+
|
|
10
22
|
def test_load_many(self):
|
|
11
23
|
# NDJSON-like: one JSON value per line
|
|
12
24
|
payload = "\n".join([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import json
|
|
3
|
-
from io import StringIO
|
|
3
|
+
from io import BytesIO, StringIO
|
|
4
4
|
|
|
5
5
|
from json_stream import load
|
|
6
6
|
from json_stream.base import (
|
|
@@ -14,6 +14,19 @@ from json_stream.tests import JSONLoadTestCase
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class TestLoader(JSONLoadTestCase):
|
|
17
|
+
def test_load_without_json_value(self):
|
|
18
|
+
for persistent in (False, True):
|
|
19
|
+
for text in ('', ' \t\r\n'):
|
|
20
|
+
sources = [
|
|
21
|
+
StringIO(text), BytesIO(text.encode()),
|
|
22
|
+
[text], [text.encode()],
|
|
23
|
+
list(text), [char.encode() for char in text],
|
|
24
|
+
]
|
|
25
|
+
for source in sources:
|
|
26
|
+
with self.subTest(persistent=persistent, text=text, source=source):
|
|
27
|
+
with self.assertRaisesRegex(ValueError, 'No JSON value found'):
|
|
28
|
+
load(source, persistent=persistent)
|
|
29
|
+
|
|
17
30
|
def test_load_empty_object(self):
|
|
18
31
|
obj = {}
|
|
19
32
|
self._test_object(obj, persistent=True)
|
|
@@ -177,9 +190,9 @@ class TestLoader(JSONLoadTestCase):
|
|
|
177
190
|
|
|
178
191
|
def test_not_copiable(self):
|
|
179
192
|
json_str = '[["a"], "b", "c"]'
|
|
180
|
-
with self.assertRaisesRegex(copy.Error, "^Copying
|
|
193
|
+
with self.assertRaisesRegex(copy.Error, "^Copying json_stream objects leads to a bad time$"):
|
|
181
194
|
copy.copy(load(StringIO(json_str)))
|
|
182
|
-
with self.assertRaisesRegex(copy.Error, "^Copying
|
|
195
|
+
with self.assertRaisesRegex(copy.Error, "^Copying json_stream objects leads to a bad time$"):
|
|
183
196
|
copy.deepcopy(load(StringIO(json_str)))
|
|
184
197
|
|
|
185
198
|
def test_transient_to_persistent(self):
|
|
@@ -218,6 +231,7 @@ class TestLoader(JSONLoadTestCase):
|
|
|
218
231
|
|
|
219
232
|
def test_primitives(self):
|
|
220
233
|
primitives = (
|
|
234
|
+
("null", None),
|
|
221
235
|
("true", True),
|
|
222
236
|
("false", False),
|
|
223
237
|
("123", 123),
|
|
@@ -22,6 +22,28 @@ class TestVisitor(TestCase):
|
|
|
22
22
|
json_stream.visit(StringIO("1"), lambda a, b: visited.append((a, b)))
|
|
23
23
|
self.assertListEqual([(1, ())], visited)
|
|
24
24
|
|
|
25
|
+
def test_visitor_without_json_value(self):
|
|
26
|
+
for text in ('', ' \t\r\n'):
|
|
27
|
+
sources = [
|
|
28
|
+
StringIO(text), BytesIO(text.encode()),
|
|
29
|
+
[text], [text.encode()],
|
|
30
|
+
list(text), [char.encode() for char in text],
|
|
31
|
+
]
|
|
32
|
+
for source in sources:
|
|
33
|
+
with self.subTest(text=text, source=source):
|
|
34
|
+
visited = []
|
|
35
|
+
with self.assertRaisesRegex(ValueError, 'No JSON value found'):
|
|
36
|
+
json_stream.visit(source, lambda a, b: visited.append((a, b)))
|
|
37
|
+
self.assertListEqual([], visited)
|
|
38
|
+
|
|
39
|
+
def test_visit_many_without_json_value(self):
|
|
40
|
+
for text in ('', ' \t\r\n'):
|
|
41
|
+
for source in (StringIO(text), BytesIO(text.encode())):
|
|
42
|
+
with self.subTest(text=text, source=source):
|
|
43
|
+
visited = []
|
|
44
|
+
self.assertListEqual([], list(json_stream.visit_many(source, lambda a, b: visited.append((a, b)))))
|
|
45
|
+
self.assertListEqual([], visited)
|
|
46
|
+
|
|
25
47
|
def _assert_data_okay(self, visited):
|
|
26
48
|
self.assertListEqual([
|
|
27
49
|
(1, ('x',)),
|
|
@@ -34,4 +34,7 @@ def visit_many(fp_or_iterator, visitor, tokenizer=default_tokenizer, **tokenizer
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
def visit(fp_or_iterator, visitor, tokenizer=default_tokenizer, **tokenizer_kwargs):
|
|
37
|
-
|
|
37
|
+
try:
|
|
38
|
+
next(visit_many(fp_or_iterator, visitor, tokenizer, **tokenizer_kwargs))
|
|
39
|
+
except StopIteration:
|
|
40
|
+
raise ValueError('No JSON value found') from None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|