python-rapidjson 1.18__tar.gz → 1.20__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 (95) hide show
  1. {python-rapidjson-1.18 → python_rapidjson-1.20}/CHANGES.rst +22 -0
  2. {python-rapidjson-1.18 → python_rapidjson-1.20}/PKG-INFO +23 -1
  3. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/changes.rst +22 -0
  4. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/validator.rst +3 -3
  5. {python-rapidjson-1.18 → python_rapidjson-1.20}/python_rapidjson.egg-info/PKG-INFO +23 -1
  6. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson.cpp +42 -20
  7. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_base_types.py +14 -1
  8. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_float.py +13 -1
  9. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_validator.py +5 -3
  10. {python-rapidjson-1.18 → python_rapidjson-1.20}/typings/rapidjson/__init__.pyi +4 -4
  11. python_rapidjson-1.20/version.txt +1 -0
  12. python-rapidjson-1.18/version.txt +0 -1
  13. {python-rapidjson-1.18 → python_rapidjson-1.20}/.dir-locals.el +0 -0
  14. {python-rapidjson-1.18 → python_rapidjson-1.20}/LICENSE +0 -0
  15. {python-rapidjson-1.18 → python_rapidjson-1.20}/MANIFEST.in +0 -0
  16. {python-rapidjson-1.18 → python_rapidjson-1.20}/README.rst +0 -0
  17. {python-rapidjson-1.18 → python_rapidjson-1.20}/benchmarks/conftest.py +0 -0
  18. {python-rapidjson-1.18 → python_rapidjson-1.20}/benchmarks/tablize.py +0 -0
  19. {python-rapidjson-1.18 → python_rapidjson-1.20}/benchmarks/test_benchmark.py +0 -0
  20. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/Makefile +0 -0
  21. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/api.rst +0 -0
  22. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/benchmarks-tables.rst +0 -0
  23. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/benchmarks.rst +0 -0
  24. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/conf.py +0 -0
  25. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/decoder.rst +0 -0
  26. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/dump.rst +0 -0
  27. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/dumps.rst +0 -0
  28. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/encoder.rst +0 -0
  29. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/index.rst +0 -0
  30. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/load.rst +0 -0
  31. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/loads.rst +0 -0
  32. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/quickstart.rst +0 -0
  33. {python-rapidjson-1.18 → python_rapidjson-1.20}/docs/rawjson.rst +0 -0
  34. {python-rapidjson-1.18 → python_rapidjson-1.20}/python_rapidjson.egg-info/SOURCES.txt +0 -0
  35. {python-rapidjson-1.18 → python_rapidjson-1.20}/python_rapidjson.egg-info/dependency_links.txt +0 -0
  36. {python-rapidjson-1.18 → python_rapidjson-1.20}/python_rapidjson.egg-info/top_level.txt +0 -0
  37. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/allocators.h +0 -0
  38. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/cursorstreamwrapper.h +0 -0
  39. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/document.h +0 -0
  40. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/encodedstream.h +0 -0
  41. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/encodings.h +0 -0
  42. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/error/en.h +0 -0
  43. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/error/error.h +0 -0
  44. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/filereadstream.h +0 -0
  45. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/filewritestream.h +0 -0
  46. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/fwd.h +0 -0
  47. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/biginteger.h +0 -0
  48. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/clzll.h +0 -0
  49. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/diyfp.h +0 -0
  50. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/dtoa.h +0 -0
  51. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/ieee754.h +0 -0
  52. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/itoa.h +0 -0
  53. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/meta.h +0 -0
  54. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/pow10.h +0 -0
  55. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/regex.h +0 -0
  56. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/stack.h +0 -0
  57. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/strfunc.h +0 -0
  58. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/strtod.h +0 -0
  59. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/internal/swap.h +0 -0
  60. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/istreamwrapper.h +0 -0
  61. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/memorybuffer.h +0 -0
  62. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/memorystream.h +0 -0
  63. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/msinttypes/inttypes.h +0 -0
  64. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/msinttypes/stdint.h +0 -0
  65. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/ostreamwrapper.h +0 -0
  66. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/pointer.h +0 -0
  67. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/prettywriter.h +0 -0
  68. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/rapidjson.h +0 -0
  69. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/reader.h +0 -0
  70. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/schema.h +0 -0
  71. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/stream.h +0 -0
  72. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/stringbuffer.h +0 -0
  73. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/uri.h +0 -0
  74. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/include/rapidjson/writer.h +0 -0
  75. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/license.txt +0 -0
  76. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson/readme.md +0 -0
  77. {python-rapidjson-1.18 → python_rapidjson-1.20}/rapidjson_exact_version.txt +0 -0
  78. {python-rapidjson-1.18 → python_rapidjson-1.20}/requirements-test.txt +0 -0
  79. {python-rapidjson-1.18 → python_rapidjson-1.20}/requirements.txt +0 -0
  80. {python-rapidjson-1.18 → python_rapidjson-1.20}/setup.cfg +0 -0
  81. {python-rapidjson-1.18 → python_rapidjson-1.20}/setup.py +0 -0
  82. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/conftest.py +0 -0
  83. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_circular.py +0 -0
  84. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_dict_subclass.py +0 -0
  85. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_enum.py +0 -0
  86. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_memory_leaks.py +0 -0
  87. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_params.py +0 -0
  88. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_pass1.py +0 -0
  89. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_pass2.py +0 -0
  90. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_pass3.py +0 -0
  91. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_rawjson.py +0 -0
  92. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_refs_count.py +0 -0
  93. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_streams.py +0 -0
  94. {python-rapidjson-1.18 → python_rapidjson-1.20}/tests/test_unicode.py +0 -0
  95. {python-rapidjson-1.18 → python_rapidjson-1.20}/tox.ini +0 -0
@@ -1,6 +1,28 @@
1
1
  Changes
2
2
  -------
3
3
 
4
+ 1.20 (2024-08-05)
5
+ ~~~~~~~~~~~~~~~~~
6
+
7
+ * Rectify type hints if ``loads()`` and ``Decoder.__call__()`` (`issue #214`__)
8
+
9
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/214
10
+
11
+ * Ensure ``Validator`` receives valid UTF-8 ``bytes``/``bytearray`` arguments
12
+
13
+ * Generate wheels on PyPI using Python 3.13.0rc1 release, thanks to cibuildwheel `2.20.0`__
14
+
15
+ __ https://cibuildwheel.pypa.io/en/stable/changelog/#v2200
16
+
17
+
18
+ 1.19 (2024-07-28)
19
+ ~~~~~~~~~~~~~~~~~
20
+
21
+ * Properly dump subclasses of ``float`` with custom ``__repr__()`` method ( `issue #213`__)
22
+
23
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/213
24
+
25
+
4
26
  1.18 (2024-06-29)
5
27
  ~~~~~~~~~~~~~~~~~
6
28
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-rapidjson
3
- Version: 1.18
3
+ Version: 1.20
4
4
  Summary: Python wrapper around rapidjson
5
5
  Home-page: https://github.com/python-rapidjson/python-rapidjson
6
6
  Author: Ken Robbins
@@ -155,6 +155,28 @@ __ https://python-rapidjson.readthedocs.io/en/latest/quickstart.html#incompatibi
155
155
  Changes
156
156
  -------
157
157
 
158
+ 1.20 (2024-08-05)
159
+ ~~~~~~~~~~~~~~~~~
160
+
161
+ * Rectify type hints if ``loads()`` and ``Decoder.__call__()`` (`issue #214`__)
162
+
163
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/214
164
+
165
+ * Ensure ``Validator`` receives valid UTF-8 ``bytes``/``bytearray`` arguments
166
+
167
+ * Generate wheels on PyPI using Python 3.13.0rc1 release, thanks to cibuildwheel `2.20.0`__
168
+
169
+ __ https://cibuildwheel.pypa.io/en/stable/changelog/#v2200
170
+
171
+
172
+ 1.19 (2024-07-28)
173
+ ~~~~~~~~~~~~~~~~~
174
+
175
+ * Properly dump subclasses of ``float`` with custom ``__repr__()`` method ( `issue #213`__)
176
+
177
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/213
178
+
179
+
158
180
  1.18 (2024-06-29)
