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
ae20722d
Kaydet (Commit)
ae20722d
authored
May 06, 2004
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Consider output encoding in XMLGenerator. Fixes #938076.
Backported to 2.3.
üst
0ea558f7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
13 deletions
+28
-13
saxutils.py
Lib/xml/sax/saxutils.py
+28
-13
No files found.
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
ae20722d
...
@@ -12,6 +12,15 @@ try:
...
@@ -12,6 +12,15 @@ try:
except
AttributeError
:
except
AttributeError
:
_StringTypes
=
[
types
.
StringType
]
_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
):
def
__dict_replace
(
s
,
d
):
"""Replace substrings of a string using a dictionary."""
"""Replace substrings of a string using a dictionary."""
for
key
,
value
in
d
.
items
():
for
key
,
value
in
d
.
items
():
...
@@ -83,10 +92,16 @@ class XMLGenerator(handler.ContentHandler):
...
@@ -83,10 +92,16 @@ class XMLGenerator(handler.ContentHandler):
self
.
_undeclared_ns_maps
=
[]
self
.
_undeclared_ns_maps
=
[]
self
.
_encoding
=
encoding
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
# ContentHandler methods
def
startDocument
(
self
):
def
startDocument
(
self
):
self
.
_
out
.
write
(
'<?xml version="1.0" encoding="
%
s"?>
\n
'
%
self
.
_write
(
'<?xml version="1.0" encoding="
%
s"?>
\n
'
%
self
.
_encoding
)
self
.
_encoding
)
def
startPrefixMapping
(
self
,
prefix
,
uri
):
def
startPrefixMapping
(
self
,
prefix
,
uri
):
...
@@ -99,13 +114,13 @@ class XMLGenerator(handler.ContentHandler):
...
@@ -99,13 +114,13 @@ class XMLGenerator(handler.ContentHandler):
del
self
.
_ns_contexts
[
-
1
]
del
self
.
_ns_contexts
[
-
1
]
def
startElement
(
self
,
name
,
attrs
):
def
startElement
(
self
,
name
,
attrs
):
self
.
_
out
.
write
(
'<'
+
name
)
self
.
_write
(
'<'
+
name
)
for
(
name
,
value
)
in
attrs
.
items
():
for
(
name
,
value
)
in
attrs
.
items
():
self
.
_
out
.
write
(
'
%
s=
%
s'
%
(
name
,
quoteattr
(
value
)))
self
.
_write
(
'
%
s=
%
s'
%
(
name
,
quoteattr
(
value
)))
self
.
_
out
.
write
(
'>'
)
self
.
_write
(
'>'
)
def
endElement
(
self
,
name
):
def
endElement
(
self
,
name
):
self
.
_
out
.
write
(
'</
%
s>'
%
name
)
self
.
_write
(
'</
%
s>'
%
name
)
def
startElementNS
(
self
,
name
,
qname
,
attrs
):
def
startElementNS
(
self
,
name
,
qname
,
attrs
):
if
name
[
0
]
is
None
:
if
name
[
0
]
is
None
:
...
@@ -114,32 +129,32 @@ class XMLGenerator(handler.ContentHandler):
...
@@ -114,32 +129,32 @@ class XMLGenerator(handler.ContentHandler):
else
:
else
:
# else try to restore the original prefix from the namespace
# else try to restore the original prefix from the namespace
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
'<'
+
name
)
self
.
_write
(
'<'
+
name
)
for
pair
in
self
.
_undeclared_ns_maps
:
for
pair
in
self
.
_undeclared_ns_maps
:
self
.
_
out
.
write
(
' xmlns:
%
s="
%
s"'
%
pair
)
self
.
_write
(
' xmlns:
%
s="
%
s"'
%
pair
)
self
.
_undeclared_ns_maps
=
[]
self
.
_undeclared_ns_maps
=
[]
for
(
name
,
value
)
in
attrs
.
items
():
for
(
name
,
value
)
in
attrs
.
items
():
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
'
%
s=
%
s'
%
(
name
,
quoteattr
(
value
)))
self
.
_write
(
'
%
s=
%
s'
%
(
name
,
quoteattr
(
value
)))
self
.
_
out
.
write
(
'>'
)
self
.
_write
(
'>'
)
def
endElementNS
(
self
,
name
,
qname
):
def
endElementNS
(
self
,
name
,
qname
):
if
name
[
0
]
is
None
:
if
name
[
0
]
is
None
:
name
=
name
[
1
]
name
=
name
[
1
]
else
:
else
:
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_
out
.
write
(
'</
%
s>'
%
name
)
self
.
_write
(
'</
%
s>'
%
name
)
def
characters
(
self
,
content
):
def
characters
(
self
,
content
):
self
.
_
out
.
write
(
escape
(
content
))
self
.
_write
(
escape
(
content
))
def
ignorableWhitespace
(
self
,
content
):
def
ignorableWhitespace
(
self
,
content
):
self
.
_
out
.
write
(
content
)
self
.
_write
(
content
)
def
processingInstruction
(
self
,
target
,
data
):
def
processingInstruction
(
self
,
target
,
data
):
self
.
_
out
.
write
(
'<?
%
s
%
s?>'
%
(
target
,
data
))
self
.
_write
(
'<?
%
s
%
s?>'
%
(
target
,
data
))
class
XMLFilterBase
(
xmlreader
.
XMLReader
):
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