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
ae20722d
Commit
ae20722d
authored
May 06, 2004
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consider output encoding in XMLGenerator. Fixes #938076.
Backported to 2.3.
parent
0ea558f7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
13 deletions
+28
-13
Lib/xml/sax/saxutils.py
Lib/xml/sax/saxutils.py
+28
-13
No files found.
Lib/xml/sax/saxutils.py
View file @
ae20722d
...
...
@@ -12,6 +12,15 @@ try:
except
AttributeError
:
_StringTypes
=
[
types
.
StringType
]
# See whether the xmlcharrefreplace error handler is
# supported
try
:
from
codecs
import
xmlcharrefreplace_errors
_error_handling
=
"xmlcharrefreplace"
del
xmlcharrefreplace_errors
except
ImportError
:
_error_handling
=
"strict"
def
__dict_replace
(
s
,
d
):
"""Replace substrings of a string using a dictionary."""
for
key
,
value
in
d
.
items
():
...
...
@@ -83,10 +92,16 @@ class XMLGenerator(handler.ContentHandler):
self
.
_undeclared_ns_maps
=
[]
self
.
_encoding
=
encoding
def
_write
(
self
,
text
):
if
isinstance
(
text
,
str
):
self
.
_out
.
write
(
text
)
else
:
self
.
_out
.
write
(
text
.
encode
(
self
.
_encoding
,
_error_handling
))
# ContentHandler methods
def
startDocument
(
self
):
self
.
_
out
.
write
(
'<?xml version="1.0" encoding="%s"?>
\
n
'
%
self
.
_write
(
'<?xml version="1.0" encoding="%s"?>
\
n
'
%
self
.
_encoding
)
def
startPrefixMapping
(
self
,
prefix
,
uri
):
...
...
@@ -99,13 +114,13 @@ class XMLGenerator(handler.ContentHandler):
del
self
.
_ns_contexts
[
-
1
]
def
startElement
(
self
,
name
,
attrs
):
self
.
_
out
.
write
(
'<'
+
name
)
self
.
_write
(
'<'
+
name
)
for
(
name
,
value
)
in
attrs
.
items
():
self
.
_
out
.
write
(
' %s=%s'
%
(
name
,
quoteattr
(
value
)))
self
.
_
out
.
write
(
'>'
)
self
.
_write
(
' %s=%s'
%
(
name
,
quoteattr
(
value
)))
self
.
_write
(
'>'
)
def
endElement
(
self
,
name
):
self
.
_
out
.
write
(
'</%s>'
%
name
)
self
.
_write
(
'</%s>'
%
name
)
def
startElementNS
(
self
,
name
,
qname
,
attrs
):
if
name
[
0
]
is
None
:
...
...
@@ -114,32 +129,32 @@ class XMLGenerator(handler.ContentHandler):
else
:
# else try to restore the original prefix from the namespace
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
'<'
+
name
)
self
.
_write
(
'<'
+
name
)
for
pair
in
self
.
_undeclared_ns_maps
:
self
.
_
out
.
write
(
' xmlns:%s="%s"'
%
pair
)
self
.
_write
(
' xmlns:%s="%s"'
%
pair
)
self
.
_undeclared_ns_maps
=
[]
for
(
name
,
value
)
in
attrs
.
items
():
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
' %s=%s'
%
(
name
,
quoteattr
(
value
)))
self
.
_
out
.
write
(
'>'
)
self
.
_write
(
' %s=%s'
%
(
name
,
quoteattr
(
value
)))
self
.
_write
(
'>'
)
def
endElementNS
(
self
,
name
,
qname
):
if
name
[
0
]
is
None
:
name
=
name
[
1
]
else
:
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
'</%s>'
%
name
)
self
.
_write
(
'</%s>'
%
name
)
def
characters
(
self
,
content
):
self
.
_
out
.
write
(
escape
(
content
))
self
.
_write
(
escape
(
content
))
def
ignorableWhitespace
(
self
,
content
):
self
.
_
out
.
write
(
content
)
self
.
_write
(
content
)
def
processingInstruction
(
self
,
target
,
data
):
self
.
_
out
.
write
(
'<?%s %s?>'
%
(
target
,
data
))
self
.
_write
(
'<?%s %s?>'
%
(
target
,
data
))
class
XMLFilterBase
(
xmlreader
.
XMLReader
):
...
...
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