Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b9c551dc
Commit
b9c551dc
authored
Apr 04, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10590: xml.sax.parseString() now supports string argument.
parent
93836ba2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
4 deletions
+19
-4
Doc/library/xml.sax.rst
Doc/library/xml.sax.rst
+5
-1
Lib/test/test_sax.py
Lib/test/test_sax.py
+7
-0
Lib/xml/sax/__init__.py
Lib/xml/sax/__init__.py
+5
-3
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/xml.sax.rst
View file @
b9c551dc
...
...
@@ -47,7 +47,11 @@ The convenience functions are:
.. function:: parseString(string, handler, error_handler=handler.ErrorHandler())
Similar to :func:`parse`, but parses from a buffer *string* received as a
parameter.
parameter. *string* must be a :class:`str` instance or a
:term:`bytes-like object`.
.. versionchanged:: 3.5
Added support of :class:`str` instances.
A typical SAX application uses three kinds of objects: readers, handlers and
input sources. "Reader" in this context is another term for parser, i.e. some
...
...
Lib/test/test_sax.py
View file @
b9c551dc
...
...
@@ -200,6 +200,13 @@ class ParseTest(unittest.TestCase):
parseString
(
s
,
XMLGenerator
(
result
,
'utf-8'
))
self
.
assertEqual
(
result
.
getvalue
(),
xml_str
(
self
.
data
,
'utf-8'
))
def
test_parseString_text
(
self
):
encodings
=
(
'us-ascii'
,
'iso-8859-1'
,
'utf-8'
,
'utf-16'
,
'utf-16le'
,
'utf-16be'
)
for
encoding
in
encodings
:
self
.
check_parseString
(
xml_str
(
self
.
data
,
encoding
))
self
.
check_parseString
(
self
.
data
)
def
test_parseString_bytes
(
self
):
# UTF-8 is default encoding, US-ASCII is compatible with UTF-8,
# UTF-16 is autodetected
...
...
Lib/xml/sax/__init__.py
View file @
b9c551dc
...
...
@@ -33,8 +33,7 @@ def parse(source, handler, errorHandler=ErrorHandler()):
parser
.
parse
(
source
)
def
parseString
(
string
,
handler
,
errorHandler
=
ErrorHandler
()):
from
io
import
BytesIO
import
io
if
errorHandler
is
None
:
errorHandler
=
ErrorHandler
()
parser
=
make_parser
()
...
...
@@ -42,7 +41,10 @@ def parseString(string, handler, errorHandler=ErrorHandler()):
parser
.
setErrorHandler
(
errorHandler
)
inpsrc
=
InputSource
()
inpsrc
.
setByteStream
(
BytesIO
(
string
))
if
isinstance
(
string
,
str
):
inpsrc
.
setCharacterStream
(
io
.
StringIO
(
string
))
else
:
inpsrc
.
setByteStream
(
io
.
BytesIO
(
string
))
parser
.
parse
(
inpsrc
)
# this is the parser list used by the make_parser function if no
...
...
Misc/NEWS
View file @
b9c551dc
...
...
@@ -19,6 +19,8 @@ Core and Builtins
Library
-------
- Issue #10590: xml.sax.parseString() now supports string argument.
- Issue #23338: Fixed formatting ctypes error messages on Cygwin.
Patch by Makoto Kato.
...
...
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