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:
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