partialjson 0.0.9__tar.gz → 1.0.0__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: partialjson
3
- Version: 0.0.9
3
+ Version: 1.0.0
4
4
  Summary: Parse incomplete or partial json
5
5
  Home-page: https://github.com/iw4p/partialjson
6
6
  Author: Nima Akbarzadeh
@@ -14,6 +14,7 @@ Dynamic: description
14
14
  Dynamic: description-content-type
15
15
  Dynamic: home-page
16
16
  Dynamic: license
17
+ Dynamic: license-file
17
18
  Dynamic: summary
18
19
 
19
20
  # PartialJson
@@ -65,6 +66,18 @@ Also can be found on [pypi](https://pypi.org/project/partialjson/)
65
66
  - Install the package by pip package manager.
66
67
  - After installing, you can use it and call the library.
67
68
 
69
+ ## Testing
70
+
71
+ ```bash
72
+ pip install -e .
73
+ pip install -r requirements-dev.txt
74
+ pytest -q
75
+ ```
76
+
77
+ ## Citation
78
+
79
+ If you use this software, please cite it using the metadata in `CITATION.cff`.
80
+
68
81
  ## Star History
69
82
 
70
83
  [![Star History Chart](https://api.star-history.com/svg?repos=iw4p/partialjson&type=Date)](https://star-history.com/#iw4p/partialjson&Date)
@@ -47,6 +47,18 @@ Also can be found on [pypi](https://pypi.org/project/partialjson/)
47
47
  - Install the package by pip package manager.
48
48
  - After installing, you can use it and call the library.
49
49
 
50
+ ## Testing
51
+
52
+ ```bash
53
+ pip install -e .
54
+ pip install -r requirements-dev.txt
55
+ pytest -q
56
+ ```
57
+
58
+ ## Citation
59
+
60
+ If you use this software, please cite it using the metadata in `CITATION.cff`.
61
+
50
62
  ## Star History
51
63
 
52
64
  [![Star History Chart](https://api.star-history.com/svg?repos=iw4p/partialjson&type=Date)](https://star-history.com/#iw4p/partialjson&Date)
@@ -6,7 +6,7 @@ Parsing ChatGPT JSON stream response — Partial and incomplete JSON parser pyth
6
6
 
7
7
  from .json_parser import JSONParser
8
8
 
9
- __version__ = "0.0.9"
9
+ __version__ = "1.0.0"
10
10
  __author__ = "Nima Akbarzadeh"
11
11
  __author_email__ = "iw4p@protonmail.com"
12
12
  __license__ = "MIT"
@@ -117,14 +117,14 @@ class JSONParser:
117
117
  return s[1:], ""
118
118
  return s[1:], ""
119
119
  else:
120
- # Check for incomplete escape sequences
120
+ # Handle incomplete escape sequences
121
121
  if incomplete_escape_regex.match(s[1:]):
122
- return s[1:], ""
122
+ return "", ""
123
123
  # Attempt to parse the string without incomplete escape sequences
124
124
  try:
125
125
  return json.loads(f'"{s[1:]}"'), ""
126
126
  except json.JSONDecodeError:
127
- return s[1:], ""
127
+ return "", ""
128
128
  str_val = s[: end + 1]
129
129
  s = s[end + 1 :]
130
130
  if not self.strict:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: partialjson
3
- Version: 0.0.9
3
+ Version: 1.0.0
4
4
  Summary: Parse incomplete or partial json
5
5
  Home-page: https://github.com/iw4p/partialjson
6
6
  Author: Nima Akbarzadeh
@@ -14,6 +14,7 @@ Dynamic: description
14
14
  Dynamic: description-content-type
15
15
  Dynamic: home-page
16
16
  Dynamic: license
17
+ Dynamic: license-file
17
18
  Dynamic: summary
18
19
 
19
20
  # PartialJson
@@ -65,6 +66,18 @@ Also can be found on [pypi](https://pypi.org/project/partialjson/)
65
66
  - Install the package by pip package manager.
66
67
  - After installing, you can use it and call the library.
67
68
 
69
+ ## Testing
70
+
71
+ ```bash
72
+ pip install -e .
73
+ pip install -r requirements-dev.txt
74
+ pytest -q
75
+ ```
76
+
77
+ ## Citation
78
+
79
+ If you use this software, please cite it using the metadata in `CITATION.cff`.
80
+
68
81
  ## Star History
69
82
 
70
83
  [![Star History Chart](https://api.star-history.com/svg?repos=iw4p/partialjson&type=Date)](https://star-history.com/#iw4p/partialjson&Date)
@@ -6,4 +6,5 @@ partialjson/json_parser.py
6
6
  partialjson.egg-info/PKG-INFO
7
7
  partialjson.egg-info/SOURCES.txt
8
8
  partialjson.egg-info/dependency_links.txt
9
- partialjson.egg-info/top_level.txt
9
+ partialjson.egg-info/top_level.txt
10
+ tests/test_parser.py
@@ -0,0 +1,91 @@
1
+ import pytest
2
+ from partialjson.json_parser import JSONParser
3
+
4
+
5
+ def test_numbers_and_floats():
6
+ parser = JSONParser(strict=True)
7
+ assert parser.parse("42") == 42
8
+ assert parser.parse("-42") == -42
9
+ assert parser.parse("12.34") == 12.34
10
+ assert parser.parse("-12.34") == -12.34
11
+ assert parser.parse("12.") == 12
12
+ assert parser.parse("-12.") == -12
13
+
14
+
15
+ def test_invalid_number_raises_error():
16
+ parser = JSONParser(strict=True)
17
+ with pytest.raises(Exception):
18
+ parser.parse("1.2.3.4")
19
+
20
+
21
+ def test_booleans_and_null():
22
+ parser = JSONParser(strict=True)
23
+ assert parser.parse("true") is True
24
+ assert parser.parse("false") is False
25
+ assert parser.parse("null") is None
26
+
27
+
28
+ def test_array_complete_and_incomplete():
29
+ parser = JSONParser(strict=True)
30
+ assert parser.parse("[]") == []
31
+ assert parser.parse("[1,2,3]") == [1, 2, 3]
32
+ assert parser.parse("[1,2,3") == [1, 2, 3]
33
+ assert parser.parse("[1,2,") == [1, 2]
34
+ assert parser.parse("[1,") == [1]
35
+ assert parser.parse("[") == []
36
+
37
+
38
+ def test_object_complete():
39
+ parser = JSONParser(strict=True)
40
+ expected = {"a": "apple", "b": "banana"}
41
+ assert parser.parse('{"a":"apple","b":"banana"}') == expected
42
+ assert parser.parse('{"a": "apple","b": "banana"}') == expected
43
+
44
+
45
+ def test_string_strict_complete_and_incomplete_in_object():
46
+ parser = JSONParser(strict=True)
47
+ assert parser.parse('{"x": "1st line\\n2nd line"}') == {"x": "1st line\n2nd line"}
48
+ assert parser.parse('{"x": "1st line\\n2nd line') == {"x": "1st line\n2nd line"}
49
+
50
+
51
+ def test_top_level_string():
52
+ parser = JSONParser(strict=True)
53
+ assert parser.parse('"I am text"') == "I am text"
54
+ assert parser.parse('"I\\"m text"') == 'I"m text'
55
+
56
+
57
+ def test_top_level_incomplete_string_strict():
58
+ parser = JSONParser(strict=True)
59
+ assert parser.parse('"I am text') == "I am text"
60
+
61
+
62
+ def test_string_relaxed_returns_raw_content_when_incomplete():
63
+ parser = JSONParser(strict=False)
64
+ result = parser.parse('"A\\nB')
65
+ assert result == "A\\nB"
66
+
67
+
68
+ def test_spaces_and_extra_tokens():
69
+ parser = JSONParser(strict=True)
70
+ assert parser.parse(" [1] ") == [1]
71
+ assert parser.parse(" [1 ") == [1]
72
+
73
+
74
+ def test_invalid_input_raises_error():
75
+ parser = JSONParser(strict=True)
76
+ with pytest.raises(Exception):
77
+ parser.parse(":atom")
78
+
79
+
80
+ def test_unicode_escape_complete():
81
+ parser = JSONParser(strict=True)
82
+ assert parser.parse('{"a":"\\u0041"}') == {"a": "A"}
83
+ assert parser.parse('{"a":"\\u00E9"}') == {"a": "é"}
84
+ assert parser.parse('{"a":"\\u20AC"}') == {"a": "€"}
85
+
86
+
87
+ def test_unicode_escape_incomplete_strict():
88
+ parser = JSONParser(strict=True)
89
+ assert parser.parse('{"a":"\\u123"') == {"a": "\u1234"}
90
+ assert parser.parse('{"a":"\\u"') == {"a": ""}
91
+ assert parser.parse('{"a":"\\""') == {"a": ""}
File without changes
File without changes
File without changes