python-rapidjson 1.25__tar.gz → 1.26__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.
Files changed (93) hide show
  1. {python_rapidjson-1.25 → python_rapidjson-1.26}/CHANGES.rst +46 -0
  2. {python_rapidjson-1.25 → python_rapidjson-1.26}/PKG-INFO +47 -1
  3. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/changes.rst +46 -0
  4. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/loads.rst +10 -2
  5. {python_rapidjson-1.25 → python_rapidjson-1.26}/python_rapidjson.egg-info/PKG-INFO +47 -1
  6. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson.cpp +80 -94
  7. {python_rapidjson-1.25 → python_rapidjson-1.26}/requirements-test.txt +4 -4
  8. {python_rapidjson-1.25 → python_rapidjson-1.26}/requirements.txt +3 -3
  9. {python_rapidjson-1.25 → python_rapidjson-1.26}/setup.py +1 -1
  10. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_float.py +23 -0
  11. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_memory_leaks.py +11 -7
  12. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_params.py +152 -0
  13. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_refs_count.py +3 -0
  14. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_streams.py +32 -0
  15. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_unicode.py +21 -0
  16. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_validator.py +37 -0
  17. {python_rapidjson-1.25 → python_rapidjson-1.26}/.dir-locals.el +0 -0
  18. {python_rapidjson-1.25 → python_rapidjson-1.26}/LICENSE +0 -0
  19. {python_rapidjson-1.25 → python_rapidjson-1.26}/MANIFEST.in +0 -0
  20. {python_rapidjson-1.25 → python_rapidjson-1.26}/README.rst +0 -0
  21. {python_rapidjson-1.25 → python_rapidjson-1.26}/benchmarks/conftest.py +0 -0
  22. {python_rapidjson-1.25 → python_rapidjson-1.26}/benchmarks/tablize.py +0 -0
  23. {python_rapidjson-1.25 → python_rapidjson-1.26}/benchmarks/test_benchmark.py +0 -0
  24. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/Makefile +0 -0
  25. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/api.rst +0 -0
  26. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/benchmarks-tables.rst +0 -0
  27. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/benchmarks.rst +0 -0
  28. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/conf.py +0 -0
  29. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/decoder.rst +0 -0
  30. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/dump.rst +0 -0
  31. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/dumps.rst +0 -0
  32. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/encoder.rst +0 -0
  33. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/index.rst +0 -0
  34. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/load.rst +0 -0
  35. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/quickstart.rst +0 -0
  36. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/rawjson.rst +0 -0
  37. {python_rapidjson-1.25 → python_rapidjson-1.26}/docs/validator.rst +0 -0
  38. {python_rapidjson-1.25 → python_rapidjson-1.26}/python_rapidjson.egg-info/SOURCES.txt +0 -0
  39. {python_rapidjson-1.25 → python_rapidjson-1.26}/python_rapidjson.egg-info/dependency_links.txt +0 -0
  40. {python_rapidjson-1.25 → python_rapidjson-1.26}/python_rapidjson.egg-info/top_level.txt +0 -0
  41. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/allocators.h +0 -0
  42. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/cursorstreamwrapper.h +0 -0
  43. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/document.h +0 -0
  44. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/encodedstream.h +0 -0
  45. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/encodings.h +0 -0
  46. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/error/en.h +0 -0
  47. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/error/error.h +0 -0
  48. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/filereadstream.h +0 -0
  49. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/filewritestream.h +0 -0
  50. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/fwd.h +0 -0
  51. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/biginteger.h +0 -0
  52. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/clzll.h +0 -0
  53. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/diyfp.h +0 -0
  54. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/dtoa.h +0 -0
  55. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/ieee754.h +0 -0
  56. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/itoa.h +0 -0
  57. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/meta.h +0 -0
  58. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/pow10.h +0 -0
  59. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/regex.h +0 -0
  60. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/stack.h +0 -0
  61. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/strfunc.h +0 -0
  62. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/strtod.h +0 -0
  63. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/internal/swap.h +0 -0
  64. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/istreamwrapper.h +0 -0
  65. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/memorybuffer.h +0 -0
  66. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/memorystream.h +0 -0
  67. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/msinttypes/inttypes.h +0 -0
  68. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/msinttypes/stdint.h +0 -0
  69. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/ostreamwrapper.h +0 -0
  70. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/pointer.h +0 -0
  71. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/prettywriter.h +0 -0
  72. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/rapidjson.h +0 -0
  73. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/reader.h +0 -0
  74. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/schema.h +0 -0
  75. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/stream.h +0 -0
  76. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/stringbuffer.h +0 -0
  77. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/uri.h +0 -0
  78. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/include/rapidjson/writer.h +0 -0
  79. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/license.txt +0 -0
  80. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson/readme.md +0 -0
  81. {python_rapidjson-1.25 → python_rapidjson-1.26}/rapidjson_exact_version.txt +0 -0
  82. {python_rapidjson-1.25 → python_rapidjson-1.26}/setup.cfg +0 -0
  83. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/conftest.py +0 -0
  84. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_base_types.py +0 -0
  85. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_circular.py +0 -0
  86. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_dict_subclass.py +0 -0
  87. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_enum.py +0 -0
  88. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_pass1.py +0 -0
  89. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_pass2.py +0 -0
  90. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_pass3.py +0 -0
  91. {python_rapidjson-1.25 → python_rapidjson-1.26}/tests/test_rawjson.py +0 -0
  92. {python_rapidjson-1.25 → python_rapidjson-1.26}/tox.ini +0 -0
  93. {python_rapidjson-1.25 → python_rapidjson-1.26}/typings/rapidjson/__init__.pyi +0 -0
