Mercurial > cpython-lru_cache-weakref
annotate Modules/_json.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | 33ae62a4ecf5 |
| children | c85305a54e6d |
| rev | line source |
|---|---|
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
1 #include "Python.h" |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2 #include "structmember.h" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
3 #if PY_VERSION_HEX < 0x02060000 && !defined(Py_TYPE) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
4 #define Py_TYPE(ob) (((PyObject*)(ob))->ob_type) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
5 #endif |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
6 #if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
7 typedef int Py_ssize_t; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
8 #define PY_SSIZE_T_MAX INT_MAX |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
9 #define PY_SSIZE_T_MIN INT_MIN |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
10 #define PyInt_FromSsize_t PyInt_FromLong |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
11 #define PyInt_AsSsize_t PyInt_AsLong |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
12 #endif |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
13 #ifndef Py_IS_FINITE |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
14 #define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
15 #endif |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
16 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
17 #ifdef __GNUC__ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
18 #define UNUSED __attribute__((__unused__)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
19 #else |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
20 #define UNUSED |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
21 #endif |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
22 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
23 #define DEFAULT_ENCODING "utf-8" |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
24 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
25 #define PyScanner_Check(op) PyObject_TypeCheck(op, &PyScannerType) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
26 #define PyScanner_CheckExact(op) (Py_TYPE(op) == &PyScannerType) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
27 #define PyEncoder_Check(op) PyObject_TypeCheck(op, &PyEncoderType) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
28 #define PyEncoder_CheckExact(op) (Py_TYPE(op) == &PyEncoderType) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
29 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
30 static PyTypeObject PyScannerType; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
31 static PyTypeObject PyEncoderType; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
32 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
33 typedef struct _PyScannerObject { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
34 PyObject_HEAD |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
35 PyObject *encoding; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
36 PyObject *strict; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
37 PyObject *object_hook; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
38 PyObject *pairs_hook; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
39 PyObject *parse_float; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
40 PyObject *parse_int; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
41 PyObject *parse_constant; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
42 } PyScannerObject; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
43 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
44 static PyMemberDef scanner_members[] = { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
45 {"encoding", T_OBJECT, offsetof(PyScannerObject, encoding), READONLY, "encoding"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
46 {"strict", T_OBJECT, offsetof(PyScannerObject, strict), READONLY, "strict"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
47 {"object_hook", T_OBJECT, offsetof(PyScannerObject, object_hook), READONLY, "object_hook"}, |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
48 {"object_pairs_hook", T_OBJECT, offsetof(PyScannerObject, pairs_hook), READONLY, "object_pairs_hook"}, |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
49 {"parse_float", T_OBJECT, offsetof(PyScannerObject, parse_float), READONLY, "parse_float"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
50 {"parse_int", T_OBJECT, offsetof(PyScannerObject, parse_int), READONLY, "parse_int"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
51 {"parse_constant", T_OBJECT, offsetof(PyScannerObject, parse_constant), READONLY, "parse_constant"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
52 {NULL} |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
53 }; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
54 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
55 typedef struct _PyEncoderObject { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
56 PyObject_HEAD |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
57 PyObject *markers; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
58 PyObject *defaultfn; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
59 PyObject *encoder; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
60 PyObject *indent; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
61 PyObject *key_separator; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
62 PyObject *item_separator; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
63 PyObject *sort_keys; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
64 PyObject *skipkeys; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
65 int fast_encode; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
66 int allow_nan; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
67 } PyEncoderObject; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
68 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
69 static PyMemberDef encoder_members[] = { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
70 {"markers", T_OBJECT, offsetof(PyEncoderObject, markers), READONLY, "markers"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
71 {"default", T_OBJECT, offsetof(PyEncoderObject, defaultfn), READONLY, "default"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
72 {"encoder", T_OBJECT, offsetof(PyEncoderObject, encoder), READONLY, "encoder"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
73 {"indent", T_OBJECT, offsetof(PyEncoderObject, indent), READONLY, "indent"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
74 {"key_separator", T_OBJECT, offsetof(PyEncoderObject, key_separator), READONLY, "key_separator"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
75 {"item_separator", T_OBJECT, offsetof(PyEncoderObject, item_separator), READONLY, "item_separator"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
76 {"sort_keys", T_OBJECT, offsetof(PyEncoderObject, sort_keys), READONLY, "sort_keys"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
77 {"skipkeys", T_OBJECT, offsetof(PyEncoderObject, skipkeys), READONLY, "skipkeys"}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
78 {NULL} |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
79 }; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
80 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
81 static Py_ssize_t |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
82 ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
83 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
84 ascii_escape_unicode(PyObject *pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
85 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
86 ascii_escape_str(PyObject *pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
87 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
88 py_encode_basestring_ascii(PyObject* self UNUSED, PyObject *pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
89 void init_json(void); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
90 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
91 scan_once_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
92 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
93 scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
94 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
95 _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
96 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
97 scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
98 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
99 scanner_init(PyObject *self, PyObject *args, PyObject *kwds); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
100 static void |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
101 scanner_dealloc(PyObject *self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
102 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
103 scanner_clear(PyObject *self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
104 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
105 encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
106 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
107 encoder_init(PyObject *self, PyObject *args, PyObject *kwds); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
108 static void |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
109 encoder_dealloc(PyObject *self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
110 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
111 encoder_clear(PyObject *self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
112 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
113 encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ssize_t indent_level); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
114 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
115 encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssize_t indent_level); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
116 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
117 encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ssize_t indent_level); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
118 static PyObject * |
|
52226
ead3de48aadd
Silence a compiler warning.
Raymond Hettinger <python@rcn.com>
parents:
52225
diff
changeset
|
119 _encoded_const(PyObject *obj); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
120 static void |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
121 raise_errmsg(char *msg, PyObject *s, Py_ssize_t end); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
122 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
123 encoder_encode_string(PyEncoderObject *s, PyObject *obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
124 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
125 _convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
126 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
127 _convertPyInt_FromSsize_t(Py_ssize_t *size_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
128 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
129 encoder_encode_float(PyEncoderObject *s, PyObject *obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
130 |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
131 #define S_CHAR(c) (c >= ' ' && c <= '~' && c != '\\' && c != '"') |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
132 #define IS_WHITESPACE(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r')) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
133 |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
134 #define MIN_EXPANSION 6 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
135 #ifdef Py_UNICODE_WIDE |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
136 #define MAX_EXPANSION (2 * MIN_EXPANSION) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
137 #else |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
138 #define MAX_EXPANSION MIN_EXPANSION |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
139 #endif |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
140 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
141 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
142 _convertPyInt_AsSsize_t(PyObject *o, Py_ssize_t *size_ptr) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
143 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
144 /* PyObject to Py_ssize_t converter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
145 *size_ptr = PyInt_AsSsize_t(o); |
|
53768
4e5834b322c1
#5932: fix error return in _convertPyInt_AsSsize_t() conversion function.
Georg Brandl <georg@python.org>
parents:
52427
diff
changeset
|
146 if (*size_ptr == -1 && PyErr_Occurred()) |
|
4e5834b322c1
#5932: fix error return in _convertPyInt_AsSsize_t() conversion function.
Georg Brandl <georg@python.org>
parents:
52427
diff
changeset
|
147 return 0; |
|
4e5834b322c1
#5932: fix error return in _convertPyInt_AsSsize_t() conversion function.
Georg Brandl <georg@python.org>
parents:
52427
diff
changeset
|
148 return 1; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
149 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
150 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
151 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
152 _convertPyInt_FromSsize_t(Py_ssize_t *size_ptr) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
153 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
154 /* Py_ssize_t to PyObject converter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
155 return PyInt_FromSsize_t(*size_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
156 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
157 |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
158 static Py_ssize_t |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
159 ascii_escape_char(Py_UNICODE c, char *output, Py_ssize_t chars) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
160 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
161 /* Escape unicode code point c to ASCII escape sequences |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
162 in char *output. output must have at least 12 bytes unused to |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
163 accommodate an escaped surrogate pair "\uXXXX\uXXXX" */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
164 output[chars++] = '\\'; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
165 switch (c) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
166 case '\\': output[chars++] = (char)c; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
167 case '"': output[chars++] = (char)c; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
168 case '\b': output[chars++] = 'b'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
169 case '\f': output[chars++] = 'f'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
170 case '\n': output[chars++] = 'n'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
171 case '\r': output[chars++] = 'r'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
172 case '\t': output[chars++] = 't'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
173 default: |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
174 #ifdef Py_UNICODE_WIDE |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
175 if (c >= 0x10000) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
176 /* UTF-16 surrogate pair */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
177 Py_UNICODE v = c - 0x10000; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
178 c = 0xd800 | ((v >> 10) & 0x3ff); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
179 output[chars++] = 'u'; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
180 output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
181 output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
182 output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
183 output[chars++] = "0123456789abcdef"[(c ) & 0xf]; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
184 c = 0xdc00 | (v & 0x3ff); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
185 output[chars++] = '\\'; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
186 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
187 #endif |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
188 output[chars++] = 'u'; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
189 output[chars++] = "0123456789abcdef"[(c >> 12) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
190 output[chars++] = "0123456789abcdef"[(c >> 8) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
191 output[chars++] = "0123456789abcdef"[(c >> 4) & 0xf]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
192 output[chars++] = "0123456789abcdef"[(c ) & 0xf]; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
193 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
194 return chars; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
195 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
196 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
197 static PyObject * |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
198 ascii_escape_unicode(PyObject *pystr) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
199 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
200 /* Take a PyUnicode pystr and return a new ASCII-only escaped PyString */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
201 Py_ssize_t i; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
202 Py_ssize_t input_chars; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
203 Py_ssize_t output_size; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
204 Py_ssize_t max_output_size; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
205 Py_ssize_t chars; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
206 PyObject *rval; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
207 char *output; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
208 Py_UNICODE *input_unicode; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
209 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
210 input_chars = PyUnicode_GET_SIZE(pystr); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
211 input_unicode = PyUnicode_AS_UNICODE(pystr); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
212 |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
213 /* One char input can be up to 6 chars output, estimate 4 of these */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
214 output_size = 2 + (MIN_EXPANSION * 4) + input_chars; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
215 max_output_size = 2 + (input_chars * MAX_EXPANSION); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
216 rval = PyString_FromStringAndSize(NULL, output_size); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
217 if (rval == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
218 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
219 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
220 output = PyString_AS_STRING(rval); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
221 chars = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
222 output[chars++] = '"'; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
223 for (i = 0; i < input_chars; i++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
224 Py_UNICODE c = input_unicode[i]; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
225 if (S_CHAR(c)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
226 output[chars++] = (char)c; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
227 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
228 else { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
229 chars = ascii_escape_char(c, output, chars); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
230 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
231 if (output_size - chars < (1 + MAX_EXPANSION)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
232 /* There's more than four, so let's resize by a lot */ |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
233 Py_ssize_t new_output_size = output_size * 2; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
234 /* This is an upper bound */ |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
235 if (new_output_size > max_output_size) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
236 new_output_size = max_output_size; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
237 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
238 /* Make sure that the output size changed before resizing */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
239 if (new_output_size != output_size) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
240 output_size = new_output_size; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
241 if (_PyString_Resize(&rval, output_size) == -1) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
242 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
243 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
244 output = PyString_AS_STRING(rval); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
245 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
246 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
247 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
248 output[chars++] = '"'; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
249 if (_PyString_Resize(&rval, chars) == -1) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
250 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
251 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
252 return rval; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
253 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
254 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
255 static PyObject * |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
256 ascii_escape_str(PyObject *pystr) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
257 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
258 /* Take a PyString pystr and return a new ASCII-only escaped PyString */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
259 Py_ssize_t i; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
260 Py_ssize_t input_chars; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
261 Py_ssize_t output_size; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
262 Py_ssize_t chars; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
263 PyObject *rval; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
264 char *output; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
265 char *input_str; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
266 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
267 input_chars = PyString_GET_SIZE(pystr); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
268 input_str = PyString_AS_STRING(pystr); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
269 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
270 /* Fast path for a string that's already ASCII */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
271 for (i = 0; i < input_chars; i++) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
272 Py_UNICODE c = (Py_UNICODE)(unsigned char)input_str[i]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
273 if (!S_CHAR(c)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
274 /* If we have to escape something, scan the string for unicode */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
275 Py_ssize_t j; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
276 for (j = i; j < input_chars; j++) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
277 c = (Py_UNICODE)(unsigned char)input_str[j]; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
278 if (c > 0x7f) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
279 /* We hit a non-ASCII character, bail to unicode mode */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
280 PyObject *uni; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
281 uni = PyUnicode_DecodeUTF8(input_str, input_chars, "strict"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
282 if (uni == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
283 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
284 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
285 rval = ascii_escape_unicode(uni); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
286 Py_DECREF(uni); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
287 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
288 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
289 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
290 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
291 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
292 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
293 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
294 if (i == input_chars) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
295 /* Input is already ASCII */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
296 output_size = 2 + input_chars; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
297 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
298 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
299 /* One char input can be up to 6 chars output, estimate 4 of these */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
300 output_size = 2 + (MIN_EXPANSION * 4) + input_chars; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
301 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
302 rval = PyString_FromStringAndSize(NULL, output_size); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
303 if (rval == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
304 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
305 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
306 output = PyString_AS_STRING(rval); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
307 output[0] = '"'; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
308 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
309 /* We know that everything up to i is ASCII already */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
310 chars = i + 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
311 memcpy(&output[1], input_str, i); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
312 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
313 for (; i < input_chars; i++) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
314 Py_UNICODE c = (Py_UNICODE)(unsigned char)input_str[i]; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
315 if (S_CHAR(c)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
316 output[chars++] = (char)c; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
317 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
318 else { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
319 chars = ascii_escape_char(c, output, chars); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
320 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
321 /* An ASCII char can't possibly expand to a surrogate! */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
322 if (output_size - chars < (1 + MIN_EXPANSION)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
323 /* There's more than four, so let's resize by a lot */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
324 output_size *= 2; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
325 if (output_size > 2 + (input_chars * MIN_EXPANSION)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
326 output_size = 2 + (input_chars * MIN_EXPANSION); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
327 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
328 if (_PyString_Resize(&rval, output_size) == -1) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
329 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
330 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
331 output = PyString_AS_STRING(rval); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
332 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
333 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
334 output[chars++] = '"'; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
335 if (_PyString_Resize(&rval, chars) == -1) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
336 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
337 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
338 return rval; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
339 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
340 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
341 static void |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
342 raise_errmsg(char *msg, PyObject *s, Py_ssize_t end) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
343 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
344 /* Use the Python function json.decoder.errmsg to raise a nice |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
345 looking ValueError exception */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
346 static PyObject *errmsg_fn = NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
347 PyObject *pymsg; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
348 if (errmsg_fn == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
349 PyObject *decoder = PyImport_ImportModule("json.decoder"); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
350 if (decoder == NULL) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
351 return; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
352 errmsg_fn = PyObject_GetAttrString(decoder, "errmsg"); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
353 Py_DECREF(decoder); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
354 if (errmsg_fn == NULL) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
355 return; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
356 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
357 pymsg = PyObject_CallFunction(errmsg_fn, "(zOO&)", msg, s, _convertPyInt_FromSsize_t, &end); |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
358 if (pymsg) { |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
359 PyErr_SetObject(PyExc_ValueError, pymsg); |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
360 Py_DECREF(pymsg); |
|
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
361 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
362 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
363 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
364 static PyObject * |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
365 join_list_unicode(PyObject *lst) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
366 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
367 /* return u''.join(lst) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
368 static PyObject *joinfn = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
369 if (joinfn == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
370 PyObject *ustr = PyUnicode_FromUnicode(NULL, 0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
371 if (ustr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
372 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
373 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
374 joinfn = PyObject_GetAttrString(ustr, "join"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
375 Py_DECREF(ustr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
376 if (joinfn == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
377 return NULL; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
378 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
379 return PyObject_CallFunctionObjArgs(joinfn, lst, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
380 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
381 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
382 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
383 _build_rval_index_tuple(PyObject *rval, Py_ssize_t idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
384 /* return (rval, idx) tuple, stealing reference to rval */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
385 PyObject *tpl; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
386 PyObject *pyidx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
387 /* |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
388 steal a reference to rval, returns (rval, idx) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
389 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
390 if (rval == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
391 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
392 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
393 pyidx = PyInt_FromSsize_t(idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
394 if (pyidx == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
395 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
396 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
397 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
398 tpl = PyTuple_New(2); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
399 if (tpl == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
400 Py_DECREF(pyidx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
401 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
402 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
403 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
404 PyTuple_SET_ITEM(tpl, 0, rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
405 PyTuple_SET_ITEM(tpl, 1, pyidx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
406 return tpl; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
407 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
408 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
409 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
410 scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_ssize_t *next_end_ptr) |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
411 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
412 /* Read the JSON string from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
413 end is the index of the first character after the quote. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
414 encoding is the encoding of pystr (must be an ASCII superset) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
415 if strict is zero then literal control characters are allowed |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
416 *next_end_ptr is a return-by-reference index of the character |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
417 after the end quote |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
418 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
419 Return value is a new PyString (if ASCII-only) or PyUnicode |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
420 */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
421 PyObject *rval; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
422 Py_ssize_t len = PyString_GET_SIZE(pystr); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
423 Py_ssize_t begin = end - 1; |
|
61192
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
424 Py_ssize_t next; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
425 char *buf = PyString_AS_STRING(pystr); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
426 PyObject *chunks = PyList_New(0); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
427 if (chunks == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
428 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
429 } |
|
48031
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
430 if (end < 0 || len <= end) { |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
431 PyErr_SetString(PyExc_ValueError, "end is out of bounds"); |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
432 goto bail; |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
433 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
434 while (1) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
435 /* Find the end of the string or the next escape */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
436 Py_UNICODE c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
437 PyObject *chunk = NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
438 for (next = end; next < len; next++) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
439 c = (unsigned char)buf[next]; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
440 if (c == '"' || c == '\\') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
441 break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
442 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
443 else if (strict && c <= 0x1f) { |
|
48031
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
444 raise_errmsg("Invalid control character at", pystr, next); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
445 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
446 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
447 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
448 if (!(c == '"' || c == '\\')) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
449 raise_errmsg("Unterminated string starting at", pystr, begin); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
450 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
451 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
452 /* Pick up this chunk if it's not zero length */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
453 if (next != end) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
454 PyObject *strchunk = PyString_FromStringAndSize(&buf[end], next - end); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
455 if (strchunk == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
456 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
457 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
458 chunk = PyUnicode_FromEncodedObject(strchunk, encoding, NULL); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
459 Py_DECREF(strchunk); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
460 if (chunk == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
461 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
462 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
463 if (PyList_Append(chunks, chunk)) { |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
464 Py_DECREF(chunk); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
465 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
466 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
467 Py_DECREF(chunk); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
468 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
469 next++; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
470 if (c == '"') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
471 end = next; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
472 break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
473 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
474 if (next == len) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
475 raise_errmsg("Unterminated string starting at", pystr, begin); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
476 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
477 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
478 c = buf[next]; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
479 if (c != 'u') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
480 /* Non-unicode backslash escapes */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
481 end = next + 1; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
482 switch (c) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
483 case '"': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
484 case '\\': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
485 case '/': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
486 case 'b': c = '\b'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
487 case 'f': c = '\f'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
488 case 'n': c = '\n'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
489 case 'r': c = '\r'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
490 case 't': c = '\t'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
491 default: c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
492 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
493 if (c == 0) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
494 raise_errmsg("Invalid \\escape", pystr, end - 2); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
495 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
496 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
497 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
498 else { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
499 c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
500 next++; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
501 end = next + 4; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
502 if (end >= len) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
503 raise_errmsg("Invalid \\uXXXX escape", pystr, next - 1); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
504 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
505 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
506 /* Decode 4 hex digits */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
507 for (; next < end; next++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
508 Py_UNICODE digit = buf[next]; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
509 c <<= 4; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
510 switch (digit) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
511 case '0': case '1': case '2': case '3': case '4': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
512 case '5': case '6': case '7': case '8': case '9': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
513 c |= (digit - '0'); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
514 case 'a': case 'b': case 'c': case 'd': case 'e': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
515 case 'f': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
516 c |= (digit - 'a' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
517 case 'A': case 'B': case 'C': case 'D': case 'E': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
518 case 'F': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
519 c |= (digit - 'A' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
520 default: |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
521 raise_errmsg("Invalid \\uXXXX escape", pystr, end - 5); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
522 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
523 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
524 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
525 #ifdef Py_UNICODE_WIDE |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
526 /* Surrogate pair */ |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
527 if ((c & 0xfc00) == 0xd800) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
528 Py_UNICODE c2 = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
529 if (end + 6 >= len) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
530 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
531 goto bail; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
532 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
533 if (buf[next++] != '\\' || buf[next++] != 'u') { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
534 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
535 goto bail; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
536 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
537 end += 6; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
538 /* Decode 4 hex digits */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
539 for (; next < end; next++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
540 Py_UNICODE digit = buf[next]; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
541 c2 <<= 4; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
542 switch (digit) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
543 case '0': case '1': case '2': case '3': case '4': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
544 case '5': case '6': case '7': case '8': case '9': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
545 c2 |= (digit - '0'); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
546 case 'a': case 'b': case 'c': case 'd': case 'e': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
547 case 'f': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
548 c2 |= (digit - 'a' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
549 case 'A': case 'B': case 'C': case 'D': case 'E': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
550 case 'F': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
551 c2 |= (digit - 'A' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
552 default: |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
553 raise_errmsg("Invalid \\uXXXX escape", pystr, end - 5); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
554 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
555 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
556 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
557 if ((c2 & 0xfc00) != 0xdc00) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
558 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
559 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
560 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
561 c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00)); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
562 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
563 else if ((c & 0xfc00) == 0xdc00) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
564 raise_errmsg("Unpaired low surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
565 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
566 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
567 #endif |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
568 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
569 chunk = PyUnicode_FromUnicode(&c, 1); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
570 if (chunk == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
571 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
572 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
573 if (PyList_Append(chunks, chunk)) { |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
574 Py_DECREF(chunk); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
575 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
576 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
577 Py_DECREF(chunk); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
578 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
579 |
|
69822
9d5a50e5d8a2
#11982: fix json.loads('""') to return u'' rather than ''.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
68256
diff
changeset
|
580 rval = join_list_unicode(chunks); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
581 if (rval == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
582 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
583 } |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
584 Py_CLEAR(chunks); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
585 *next_end_ptr = end; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
586 return rval; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
587 bail: |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
588 *next_end_ptr = -1; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
589 Py_XDECREF(chunks); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
590 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
591 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
592 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
593 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
594 static PyObject * |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
595 scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next_end_ptr) |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
596 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
597 /* Read the JSON string from PyUnicode pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
598 end is the index of the first character after the quote. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
599 if strict is zero then literal control characters are allowed |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
600 *next_end_ptr is a return-by-reference index of the character |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
601 after the end quote |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
602 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
603 Return value is a new PyUnicode |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
604 */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
605 PyObject *rval; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
606 Py_ssize_t len = PyUnicode_GET_SIZE(pystr); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
607 Py_ssize_t begin = end - 1; |
|
61192
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
608 Py_ssize_t next; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
609 const Py_UNICODE *buf = PyUnicode_AS_UNICODE(pystr); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
610 PyObject *chunks = PyList_New(0); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
611 if (chunks == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
612 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
613 } |
|
48031
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
614 if (end < 0 || len <= end) { |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
615 PyErr_SetString(PyExc_ValueError, "end is out of bounds"); |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
616 goto bail; |
|
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
617 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
618 while (1) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
619 /* Find the end of the string or the next escape */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
620 Py_UNICODE c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
621 PyObject *chunk = NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
622 for (next = end; next < len; next++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
623 c = buf[next]; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
624 if (c == '"' || c == '\\') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
625 break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
626 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
627 else if (strict && c <= 0x1f) { |
|
48031
7c147a76a0b2
#3322: bounds checking for _json.scanstring
Bob Ippolito <bob@redivi.com>
parents:
47527
diff
changeset
|
628 raise_errmsg("Invalid control character at", pystr, next); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
629 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
630 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
631 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
632 if (!(c == '"' || c == '\\')) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
633 raise_errmsg("Unterminated string starting at", pystr, begin); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
634 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
635 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
636 /* Pick up this chunk if it's not zero length */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
637 if (next != end) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
638 chunk = PyUnicode_FromUnicode(&buf[end], next - end); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
639 if (chunk == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
640 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
641 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
642 if (PyList_Append(chunks, chunk)) { |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
643 Py_DECREF(chunk); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
644 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
645 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
646 Py_DECREF(chunk); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
647 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
648 next++; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
649 if (c == '"') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
650 end = next; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
651 break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
652 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
653 if (next == len) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
654 raise_errmsg("Unterminated string starting at", pystr, begin); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
655 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
656 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
657 c = buf[next]; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
658 if (c != 'u') { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
659 /* Non-unicode backslash escapes */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
660 end = next + 1; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
661 switch (c) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
662 case '"': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
663 case '\\': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
664 case '/': break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
665 case 'b': c = '\b'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
666 case 'f': c = '\f'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
667 case 'n': c = '\n'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
668 case 'r': c = '\r'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
669 case 't': c = '\t'; break; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
670 default: c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
671 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
672 if (c == 0) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
673 raise_errmsg("Invalid \\escape", pystr, end - 2); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
674 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
675 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
676 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
677 else { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
678 c = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
679 next++; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
680 end = next + 4; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
681 if (end >= len) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
682 raise_errmsg("Invalid \\uXXXX escape", pystr, next - 1); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
683 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
684 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
685 /* Decode 4 hex digits */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
686 for (; next < end; next++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
687 Py_UNICODE digit = buf[next]; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
688 c <<= 4; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
689 switch (digit) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
690 case '0': case '1': case '2': case '3': case '4': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
691 case '5': case '6': case '7': case '8': case '9': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
692 c |= (digit - '0'); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
693 case 'a': case 'b': case 'c': case 'd': case 'e': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
694 case 'f': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
695 c |= (digit - 'a' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
696 case 'A': case 'B': case 'C': case 'D': case 'E': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
697 case 'F': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
698 c |= (digit - 'A' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
699 default: |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
700 raise_errmsg("Invalid \\uXXXX escape", pystr, end - 5); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
701 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
702 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
703 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
704 #ifdef Py_UNICODE_WIDE |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
705 /* Surrogate pair */ |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
706 if ((c & 0xfc00) == 0xd800) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
707 Py_UNICODE c2 = 0; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
708 if (end + 6 >= len) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
709 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
710 goto bail; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
711 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
712 if (buf[next++] != '\\' || buf[next++] != 'u') { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
713 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
714 goto bail; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
715 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
716 end += 6; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
717 /* Decode 4 hex digits */ |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
718 for (; next < end; next++) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
719 Py_UNICODE digit = buf[next]; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
720 c2 <<= 4; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
721 switch (digit) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
722 case '0': case '1': case '2': case '3': case '4': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
723 case '5': case '6': case '7': case '8': case '9': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
724 c2 |= (digit - '0'); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
725 case 'a': case 'b': case 'c': case 'd': case 'e': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
726 case 'f': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
727 c2 |= (digit - 'a' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
728 case 'A': case 'B': case 'C': case 'D': case 'E': |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
729 case 'F': |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
730 c2 |= (digit - 'A' + 10); break; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
731 default: |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
732 raise_errmsg("Invalid \\uXXXX escape", pystr, end - 5); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
733 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
734 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
735 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
736 if ((c2 & 0xfc00) != 0xdc00) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
737 raise_errmsg("Unpaired high surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
738 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
739 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
740 c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00)); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
741 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
742 else if ((c & 0xfc00) == 0xdc00) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
743 raise_errmsg("Unpaired low surrogate", pystr, end - 5); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
744 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
745 } |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
746 #endif |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
747 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
748 chunk = PyUnicode_FromUnicode(&c, 1); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
749 if (chunk == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
750 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
751 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
752 if (PyList_Append(chunks, chunk)) { |
|
49677
82ccc7e77ec5
Merged revisions 66801,66803-66804,66813,66854-66856,66866,66870-66872,66874,66887,66903,66905,66911,66913,66927,66932,66938,66942,66962,66964,66973-66974,66977,66992,66998-66999,67002,67005,67007,67028,67040-67041,67044,67070,67089,67091,67101,67117-67119,67123-67124 via svnmerge from
Georg Brandl <georg@python.org>
parents:
48031
diff
changeset
|
753 Py_DECREF(chunk); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
754 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
755 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
756 Py_DECREF(chunk); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
757 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
758 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
759 rval = join_list_unicode(chunks); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
760 if (rval == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
761 goto bail; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
762 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
763 Py_DECREF(chunks); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
764 *next_end_ptr = end; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
765 return rval; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
766 bail: |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
767 *next_end_ptr = -1; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
768 Py_XDECREF(chunks); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
769 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
770 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
771 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
772 PyDoc_STRVAR(pydoc_scanstring, |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
773 "scanstring(basestring, end, encoding, strict=True) -> (str, end)\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
774 "\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
775 "Scan the string s for a JSON string. End is the index of the\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
776 "character in s after the quote that started the JSON string.\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
777 "Unescapes all valid JSON string escape sequences and raises ValueError\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
778 "on attempt to decode an invalid string. If strict is False then literal\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
779 "control characters are allowed in the string.\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
780 "\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
781 "Returns a tuple of the decoded string and the index of the character in s\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
782 "after the end quote." |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
783 ); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
784 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
785 static PyObject * |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
786 py_scanstring(PyObject* self UNUSED, PyObject *args) |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
787 { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
788 PyObject *pystr; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
789 PyObject *rval; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
790 Py_ssize_t end; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
791 Py_ssize_t next_end = -1; |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
792 char *encoding = NULL; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
793 int strict = 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
794 if (!PyArg_ParseTuple(args, "OO&|zi:scanstring", &pystr, _convertPyInt_AsSsize_t, &end, &encoding, &strict)) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
795 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
796 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
797 if (encoding == NULL) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
798 encoding = DEFAULT_ENCODING; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
799 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
800 if (PyString_Check(pystr)) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
801 rval = scanstring_str(pystr, end, encoding, strict, &next_end); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
802 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
803 else if (PyUnicode_Check(pystr)) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
804 rval = scanstring_unicode(pystr, end, strict, &next_end); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
805 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
806 else { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
807 PyErr_Format(PyExc_TypeError, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
808 "first argument must be a string, not %.80s", |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
809 Py_TYPE(pystr)->tp_name); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
810 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
811 } |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
812 return _build_rval_index_tuple(rval, next_end); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
813 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
814 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
815 PyDoc_STRVAR(pydoc_encode_basestring_ascii, |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
816 "encode_basestring_ascii(basestring) -> str\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
817 "\n" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
818 "Return an ASCII-only JSON representation of a Python string" |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
819 ); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
820 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
821 static PyObject * |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
822 py_encode_basestring_ascii(PyObject* self UNUSED, PyObject *pystr) |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
823 { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
824 /* Return an ASCII-only JSON representation of a Python string */ |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
825 /* METH_O */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
826 if (PyString_Check(pystr)) { |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
827 return ascii_escape_str(pystr); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
828 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
829 else if (PyUnicode_Check(pystr)) { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
830 return ascii_escape_unicode(pystr); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
831 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
832 else { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
833 PyErr_Format(PyExc_TypeError, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
834 "first argument must be a string, not %.80s", |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
835 Py_TYPE(pystr)->tp_name); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
836 return NULL; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
837 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
838 } |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
839 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
840 static void |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
841 scanner_dealloc(PyObject *self) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
842 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
843 /* Deallocate scanner object */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
844 scanner_clear(self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
845 Py_TYPE(self)->tp_free(self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
846 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
847 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
848 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
849 scanner_traverse(PyObject *self, visitproc visit, void *arg) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
850 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
851 PyScannerObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
852 assert(PyScanner_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
853 s = (PyScannerObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
854 Py_VISIT(s->encoding); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
855 Py_VISIT(s->strict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
856 Py_VISIT(s->object_hook); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
857 Py_VISIT(s->pairs_hook); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
858 Py_VISIT(s->parse_float); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
859 Py_VISIT(s->parse_int); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
860 Py_VISIT(s->parse_constant); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
861 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
862 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
863 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
864 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
865 scanner_clear(PyObject *self) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
866 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
867 PyScannerObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
868 assert(PyScanner_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
869 s = (PyScannerObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
870 Py_CLEAR(s->encoding); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
871 Py_CLEAR(s->strict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
872 Py_CLEAR(s->object_hook); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
873 Py_CLEAR(s->pairs_hook); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
874 Py_CLEAR(s->parse_float); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
875 Py_CLEAR(s->parse_int); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
876 Py_CLEAR(s->parse_constant); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
877 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
878 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
879 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
880 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
881 _parse_object_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
882 /* Read a JSON object from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
883 idx is the index of the first character after the opening curly brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
884 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
885 the closing curly brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
886 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
887 Returns a new PyObject (usually a dict, but object_hook can change that) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
888 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
889 char *str = PyString_AS_STRING(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
890 Py_ssize_t end_idx = PyString_GET_SIZE(pystr) - 1; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
891 PyObject *rval; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
892 PyObject *pairs; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
893 PyObject *item; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
894 PyObject *key = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
895 PyObject *val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
896 char *encoding = PyString_AS_STRING(s->encoding); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
897 int strict = PyObject_IsTrue(s->strict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
898 Py_ssize_t next_idx; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
899 |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
900 pairs = PyList_New(0); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
901 if (pairs == NULL) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
902 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
903 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
904 /* skip whitespace after { */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
905 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
906 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
907 /* only loop if the object is non-empty */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
908 if (idx <= end_idx && str[idx] != '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
909 while (idx <= end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
910 /* read key */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
911 if (str[idx] != '"') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
912 raise_errmsg("Expecting property name", pystr, idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
913 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
914 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
915 key = scanstring_str(pystr, idx + 1, encoding, strict, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
916 if (key == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
917 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
918 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
919 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
920 /* skip whitespace between key and : delimiter, read :, skip whitespace */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
921 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
922 if (idx > end_idx || str[idx] != ':') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
923 raise_errmsg("Expecting : delimiter", pystr, idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
924 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
925 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
926 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
927 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
928 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
929 /* read any JSON data type */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
930 val = scan_once_str(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
931 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
932 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
933 |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
934 item = PyTuple_Pack(2, key, val); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
935 if (item == NULL) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
936 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
937 Py_CLEAR(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
938 Py_CLEAR(val); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
939 if (PyList_Append(pairs, item) == -1) { |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
940 Py_DECREF(item); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
941 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
942 } |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
943 Py_DECREF(item); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
944 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
945 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
946 /* skip whitespace before } or , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
947 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
948 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
949 /* bail if the object is closed or we didn't get the , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
950 if (idx > end_idx) break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
951 if (str[idx] == '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
952 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
953 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
954 else if (str[idx] != ',') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
955 raise_errmsg("Expecting , delimiter", pystr, idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
956 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
957 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
958 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
959 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
960 /* skip whitespace after , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
961 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
962 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
963 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
964 /* verify that idx < end_idx, str[idx] should be '}' */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
965 if (idx > end_idx || str[idx] != '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
966 raise_errmsg("Expecting object", pystr, end_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
967 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
968 } |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
969 |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
970 /* if pairs_hook is not None: rval = object_pairs_hook(pairs) */ |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
971 if (s->pairs_hook != Py_None) { |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
972 val = PyObject_CallFunctionObjArgs(s->pairs_hook, pairs, NULL); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
973 if (val == NULL) |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
974 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
975 Py_DECREF(pairs); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
976 *next_idx_ptr = idx + 1; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
977 return val; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
978 } |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
979 |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
980 rval = PyObject_CallFunctionObjArgs((PyObject *)(&PyDict_Type), |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
981 pairs, NULL); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
982 if (rval == NULL) |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
983 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
984 Py_CLEAR(pairs); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
985 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
986 /* if object_hook is not None: rval = object_hook(rval) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
987 if (s->object_hook != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
988 val = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
989 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
990 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
991 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
992 rval = val; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
993 val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
994 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
995 *next_idx_ptr = idx + 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
996 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
997 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
998 Py_XDECREF(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
999 Py_XDECREF(val); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1000 Py_XDECREF(pairs); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1001 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1002 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1003 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1004 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1005 _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1006 /* Read a JSON object from PyUnicode pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1007 idx is the index of the first character after the opening curly brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1008 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1009 the closing curly brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1010 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1011 Returns a new PyObject (usually a dict, but object_hook can change that) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1012 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1013 Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1014 Py_ssize_t end_idx = PyUnicode_GET_SIZE(pystr) - 1; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1015 PyObject *rval; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1016 PyObject *pairs; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1017 PyObject *item; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1018 PyObject *key = NULL; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1019 PyObject *val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1020 int strict = PyObject_IsTrue(s->strict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1021 Py_ssize_t next_idx; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1022 |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1023 pairs = PyList_New(0); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1024 if (pairs == NULL) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1025 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1026 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1027 /* skip whitespace after { */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1028 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1029 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1030 /* only loop if the object is non-empty */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1031 if (idx <= end_idx && str[idx] != '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1032 while (idx <= end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1033 /* read key */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1034 if (str[idx] != '"') { |
|
77842
7762816e3fcd
Issue #5067: improve some json error messages.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74369
diff
changeset
|
1035 raise_errmsg("Expecting property name enclosed in double quotes", pystr, idx); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1036 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1037 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1038 key = scanstring_unicode(pystr, idx + 1, strict, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1039 if (key == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1040 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1041 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1042 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1043 /* skip whitespace between key and : delimiter, read :, skip whitespace */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1044 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1045 if (idx > end_idx || str[idx] != ':') { |
|
77842
7762816e3fcd
Issue #5067: improve some json error messages.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74369
diff
changeset
|
1046 raise_errmsg("Expecting ':' delimiter", pystr, idx); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1047 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1048 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1049 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1050 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1051 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1052 /* read any JSON term */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1053 val = scan_once_unicode(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1054 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1055 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1056 |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1057 item = PyTuple_Pack(2, key, val); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1058 if (item == NULL) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1059 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1060 Py_CLEAR(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1061 Py_CLEAR(val); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1062 if (PyList_Append(pairs, item) == -1) { |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1063 Py_DECREF(item); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1064 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1065 } |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1066 Py_DECREF(item); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1067 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1068 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1069 /* skip whitespace before } or , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1070 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1071 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1072 /* bail if the object is closed or we didn't get the , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1073 if (idx > end_idx) break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1074 if (str[idx] == '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1075 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1076 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1077 else if (str[idx] != ',') { |
|
77842
7762816e3fcd
Issue #5067: improve some json error messages.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74369
diff
changeset
|
1078 raise_errmsg("Expecting ',' delimiter", pystr, idx); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1079 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1080 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1081 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1082 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1083 /* skip whitespace after , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1084 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1085 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1086 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1087 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1088 /* verify that idx < end_idx, str[idx] should be '}' */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1089 if (idx > end_idx || str[idx] != '}') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1090 raise_errmsg("Expecting object", pystr, end_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1091 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1092 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1093 |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1094 /* if pairs_hook is not None: rval = object_pairs_hook(pairs) */ |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1095 if (s->pairs_hook != Py_None) { |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1096 val = PyObject_CallFunctionObjArgs(s->pairs_hook, pairs, NULL); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1097 if (val == NULL) |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1098 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1099 Py_DECREF(pairs); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1100 *next_idx_ptr = idx + 1; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1101 return val; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1102 } |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1103 |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1104 rval = PyObject_CallFunctionObjArgs((PyObject *)(&PyDict_Type), |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1105 pairs, NULL); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1106 if (rval == NULL) |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1107 goto bail; |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1108 Py_CLEAR(pairs); |
|
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1109 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1110 /* if object_hook is not None: rval = object_hook(rval) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1111 if (s->object_hook != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1112 val = PyObject_CallFunctionObjArgs(s->object_hook, rval, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1113 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1114 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1115 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1116 rval = val; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1117 val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1118 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1119 *next_idx_ptr = idx + 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1120 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1121 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1122 Py_XDECREF(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1123 Py_XDECREF(val); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1124 Py_XDECREF(pairs); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1125 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1126 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1127 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1128 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1129 _parse_array_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1130 /* Read a JSON array from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1131 idx is the index of the first character after the opening brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1132 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1133 the closing brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1134 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1135 Returns a new PyList |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1136 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1137 char *str = PyString_AS_STRING(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1138 Py_ssize_t end_idx = PyString_GET_SIZE(pystr) - 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1139 PyObject *val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1140 PyObject *rval = PyList_New(0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1141 Py_ssize_t next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1142 if (rval == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1143 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1144 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1145 /* skip whitespace after [ */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1146 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1147 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1148 /* only loop if the array is non-empty */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1149 if (idx <= end_idx && str[idx] != ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1150 while (idx <= end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1151 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1152 /* read any JSON term and de-tuplefy the (rval, idx) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1153 val = scan_once_str(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1154 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1155 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1156 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1157 if (PyList_Append(rval, val) == -1) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1158 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1159 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1160 Py_CLEAR(val); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1161 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1162 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1163 /* skip whitespace between term and , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1164 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1165 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1166 /* bail if the array is closed or we didn't get the , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1167 if (idx > end_idx) break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1168 if (str[idx] == ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1169 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1170 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1171 else if (str[idx] != ',') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1172 raise_errmsg("Expecting , delimiter", pystr, idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1173 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1174 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1175 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1176 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1177 /* skip whitespace after , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1178 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1179 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1180 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1181 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1182 /* verify that idx < end_idx, str[idx] should be ']' */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1183 if (idx > end_idx || str[idx] != ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1184 raise_errmsg("Expecting object", pystr, end_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1185 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1186 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1187 *next_idx_ptr = idx + 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1188 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1189 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1190 Py_XDECREF(val); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1191 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1192 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1193 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1194 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1195 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1196 _parse_array_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1197 /* Read a JSON array from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1198 idx is the index of the first character after the opening brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1199 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1200 the closing brace. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1201 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1202 Returns a new PyList |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1203 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1204 Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1205 Py_ssize_t end_idx = PyUnicode_GET_SIZE(pystr) - 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1206 PyObject *val = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1207 PyObject *rval = PyList_New(0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1208 Py_ssize_t next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1209 if (rval == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1210 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1211 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1212 /* skip whitespace after [ */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1213 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1214 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1215 /* only loop if the array is non-empty */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1216 if (idx <= end_idx && str[idx] != ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1217 while (idx <= end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1218 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1219 /* read any JSON term */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1220 val = scan_once_unicode(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1221 if (val == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1222 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1223 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1224 if (PyList_Append(rval, val) == -1) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1225 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1226 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1227 Py_CLEAR(val); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1228 idx = next_idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1229 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1230 /* skip whitespace between term and , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1231 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1232 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1233 /* bail if the array is closed or we didn't get the , delimiter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1234 if (idx > end_idx) break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1235 if (str[idx] == ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1236 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1237 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1238 else if (str[idx] != ',') { |
|
77842
7762816e3fcd
Issue #5067: improve some json error messages.
Antoine Pitrou <solipsis@pitrou.net>
parents:
74369
diff
changeset
|
1239 raise_errmsg("Expecting ',' delimiter", pystr, idx); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1240 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1241 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1242 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1243 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1244 /* skip whitespace after , */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1245 while (idx <= end_idx && IS_WHITESPACE(str[idx])) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1246 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1247 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1248 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1249 /* verify that idx < end_idx, str[idx] should be ']' */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1250 if (idx > end_idx || str[idx] != ']') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1251 raise_errmsg("Expecting object", pystr, end_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1252 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1253 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1254 *next_idx_ptr = idx + 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1255 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1256 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1257 Py_XDECREF(val); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1258 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1259 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1260 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1261 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1262 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1263 _parse_constant(PyScannerObject *s, char *constant, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1264 /* Read a JSON constant from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1265 constant is the constant string that was found |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1266 ("NaN", "Infinity", "-Infinity"). |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1267 idx is the index of the first character of the constant |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1268 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1269 the constant. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1270 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1271 Returns the result of parse_constant |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1272 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1273 PyObject *cstr; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1274 PyObject *rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1275 /* constant is "NaN", "Infinity", or "-Infinity" */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1276 cstr = PyString_InternFromString(constant); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1277 if (cstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1278 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1279 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1280 /* rval = parse_constant(constant) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1281 rval = PyObject_CallFunctionObjArgs(s->parse_constant, cstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1282 idx += PyString_GET_SIZE(cstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1283 Py_DECREF(cstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1284 *next_idx_ptr = idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1285 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1286 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1287 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1288 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1289 _match_number_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1290 /* Read a JSON number from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1291 idx is the index of the first character of the number |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1292 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1293 the number. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1294 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1295 Returns a new PyObject representation of that number: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1296 PyInt, PyLong, or PyFloat. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1297 May return other types if parse_int or parse_float are set |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1298 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1299 char *str = PyString_AS_STRING(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1300 Py_ssize_t end_idx = PyString_GET_SIZE(pystr) - 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1301 Py_ssize_t idx = start; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1302 int is_float = 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1303 PyObject *rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1304 PyObject *numstr; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1305 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1306 /* read a sign if it's there, make sure it's not the end of the string */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1307 if (str[idx] == '-') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1308 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1309 if (idx > end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1310 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1311 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1312 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1313 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1314 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1315 /* read as many integer digits as we find as long as it doesn't start with 0 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1316 if (str[idx] >= '1' && str[idx] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1317 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1318 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1319 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1320 /* if it starts with 0 we only expect one integer digit */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1321 else if (str[idx] == '0') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1322 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1323 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1324 /* no integer digits, error */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1325 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1326 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1327 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1328 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1329 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1330 /* if the next char is '.' followed by a digit then read all float digits */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1331 if (idx < end_idx && str[idx] == '.' && str[idx + 1] >= '0' && str[idx + 1] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1332 is_float = 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1333 idx += 2; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1334 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1335 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1336 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1337 /* if the next char is 'e' or 'E' then maybe read the exponent (or backtrack) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1338 if (idx < end_idx && (str[idx] == 'e' || str[idx] == 'E')) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1339 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1340 /* save the index of the 'e' or 'E' just in case we need to backtrack */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1341 Py_ssize_t e_start = idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1342 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1343 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1344 /* read an exponent sign if present */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1345 if (idx < end_idx && (str[idx] == '-' || str[idx] == '+')) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1346 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1347 /* read all digits */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1348 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1349 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1350 /* if we got a digit, then parse as float. if not, backtrack */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1351 if (str[idx - 1] >= '0' && str[idx - 1] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1352 is_float = 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1353 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1354 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1355 idx = e_start; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1356 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1357 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1358 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1359 /* copy the section we determined to be a number */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1360 numstr = PyString_FromStringAndSize(&str[start], idx - start); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1361 if (numstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1362 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1363 if (is_float) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1364 /* parse as a float using a fast path if available, otherwise call user defined method */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1365 if (s->parse_float != (PyObject *)&PyFloat_Type) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1366 rval = PyObject_CallFunctionObjArgs(s->parse_float, numstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1367 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1368 else { |
|
56943
2a961d7f2028
Issue 7117: Replace PyOS_ascii_strtod with PyOS_string_to_double in _json.c as part of short float repr. Change made after consulting with Bob Ippolito. This completes the removal of calls to PyOS_ascii_strtod.
Eric Smith <eric@trueblade.com>
parents:
53768
diff
changeset
|
1369 double d = PyOS_string_to_double(PyString_AS_STRING(numstr), |
|
2a961d7f2028
Issue 7117: Replace PyOS_ascii_strtod with PyOS_string_to_double in _json.c as part of short float repr. Change made after consulting with Bob Ippolito. This completes the removal of calls to PyOS_ascii_strtod.
Eric Smith <eric@trueblade.com>
parents:
53768
diff
changeset
|
1370 NULL, NULL); |
|
2a961d7f2028
Issue 7117: Replace PyOS_ascii_strtod with PyOS_string_to_double in _json.c as part of short float repr. Change made after consulting with Bob Ippolito. This completes the removal of calls to PyOS_ascii_strtod.
Eric Smith <eric@trueblade.com>
parents:
53768
diff
changeset
|
1371 if (d == -1.0 && PyErr_Occurred()) |
|
2a961d7f2028
Issue 7117: Replace PyOS_ascii_strtod with PyOS_string_to_double in _json.c as part of short float repr. Change made after consulting with Bob Ippolito. This completes the removal of calls to PyOS_ascii_strtod.
Eric Smith <eric@trueblade.com>
parents:
53768
diff
changeset
|
1372 return NULL; |
|
2a961d7f2028
Issue 7117: Replace PyOS_ascii_strtod with PyOS_string_to_double in _json.c as part of short float repr. Change made after consulting with Bob Ippolito. This completes the removal of calls to PyOS_ascii_strtod.
Eric Smith <eric@trueblade.com>
parents:
53768
diff
changeset
|
1373 rval = PyFloat_FromDouble(d); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1374 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1375 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1376 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1377 /* parse as an int using a fast path if available, otherwise call user defined method */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1378 if (s->parse_int != (PyObject *)&PyInt_Type) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1379 rval = PyObject_CallFunctionObjArgs(s->parse_int, numstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1380 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1381 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1382 rval = PyInt_FromString(PyString_AS_STRING(numstr), NULL, 10); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1383 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1384 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1385 Py_DECREF(numstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1386 *next_idx_ptr = idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1387 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1388 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1389 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1390 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1391 _match_number_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t start, Py_ssize_t *next_idx_ptr) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1392 /* Read a JSON number from PyUnicode pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1393 idx is the index of the first character of the number |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1394 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1395 the number. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1396 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1397 Returns a new PyObject representation of that number: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1398 PyInt, PyLong, or PyFloat. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1399 May return other types if parse_int or parse_float are set |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1400 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1401 Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1402 Py_ssize_t end_idx = PyUnicode_GET_SIZE(pystr) - 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1403 Py_ssize_t idx = start; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1404 int is_float = 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1405 PyObject *rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1406 PyObject *numstr; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1407 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1408 /* read a sign if it's there, make sure it's not the end of the string */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1409 if (str[idx] == '-') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1410 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1411 if (idx > end_idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1412 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1413 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1414 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1415 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1416 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1417 /* read as many integer digits as we find as long as it doesn't start with 0 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1418 if (str[idx] >= '1' && str[idx] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1419 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1420 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1421 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1422 /* if it starts with 0 we only expect one integer digit */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1423 else if (str[idx] == '0') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1424 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1425 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1426 /* no integer digits, error */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1427 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1428 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1429 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1430 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1431 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1432 /* if the next char is '.' followed by a digit then read all float digits */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1433 if (idx < end_idx && str[idx] == '.' && str[idx + 1] >= '0' && str[idx + 1] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1434 is_float = 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1435 idx += 2; |
|
52427
685f1791fbc5
Issue 5381: fix regression in pure python code path, Issue 5584: fix a decoder bug for unicode float literals outside of a container
Bob Ippolito <bob@redivi.com>
parents:
52226
diff
changeset
|
1436 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1437 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1438 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1439 /* if the next char is 'e' or 'E' then maybe read the exponent (or backtrack) */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1440 if (idx < end_idx && (str[idx] == 'e' || str[idx] == 'E')) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1441 Py_ssize_t e_start = idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1442 idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1443 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1444 /* read an exponent sign if present */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1445 if (idx < end_idx && (str[idx] == '-' || str[idx] == '+')) idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1446 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1447 /* read all digits */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1448 while (idx <= end_idx && str[idx] >= '0' && str[idx] <= '9') idx++; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1449 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1450 /* if we got a digit, then parse as float. if not, backtrack */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1451 if (str[idx - 1] >= '0' && str[idx - 1] <= '9') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1452 is_float = 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1453 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1454 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1455 idx = e_start; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1456 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1457 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1458 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1459 /* copy the section we determined to be a number */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1460 numstr = PyUnicode_FromUnicode(&str[start], idx - start); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1461 if (numstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1462 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1463 if (is_float) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1464 /* parse as a float using a fast path if available, otherwise call user defined method */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1465 if (s->parse_float != (PyObject *)&PyFloat_Type) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1466 rval = PyObject_CallFunctionObjArgs(s->parse_float, numstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1467 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1468 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1469 rval = PyFloat_FromString(numstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1470 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1471 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1472 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1473 /* no fast path for unicode -> int, just call */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1474 rval = PyObject_CallFunctionObjArgs(s->parse_int, numstr, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1475 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1476 Py_DECREF(numstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1477 *next_idx_ptr = idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1478 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1479 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1480 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1481 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1482 scan_once_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1483 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1484 /* Read one JSON term (of any kind) from PyString pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1485 idx is the index of the first character of the term |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1486 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1487 the number. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1488 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1489 Returns a new PyObject representation of the term. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1490 */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1491 PyObject *res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1492 char *str = PyString_AS_STRING(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1493 Py_ssize_t length = PyString_GET_SIZE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1494 if (idx >= length) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1495 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1496 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1497 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1498 switch (str[idx]) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1499 case '"': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1500 /* string */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1501 return scanstring_str(pystr, idx + 1, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1502 PyString_AS_STRING(s->encoding), |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1503 PyObject_IsTrue(s->strict), |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1504 next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1505 case '{': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1506 /* object */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1507 if (Py_EnterRecursiveCall(" while decoding a JSON object " |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1508 "from a byte string")) |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1509 return NULL; |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1510 res = _parse_object_str(s, pystr, idx + 1, next_idx_ptr); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1511 Py_LeaveRecursiveCall(); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1512 return res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1513 case '[': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1514 /* array */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1515 if (Py_EnterRecursiveCall(" while decoding a JSON array " |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1516 "from a byte string")) |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1517 return NULL; |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1518 res = _parse_array_str(s, pystr, idx + 1, next_idx_ptr); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1519 Py_LeaveRecursiveCall(); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1520 return res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1521 case 'n': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1522 /* null */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1523 if ((idx + 3 < length) && str[idx + 1] == 'u' && str[idx + 2] == 'l' && str[idx + 3] == 'l') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1524 Py_INCREF(Py_None); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1525 *next_idx_ptr = idx + 4; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1526 return Py_None; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1527 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1528 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1529 case 't': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1530 /* true */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1531 if ((idx + 3 < length) && str[idx + 1] == 'r' && str[idx + 2] == 'u' && str[idx + 3] == 'e') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1532 Py_INCREF(Py_True); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1533 *next_idx_ptr = idx + 4; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1534 return Py_True; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1535 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1536 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1537 case 'f': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1538 /* false */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1539 if ((idx + 4 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'l' && str[idx + 3] == 's' && str[idx + 4] == 'e') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1540 Py_INCREF(Py_False); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1541 *next_idx_ptr = idx + 5; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1542 return Py_False; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1543 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1544 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1545 case 'N': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1546 /* NaN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1547 if ((idx + 2 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'N') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1548 return _parse_constant(s, "NaN", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1549 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1550 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1551 case 'I': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1552 /* Infinity */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1553 if ((idx + 7 < length) && str[idx + 1] == 'n' && str[idx + 2] == 'f' && str[idx + 3] == 'i' && str[idx + 4] == 'n' && str[idx + 5] == 'i' && str[idx + 6] == 't' && str[idx + 7] == 'y') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1554 return _parse_constant(s, "Infinity", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1555 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1556 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1557 case '-': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1558 /* -Infinity */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1559 if ((idx + 8 < length) && str[idx + 1] == 'I' && str[idx + 2] == 'n' && str[idx + 3] == 'f' && str[idx + 4] == 'i' && str[idx + 5] == 'n' && str[idx + 6] == 'i' && str[idx + 7] == 't' && str[idx + 8] == 'y') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1560 return _parse_constant(s, "-Infinity", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1561 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1562 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1563 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1564 /* Didn't find a string, object, array, or named constant. Look for a number. */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1565 return _match_number_str(s, pystr, idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1566 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1567 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1568 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1569 scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *next_idx_ptr) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1570 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1571 /* Read one JSON term (of any kind) from PyUnicode pystr. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1572 idx is the index of the first character of the term |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1573 *next_idx_ptr is a return-by-reference index to the first character after |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1574 the number. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1575 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1576 Returns a new PyObject representation of the term. |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1577 */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1578 PyObject *res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1579 Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1580 Py_ssize_t length = PyUnicode_GET_SIZE(pystr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1581 if (idx >= length) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1582 PyErr_SetNone(PyExc_StopIteration); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1583 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1584 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1585 switch (str[idx]) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1586 case '"': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1587 /* string */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1588 return scanstring_unicode(pystr, idx + 1, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1589 PyObject_IsTrue(s->strict), |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1590 next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1591 case '{': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1592 /* object */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1593 if (Py_EnterRecursiveCall(" while decoding a JSON object " |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1594 "from a unicode string")) |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1595 return NULL; |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1596 res = _parse_object_unicode(s, pystr, idx + 1, next_idx_ptr); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1597 Py_LeaveRecursiveCall(); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1598 return res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1599 case '[': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1600 /* array */ |
|
69909
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1601 if (Py_EnterRecursiveCall(" while decoding a JSON array " |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1602 "from a unicode string")) |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1603 return NULL; |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1604 res = _parse_array_unicode(s, pystr, idx + 1, next_idx_ptr); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1605 Py_LeaveRecursiveCall(); |
|
6fa20e360e5e
#12017: Fix segfault in json.loads() while decoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69825
diff
changeset
|
1606 return res; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1607 case 'n': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1608 /* null */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1609 if ((idx + 3 < length) && str[idx + 1] == 'u' && str[idx + 2] == 'l' && str[idx + 3] == 'l') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1610 Py_INCREF(Py_None); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1611 *next_idx_ptr = idx + 4; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1612 return Py_None; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1613 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1614 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1615 case 't': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1616 /* true */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1617 if ((idx + 3 < length) && str[idx + 1] == 'r' && str[idx + 2] == 'u' && str[idx + 3] == 'e') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1618 Py_INCREF(Py_True); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1619 *next_idx_ptr = idx + 4; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1620 return Py_True; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1621 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1622 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1623 case 'f': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1624 /* false */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1625 if ((idx + 4 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'l' && str[idx + 3] == 's' && str[idx + 4] == 'e') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1626 Py_INCREF(Py_False); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1627 *next_idx_ptr = idx + 5; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1628 return Py_False; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1629 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1630 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1631 case 'N': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1632 /* NaN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1633 if ((idx + 2 < length) && str[idx + 1] == 'a' && str[idx + 2] == 'N') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1634 return _parse_constant(s, "NaN", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1635 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1636 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1637 case 'I': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1638 /* Infinity */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1639 if ((idx + 7 < length) && str[idx + 1] == 'n' && str[idx + 2] == 'f' && str[idx + 3] == 'i' && str[idx + 4] == 'n' && str[idx + 5] == 'i' && str[idx + 6] == 't' && str[idx + 7] == 'y') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1640 return _parse_constant(s, "Infinity", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1641 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1642 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1643 case '-': |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1644 /* -Infinity */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1645 if ((idx + 8 < length) && str[idx + 1] == 'I' && str[idx + 2] == 'n' && str[idx + 3] == 'f' && str[idx + 4] == 'i' && str[idx + 5] == 'n' && str[idx + 6] == 'i' && str[idx + 7] == 't' && str[idx + 8] == 'y') { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1646 return _parse_constant(s, "-Infinity", idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1647 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1648 break; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1649 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1650 /* Didn't find a string, object, array, or named constant. Look for a number. */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1651 return _match_number_unicode(s, pystr, idx, next_idx_ptr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1652 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1653 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1654 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1655 scanner_call(PyObject *self, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1656 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1657 /* Python callable interface to scan_once_{str,unicode} */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1658 PyObject *pystr; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1659 PyObject *rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1660 Py_ssize_t idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1661 Py_ssize_t next_idx = -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1662 static char *kwlist[] = {"string", "idx", NULL}; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1663 PyScannerObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1664 assert(PyScanner_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1665 s = (PyScannerObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1666 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:scan_once", kwlist, &pystr, _convertPyInt_AsSsize_t, &idx)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1667 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1668 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1669 if (PyString_Check(pystr)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1670 rval = scan_once_str(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1671 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1672 else if (PyUnicode_Check(pystr)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1673 rval = scan_once_unicode(s, pystr, idx, &next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1674 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1675 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1676 PyErr_Format(PyExc_TypeError, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1677 "first argument must be a string, not %.80s", |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1678 Py_TYPE(pystr)->tp_name); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1679 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1680 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1681 return _build_rval_index_tuple(rval, next_idx); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1682 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1683 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1684 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1685 scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1686 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1687 PyScannerObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1688 s = (PyScannerObject *)type->tp_alloc(type, 0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1689 if (s != NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1690 s->encoding = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1691 s->strict = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1692 s->object_hook = NULL; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1693 s->pairs_hook = NULL; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1694 s->parse_float = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1695 s->parse_int = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1696 s->parse_constant = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1697 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1698 return (PyObject *)s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1699 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1700 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1701 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1702 scanner_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1703 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1704 /* Initialize Scanner object */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1705 PyObject *ctx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1706 static char *kwlist[] = {"context", NULL}; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1707 PyScannerObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1708 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1709 assert(PyScanner_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1710 s = (PyScannerObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1711 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1712 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:make_scanner", kwlist, &ctx)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1713 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1714 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1715 /* PyString_AS_STRING is used on encoding */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1716 s->encoding = PyObject_GetAttrString(ctx, "encoding"); |
|
57607
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1717 if (s->encoding == NULL) |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1718 goto bail; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1719 if (s->encoding == Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1720 Py_DECREF(Py_None); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1721 s->encoding = PyString_InternFromString(DEFAULT_ENCODING); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1722 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1723 else if (PyUnicode_Check(s->encoding)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1724 PyObject *tmp = PyUnicode_AsEncodedString(s->encoding, NULL, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1725 Py_DECREF(s->encoding); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1726 s->encoding = tmp; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1727 } |
|
74369
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1728 if (s->encoding == NULL) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1729 goto bail; |
|
74369
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1730 if (!PyString_Check(s->encoding)) { |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1731 PyErr_Format(PyExc_TypeError, |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1732 "encoding must be a string, not %.80s", |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1733 Py_TYPE(s->encoding)->tp_name); |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1734 goto bail; |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1735 } |
|
a9680746ae4a
Issue #13774: json: Fix a SystemError when a bogus encoding is passed to
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
70020
diff
changeset
|
1736 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1737 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1738 /* All of these will fail "gracefully" so we don't need to verify them */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1739 s->strict = PyObject_GetAttrString(ctx, "strict"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1740 if (s->strict == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1741 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1742 s->object_hook = PyObject_GetAttrString(ctx, "object_hook"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1743 if (s->object_hook == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1744 goto bail; |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1745 s->pairs_hook = PyObject_GetAttrString(ctx, "object_pairs_hook"); |
|
67255
3feada72233c
#10804: fix copy-paste error when checking assigned fields for NULL.
Georg Brandl <georg@python.org>
parents:
65901
diff
changeset
|
1746 if (s->pairs_hook == NULL) |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1747 goto bail; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1748 s->parse_float = PyObject_GetAttrString(ctx, "parse_float"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1749 if (s->parse_float == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1750 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1751 s->parse_int = PyObject_GetAttrString(ctx, "parse_int"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1752 if (s->parse_int == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1753 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1754 s->parse_constant = PyObject_GetAttrString(ctx, "parse_constant"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1755 if (s->parse_constant == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1756 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1757 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1758 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1759 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1760 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1761 Py_CLEAR(s->encoding); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1762 Py_CLEAR(s->strict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1763 Py_CLEAR(s->object_hook); |
|
52225
a11a676fe6c0
Issue 5381: Add object_pairs_hook to the json module.
Raymond Hettinger <python@rcn.com>
parents:
52199
diff
changeset
|
1764 Py_CLEAR(s->pairs_hook); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1765 Py_CLEAR(s->parse_float); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1766 Py_CLEAR(s->parse_int); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1767 Py_CLEAR(s->parse_constant); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1768 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1769 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1770 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1771 PyDoc_STRVAR(scanner_doc, "JSON scanner object"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1772 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1773 static |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1774 PyTypeObject PyScannerType = { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1775 PyObject_HEAD_INIT(NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1776 0, /* tp_internal */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1777 "_json.Scanner", /* tp_name */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1778 sizeof(PyScannerObject), /* tp_basicsize */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1779 0, /* tp_itemsize */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1780 scanner_dealloc, /* tp_dealloc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1781 0, /* tp_print */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1782 0, /* tp_getattr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1783 0, /* tp_setattr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1784 0, /* tp_compare */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1785 0, /* tp_repr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1786 0, /* tp_as_number */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1787 0, /* tp_as_sequence */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1788 0, /* tp_as_mapping */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1789 0, /* tp_hash */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1790 scanner_call, /* tp_call */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1791 0, /* tp_str */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1792 0,/* PyObject_GenericGetAttr, */ /* tp_getattro */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1793 0,/* PyObject_GenericSetAttr, */ /* tp_setattro */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1794 0, /* tp_as_buffer */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1795 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1796 scanner_doc, /* tp_doc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1797 scanner_traverse, /* tp_traverse */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1798 scanner_clear, /* tp_clear */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1799 0, /* tp_richcompare */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1800 0, /* tp_weaklistoffset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1801 0, /* tp_iter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1802 0, /* tp_iternext */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1803 0, /* tp_methods */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1804 scanner_members, /* tp_members */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1805 0, /* tp_getset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1806 0, /* tp_base */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1807 0, /* tp_dict */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1808 0, /* tp_descr_get */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1809 0, /* tp_descr_set */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1810 0, /* tp_dictoffset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1811 scanner_init, /* tp_init */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1812 0,/* PyType_GenericAlloc, */ /* tp_alloc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1813 scanner_new, /* tp_new */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1814 0,/* PyObject_GC_Del, */ /* tp_free */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1815 }; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1816 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1817 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1818 encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1819 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1820 PyEncoderObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1821 s = (PyEncoderObject *)type->tp_alloc(type, 0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1822 if (s != NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1823 s->markers = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1824 s->defaultfn = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1825 s->encoder = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1826 s->indent = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1827 s->key_separator = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1828 s->item_separator = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1829 s->sort_keys = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1830 s->skipkeys = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1831 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1832 return (PyObject *)s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1833 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1834 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1835 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1836 encoder_init(PyObject *self, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1837 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1838 /* initialize Encoder object */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1839 static char *kwlist[] = {"markers", "default", "encoder", "indent", "key_separator", "item_separator", "sort_keys", "skipkeys", "allow_nan", NULL}; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1840 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1841 PyEncoderObject *s; |
|
57607
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1842 PyObject *markers, *defaultfn, *encoder, *indent, *key_separator; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1843 PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1844 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1845 assert(PyEncoder_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1846 s = (PyEncoderObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1847 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1848 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOO:make_encoder", kwlist, |
|
57607
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1849 &markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator, |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1850 &sort_keys, &skipkeys, &allow_nan)) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1851 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1852 |
|
57607
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1853 s->markers = markers; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1854 s->defaultfn = defaultfn; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1855 s->encoder = encoder; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1856 s->indent = indent; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1857 s->key_separator = key_separator; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1858 s->item_separator = item_separator; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1859 s->sort_keys = sort_keys; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1860 s->skipkeys = skipkeys; |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1861 s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii); |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1862 s->allow_nan = PyObject_IsTrue(allow_nan); |
|
db28aeb2fb7a
Issue #6986: Fix crash in the JSON C accelerator when called with the
Antoine Pitrou <solipsis@pitrou.net>
parents:
56943
diff
changeset
|
1863 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1864 Py_INCREF(s->markers); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1865 Py_INCREF(s->defaultfn); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1866 Py_INCREF(s->encoder); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1867 Py_INCREF(s->indent); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1868 Py_INCREF(s->key_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1869 Py_INCREF(s->item_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1870 Py_INCREF(s->sort_keys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1871 Py_INCREF(s->skipkeys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1872 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1873 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1874 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1875 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1876 encoder_call(PyObject *self, PyObject *args, PyObject *kwds) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1877 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1878 /* Python callable interface to encode_listencode_obj */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1879 static char *kwlist[] = {"obj", "_current_indent_level", NULL}; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1880 PyObject *obj; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1881 PyObject *rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1882 Py_ssize_t indent_level; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1883 PyEncoderObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1884 assert(PyEncoder_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1885 s = (PyEncoderObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1886 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO&:_iterencode", kwlist, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1887 &obj, _convertPyInt_AsSsize_t, &indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1888 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1889 rval = PyList_New(0); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1890 if (rval == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1891 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1892 if (encoder_listencode_obj(s, rval, obj, indent_level)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1893 Py_DECREF(rval); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1894 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1895 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1896 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1897 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1898 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1899 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1900 _encoded_const(PyObject *obj) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1901 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1902 /* Return the JSON string representation of None, True, False */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1903 if (obj == Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1904 static PyObject *s_null = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1905 if (s_null == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1906 s_null = PyString_InternFromString("null"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1907 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1908 Py_INCREF(s_null); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1909 return s_null; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1910 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1911 else if (obj == Py_True) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1912 static PyObject *s_true = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1913 if (s_true == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1914 s_true = PyString_InternFromString("true"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1915 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1916 Py_INCREF(s_true); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1917 return s_true; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1918 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1919 else if (obj == Py_False) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1920 static PyObject *s_false = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1921 if (s_false == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1922 s_false = PyString_InternFromString("false"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1923 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1924 Py_INCREF(s_false); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1925 return s_false; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1926 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1927 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1928 PyErr_SetString(PyExc_ValueError, "not a const"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1929 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1930 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1931 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1932 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1933 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1934 encoder_encode_float(PyEncoderObject *s, PyObject *obj) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1935 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1936 /* Return the JSON representation of a PyFloat */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1937 double i = PyFloat_AS_DOUBLE(obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1938 if (!Py_IS_FINITE(i)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1939 if (!s->allow_nan) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1940 PyErr_SetString(PyExc_ValueError, "Out of range float values are not JSON compliant"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1941 return NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1942 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1943 if (i > 0) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1944 return PyString_FromString("Infinity"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1945 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1946 else if (i < 0) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1947 return PyString_FromString("-Infinity"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1948 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1949 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1950 return PyString_FromString("NaN"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1951 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1952 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1953 /* Use a better float format here? */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1954 return PyObject_Repr(obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1955 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1956 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1957 static PyObject * |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1958 encoder_encode_string(PyEncoderObject *s, PyObject *obj) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1959 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1960 /* Return the JSON representation of a string */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1961 if (s->fast_encode) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1962 return py_encode_basestring_ascii(NULL, obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1963 else |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1964 return PyObject_CallFunctionObjArgs(s->encoder, obj, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1965 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1966 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1967 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1968 _steal_list_append(PyObject *lst, PyObject *stolen) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1969 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1970 /* Append stolen and then decrement its reference count */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1971 int rval = PyList_Append(lst, stolen); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1972 Py_DECREF(stolen); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1973 return rval; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1974 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1975 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1976 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1977 encoder_listencode_obj(PyEncoderObject *s, PyObject *rval, PyObject *obj, Py_ssize_t indent_level) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1978 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1979 /* Encode Python object obj to a JSON term, rval is a PyList */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1980 PyObject *newobj; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1981 int rv; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1982 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1983 if (obj == Py_None || obj == Py_True || obj == Py_False) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1984 PyObject *cstr = _encoded_const(obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1985 if (cstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1986 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1987 return _steal_list_append(rval, cstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1988 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1989 else if (PyString_Check(obj) || PyUnicode_Check(obj)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1990 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1991 PyObject *encoded = encoder_encode_string(s, obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1992 if (encoded == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1993 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1994 return _steal_list_append(rval, encoded); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1995 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1996 else if (PyInt_Check(obj) || PyLong_Check(obj)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1997 PyObject *encoded = PyObject_Str(obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1998 if (encoded == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
1999 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2000 return _steal_list_append(rval, encoded); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2001 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2002 else if (PyFloat_Check(obj)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2003 PyObject *encoded = encoder_encode_float(s, obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2004 if (encoded == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2005 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2006 return _steal_list_append(rval, encoded); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2007 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2008 else if (PyList_Check(obj) || PyTuple_Check(obj)) { |
|
70020
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2009 if (Py_EnterRecursiveCall(" while encoding a JSON object")) |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2010 return -1; |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2011 rv = encoder_listencode_list(s, rval, obj, indent_level); |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2012 Py_LeaveRecursiveCall(); |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2013 return rv; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2014 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2015 else if (PyDict_Check(obj)) { |
|
70020
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2016 if (Py_EnterRecursiveCall(" while encoding a JSON object")) |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2017 return -1; |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2018 rv = encoder_listencode_dict(s, rval, obj, indent_level); |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2019 Py_LeaveRecursiveCall(); |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2020 return rv; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2021 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2022 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2023 PyObject *ident = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2024 if (s->markers != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2025 int has_key; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2026 ident = PyLong_FromVoidPtr(obj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2027 if (ident == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2028 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2029 has_key = PyDict_Contains(s->markers, ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2030 if (has_key) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2031 if (has_key != -1) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2032 PyErr_SetString(PyExc_ValueError, "Circular reference detected"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2033 Py_DECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2034 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2035 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2036 if (PyDict_SetItem(s->markers, ident, obj)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2037 Py_DECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2038 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2039 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2040 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2041 newobj = PyObject_CallFunctionObjArgs(s->defaultfn, obj, NULL); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2042 if (newobj == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2043 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2044 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2045 } |
|
70020
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2046 |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2047 if (Py_EnterRecursiveCall(" while encoding a JSON object")) |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2048 return -1; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2049 rv = encoder_listencode_obj(s, rval, newobj, indent_level); |
|
70020
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2050 Py_LeaveRecursiveCall(); |
|
a21f5af476cb
#12051: Fix segfault in json.dumps() while encoding highly-nested objects using the C accelerations.
Ezio Melotti <ezio.melotti@gmail.com>
parents:
69909
diff
changeset
|
2051 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2052 Py_DECREF(newobj); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2053 if (rv) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2054 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2055 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2056 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2057 if (ident != NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2058 if (PyDict_DelItem(s->markers, ident)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2059 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2060 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2061 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2062 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2063 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2064 return rv; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2065 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2066 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2067 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2068 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2069 encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ssize_t indent_level) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2070 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2071 /* Encode Python dict dct a JSON term, rval is a PyList */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2072 static PyObject *open_dict = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2073 static PyObject *close_dict = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2074 static PyObject *empty_dict = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2075 PyObject *kstr = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2076 PyObject *ident = NULL; |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2077 PyObject *key = NULL; |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2078 PyObject *value = NULL; |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2079 PyObject *it = NULL; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2080 int skipkeys; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2081 Py_ssize_t idx; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2082 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2083 if (open_dict == NULL || close_dict == NULL || empty_dict == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2084 open_dict = PyString_InternFromString("{"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2085 close_dict = PyString_InternFromString("}"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2086 empty_dict = PyString_InternFromString("{}"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2087 if (open_dict == NULL || close_dict == NULL || empty_dict == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2088 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2089 } |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2090 if (Py_SIZE(dct) == 0) |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2091 return PyList_Append(rval, empty_dict); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2092 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2093 if (s->markers != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2094 int has_key; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2095 ident = PyLong_FromVoidPtr(dct); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2096 if (ident == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2097 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2098 has_key = PyDict_Contains(s->markers, ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2099 if (has_key) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2100 if (has_key != -1) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2101 PyErr_SetString(PyExc_ValueError, "Circular reference detected"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2102 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2103 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2104 if (PyDict_SetItem(s->markers, ident, dct)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2105 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2106 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2107 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2108 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2109 if (PyList_Append(rval, open_dict)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2110 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2111 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2112 if (s->indent != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2113 /* TODO: DOES NOT RUN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2114 indent_level += 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2115 /* |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2116 newline_indent = '\n' + (' ' * (_indent * _current_indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2117 separator = _item_separator + newline_indent |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2118 buf += newline_indent |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2119 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2120 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2121 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2122 /* TODO: C speedup not implemented for sort_keys */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2123 |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2124 it = PyObject_GetIter(dct); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2125 if (it == NULL) |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2126 goto bail; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2127 skipkeys = PyObject_IsTrue(s->skipkeys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2128 idx = 0; |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2129 while ((key = PyIter_Next(it)) != NULL) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2130 PyObject *encoded; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2131 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2132 if (PyString_Check(key) || PyUnicode_Check(key)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2133 Py_INCREF(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2134 kstr = key; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2135 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2136 else if (PyFloat_Check(key)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2137 kstr = encoder_encode_float(s, key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2138 if (kstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2139 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2140 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2141 else if (PyInt_Check(key) || PyLong_Check(key)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2142 kstr = PyObject_Str(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2143 if (kstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2144 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2145 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2146 else if (key == Py_True || key == Py_False || key == Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2147 kstr = _encoded_const(key); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2148 if (kstr == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2149 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2150 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2151 else if (skipkeys) { |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2152 Py_DECREF(key); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2153 continue; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2154 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2155 else { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2156 /* TODO: include repr of key */ |
|
63124
2f1a836f0fac
Apply patch from Ray Allen for issue 9296
Doug Hellmann <doug.hellmann@gmail.com>
parents:
61192
diff
changeset
|
2157 PyErr_SetString(PyExc_TypeError, "keys must be a string"); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2158 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2159 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2160 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2161 if (idx) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2162 if (PyList_Append(rval, s->item_separator)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2163 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2164 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2165 |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2166 value = PyObject_GetItem(dct, key); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2167 if (value == NULL) |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2168 goto bail; |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2169 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2170 encoded = encoder_encode_string(s, kstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2171 Py_CLEAR(kstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2172 if (encoded == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2173 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2174 if (PyList_Append(rval, encoded)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2175 Py_DECREF(encoded); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2176 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2177 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2178 Py_DECREF(encoded); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2179 if (PyList_Append(rval, s->key_separator)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2180 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2181 if (encoder_listencode_obj(s, rval, value, indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2182 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2183 idx += 1; |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2184 Py_CLEAR(value); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2185 Py_DECREF(key); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2186 } |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2187 if (PyErr_Occurred()) |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2188 goto bail; |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2189 Py_CLEAR(it); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2190 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2191 if (ident != NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2192 if (PyDict_DelItem(s->markers, ident)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2193 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2194 Py_CLEAR(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2195 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2196 if (s->indent != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2197 /* TODO: DOES NOT RUN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2198 /* |
|
61192
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
2199 indent_level -= 1; |
|
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
2200 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2201 yield '\n' + (' ' * (_indent * _current_indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2202 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2203 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2204 if (PyList_Append(rval, close_dict)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2205 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2206 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2207 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2208 bail: |
|
65752
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2209 Py_XDECREF(it); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2210 Py_XDECREF(key); |
|
64a97c4ebadc
Backport r72961 fixing issue #6105: json.dumps not following OrderedDict iteration order.
Raymond Hettinger <python@rcn.com>
parents:
65197
diff
changeset
|
2211 Py_XDECREF(value); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2212 Py_XDECREF(kstr); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2213 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2214 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2215 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2216 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2217 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2218 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2219 encoder_listencode_list(PyEncoderObject *s, PyObject *rval, PyObject *seq, Py_ssize_t indent_level) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2220 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2221 /* Encode Python list seq to a JSON term, rval is a PyList */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2222 static PyObject *open_array = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2223 static PyObject *close_array = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2224 static PyObject *empty_array = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2225 PyObject *ident = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2226 PyObject *s_fast = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2227 Py_ssize_t i; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2228 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2229 if (open_array == NULL || close_array == NULL || empty_array == NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2230 open_array = PyString_InternFromString("["); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2231 close_array = PyString_InternFromString("]"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2232 empty_array = PyString_InternFromString("[]"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2233 if (open_array == NULL || close_array == NULL || empty_array == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2234 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2235 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2236 ident = NULL; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2237 s_fast = PySequence_Fast(seq, "_iterencode_list needs a sequence"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2238 if (s_fast == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2239 return -1; |
|
80160
33ae62a4ecf5
Issue #16228: Fix a crash in the json module where a list changes size while it is being encoded.
Antoine Pitrou <solipsis@pitrou.net>
parents:
77842
diff
changeset
|
2240 if (PySequence_Fast_GET_SIZE(s_fast) == 0) { |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2241 Py_DECREF(s_fast); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2242 return PyList_Append(rval, empty_array); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2243 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2244 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2245 if (s->markers != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2246 int has_key; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2247 ident = PyLong_FromVoidPtr(seq); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2248 if (ident == NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2249 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2250 has_key = PyDict_Contains(s->markers, ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2251 if (has_key) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2252 if (has_key != -1) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2253 PyErr_SetString(PyExc_ValueError, "Circular reference detected"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2254 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2255 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2256 if (PyDict_SetItem(s->markers, ident, seq)) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2257 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2258 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2259 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2260 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2261 if (PyList_Append(rval, open_array)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2262 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2263 if (s->indent != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2264 /* TODO: DOES NOT RUN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2265 indent_level += 1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2266 /* |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2267 newline_indent = '\n' + (' ' * (_indent * _current_indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2268 separator = _item_separator + newline_indent |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2269 buf += newline_indent |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2270 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2271 } |
|
80160
33ae62a4ecf5
Issue #16228: Fix a crash in the json module where a list changes size while it is being encoded.
Antoine Pitrou <solipsis@pitrou.net>
parents:
77842
diff
changeset
|
2272 for (i = 0; i < PySequence_Fast_GET_SIZE(s_fast); i++) { |
|
33ae62a4ecf5
Issue #16228: Fix a crash in the json module where a list changes size while it is being encoded.
Antoine Pitrou <solipsis@pitrou.net>
parents:
77842
diff
changeset
|
2273 PyObject *obj = PySequence_Fast_GET_ITEM(s_fast, i); |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2274 if (i) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2275 if (PyList_Append(rval, s->item_separator)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2276 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2277 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2278 if (encoder_listencode_obj(s, rval, obj, indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2279 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2280 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2281 if (ident != NULL) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2282 if (PyDict_DelItem(s->markers, ident)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2283 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2284 Py_CLEAR(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2285 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2286 if (s->indent != Py_None) { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2287 /* TODO: DOES NOT RUN */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2288 /* |
|
61192
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
2289 indent_level -= 1; |
|
0cf80b70f838
Remove unneeded variable mutation and initializations.
Brett Cannon <bcannon@gmail.com>
parents:
57607
diff
changeset
|
2290 |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2291 yield '\n' + (' ' * (_indent * _current_indent_level)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2292 */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2293 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2294 if (PyList_Append(rval, close_array)) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2295 goto bail; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2296 Py_DECREF(s_fast); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2297 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2298 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2299 bail: |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2300 Py_XDECREF(ident); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2301 Py_DECREF(s_fast); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2302 return -1; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2303 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2304 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2305 static void |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2306 encoder_dealloc(PyObject *self) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2307 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2308 /* Deallocate Encoder */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2309 encoder_clear(self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2310 Py_TYPE(self)->tp_free(self); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2311 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2312 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2313 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2314 encoder_traverse(PyObject *self, visitproc visit, void *arg) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2315 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2316 PyEncoderObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2317 assert(PyEncoder_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2318 s = (PyEncoderObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2319 Py_VISIT(s->markers); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2320 Py_VISIT(s->defaultfn); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2321 Py_VISIT(s->encoder); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2322 Py_VISIT(s->indent); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2323 Py_VISIT(s->key_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2324 Py_VISIT(s->item_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2325 Py_VISIT(s->sort_keys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2326 Py_VISIT(s->skipkeys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2327 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2328 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2329 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2330 static int |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2331 encoder_clear(PyObject *self) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2332 { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2333 /* Deallocate Encoder */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2334 PyEncoderObject *s; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2335 assert(PyEncoder_Check(self)); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2336 s = (PyEncoderObject *)self; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2337 Py_CLEAR(s->markers); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2338 Py_CLEAR(s->defaultfn); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2339 Py_CLEAR(s->encoder); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2340 Py_CLEAR(s->indent); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2341 Py_CLEAR(s->key_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2342 Py_CLEAR(s->item_separator); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2343 Py_CLEAR(s->sort_keys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2344 Py_CLEAR(s->skipkeys); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2345 return 0; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2346 } |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2347 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2348 PyDoc_STRVAR(encoder_doc, "_iterencode(obj, _current_indent_level) -> iterable"); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2349 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2350 static |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2351 PyTypeObject PyEncoderType = { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2352 PyObject_HEAD_INIT(NULL) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2353 0, /* tp_internal */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2354 "_json.Encoder", /* tp_name */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2355 sizeof(PyEncoderObject), /* tp_basicsize */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2356 0, /* tp_itemsize */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2357 encoder_dealloc, /* tp_dealloc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2358 0, /* tp_print */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2359 0, /* tp_getattr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2360 0, /* tp_setattr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2361 0, /* tp_compare */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2362 0, /* tp_repr */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2363 0, /* tp_as_number */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2364 0, /* tp_as_sequence */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2365 0, /* tp_as_mapping */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2366 0, /* tp_hash */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2367 encoder_call, /* tp_call */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2368 0, /* tp_str */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2369 0, /* tp_getattro */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2370 0, /* tp_setattro */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2371 0, /* tp_as_buffer */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2372 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2373 encoder_doc, /* tp_doc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2374 encoder_traverse, /* tp_traverse */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2375 encoder_clear, /* tp_clear */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2376 0, /* tp_richcompare */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2377 0, /* tp_weaklistoffset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2378 0, /* tp_iter */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2379 0, /* tp_iternext */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2380 0, /* tp_methods */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2381 encoder_members, /* tp_members */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2382 0, /* tp_getset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2383 0, /* tp_base */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2384 0, /* tp_dict */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2385 0, /* tp_descr_get */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2386 0, /* tp_descr_set */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2387 0, /* tp_dictoffset */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2388 encoder_init, /* tp_init */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2389 0, /* tp_alloc */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2390 encoder_new, /* tp_new */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2391 0, /* tp_free */ |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2392 }; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2393 |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2394 static PyMethodDef speedups_methods[] = { |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2395 {"encode_basestring_ascii", |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2396 (PyCFunction)py_encode_basestring_ascii, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2397 METH_O, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2398 pydoc_encode_basestring_ascii}, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2399 {"scanstring", |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2400 (PyCFunction)py_scanstring, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2401 METH_VARARGS, |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2402 pydoc_scanstring}, |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2403 {NULL, NULL, 0, NULL} |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2404 }; |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2405 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2406 PyDoc_STRVAR(module_doc, |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2407 "json speedups\n"); |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2408 |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2409 void |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2410 init_json(void) |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2411 { |
|
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2412 PyObject *m; |
|
52199
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2413 PyScannerType.tp_new = PyType_GenericNew; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2414 if (PyType_Ready(&PyScannerType) < 0) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2415 return; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2416 PyEncoderType.tp_new = PyType_GenericNew; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2417 if (PyType_Ready(&PyEncoderType) < 0) |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2418 return; |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2419 m = Py_InitModule3("_json", speedups_methods, module_doc); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2420 Py_INCREF((PyObject*)&PyScannerType); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2421 PyModule_AddObject(m, "make_scanner", (PyObject*)&PyScannerType); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2422 Py_INCREF((PyObject*)&PyEncoderType); |
|
d95e5add3ca4
merge json library with simplejson 2.0.9 (issue 4136)
Bob Ippolito <bob@redivi.com>
parents:
49530
diff
changeset
|
2423 PyModule_AddObject(m, "make_encoder", (PyObject*)&PyEncoderType); |
|
46676
4ded35754cb7
Add the 'json' package. Code taken from simplejson 1.9 and contributed by Bob
Brett Cannon <bcannon@gmail.com>
parents:
diff
changeset
|
2424 } |
