json-stream 2.5.0__tar.gz → 2.5.1__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.0/src/json_stream.egg-info → json_stream-2.5.1}/PKG-INFO +1 -1
- {json_stream-2.5.0 → json_stream-2.5.1}/pyproject.toml +1 -1
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_tokenizer.py +28 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tokenizer.py +65 -1
- {json_stream-2.5.0 → json_stream-2.5.1/src/json_stream.egg-info}/PKG-INFO +1 -1
- {json_stream-2.5.0 → json_stream-2.5.1}/LICENSE.txt +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/README.md +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/setup.cfg +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/base.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/dump/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/dump/tests/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/dump/tests/test_dump.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/dump/threading.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/httpx/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/httpx/tests/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/httpx/tests/test_httpx.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/iterators.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/loader.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/requests/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/requests/tests/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/requests/tests/test_requests.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/select_tokenizer.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/__init__.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_binary_resumption.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_buffering.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_collection_abcs.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_iterators.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_load_many.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_loader.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_tokenizer_integration.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_util.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_visit_many.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_visitor.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/tests/test_writer.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/util.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/visitor.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream/writer.py +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream.egg-info/SOURCES.txt +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream.egg-info/dependency_links.txt +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream.egg-info/requires.txt +0 -0
- {json_stream-2.5.0 → json_stream-2.5.1}/src/json_stream.egg-info/top_level.txt +0 -0
|
@@ -5,6 +5,7 @@ https://github.com/danielyule/naya
|
|
|
5
5
|
|
|
6
6
|
Copyright (c) 2019 Daniel Yule
|
|
7
7
|
"""
|
|
8
|
+
import math
|
|
8
9
|
import re
|
|
9
10
|
from io import StringIO
|
|
10
11
|
from unittest import TestCase
|
|
@@ -59,6 +60,33 @@ class TestJsonTokenization(TestCase):
|
|
|
59
60
|
self.assertRaises(ValueError, self.tokenize_sequence, "3.6ea")
|
|
60
61
|
self.assertRaises(ValueError, self.tokenize_sequence, "67.8e+a")
|
|
61
62
|
|
|
63
|
+
def test_nan_infinity_parsing(self):
|
|
64
|
+
token_list = self.tokenize_sequence("NaN")
|
|
65
|
+
self.assertEqual(1, len(token_list))
|
|
66
|
+
ttype, token = token_list[0]
|
|
67
|
+
self.assertTrue(math.isnan(token))
|
|
68
|
+
self.assertEqual(ttype, TokenType.NUMBER)
|
|
69
|
+
|
|
70
|
+
self.assertNumberEquals(float("inf"), "Infinity")
|
|
71
|
+
self.assertNumberEquals(float("-inf"), "-Infinity")
|
|
72
|
+
|
|
73
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Na")
|
|
74
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Nax")
|
|
75
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "In")
|
|
76
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Inf")
|
|
77
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Infi")
|
|
78
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Infin")
|
|
79
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Infini")
|
|
80
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Infinit")
|
|
81
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "Infinityx")
|
|
82
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-In")
|
|
83
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Inf")
|
|
84
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Infi")
|
|
85
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Infin")
|
|
86
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Infini")
|
|
87
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Infinit")
|
|
88
|
+
self.assertRaises(ValueError, self.tokenize_sequence, "-Infinityx")
|
|
89
|
+
|
|
62
90
|
def test_operator_parsing(self):
|
|
63
91
|
self.assertOperatorEquals("{", "{")
|
|
64
92
|
self.assertOperatorEquals("}", "}")
|
|
@@ -45,6 +45,15 @@ class State:
|
|
|
45
45
|
UNICODE_SURROGATE_START = 23
|
|
46
46
|
UNICODE_SURROGATE_STRING_ESCAPE = 24
|
|
47
47
|
UNICODE_SURROGATE = 25
|
|
48
|
+
NAN_1 = 26
|
|
49
|
+
NAN_2 = 27
|
|
50
|
+
INF_1 = 28
|
|
51
|
+
INF_2 = 29
|
|
52
|
+
INF_3 = 30
|
|
53
|
+
INF_4 = 31
|
|
54
|
+
INF_5 = 32
|
|
55
|
+
INF_6 = 33
|
|
56
|
+
INF_7 = 34
|
|
48
57
|
|
|
49
58
|
|
|
50
59
|
class SpecialChar:
|
|
@@ -130,6 +139,10 @@ def tokenize(stream):
|
|
|
130
139
|
next_state = State.TRUE_1
|
|
131
140
|
elif char == "n":
|
|
132
141
|
next_state = State.NULL_1
|
|
142
|
+
elif char == "N":
|
|
143
|
+
next_state = State.NAN_1
|
|
144
|
+
elif char == "I":
|
|
145
|
+
next_state = State.INF_1
|
|
133
146
|
elif not char.isspace() and not char == SpecialChar.EOF:
|
|
134
147
|
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
135
148
|
elif state == State.INTEGER:
|
|
@@ -169,8 +182,10 @@ def tokenize(stream):
|
|
|
169
182
|
elif char in "123456789":
|
|
170
183
|
next_state = State.INTEGER
|
|
171
184
|
add_char = True
|
|
185
|
+
elif char == "I":
|
|
186
|
+
next_state = State.INF_1
|
|
172
187
|
else:
|
|
173
|
-
raise ValueError("A - must be followed by a digit. Got '{0}'".format(char))
|
|
188
|
+
raise ValueError("A - must be followed by a digit or Infinity. Got '{0}'".format(char))
|
|
174
189
|
elif state == State.INTEGER_EXP_0:
|
|
175
190
|
if char == "+" or char == "-" or char in "0123456789":
|
|
176
191
|
next_state = State.INTEGER_EXP
|
|
@@ -262,6 +277,55 @@ def tokenize(stream):
|
|
|
262
277
|
now_token = (TokenType.NULL, None)
|
|
263
278
|
else:
|
|
264
279
|
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
280
|
+
elif state == State.NAN_1:
|
|
281
|
+
if char == "a":
|
|
282
|
+
next_state = State.NAN_2
|
|
283
|
+
else:
|
|
284
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
285
|
+
elif state == State.NAN_2:
|
|
286
|
+
if char == "N":
|
|
287
|
+
next_state = State.WHITESPACE
|
|
288
|
+
completed = True
|
|
289
|
+
now_token = (TokenType.NUMBER, float("NaN"))
|
|
290
|
+
else:
|
|
291
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
292
|
+
elif state == State.INF_1:
|
|
293
|
+
if char == "n":
|
|
294
|
+
next_state = State.INF_2
|
|
295
|
+
else:
|
|
296
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
297
|
+
elif state == State.INF_2:
|
|
298
|
+
if char == "f":
|
|
299
|
+
next_state = State.INF_3
|
|
300
|
+
else:
|
|
301
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
302
|
+
elif state == State.INF_3:
|
|
303
|
+
if char == "i":
|
|
304
|
+
next_state = State.INF_4
|
|
305
|
+
else:
|
|
306
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
307
|
+
elif state == State.INF_4:
|
|
308
|
+
if char == "n":
|
|
309
|
+
next_state = State.INF_5
|
|
310
|
+
else:
|
|
311
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
312
|
+
elif state == State.INF_5:
|
|
313
|
+
if char == "i":
|
|
314
|
+
next_state = State.INF_6
|
|
315
|
+
else:
|
|
316
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
317
|
+
elif state == State.INF_6:
|
|
318
|
+
if char == "t":
|
|
319
|
+
next_state = State.INF_7
|
|
320
|
+
else:
|
|
321
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
322
|
+
elif state == State.INF_7:
|
|
323
|
+
if char == "y":
|
|
324
|
+
next_state = State.WHITESPACE
|
|
325
|
+
completed = True
|
|
326
|
+
now_token = (TokenType.NUMBER, float("".join(token) + "Infinity"))
|
|
327
|
+
else:
|
|
328
|
+
raise ValueError("Invalid JSON character: '{0}'".format(char))
|
|
265
329
|
elif state == State.STRING:
|
|
266
330
|
if char == "\"":
|
|
267
331
|
completed = True
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|