159
181
  ~~~~~~~~~~~~~~~~~
160
182
 
@@ -1,6 +1,28 @@
1
1
  Changes
2
2
  -------
3
3
 
4
+ 1.20 (2024-08-05)
5
+ ~~~~~~~~~~~~~~~~~
6
+
7
+ * Rectify type hints if ``loads()`` and ``Decoder.__call__()`` (`issue #214`__)
8
+
9
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/214
10
+
11
+ * Ensure ``Validator`` receives valid UTF-8 ``bytes``/``bytearray`` arguments
12
+
13
+ * Generate wheels on PyPI using Python 3.13.0rc1 release, thanks to cibuildwheel `2.20.0`__
14
+
15
+ __ https://cibuildwheel.pypa.io/en/stable/changelog/#v2200
16
+
17
+
18
+ 1.19 (2024-07-28)
19
+ ~~~~~~~~~~~~~~~~~
20
+
21
+ * Properly dump subclasses of ``float`` with custom ``__repr__()`` method ( `issue #213`__)
22
+
23
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/213
24
+
25
+
4
26
  1.18 (2024-06-29)
5
27
  ~~~~~~~~~~~~~~~~~
6
28
 
@@ -2,7 +2,7 @@
2
2
  .. :Project: python-rapidjson -- Validator class documentation
3
3
  .. :Author: Lele Gaifax <lele@metapensiero.it>
4
4
  .. :License: MIT License
5
- .. :Copyright: © 2017, 2018, 2019, 2020 Lele Gaifax
5
+ .. :Copyright: © 2017, 2018, 2019, 2020, 2024 Lele Gaifax
6
6
  ..
7
7
 
8
8
  =================
@@ -18,7 +18,7 @@
18
18
  .. class:: Validator(json_schema)
19
19
 
20
20
  :param json_schema: the `JSON schema`__, specified as a ``str`` instance or an *UTF-8*
21
- ``bytes`` instance
21
+ :class:`bytes`/:class:`bytearray` instance
22
22
  :raises JSONDecodeError: if `json_schema` is not a valid ``JSON`` value
23
23
 
24
24
  __ http://json-schema.org/documentation.html
@@ -26,7 +26,7 @@
26
26
  .. method:: __call__(json)
27
27
 
28
28
  :param json: the ``JSON`` value, specified as a ``str`` instance or an *UTF-8*
29
- ``bytes`` instance, that will be validated
29
+ :class:`bytes`/:class:`bytearray` instance, that will be validated
30
30
  :raises JSONDecodeError: if `json` is not a valid ``JSON`` value
31
31
 
32
32
  The given `json` value will be validated accordingly to the *schema*: a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-rapidjson
3
- Version: 1.18
3
+ Version: 1.20
4
4
  Summary: Python wrapper around rapidjson
5
5
  Home-page: https://github.com/python-rapidjson/python-rapidjson
6
6
  Author: Ken Robbins
@@ -155,6 +155,28 @@ __ https://python-rapidjson.readthedocs.io/en/latest/quickstart.html#incompatibi
155
155
  Changes
156
156
  -------
157
157
 
158
+ 1.20 (2024-08-05)
159
+ ~~~~~~~~~~~~~~~~~
160
+
161
+ * Rectify type hints if ``loads()`` and ``Decoder.__call__()`` (`issue #214`__)
162
+
163
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/214
164
+
165
+ * Ensure ``Validator`` receives valid UTF-8 ``bytes``/``bytearray`` arguments
166
+
167
+ * Generate wheels on PyPI using Python 3.13.0rc1 release, thanks to cibuildwheel `2.20.0`__
168
+
169
+ __ https://cibuildwheel.pypa.io/en/stable/changelog/#v2200
170
+
171
+
172
+ 1.19 (2024-07-28)
173
+ ~~~~~~~~~~~~~~~~~
174
+
175
+ * Properly dump subclasses of ``float`` with custom ``__repr__()`` method ( `issue #213`__)
176
+
177
+ __ https://github.com/python-rapidjson/python-rapidjson/issues/213
178
+
179
+
158
180
  1.18 (2024-06-29)
