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
9f1340b9
Commit
9f1340b9
authored
May 02, 2004
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not use the default namespace for attributes.
Fixes
http://bugs.debian.org/229885
Will backport to 2.3.
parent
d7911a33
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
16 deletions
+26
-16
Lib/test/test_xmllib.py
Lib/test/test_xmllib.py
+14
-0
Lib/xmllib.py
Lib/xmllib.py
+12
-16
No files found.
Lib/test/test_xmllib.py
View file @
9f1340b9
...
...
@@ -13,6 +13,8 @@ testdoc = """\
<greeting>Hello, world!</greeting>
"""
nsdoc
=
"<foo xmlns='URI' attr='val'/>"
import
warnings
warnings
.
filterwarnings
(
"ignore"
,
".* xmllib .* obsolete.*"
,
DeprecationWarning
,
r'xmllib$'
)
...
...
@@ -29,6 +31,18 @@ class XMLParserTestCase(unittest.TestCase):
parser
.
feed
(
c
)
parser
.
close
()
def
test_default_namespace
(
self
):
class
H
(
xmllib
.
XMLParser
):
def
unknown_starttag
(
self
,
name
,
attr
):
self
.
name
,
self
.
attr
=
name
,
attr
h
=
H
()
h
.
feed
(
nsdoc
)
h
.
close
()
# The default namespace applies to elements...
self
.
assertEquals
(
h
.
name
,
"URI foo"
)
# but not to attributes
self
.
assertEquals
(
h
.
attr
,
{
'attr'
:
'val'
})
def
test_main
():
test_support
.
run_unittest
(
XMLParserTestCase
)
...
...
Lib/xmllib.py
View file @
9f1340b9
...
...
@@ -6,8 +6,7 @@ import re
import
string
import
warnings
warnings
.
warn
(
"The xmllib module is obsolete. Use xml.sax instead."
,
DeprecationWarning
)
warnings
.
warn
(
"The xmllib module is obsolete. Use xml.sax instead."
,
DeprecationWarning
)
del
warnings
version
=
'0.3'
...
...
@@ -641,20 +640,17 @@ class XMLParser:
aprefix
,
key
=
res
.
group
(
'prefix'
,
'local'
)
if
self
.
__map_case
:
key
=
key
.
lower
()
if
aprefix
is
None
:
aprefix
=
''
ans
=
None
for
t
,
d
,
nst
in
self
.
stack
:
if
aprefix
in
d
:
ans
=
d
[
aprefix
]
if
ans
is
None
and
aprefix
!=
''
:
ans
=
self
.
__namespaces
.
get
(
aprefix
)
if
ans
is
not
None
:
key
=
ans
+
' '
+
key
elif
aprefix
!=
''
:
key
=
aprefix
+
':'
+
key
elif
ns
is
not
None
:
key
=
ns
+
' '
+
key
if
aprefix
is
not
None
:
ans
=
None
for
t
,
d
,
nst
in
self
.
stack
:
if
aprefix
in
d
:
ans
=
d
[
aprefix
]
if
ans
is
None
:
ans
=
self
.
__namespaces
.
get
(
aprefix
)
if
ans
is
not
None
:
key
=
ans
+
' '
+
key
else
:
key
=
aprefix
+
':'
+
key
nattrdict
[
key
]
=
val
attrnamemap
[
key
]
=
okey
attrdict
=
nattrdict
...
...
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