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
929b7047
Kaydet (Commit)
929b7047
authored
Nis 14, 2019
tarafından
Mickaël Schoentgen
Kaydeden (comit)
Stefan Behnel
Nis 14, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-31658: Make xml.sax.parse accepting Path objects (GH-8564)
üst
e9927e18
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
2 deletions
+21
-2
xml.sax.reader.rst
Doc/library/xml.sax.reader.rst
+5
-1
test_sax.py
Lib/test/test_sax.py
+12
-1
saxutils.py
Lib/xml/sax/saxutils.py
+2
-0
2018-07-30-12-00-15.bpo-31658._bx7a_.rst
...S.d/next/Library/2018-07-30-12-00-15.bpo-31658._bx7a_.rst
+2
-0
No files found.
Doc/library/xml.sax.reader.rst
Dosyayı görüntüle @
929b7047
...
...
@@ -102,13 +102,17 @@ The :class:`XMLReader` interface supports the following methods:
Process an input source, producing SAX events. The *source* object can be a
system identifier (a string identifying the input source -- typically a file
name or a URL), a file-like object, or an :class:`InputSource` object. When
name or a URL), a :class:`pathlib.Path` or :term:`path-like <path-like object>`
object, or an :class:`InputSource` object. When
:meth:`parse` returns, the input is completely processed, and the parser object
can be discarded or reset.
.. versionchanged:: 3.5
Added support of character streams.
.. versionchanged:: 3.8
Added support of path-like objects.
.. method:: XMLReader.getContentHandler()
...
...
Lib/test/test_sax.py
Dosyayı görüntüle @
929b7047
...
...
@@ -21,7 +21,7 @@ import os.path
import
shutil
from
urllib.error
import
URLError
from
test
import
support
from
test.support
import
findfile
,
run_unittest
,
TESTFN
from
test.support
import
findfile
,
run_unittest
,
FakePath
,
TESTFN
TEST_XMLFILE
=
findfile
(
"test.xml"
,
subdir
=
"xmltestdata"
)
TEST_XMLFILE_OUT
=
findfile
(
"test.xml.out"
,
subdir
=
"xmltestdata"
)
...
...
@@ -182,6 +182,10 @@ class ParseTest(unittest.TestCase):
with
self
.
assertRaises
(
SAXException
):
self
.
check_parse
(
f
)
def
test_parse_path_object
(
self
):
make_xml_file
(
self
.
data
,
'utf-8'
,
None
)
self
.
check_parse
(
FakePath
(
TESTFN
))
def
test_parse_InputSource
(
self
):
# accept data without declared but with explicitly specified encoding
make_xml_file
(
self
.
data
,
'iso-8859-1'
,
None
)
...
...
@@ -397,6 +401,13 @@ class PrepareInputSourceTest(unittest.TestCase):
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This was read from a file."
)
def
test_path_objects
(
self
):
# If the source is a Path object, use it as a system ID and open it.
prep
=
prepare_input_source
(
FakePath
(
self
.
file
))
self
.
assertIsNone
(
prep
.
getCharacterStream
())
self
.
checkContent
(
prep
.
getByteStream
(),
b
"This was read from a file."
)
def
test_binary_file
(
self
):
# If the source is a binary file-like object, use it as a byte
# stream.
...
...
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
929b7047
...
...
@@ -339,6 +339,8 @@ def prepare_input_source(source, base=""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
if
isinstance
(
source
,
os
.
PathLike
):
source
=
os
.
fspath
(
source
)
if
isinstance
(
source
,
str
):
source
=
xmlreader
.
InputSource
(
source
)
elif
hasattr
(
source
,
"read"
):
...
...
Misc/NEWS.d/next/Library/2018-07-30-12-00-15.bpo-31658._bx7a_.rst
0 → 100644
Dosyayı görüntüle @
929b7047
:func:`xml.sax.parse` now supports :term:`path-like <path-like object>`.
Patch by Mickaël Schoentgen.
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