Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
c8d952df
Kaydet (Commit)
c8d952df
authored
May 27, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 6105: json encoder to respect iteration order of its inputs.
üst
0ffaaa63
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
5 deletions
+30
-5
test_encode_basestring_ascii.py
Lib/json/tests/test_encode_basestring_ascii.py
+8
-0
_json.c
Modules/_json.c
+22
-5
No files found.
Lib/json/tests/test_encode_basestring_ascii.py
Dosyayı görüntüle @
c8d952df
from
unittest
import
TestCase
import
json.encoder
from
json
import
dumps
from
collections
import
OrderedDict
CASES
=
[
(
'/
\\
"
\ucafe\ubabe\uab98\ufcde\ubcda\uef4a\x08\x0c\n\r\t
`1~!@#$
%
^&*()_+-=[]{}|;:
\'
,./<>?'
,
'"/
\\\\\\
"
\\
ucafe
\\
ubabe
\\
uab98
\\
ufcde
\\
ubcda
\\
uef4a
\\
b
\\
f
\\
n
\\
r
\\
t`1~!@#$
%
^&*()_+-=[]{}|;:
\'
,./<>?"'
),
...
...
@@ -35,3 +37,9 @@ class TestEncodeBaseStringAscii(TestCase):
self
.
assertEquals
(
result
,
expect
,
'{0!r} != {1!r} for {2}({3!r})'
.
format
(
result
,
expect
,
fname
,
input_string
))
def
test_ordered_dict
(
self
):
# See issue 6105
items
=
[(
'one'
,
1
),
(
'two'
,
2
),
(
'three'
,
3
),
(
'four'
,
4
),
(
'five'
,
5
)]
s
=
json
.
dumps
(
OrderedDict
(
items
))
self
.
assertEqual
(
s
,
'{"one": 1, "two": 2, "three": 3, "four": 4, "five": 5}'
)
Modules/_json.c
Dosyayı görüntüle @
c8d952df
...
...
@@ -1334,8 +1334,9 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
static
PyObject
*
empty_dict
=
NULL
;
PyObject
*
kstr
=
NULL
;
PyObject
*
ident
=
NULL
;
PyObject
*
key
,
*
value
;
Py_ssize_t
pos
;
PyObject
*
key
=
NULL
;
PyObject
*
value
=
NULL
;
PyObject
*
it
=
NULL
;
int
skipkeys
;
Py_ssize_t
idx
;
...
...
@@ -1346,7 +1347,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
if
(
open_dict
==
NULL
||
close_dict
==
NULL
||
empty_dict
==
NULL
)
return
-
1
;
}
if
(
Py
Dict_Size
(
dct
)
==
0
)
if
(
Py
_SIZE
(
dct
)
==
0
)
return
PyList_Append
(
rval
,
empty_dict
);
if
(
s
->
markers
!=
Py_None
)
{
...
...
@@ -1380,10 +1381,12 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
/* TODO: C speedup not implemented for sort_keys */
pos
=
0
;
it
=
PyObject_GetIter
(
dct
);
if
(
it
==
NULL
)
goto
bail
;
skipkeys
=
PyObject_IsTrue
(
s
->
skipkeys
);
idx
=
0
;
while
(
PyDict_Next
(
dct
,
&
pos
,
&
key
,
&
value
)
)
{
while
(
(
key
=
PyIter_Next
(
it
))
!=
NULL
)
{
PyObject
*
encoded
;
if
(
PyUnicode_Check
(
key
))
{
...
...
@@ -1406,6 +1409,7 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
goto
bail
;
}
else
if
(
skipkeys
)
{
Py_DECREF
(
key
);
continue
;
}
else
{
...
...
@@ -1430,10 +1434,20 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
Py_DECREF
(
encoded
);
if
(
PyList_Append
(
rval
,
s
->
key_separator
))
goto
bail
;
value
=
PyObject_GetItem
(
dct
,
key
);
if
(
value
==
NULL
)
goto
bail
;
if
(
encoder_listencode_obj
(
s
,
rval
,
value
,
indent_level
))
goto
bail
;
idx
+=
1
;
Py_CLEAR
(
value
);
Py_DECREF
(
key
);
}
if
(
PyErr_Occurred
())
goto
bail
;
Py_CLEAR
(
it
);
if
(
ident
!=
NULL
)
{
if
(
PyDict_DelItem
(
s
->
markers
,
ident
))
goto
bail
;
...
...
@@ -1451,6 +1465,9 @@ encoder_listencode_dict(PyEncoderObject *s, PyObject *rval, PyObject *dct, Py_ss
return
0
;
bail:
Py_XDECREF
(
it
);
Py_XDECREF
(
key
);
Py_XDECREF
(
value
);
Py_XDECREF
(
kstr
);
Py_XDECREF
(
ident
);
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment