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
2bad58f5
Kaydet (Commit)
2bad58f5
authored
Şub 12, 2007
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Patch 1463026: Support default namespace in XMLGenerator.
Fixes #847665. Will backport.
üst
a69aa327
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
17 deletions
+59
-17
test_sax.py
Lib/test/test_sax.py
+38
-1
saxutils.py
Lib/xml/sax/saxutils.py
+19
-16
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_sax.py
Dosyayı görüntüle @
2bad58f5
...
...
@@ -216,7 +216,44 @@ def test_xmlgen_ns():
(
'<ns1:doc xmlns:ns1="
%
s"><udoc></udoc></ns1:doc>'
%
ns_uri
)
# ===== XMLFilterBase
def
test_1463026_1
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startElementNS
((
None
,
'a'
),
'a'
,
{(
None
,
'b'
):
'c'
})
gen
.
endElementNS
((
None
,
'a'
),
'a'
)
gen
.
endDocument
()
return
result
.
getvalue
()
==
start
+
'<a b="c"></a>'
def
test_1463026_2
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startPrefixMapping
(
None
,
'qux'
)
gen
.
startElementNS
((
'qux'
,
'a'
),
'a'
,
{})
gen
.
endElementNS
((
'qux'
,
'a'
),
'a'
)
gen
.
endPrefixMapping
(
None
)
gen
.
endDocument
()
return
result
.
getvalue
()
==
start
+
'<a xmlns="qux"></a>'
def
test_1463026_3
():
result
=
StringIO
()
gen
=
XMLGenerator
(
result
)
gen
.
startDocument
()
gen
.
startPrefixMapping
(
'my'
,
'qux'
)
gen
.
startElementNS
((
'qux'
,
'a'
),
'a'
,
{(
None
,
'b'
):
'c'
})
gen
.
endElementNS
((
'qux'
,
'a'
),
'a'
)
gen
.
endPrefixMapping
(
'my'
)
gen
.
endDocument
()
return
result
.
getvalue
()
==
start
+
'<my:a xmlns:my="qux" b="c"></my:a>'
# ===== Xmlfilterbase
def
test_filter_basic
():
result
=
StringIO
()
...
...
Lib/xml/sax/saxutils.py
Dosyayı görüntüle @
2bad58f5
...
...
@@ -100,6 +100,17 @@ class XMLGenerator(handler.ContentHandler):
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
]:
# The name is in a non-empty namespace
prefix
=
self
.
_current_context
[
name
[
0
]]
if
prefix
:
# If it is not the default namespace, prepend the prefix
return
prefix
+
":"
+
name
[
1
]
# Return the unqualified name
return
name
[
1
]
# ContentHandler methods
def
startDocument
(
self
):
...
...
@@ -125,29 +136,21 @@ class XMLGenerator(handler.ContentHandler):
self
.
_write
(
'</
%
s>'
%
name
)
def
startElementNS
(
self
,
name
,
qname
,
attrs
):
if
name
[
0
]
is
None
:
# if the name was not namespace-scoped, use the unqualified part
name
=
name
[
1
]
else
:
# else try to restore the original prefix from the namespace
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_write
(
'<'
+
name
)
self
.
_write
(
'<'
+
self
.
_qname
(
name
))
for
pair
in
self
.
_undeclared_ns_maps
:
self
.
_write
(
' xmlns:
%
s="
%
s"'
%
pair
)
for
prefix
,
uri
in
self
.
_undeclared_ns_maps
:
if
prefix
:
self
.
_out
.
write
(
' xmlns:
%
s="
%
s"'
%
(
prefix
,
uri
))
else
:
self
.
_out
.
write
(
' xmlns="
%
s"'
%
uri
)
self
.
_undeclared_ns_maps
=
[]
for
(
name
,
value
)
in
attrs
.
items
():
name
=
self
.
_current_context
[
name
[
0
]]
+
":"
+
name
[
1
]
self
.
_write
(
'
%
s=
%
s'
%
(
name
,
quoteattr
(
value
)))
self
.
_write
(
'
%
s=
%
s'
%
(
self
.
_qname
(
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
.
_write
(
'</
%
s>'
%
name
)
self
.
_write
(
'</
%
s>'
%
self
.
_qname
(
name
))
def
characters
(
self
,
content
):
self
.
_write
(
escape
(
content
))
...
...
Misc/NEWS
Dosyayı görüntüle @
2bad58f5
...
...
@@ -128,6 +128,8 @@ Core and builtins
Library
-------
- Patch 1463026: Support default namespace in XMLGenerator.
- Patch 1571379: Make trace'
s
--
ignore
-
dir
facility
work
in
the
face
of
relative
directory
names
.
...
...
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