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
9fef188c
Kaydet (Commit)
9fef188c
authored
Şub 10, 2013
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #1470548: XMLGenerator now works with binary output streams.
üst
d83c8244
88efc52d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
21 deletions
+48
-21
test_sax.py
Lib/test/test_sax.py
+0
-0
saxutils.py
Lib/xml/sax/saxutils.py
+46
-21
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_sax.py
Dosyayı görüntüle @
9fef188c
This diff is collapsed.
Click to expand it.
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
9fef188c
...
...
@@ -4,18 +4,10 @@ convenience of application and driver writers.
"""
import
os
,
urllib
.
parse
,
urllib
.
request
import
io
from
.
import
handler
from
.
import
xmlreader
# 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
():
...
...
@@ -76,14 +68,50 @@ def quoteattr(data, entities={}):
return
data
def
_gettextwriter
(
out
,
encoding
):
if
out
is
None
:
import
sys
return
sys
.
stdout
if
isinstance
(
out
,
io
.
TextIOBase
):
# use a text writer as is
return
out
# wrap a binary writer with TextIOWrapper
if
isinstance
(
out
,
io
.
RawIOBase
):
# Keep the original file open when the TextIOWrapper is
# destroyed
class
_wrapper
:
__class__
=
out
.
__class__
def
__getattr__
(
self
,
name
):
return
getattr
(
out
,
name
)
buffer
=
_wrapper
()
buffer
.
close
=
lambda
:
None
else
:
# This is to handle passed objects that aren't in the
# IOBase hierarchy, but just have a write method
buffer
=
io
.
BufferedIOBase
()
buffer
.
writable
=
lambda
:
True
buffer
.
write
=
out
.
write
try
:
# TextIOWrapper uses this methods to determine
# if BOM (for UTF-16, etc) should be added
buffer
.
seekable
=
out
.
seekable
buffer
.
tell
=
out
.
tell
except
AttributeError
:
pass
return
io
.
TextIOWrapper
(
buffer
,
encoding
=
encoding
,
errors
=
'xmlcharrefreplace'
,
newline
=
'
\n
'
,
write_through
=
True
)
class
XMLGenerator
(
handler
.
ContentHandler
):
def
__init__
(
self
,
out
=
None
,
encoding
=
"iso-8859-1"
,
short_empty_elements
=
False
):
if
out
is
None
:
import
sys
out
=
sys
.
stdout
handler
.
ContentHandler
.
__init__
(
self
)
self
.
_out
=
out
out
=
_gettextwriter
(
out
,
encoding
)
self
.
_write
=
out
.
write
self
.
_flush
=
out
.
flush
self
.
_ns_contexts
=
[{}]
# contains uri -> prefix dicts
self
.
_current_context
=
self
.
_ns_contexts
[
-
1
]
self
.
_undeclared_ns_maps
=
[]
...
...
@@ -91,12 +119,6 @@ class XMLGenerator(handler.ContentHandler):
self
.
_short_empty_elements
=
short_empty_elements
self
.
_pending_start_element
=
False
def
_write
(
self
,
text
):
if
isinstance
(
text
,
str
):
self
.
_out
.
write
(
text
)
else
:
self
.
_out
.
write
(
text
.
encode
(
self
.
_encoding
,
_error_handling
))
def
_qname
(
self
,
name
):
"""Builds a qualified name from a (ns_url, localname) pair"""
if
name
[
0
]:
...
...
@@ -125,6 +147,9 @@ class XMLGenerator(handler.ContentHandler):
self
.
_write
(
'<?xml version="1.0" encoding="
%
s"?>
\n
'
%
self
.
_encoding
)
def
endDocument
(
self
):
self
.
_flush
()
def
startPrefixMapping
(
self
,
prefix
,
uri
):
self
.
_ns_contexts
.
append
(
self
.
_current_context
.
copy
())
self
.
_current_context
[
uri
]
=
prefix
...
...
@@ -157,9 +182,9 @@ class XMLGenerator(handler.ContentHandler):
for
prefix
,
uri
in
self
.
_undeclared_ns_maps
:
if
prefix
:
self
.
_
out
.
write
(
' xmlns:
%
s="
%
s"'
%
(
prefix
,
uri
))
self
.
_write
(
' xmlns:
%
s="
%
s"'
%
(
prefix
,
uri
))
else
:
self
.
_
out
.
write
(
' xmlns="
%
s"'
%
uri
)
self
.
_write
(
' xmlns="
%
s"'
%
uri
)
self
.
_undeclared_ns_maps
=
[]
for
(
name
,
value
)
in
attrs
.
items
():
...
...
Misc/NEWS
Dosyayı görüntüle @
9fef188c
...
...
@@ -172,6 +172,8 @@ Core and Builtins
Library
-------
- Issue #1470548: XMLGenerator now works with binary output streams.
- Issue #6975: os.path.realpath() now correctly resolves multiple nested
symlinks on POSIX platforms.
...
...
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