@@ -1,6 +1,52 @@
1
1
  Changes
2
2
  -------
3
3
 
4
+ 1.26 (2026-11-01)
5
+ ~~~~~~~~~~~~~~~~~
6
+
7
+ * Add Windows ARM64 build (`PR #242`__), thanks to Nikhil Dabas
8
+
9
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/242
10
+
11
+ * Fix parse_mode flags without native or NaN number modes (`PR #243`__), thanks to Ryan
12
+ Duguid
13
+
14
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/243
15
+
16
+ * Validate number_mode in load and Decoder (`PR #244`__), thanks to Ryan Duguid
17
+
18
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/244
19
+
20
+ * Reject JSON input truncated at an embedded NUL (`PR #245`__), thanks to Michał Furgała
21
+
22
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/245
23
+
24
+ * Reject oversized datetime, UUID and parse mode values before narrowing them to
25
+ their internal representations (`PR #248`__), thanks to Luochenchen
26
+
27
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/248
28
+
29
+ * Generate wheels for riscv4 (`PR #249`__), thanks to Julien Stephan
30
+
31
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/249
32
+
33
+ * Reject embedded NUL truncation in ``Validator`` schemas and documents (`PR #250`__),
34
+ thanks to Jaden Fix
35
+
36
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/250
37
+
38
+ * Preserve the numeric locale when serializing Unix timestamps (`PR #253`__), thanks to
39
+ Parijat Biswas
40
+
41
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/253
42
+
43
+ * Normalize signed, signaling and payload-bearing Decimal NaNs to the supported
44
+ ``NaN`` token when non-finite numbers are enabled, so encoded output remains
45
+ readable by the decoder (`PR #255`__), thanks to Rupayon Haldar
46
+
47
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/255
48
+
49
+
4
50
  1.25 (2026-09-06)
5
51
  ~~~~~~~~~~~~~~~~~
6
52
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-rapidjson
3
- Version: 1.25
3
+ Version: 1.26
4
4
  Summary: Python wrapper around rapidjson
5
5
  Home-page: https://github.com/python-rapidjson/python-rapidjson
6
6
  Author: Ken Robbins
@@ -188,6 +188,52 @@ __ https://python-rapidjson.readthedocs.io/en/latest/quickstart.html#incompatibi
188
188
  Changes
189
189
  -------
190
190
 
191
+ 1.26 (2026-11-01)
192
+ ~~~~~~~~~~~~~~~~~
193
+
194
+ * Add Windows ARM64 build (`PR #242`__), thanks to Nikhil Dabas
195
+
196
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/242
197
+
198
+ * Fix parse_mode flags without native or NaN number modes (`PR #243`__), thanks to Ryan
199
+ Duguid
200
+
201
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/243
202
+
203
+ * Validate number_mode in load and Decoder (`PR #244`__), thanks to Ryan Duguid
204
+
205
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/244
206
+
207
+ * Reject JSON input truncated at an embedded NUL (`PR #245`__), thanks to Michał Furgała
208
+
209
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/245
210
+
211
+ * Reject oversized datetime, UUID and parse mode values before narrowing them to
212
+ their internal representations (`PR #248`__), thanks to Luochenchen
213
+
214
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/248
215
+
216
+ * Generate wheels for riscv4 (`PR #249`__), thanks to Julien Stephan
217
+
218
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/249
219
+
220
+ * Reject embedded NUL truncation in ``Validator`` schemas and documents (`PR #250`__),
221
+ thanks to Jaden Fix
222
+
223
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/250
224
+
225
+ * Preserve the numeric locale when serializing Unix timestamps (`PR #253`__), thanks to
226
+ Parijat Biswas
227
+
228
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/253
229
+
230
+ * Normalize signed, signaling and payload-bearing Decimal NaNs to the supported
231
+ ``NaN`` token when non-finite numbers are enabled, so encoded output remains
232
+ readable by the decoder (`PR #255`__), thanks to Rupayon Haldar
233
+
234
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/255
235
+
236
+
191
237
  1.25 (2026-09-06)