159
181
  ~~~~~~~~~~~~~~~~~
160
182
 
@@ -2156,8 +2156,9 @@ decoder_call(PyObject* self, PyObject* args, PyObject* kwargs)
2156
2156
  jsonStr = NULL;
2157
2157
  jsonStrLen = 0;
2158
2158
  } else {
2159
- PyErr_SetString(PyExc_TypeError,
2160
- "Expected string or UTF-8 encoded bytes or bytearray");
2159
+ PyErr_SetString(
2160
+ PyExc_TypeError,
2161
+ "Expected string or UTF-8 encoded bytes or bytearray or a file-like object");
2161
2162
  return NULL;
2162
2163
  }
2163
2164
 
@@ -2443,10 +2444,7 @@ dumps_internal(
2443
2444
  Py_DECREF(intStrObj);
2444
2445
  }
2445
2446
  } else if (PyFloat_Check(object)) {
2446
- double d = PyFloat_AsDouble(object);
2447
- if (d == -1.0 && PyErr_Occurred())
2448
- return false;
2449
-
2447
+ double d = PyFloat_AS_DOUBLE(object);
2450
2448
  if (IS_NAN(d)) {
2451
2449
  if (numberMode & NM_NAN) {
2452
2450
  writer->RawValue("NaN", 3, kNumberType);
@@ -2469,7 +2467,7 @@ dumps_internal(
2469
2467
  // The RJ dtoa() produces "strange" results for particular values, see #101:
2470
2468
  // use Python's repr() to emit a raw value instead of writer->Double(d)
2471
2469
 
2472
- PyObject* dr = PyObject_Repr(object);
2470
+ PyObject* dr = PyFloat_Type.tp_repr(object);
2473
2471
 
2474
2472
  if (dr == NULL)
2475
2473
  return false;
@@ -3728,17 +3726,24 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3728
3726
  return NULL;
3729
3727
 
3730
3728
  const char* jsonStr;
3729
+ PyObject* asUnicode = NULL;
3731
3730
 
3732
- if (PyBytes_Check(jsonObject)) {
3733
- jsonStr = PyBytes_AsString(jsonObject);
3734
- if (jsonStr == NULL)
3735
- return NULL;
3736
- } else if (PyUnicode_Check(jsonObject)) {
3731
+ if (PyUnicode_Check(jsonObject)) {
3737
3732
  jsonStr = PyUnicode_AsUTF8(jsonObject);
3738
3733
  if (jsonStr == NULL)
3739
3734
  return NULL;
3735
+ } else if (PyBytes_Check(jsonObject) || PyByteArray_Check(jsonObject)) {
3736
+ asUnicode = PyUnicode_FromEncodedObject(jsonObject, "utf-8", NULL);
3737
+ if (asUnicode == NULL)
3738
+ return NULL;
3739
+ jsonStr = PyUnicode_AsUTF8(asUnicode);
3740
+ if (jsonStr == NULL) {
3741
+ Py_DECREF(asUnicode);
3742
+ return NULL;
3743
+ }
3740
3744
  } else {
3741
- PyErr_SetString(PyExc_TypeError, "Expected string or UTF-8 encoded bytes");
3745
+ PyErr_SetString(PyExc_TypeError,
3746
+ "Expected string or UTF-8 encoded bytes or bytearray");
3742
3747
  return NULL;
3743
3748
  }
3744
3749
 
@@ -3750,6 +3755,8 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3750
3755
  Py_END_ALLOW_THREADS
3751
3756
 
3752
3757
  if (error) {
3758
+ if (asUnicode != NULL)
3759
+ Py_DECREF(asUnicode);
3753
3760
  PyErr_SetString(decode_error, "Invalid JSON");
3754
3761
  return NULL;
3755
3762
  }
@@ -3761,6 +3768,9 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3761
3768
  accept = d.Accept(validator);
3762
3769
  Py_END_ALLOW_THREADS
3763
3770
 
3771
+ if (asUnicode != NULL)
3772
+ Py_DECREF(asUnicode);
3773
+
3764
3774
  if (!accept) {
3765
3775
  StringBuffer sptr;
3766
3776
  StringBuffer dptr;
@@ -3774,7 +3784,9 @@ static PyObject* validator_call(PyObject* self, PyObject* args, PyObject* kwargs
3774
3784
  sptr.GetString(), dptr.GetString());
3775
3785
  PyErr_SetObject(validation_error, error);
3776
3786
 
3777
- Py_XDECREF(error);
3787
+ if (error != NULL)
3788
+ Py_DECREF(error);
3789
+
3778
3790
  sptr.Clear();
3779
3791
  dptr.Clear();
3780
3792
 
@@ -3801,17 +3813,24 @@ static PyObject* validator_new(PyTypeObject* type, PyObject* args, PyObject* kwa
3801
3813
  return NULL;
3802
3814
 
3803
3815
  const char* jsonStr;
3816
+ PyObject* asUnicode = NULL;
3804
3817
 
3805
- if (PyBytes_Check(jsonObject)) {
3806
- jsonStr = PyBytes_AsString(jsonObject);
3807
- if (jsonStr == NULL)
3808
- return NULL;
3809
- } else if (PyUnicode_Check(jsonObject)) {
3818
+ if (PyUnicode_Check(jsonObject)) {
3810
3819
  jsonStr = PyUnicode_AsUTF8(jsonObject);
3811
3820
  if (jsonStr == NULL)
3812
3821
  return NULL;
3822
+ } else if (PyBytes_Check(jsonObject) || PyByteArray_Check(jsonObject)) {
3823
+ asUnicode = PyUnicode_FromEncodedObject(jsonObject, "utf-8", NULL);
3824
+ if (asUnicode == NULL)
3825
+ return NULL;
3826
+ jsonStr = PyUnicode_AsUTF8(asUnicode);
3827
+ if (jsonStr == NULL) {
3828
+ Py_DECREF(asUnicode);
3829
+ return NULL;
3830
+ }
3813
3831
  } else {
3814
- PyErr_SetString(PyExc_TypeError, "Expected string or UTF-8 encoded bytes");
3832
+ PyErr_SetString(PyExc_TypeError,
3833
+ "Expected string or UTF-8 encoded bytes or bytearray");
3815
3834
  return NULL;
3816
3835
  }
3817
3836
 
@@ -3822,6 +3841,9 @@ static PyObject* validator_new(PyTypeObject* type, PyObject* args, PyObject* kwa
3822
3841
  error = d.Parse(jsonStr).HasParseError();
3823
3842
  Py_END_ALLOW_THREADS
3824
3843
 
3844
+ if (asUnicode != NULL)
3845
+ Py_DECREF(asUnicode);
3846
+
3825
3847
  if (error) {
3826
3848
  PyErr_SetString(decode_error, "Invalid JSON");
3827
3849
  return NULL;
@@ -3,7 +3,7 @@
3
3
  # :Author: John Anderson <sontek@gmail.com>
4
4
  # :License: MIT License
5
5
  # :Copyright: © 2015 John Anderson
6
- # :Copyright: © 2016, 2017, 2018, 2019, 2020, 2021 Lele Gaifax
6
+ # :Copyright: © 2016, 2017, 2018, 2019, 2020, 2021, 2024 Lele Gaifax
7
7
  #
8
8
 
9
9
  import random
@@ -182,6 +182,19 @@ def test_decode_error(loads):
182
182
  pytest.raises(rj.JSONDecodeError, loads, '{')
183
183
 
184
184
 
185
+ def test_decode_bytes_and_bytearray():
186
+ s = 'FòBàr'
187
+ j = f'"{s}"'
188
+ utf32 = j.encode('utf-32')
189
+ for loader in (rj.loads, rj.Decoder()):
190
+ pytest.raises(UnicodeDecodeError, loader, utf32)
191
+
192
+ utf8 = j.encode('utf-8')
193
+ for loader in (rj.loads, rj.Decoder()):
194
+ for data in (utf8, bytearray(utf8)):
195
+ assert loader(data) == s
196
+
197
+
185
198
  def test_shared_keys(loads):
186
199
  res = loads('[{"key": "value1"}, {"key": "value2"}]')
187
200
  key1, = res[0].keys()
@@ -3,7 +3,7 @@
3
3
  # :Author: John Anderson <sontek@gmail.com>
4
4
  # :License: MIT License
5
5
  # :Copyright: © 2015 John Anderson
6
- # :Copyright: © 2016, 2017, 2020 Lele Gaifax
6
+ # :Copyright: © 2016, 2017, 2020, 2024 Lele Gaifax
7
7
  #
8
8
 
9
9
  from decimal import Decimal
@@ -159,3 +159,15 @@ def test_nan_c():
159
159
  dumped = rj.Encoder(number_mode=rj.NM_DECIMAL|rj.NM_NAN)(d)
160
160
  loaded = rj.Decoder(number_mode=rj.NM_DECIMAL|rj.NM_NAN)(dumped)
161
161
  assert loaded.is_nan()
162
+
163
+
164
+ def test_issue_213():
165
+ class CustomRepr(float):
166
+ def __repr__(self):
167
+ stdrepr = super().__repr__()
168
+ return f'CustomRepr({stdrepr})'
169
+
170
+ f = CustomRepr(123.45)
171
+ dumped = rj.dumps(f)
172
+ loaded = rj.loads(dumped)
173
+ assert loaded == 123.45
@@ -2,7 +2,7 @@
2
2
  # :Project: python-rapidjson -- Validator class tests
3
3
  # :Author: Lele Gaifax <lele@metapensiero.it>
4
4
  # :License: MIT License
5
- # :Copyright: © 2017, 2019, 2020 Lele Gaifax
5
+ # :Copyright: © 2017, 2019, 2020, 2024 Lele Gaifax
6
6
  #
7
7
 
8
8
  import pytest
@@ -26,8 +26,10 @@ def test_invalid_json():
26
26
  ('{ "type": ["number", "string"] }', '"Life, the universe, and everything"'),
27
27
  ))
28
28
  def test_valid(schema, json):
29
- validate = rj.Validator(schema)
30
- validate(json)
29
+ for s in (schema, schema.encode('utf-8'), bytearray(schema.encode('utf-8'))):
30
+ for j in (json, json.encode('utf-8'), bytearray(json.encode('utf-8'))):
31
+ validate = rj.Validator(s)
32
+ validate(j)
31
33
 
32
34
 
33
35
  @pytest.mark.parametrize('schema,json,details', (
@@ -148,7 +148,7 @@ def load(
148
148
  allow_nan: t.Optional[bool] = True,
149
149
  ) -> t.Any: ...
150
150
  def loads(
151
- string: str,
151
+ string: t.Union[str, bytes, bytearray],
152
152
  *,
153
153
  object_hook: t.Optional[t.Callable[[t.Dict[str, t.Any]], t.Any]] = None,
154
154
  number_mode: t.Optional[_NumberMode] = NM_NAN,
@@ -179,7 +179,7 @@ class Decoder:
179
179
  ) -> None: ...
180
180
  def __call__(
181
181
  self,
182
- json: t.Union[str, bytes, t.IO],
182
+ json: t.Union[str, bytes, bytearray, t.IO],
183
183
  chunk_size: t.Optional[int] = 65536,
184
184
  ) -> t.Any: ...
185
185
 
@@ -228,5 +228,5 @@ class RawJSON:
228
228
 
229
229
  @t.final
230
230
  class Validator:
231
- def __init__(self, json_schema: t.Union[str, bytes]) -> None: ...
232
- def __call__(self, json: t.Union[str, bytes]) -> None: ...
231
+ def __init__(self, json_schema: t.Union[str, bytes, bytearray]) -> None: ...
232
+ def __call__(self, json: t.Union[str, bytes, bytearray]) -> None: ...
@@ -0,0 +1 @@
1
+ 1.20
@@ -1 +0,0 @@
1
- 1.18
File without changes
File without changes