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
93bfe7d8
Commit
93bfe7d8
authored
Feb 25, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1470548: Do not buffer XMLGenerator output.
Add test for fragment producing with XMLGenerator.
parent
5b2cf5e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
3 deletions
+22
-3
Lib/test/test_sax.py
Lib/test/test_sax.py
+15
-0
Lib/xml/sax/saxutils.py
Lib/xml/sax/saxutils.py
+7
-3
No files found.
Lib/test/test_sax.py
View file @
93bfe7d8
...
...
@@ -403,6 +403,21 @@ class XmlgenTest:
func
(
result
)
self
.
assertFalse
(
result
.
closed
)
def
test_xmlgen_fragment
(
self
):
result
=
self
.
ioclass
()
gen
=
XMLGenerator
(
result
)
# Don't call gen.startDocument()
gen
.
startElement
(
"foo"
,
{
"a"
:
"1.0"
})
gen
.
characters
(
"Hello"
)
gen
.
endElement
(
"foo"
)
gen
.
startElement
(
"bar"
,
{
"b"
:
"2.0"
})
gen
.
endElement
(
"bar"
)
# Don't call gen.endDocument()
self
.
assertEqual
(
result
.
getvalue
(),
'<foo a="1.0">Hello</foo><bar b="2.0"></bar>'
)
class
StringXmlgenTest
(
XmlgenTest
,
unittest
.
TestCase
):
ioclass
=
StringIO
...
...
Lib/xml/sax/saxutils.py
View file @
93bfe7d8
...
...
@@ -98,9 +98,13 @@ def _gettextwriter(out, encoding):
except
AttributeError
:
pass
# wrap a binary writer with TextIOWrapper
return
io
.
TextIOWrapper
(
buffer
,
encoding
=
encoding
,
errors
=
'xmlcharrefreplace'
,
newline
=
'
\
n
'
)
class
UnbufferedTextIOWrapper
(
io
.
TextIOWrapper
):
def
write
(
self
,
s
):
super
(
UnbufferedTextIOWrapper
,
self
).
write
(
s
)
self
.
flush
()
return
UnbufferedTextIOWrapper
(
buffer
,
encoding
=
encoding
,
errors
=
'xmlcharrefreplace'
,
newline
=
'
\
n
'
)
class
XMLGenerator
(
handler
.
ContentHandler
):
...
...
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