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
f996e775
Kaydet (Commit)
f996e775
authored
Mar 16, 2012
tarafından
Eli Bendersky
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes Issue #14246: _elementtree parser will now handle io.StringIO
üst
e53d977e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
test_xml_etree.py
Lib/test/test_xml_etree.py
+14
-0
_elementtree.c
Modules/_elementtree.c
+22
-1
No files found.
Lib/test/test_xml_etree.py
Dosyayı görüntüle @
f996e775
...
...
@@ -16,6 +16,7 @@
import
sys
import
html
import
io
import
unittest
from
test
import
support
...
...
@@ -2026,6 +2027,18 @@ class ElementSlicingTest(unittest.TestCase):
del
e
[::
2
]
self
.
assertEqual
(
self
.
_subelem_tags
(
e
),
[
'a1'
])
class
StringIOTest
(
unittest
.
TestCase
):
def
test_read_from_stringio
(
self
):
tree
=
ET
.
ElementTree
()
stream
=
io
.
StringIO
()
stream
.
write
(
'''<?xml version="1.0"?><site></site>'''
)
stream
.
seek
(
0
)
tree
.
parse
(
stream
)
self
.
assertEqual
(
tree
.
getroot
()
.
tag
,
'site'
)
# --------------------------------------------------------------------
...
...
@@ -2077,6 +2090,7 @@ def test_main(module=pyET):
test_classes
=
[
ElementSlicingTest
,
StringIOTest
,
ElementTreeTest
,
TreeBuilderTest
]
if
module
is
pyET
:
...
...
Modules/_elementtree.c
Dosyayı görüntüle @
f996e775
...
...
@@ -2682,6 +2682,7 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
PyObject
*
reader
;
PyObject
*
buffer
;
PyObject
*
temp
;
PyObject
*
res
;
PyObject
*
fileobj
;
...
...
@@ -2703,7 +2704,27 @@ xmlparser_parse(XMLParserObject* self, PyObject* args)
return
NULL
;
}
if
(
!
PyBytes_CheckExact
(
buffer
)
||
PyBytes_GET_SIZE
(
buffer
)
==
0
)
{
if
(
PyUnicode_CheckExact
(
buffer
))
{
/* A unicode object is encoded into bytes using UTF-8 */
if
(
PyUnicode_GET_SIZE
(
buffer
)
==
0
)
{
Py_DECREF
(
buffer
);
break
;
}
temp
=
PyUnicode_AsEncodedString
(
buffer
,
"utf-8"
,
"surrogatepass"
);
if
(
!
temp
)
{
/* Propagate exception from PyUnicode_AsEncodedString */
Py_DECREF
(
buffer
);
Py_DECREF
(
reader
);
return
NULL
;
}
/* Here we no longer need the original buffer since it contains
* unicode. Make it point to the encoded bytes object.
*/
Py_DECREF
(
buffer
);
buffer
=
temp
;
}
else
if
(
!
PyBytes_CheckExact
(
buffer
)
||
PyBytes_GET_SIZE
(
buffer
)
==
0
)
{
Py_DECREF
(
buffer
);
break
;
}
...
...
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