192
238
  ~~~~~~~~~~~~~~~~~
193
239
 
@@ -1,6 +1,52 @@
1
1
  Changes
2
2
  -------
3
3
 
4
+ 1.26 (2026-11-01)
5
+ ~~~~~~~~~~~~~~~~~
6
+
7
+ * Add Windows ARM64 build (`PR #242`__), thanks to Nikhil Dabas
8
+
9
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/242
10
+
11
+ * Fix parse_mode flags without native or NaN number modes (`PR #243`__), thanks to Ryan
12
+ Duguid
13
+
14
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/243
15
+
16
+ * Validate number_mode in load and Decoder (`PR #244`__), thanks to Ryan Duguid
17
+
18
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/244
19
+
20
+ * Reject JSON input truncated at an embedded NUL (`PR #245`__), thanks to Michał Furgała
21
+
22
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/245
23
+
24
+ * Reject oversized datetime, UUID and parse mode values before narrowing them to
25
+ their internal representations (`PR #248`__), thanks to Luochenchen
26
+
27
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/248
28
+
29
+ * Generate wheels for riscv4 (`PR #249`__), thanks to Julien Stephan
30
+
31
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/249
32
+
33
+ * Reject embedded NUL truncation in ``Validator`` schemas and documents (`PR #250`__),
34
+ thanks to Jaden Fix
35
+
36
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/250
37
+
38
+ * Preserve the numeric locale when serializing Unix timestamps (`PR #253`__), thanks to
39
+ Parijat Biswas
40
+
41
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/253
42
+
43
+ * Normalize signed, signaling and payload-bearing Decimal NaNs to the supported
44
+ ``NaN`` token when non-finite numbers are enabled, so encoded output remains
45
+ readable by the decoder (`PR #255`__), thanks to Rupayon Haldar
46
+
47
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/255
48
+
49
+
4
50
  1.25 (2026-09-06)
5
51
  ~~~~~~~~~~~~~~~~~
6
52
 
@@ -113,8 +113,16 @@
113
113
 
114
114
  >>> loads('123456789012345678901234567890')
115
115
  123456789012345678901234567890
116
- >>> loads('123456789012345678901234567890', number_mode=NM_NATIVE)
117
- 1.2345678901234566e+29
116
+ >>> import math
117
+ >>> native = loads('123456789012345678901234567890', number_mode=NM_NATIVE)
118
+ >>> isinstance(native, float)
119
+ True
120
+ >>> math.isclose(native, float(123456789012345678901234567890),
121
+ ... rel_tol=0, abs_tol=math.ulp(native))
122
+ True
123
+
124
+ The final bit of the rounded ``double`` can differ between platforms; the example
125
+ permits a difference of one unit in the last place while requiring a ``float``.
118
126
 
119
127
  These flags can be combined together:
120
128
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-rapidjson
3
- Version: 1.25
3
+ Version: 1.26
4
4
  Summary: Python wrapper around rapidjson
5
5
  Home-page: https://github.com/python-rapidjson/python-rapidjson
6
6
  Author: Ken Robbins
@@ -188,6 +188,52 @@ __ https://python-rapidjson.readthedocs.io/en/latest/quickstart.html#incompatibi
188
188
  Changes
189
189
  -------
190
190
 
191
+ 1.26 (2026-11-01)
192
+ ~~~~~~~~~~~~~~~~~
193
+
194
+ * Add Windows ARM64 build (`PR #242`__), thanks to Nikhil Dabas
195
+
196
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/242
197
+
198
+ * Fix parse_mode flags without native or NaN number modes (`PR #243`__), thanks to Ryan
199
+ Duguid
200
+
201
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/243
202
+
203
+ * Validate number_mode in load and Decoder (`PR #244`__), thanks to Ryan Duguid
204
+
205
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/244
206
+
207
+ * Reject JSON input truncated at an embedded NUL (`PR #245`__), thanks to Michał Furgała
208
+
209
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/245
210
+
211
+ * Reject oversized datetime, UUID and parse mode values before narrowing them to
212
+ their internal representations (`PR #248`__), thanks to Luochenchen
213
+
214
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/248
215
+
216
+ * Generate wheels for riscv4 (`PR #249`__), thanks to Julien Stephan
217
+
218
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/249
219
+
220
+ * Reject embedded NUL truncation in ``Validator`` schemas and documents (`PR #250`__),
221
+ thanks to Jaden Fix
222
+
223
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/250
224
+
225
+ * Preserve the numeric locale when serializing Unix timestamps (`PR #253`__), thanks to
226
+ Parijat Biswas
227
+
228
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/253
229
+
230
+ * Normalize signed, signaling and payload-bearing Decimal NaNs to the supported
231
+ ``NaN`` token when non-finite numbers are enabled, so encoded output remains
232
+ readable by the decoder (`PR #255`__), thanks to Rupayon Haldar
233
+
234
+ __ https://github.com/python-rapidjson/python-rapidjson/pull/255
235
+
236
+
191
237
  1.25 (2026-09-06)
192
238
  ~~~~~~~~~~~~~~~~~
193
239
 
@@ -6,8 +6,6 @@
6
6
  // :Copyright: © 2015-2026 Lele Gaifax
7
7
  //
8
8
 
9
- #include <locale.h>
10
-
11
9
  #include <Python.h>
12
10
  #include <datetime.h>
13
11
  #include <structmember.h>
@@ -113,7 +111,7 @@ datetime_mode_format(unsigned mode) {
113
111
 
114
112
 
115
113
  static inline bool
116
- valid_datetime_mode(int mode) {
114
+ valid_datetime_mode(long mode) {
117
115
  int format = datetime_mode_format(mode);
118
116
  return (mode >= 0 && mode < DM_MAX
119
117
  && (format <= DM_UNIX_TIME)
@@ -276,6 +274,10 @@ public:
276
274
  return offset + pos;
277
275
  }
278
276
 
277
+ bool IsEnd() const {
278
+ return eof;
279
+ }
280
+
279
281
  void Flush() {
280
282
  assert(false);
281
283
  }
@@ -1769,35 +1771,19 @@ load(PyObject* self, PyObject* args, PyObject* kwargs)
1769
1771
  }
1770
1772
  }
1771
1773
 
1772
- if (numberModeObj) {
1773
- if (numberModeObj == Py_None) {
1774
- numberMode = NM_NONE;
1775
- } else if (PyLong_Check(numberModeObj)) {
1776
- int mode = PyLong_AsLong(numberModeObj);
1777
- if (mode < 0 || mode >= NM_MAX) {
1778
- PyErr_SetString(PyExc_ValueError, "Invalid number_mode");
1779
- return NULL;
1780
- }
1781
- numberMode = (unsigned) mode;
1782
- if (numberMode & NM_DECIMAL && numberMode & NM_NATIVE) {
1783
- PyErr_SetString(PyExc_ValueError,
1784
- "Combining NM_NATIVE with NM_DECIMAL is not supported");
1785
- return NULL;
1786
- }
1787
- }
1788
- }
1789
- if (allowNan != -1) {
1790
- if (allowNan)
1791
- numberMode |= NM_NAN;
1792
- else
1793
- numberMode &= ~NM_NAN;
1774
+ if (!accept_number_mode_arg(numberModeObj, allowNan, numberMode))
1775
+ return NULL;
1776
+ if (numberMode & NM_DECIMAL && numberMode & NM_NATIVE) {
1777
+ PyErr_SetString(PyExc_ValueError,
1778
+ "Combining NM_NATIVE with NM_DECIMAL is not supported");
1779
+ return NULL;
1794
1780
  }
1795
1781
 
1796
1782
  if (datetimeModeObj) {
1797
1783
  if (datetimeModeObj == Py_None) {
1798
1784
  datetimeMode = DM_NONE;
1799
1785
  } else if (PyLong_Check(datetimeModeObj)) {
1800
- int mode = PyLong_AsLong(datetimeModeObj);
1786
+ long mode = PyLong_AsLong(datetimeModeObj);
1801
1787
  if (!valid_datetime_mode(mode)) {
1802
1788
  PyErr_SetString(PyExc_ValueError, "Invalid datetime_mode");
1803
1789
  return NULL;
@@ -1820,7 +1806,7 @@ load(PyObject* self, PyObject* args, PyObject* kwargs)
1820
1806
  if (uuidModeObj == Py_None) {
1821
1807
  uuidMode = UM_NONE;
1822
1808
  } else if (PyLong_Check(uuidModeObj)) {
1823
- int mode = PyLong_AsLong(uuidModeObj);
1809
+ long mode = PyLong_AsLong(uuidModeObj);
1824
1810
  if (mode < 0 || mode >= UM_MAX) {
1825
1811
  PyErr_SetString(PyExc_ValueError, "Invalid uuid_mode");
1826
1812
  return NULL;
@@ -1837,7 +1823,7 @@ load(PyObject* self, PyObject* args, PyObject* kwargs)
1837
1823
  if (parseModeObj == Py_None) {
1838
1824
  parseMode = PM_NONE;
1839
1825
  } else if (PyLong_Check(parseModeObj)) {
1840
- int mode = PyLong_AsLong(parseModeObj);
1826
+ long mode = PyLong_AsLong(parseModeObj);
1841
1827
  if (mode < 0 || mode >= PM_MAX) {
1842
1828
  PyErr_SetString(PyExc_ValueError, "Invalid parse_mode");
1843
1829
  return NULL;
@@ -2029,12 +2015,17 @@ static PyTypeObject Decoder_Type = {
2029
2015
  if (parseMode & PM_COMMENTS) { \
2030
2016
  r.Parse<f | \
2031
2017
  kParseCommentsFlag | \
2032
- kParseNumbersAsStringsFlag>(s, h); \
2018
+ kParseNumbersAsStringsFlag | \
2019
+ kParseTrailingCommasFlag>(s, h); \
2033
2020
  } else { \
2034
2021
  r.Parse<f | \
2035
2022
  kParseNumbersAsStringsFlag | \
2036
2023
  kParseTrailingCommasFlag>(s, h); \
2037
2024
  } \
2025
+ } else if (parseMode & PM_COMMENTS) { \
2026
+ r.Parse<f | \
2027
+ kParseNumbersAsStringsFlag | \
2028
+ kParseCommentsFlag>(s, h); \
2038
2029
  } else { \
2039
2030
  r.Parse<f | kParseNumbersAsStringsFlag>(s, h); \
2040
2031
  } \
@@ -2049,6 +2040,7 @@ do_decode(PyObject* decoder, const char* jsonStr, Py_ssize_t jsonStrLen,
2049
2040
  {
2050
2041
  PyHandler handler(decoder, objectHook, datetimeMode, uuidMode, numberMode);
2051
2042
  Reader reader;
2043
+ ParseResult result;
2052
2044
 
2053
2045
  if (jsonStr != NULL) {
2054
2046
  char* jsonStrCopy = (char*) PyMem_Malloc(sizeof(char) * (jsonStrLen+1));
@@ -2062,15 +2054,23 @@ do_decode(PyObject* decoder, const char* jsonStr, Py_ssize_t jsonStrLen,
2062
2054
 
2063
2055
  DECODE(reader, kParseInsituFlag, ss, handler);
2064
2056
 
2057
+ result.Set(reader.GetParseErrorCode(), reader.GetErrorOffset());
2058
+ if (!result.IsError() && ss.Tell() < (size_t) jsonStrLen)
2059
+ result.Set(kParseErrorDocumentRootNotSingular, ss.Tell());
2060
+
2065
2061
  PyMem_Free(jsonStrCopy);
2066
2062
  } else {
2067
2063
  PyReadStreamWrapper sw(jsonStream, chunkSize);
2068
2064
 
2069
2065
  DECODE(reader, kParseNoFlags, sw, handler);
2066
+
2067
+ result.Set(reader.GetParseErrorCode(), reader.GetErrorOffset());
2068
+ if (!result.IsError() && !sw.IsEnd())
2069
+ result.Set(kParseErrorDocumentRootNotSingular, sw.Tell());
2070
2070
  }
2071
2071
 
2072
- if (reader.HasParseError()) {
2073
- size_t offset = reader.GetErrorOffset();
2072
+ if (result.IsError()) {
2073
+ size_t offset = result.Offset();
2074
2074
 
2075
2075
  if (PyErr_Occurred()) {
2076
2076
  PyObject* etype;
@@ -2092,7 +2092,7 @@ do_decode(PyObject* decoder, const char* jsonStr, Py_ssize_t jsonStrLen,
2092
2092
  }
2093
2093
  else
2094
2094
  PyErr_Format(decode_error, "Parse error at offset %zu: %s",
2095
- offset, GetParseError_En(reader.GetParseErrorCode()));
2095
+ offset, GetParseError_En(result.Code()));
2096
2096
 
2097
2097
  Py_XDECREF(handler.root);
2098
2098
  return NULL;
@@ -2209,29 +2209,19 @@ decoder_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
2209
2209
  &parseModeObj))
2210
2210
  return NULL;
2211
2211
 
2212
- if (numberModeObj) {
2213
- if (numberModeObj == Py_None) {
2214
- numberMode = NM_NONE;
2215
- } else if (PyLong_Check(numberModeObj)) {
2216
- int mode = PyLong_AsLong(numberModeObj);
2217
- if (mode < 0 || mode >= NM_MAX) {
2218
- PyErr_SetString(PyExc_ValueError, "Invalid number_mode");
2219
- return NULL;
2220
- }
2221
- numberMode = (unsigned) mode;
2222
- if (numberMode & NM_DECIMAL && numberMode & NM_NATIVE) {
2223
- PyErr_SetString(PyExc_ValueError,
2224
- "Combining NM_NATIVE with NM_DECIMAL is not supported");
2225
- return NULL;
2226
- }
2227
- }
2212
+ if (!accept_number_mode_arg(numberModeObj, -1, numberMode))
2213
+ return NULL;
2214
+ if (numberMode & NM_DECIMAL && numberMode & NM_NATIVE) {
2215
+ PyErr_SetString(PyExc_ValueError,
2216
+ "Combining NM_NATIVE with NM_DECIMAL is not supported");
2217
+ return NULL;
2228
2218
  }
2229
2219
 
2230
2220
  if (datetimeModeObj) {
2231
2221
  if (datetimeModeObj == Py_None) {
2232
2222
  datetimeMode = DM_NONE;
2233
2223
  } else if (PyLong_Check(datetimeModeObj)) {
2234
- int mode = PyLong_AsLong(datetimeModeObj);
2224
+ long mode = PyLong_AsLong(datetimeModeObj);
2235
2225
  if (!valid_datetime_mode(mode)) {
2236
2226
  PyErr_SetString(PyExc_ValueError, "Invalid datetime_mode");
2237
2227
  return NULL;
@@ -2254,7 +2244,7 @@ decoder_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
2254
2244
  if (uuidModeObj == Py_None) {
2255
2245
  uuidMode = UM_NONE;
2256
2246
  } else if (PyLong_Check(uuidModeObj)) {
2257
- int mode = PyLong_AsLong(uuidModeObj);
2247
+ long mode = PyLong_AsLong(uuidModeObj);
2258
2248
  if (mode < 0 || mode >= UM_MAX) {
2259
2249
  PyErr_SetString(PyExc_ValueError, "Invalid uuid_mode");
2260
2250
  return NULL;
@@ -2271,7 +2261,7 @@ decoder_new(PyTypeObject* type, PyObject* args, PyObject* kwargs)
2271
2261
  if (parseModeObj == Py_None) {
2272
2262
  parseMode = PM_NONE;
2273
2263
  } else if (PyLong_Check(parseModeObj)) {
2274
- int mode = PyLong_AsLong(parseModeObj);
2264
+ long mode = PyLong_AsLong(parseModeObj);
2275
2265
  if (mode < 0 || mode >= PM_MAX) {
2276
2266
  PyErr_SetString(PyExc_ValueError, "Invalid parse_mode");
2277
2267
  return NULL;
@@ -2395,6 +2385,19 @@ dumps_internal(
2395
2385
  }
2396
2386
  }
2397
2387
 
2388
+ if (numberMode & NM_NAN) {
2389
+ PyObject* is_nan = PyObject_CallMethodObjArgs(object, is_nan_name,
2390
+ NULL);
2391
+ if (is_nan == NULL)
2392
+ return false;
2393
+ bool nan = is_nan == Py_True;
2394
+ Py_DECREF(is_nan);
2395
+ if (nan) {
2396
+ writer->RawValue("NaN", 3, kNumberType);
2397
+ return PyErr_Occurred() ? false : true;
2398
+ }
2399
+ }
2400
+
2398
2401
  PyObject* decStrObj = PyObject_Str(object);
2399
2402
  if (decStrObj == NULL)
2400
2403
  return false;
@@ -2813,30 +2816,18 @@ dumps_internal(
2813
2816
  if (datetimeMode & DM_ONLY_SECONDS) {
2814
2817
  writer->Int64((int64_t) timestamp);
2815
2818
  } else {
2816
- // Writer.SetMaxDecimalPlaces(6) truncates the value,
2817
- // so for example 1514893636.276703 would come out as
2818
- // 1514893636.276702, because its exact double value is
2819
- // 1514893636.2767028808593750000000000...
2820
- char tsStr[12 + 1 + 6 + 1];
2821
-
2822
- // Temporarily switch to a POSIX locale, in case the outer world is
2823
- // configured differently: by chance I got one doctest failure, and I
2824
- // can only imagine that recent Sphinx (that is, 4.2+) initializes the
2825
- // locale to something that implies a decimal separator different from
2826
- // a dot ".", say a comma "," when LANG is "it_IT"... not the best
2827
- // thing to do when emitting JSON!
2828
-
2829
- const char* locale = setlocale(LC_NUMERIC, NULL);
2830
- setlocale(LC_NUMERIC, "C");
2831
-
2832
- int size = snprintf(tsStr, 12 + 1 + 6, "%.6f", timestamp);
2833
-
2834
- setlocale(LC_NUMERIC, locale);
2835
-
2836
- // Remove trailing 0s
2819
+ // Keep microsecond precision without changing the process locale.
2820
+ char* tsStr = PyOS_double_to_string(timestamp, 'f', 6, 0, NULL);
2821
+ if (tsStr == NULL) {
2822
+ Py_XDECREF(asUTC);
2823
+ return false;
2824
+ }
2825
+ size_t size = strlen(tsStr);
2826
+ // Keep one fractional digit, as before.
2837
2827
  while (tsStr[size-2] != '.' && tsStr[size-1] == '0')
2838
2828
  size--;
2839
2829
  writer->RawValue(tsStr, size, kNumberType);
2830
+ PyMem_Free(tsStr);
2840
2831
  }
2841
2832
  } else {
2842
2833
  hour = PyDateTime_TIME_GET_HOUR(dtObject);
@@ -2900,25 +2891,16 @@ dumps_internal(
2900
2891
  if (datetimeMode & DM_ONLY_SECONDS) {
2901
2892
  writer->Int64((int64_t) timestamp);
2902
2893
  } else {
2903
- // Writer.SetMaxDecimalPlaces(6) truncates the value,
2904
- // so for example 1514893636.276703 would come out as
2905
- // 1514893636.276702, because its exact double value is
2906
- // 1514893636.2767028808593750000000000...
2907
- char tsStr[12 + 1 + 6 + 1];
2908
-
2909
- // Temporarily switch to a POSIX locale, in case the outer
2910
- // world is configured differently, see above
2911
-
2912
- const char* locale = setlocale(LC_NUMERIC, NULL);
2913
- setlocale(LC_NUMERIC, "C");
2914
-
2915
- setlocale(LC_NUMERIC, locale);
2916
-
2917
- int size = snprintf(tsStr, 12 + 1 + 6, "%.6f", timestamp);
2918
- // Remove trailing 0s
2894
+ // Keep microsecond precision without changing the process locale.
2895
+ char* tsStr = PyOS_double_to_string(timestamp, 'f', 6, 0, NULL);
2896
+ if (tsStr == NULL)
2897
+ return false;
2898
+ size_t size = strlen(tsStr);
2899
+ // Keep one fractional digit, as before.
2919
2900
  while (tsStr[size-2] != '.' && tsStr[size-1] == '0')
2920
2901
  size--;
2921
2902
  writer->RawValue(tsStr, size, kNumberType);
2903
+ PyMem_Free(tsStr);
2922
2904
  }
2923
2905
  }
2924
2906
  } else if (uuidMode != UM_NONE
@@ -3724,17 +3706,18 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3724
3706
  return NULL;
3725
3707
 
3726
3708
  const char* jsonStr;
3709
+ Py_ssize_t jsonStrLen;
3727
3710
  PyObject* asUnicode = NULL;
3728
3711
 
3729
3712
  if (PyUnicode_Check(jsonObject)) {
3730
- jsonStr = PyUnicode_AsUTF8(jsonObject);
3713
+ jsonStr = PyUnicode_AsUTF8AndSize(jsonObject, &jsonStrLen);
3731
3714
  if (jsonStr == NULL)
3732
3715
  return NULL;
3733
3716
  } else if (PyBytes_Check(jsonObject) || PyByteArray_Check(jsonObject)) {
3734
3717
  asUnicode = PyUnicode_FromEncodedObject(jsonObject, "utf-8", NULL);
3735
3718
  if (asUnicode == NULL)
3736
3719
  return NULL;
3737
- jsonStr = PyUnicode_AsUTF8(asUnicode);
3720
+ jsonStr = PyUnicode_AsUTF8AndSize(asUnicode, &jsonStrLen);
3738
3721
  if (jsonStr == NULL) {
3739
3722
  Py_DECREF(asUnicode);
3740
3723
  return NULL;
@@ -3749,7 +3732,8 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3749
3732
  bool error;
3750
3733
 
3751
3734
  Py_BEGIN_ALLOW_THREADS
3752
- error = d.Parse(jsonStr).HasParseError();
3735
+ StringStream stream(jsonStr);
3736
+ error = d.ParseStream(stream).HasParseError() || stream.Tell() < (size_t) jsonStrLen;
3753
3737
  Py_END_ALLOW_THREADS
3754
3738
 
3755
3739
  if (error) {
@@ -3811,17 +3795,18 @@ static PyObject* validator_new(PyTypeObject* type, PyObject* args, PyObject* kwa
3811
3795
  return NULL;
3812
3796
 
3813
3797
  const char* jsonStr;
3798
+ Py_ssize_t jsonStrLen;
3814
3799
  PyObject* asUnicode = NULL;
3815
3800
 
3816
3801
  if (PyUnicode_Check(jsonObject)) {
3817
- jsonStr = PyUnicode_AsUTF8(jsonObject);
3802
+ jsonStr = PyUnicode_AsUTF8AndSize(jsonObject, &jsonStrLen);
3818
3803
  if (jsonStr == NULL)
3819
3804
  return NULL;
3820
3805
  } else if (PyBytes_Check(jsonObject) || PyByteArray_Check(jsonObject)) {
3821
3806
  asUnicode = PyUnicode_FromEncodedObject(jsonObject, "utf-8", NULL);
3822
3807
  if (asUnicode == NULL)
3823
3808
  return NULL;
3824
- jsonStr = PyUnicode_AsUTF8(asUnicode);
3809
+ jsonStr = PyUnicode_AsUTF8AndSize(asUnicode, &jsonStrLen);
3825
3810
  if (jsonStr == NULL) {
3826
3811
  Py_DECREF(asUnicode);
3827
3812
  return NULL;
@@ -3836,7 +3821,8 @@ static PyObject* validator_new(PyTypeObject* type, PyObject* args, PyObject* kwa
3836
3821
  bool error;
3837
3822
 
3838
3823
  Py_BEGIN_ALLOW_THREADS
3839
- error = d.Parse(jsonStr).HasParseError();
3824
+ StringStream stream(jsonStr);
3825
+ error = d.ParseStream(stream).HasParseError() || stream.Tell() < (size_t) jsonStrLen;
3840
3826
  Py_END_ALLOW_THREADS
3841
3827
 
3842
3828
  if (asUnicode != NULL)
@@ -7,8 +7,8 @@
7
7
  # :Copyright: © 2015, 2017, 2018, 2021, 2022, 2023, 2024, 2025, 2026 Lele Gaifax
8
8
  #
9
9
 
10
- mypy==2.3.1
11
- pytest==9.1.1
12
- pytz==2022.2
13
- sphinx==8.2.3
10
+ mypy==2.4.1
11
+ pytest==9.2.0
12
+ pytz==2026.2
13
+ sphinx==9.2.0
14
14
  typing-extensions==4.16.0
@@ -11,12 +11,12 @@
11
11
  setuptools
12
12
 
13
13
  # Needed by make release
14
- bump-my-version==1.5.1
15
- readme-renderer==45.0
14
+ bump-my-version==1.7.0
15
+ readme-renderer==46.0
16
16
  twine==7.0.0
17
17
 
18
18
  # Needed by make benchmarks-*
19
- pytest-benchmark==5.2.3
19
+ pytest-benchmark==5.3.1
20
20
 
21
21
  pysimdjson==7.0.2
22
22
  orjson==3.12.0
@@ -33,7 +33,7 @@ else:
33
33
  " want to report the issue.")
34
34
 
35
35
  # Automatically updated by bump-my-version at release time
36
- VERSION = '1.25'
36
+ VERSION = '1.26'
37
37
 
38
38
  with open('README.rst', encoding='utf-8') as f:
39
39
  LONG_DESCRIPTION = f.read()
@@ -14,6 +14,29 @@ import pytest
14
14
  import rapidjson as rj
15
15
 
16
16
 
17
+ @pytest.mark.parametrize('value', [
18
+ 'NaN', '-NaN', '+NaN', 'sNaN', '-sNaN', '+sNaN', 'NaN123', '-NaN123',
19
+ ])
20
+ @pytest.mark.parametrize('use_encoder', [False, True])
21
+ def test_decimal_nan_tokens(value, use_encoder):
22
+ number = Decimal(value)
23
+ mode = rj.NM_DECIMAL | rj.NM_NAN
24
+ encode = rj.Encoder(number_mode=mode) if use_encoder else (
25
+ lambda obj: rj.dumps(obj, number_mode=mode)
26
+ )
27
+ assert encode(number) == 'NaN'
28
+ encoded = encode({'value': [number]})
29
+ decoded = rj.loads(encoded, number_mode=mode)
30
+ assert decoded['value'][0].is_nan()
31
+
32
+ if use_encoder:
33
+ strict_encode = rj.Encoder(number_mode=rj.NM_DECIMAL)
34
+ else:
35
+ strict_encode = lambda obj: rj.dumps(obj, number_mode=rj.NM_DECIMAL)
36
+ with pytest.raises(ValueError, match='Out of range decimal'):
37
+ strict_encode(number)
38
+
39
+
17
40
  def test_infinity_f():
18
41
  inf = float("inf")
19
42