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
7b77188e
Commit
7b77188e
authored
Feb 19, 2012
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create _attr/_attrNS lazily.
parent
14aa280d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
9 deletions
+34
-9
Lib/xml/dom/expatbuilder.py
Lib/xml/dom/expatbuilder.py
+1
-0
Lib/xml/dom/minidom.py
Lib/xml/dom/minidom.py
+33
-9
No files found.
Lib/xml/dom/expatbuilder.py
View file @
7b77188e
...
@@ -760,6 +760,7 @@ class Namespaces:
...
@@ -760,6 +760,7 @@ class Namespaces:
del
self
.
_ns_ordered_prefixes
[:]
del
self
.
_ns_ordered_prefixes
[:]
if
attributes
:
if
attributes
:
node
.
_ensure_attributes
()
_attrs
=
node
.
_attrs
_attrs
=
node
.
_attrs
_attrsNS
=
node
.
_attrsNS
_attrsNS
=
node
.
_attrsNS
for
i
in
range
(
0
,
len
(
attributes
),
2
):
for
i
in
range
(
0
,
len
(
attributes
),
2
):
...
...
Lib/xml/dom/minidom.py
View file @
7b77188e
...
@@ -689,13 +689,21 @@ class Element(Node):
...
@@ -689,13 +689,21 @@ class Element(Node):
self
.
childNodes
=
NodeList
()
self
.
childNodes
=
NodeList
()
self
.
nextSibling
=
self
.
previousSibling
=
None
self
.
nextSibling
=
self
.
previousSibling
=
None
self
.
_attrs
=
{}
# attributes are double-indexed:
# Attribute dictionaries are lazily created
self
.
_attrsNS
=
{}
# tagName -> Attribute
# attributes are double-indexed:
# tagName -> Attribute
# URI,localName -> Attribute
# URI,localName -> Attribute
# in the future: consider lazy generation
# in the future: consider lazy generation
# of attribute objects this is too tricky
# of attribute objects this is too tricky
# for now because of headaches with
# for now because of headaches with
# namespaces.
# namespaces.
self
.
_attrs
=
None
self
.
_attrsNS
=
None
def
_ensure_attributes
(
self
):
if
self
.
_attrs
is
None
:
self
.
_attrs
=
{}
self
.
_attrsNS
=
{}
def
_get_localName
(
self
):
def
_get_localName
(
self
):
try
:
try
:
...
@@ -707,6 +715,7 @@ class Element(Node):
...
@@ -707,6 +715,7 @@ class Element(Node):
return
self
.
tagName
return
self
.
tagName
def
unlink
(
self
):
def
unlink
(
self
):
if
self
.
_attrs
is
not
None
:
for
attr
in
list
(
self
.
_attrs
.
values
()):
for
attr
in
list
(
self
.
_attrs
.
values
()):
attr
.
unlink
()
attr
.
unlink
()
self
.
_attrs
=
None
self
.
_attrs
=
None
...
@@ -755,14 +764,19 @@ class Element(Node):
...
@@ -755,14 +764,19 @@ class Element(Node):
attr
.
nodeName
=
qualifiedName
attr
.
nodeName
=
qualifiedName
def
getAttributeNode
(
self
,
attrname
):
def
getAttributeNode
(
self
,
attrname
):
if
self
.
_attrs
is
None
:
return
None
return
self
.
_attrs
.
get
(
attrname
)
return
self
.
_attrs
.
get
(
attrname
)
def
getAttributeNodeNS
(
self
,
namespaceURI
,
localName
):
def
getAttributeNodeNS
(
self
,
namespaceURI
,
localName
):
if
self
.
_attrsNS
is
None
:
return
None
return
self
.
_attrsNS
.
get
((
namespaceURI
,
localName
))
return
self
.
_attrsNS
.
get
((
namespaceURI
,
localName
))
def
setAttributeNode
(
self
,
attr
):
def
setAttributeNode
(
self
,
attr
):
if
attr
.
ownerElement
not
in
(
None
,
self
):
if
attr
.
ownerElement
not
in
(
None
,
self
):
raise
xml
.
dom
.
InuseAttributeErr
(
"attribute node already owned"
)
raise
xml
.
dom
.
InuseAttributeErr
(
"attribute node already owned"
)
self
.
_ensure_attributes
()
old1
=
self
.
_attrs
.
get
(
attr
.
name
,
None
)
old1
=
self
.
_attrs
.
get
(
attr
.
name
,
None
)
if
old1
is
not
None
:
if
old1
is
not
None
:
self
.
removeAttributeNode
(
old1
)
self
.
removeAttributeNode
(
old1
)
...
@@ -781,6 +795,8 @@ class Element(Node):
...
@@ -781,6 +795,8 @@ class Element(Node):
setAttributeNodeNS
=
setAttributeNode
setAttributeNodeNS
=
setAttributeNode
def
removeAttribute
(
self
,
name
):
def
removeAttribute
(
self
,
name
):
if
self
.
_attrsNS
is
None
:
raise
xml
.
dom
.
NotFoundErr
()
try
:
try
:
attr
=
self
.
_attrs
[
name
]
attr
=
self
.
_attrs
[
name
]
except
KeyError
:
except
KeyError
:
...
@@ -788,6 +804,8 @@ class Element(Node):
...
@@ -788,6 +804,8 @@ class Element(Node):
self
.
removeAttributeNode
(
attr
)
self
.
removeAttributeNode
(
attr
)
def
removeAttributeNS
(
self
,
namespaceURI
,
localName
):
def
removeAttributeNS
(
self
,
namespaceURI
,
localName
):
if
self
.
_attrsNS
is
None
:
raise
xml
.
dom
.
NotFoundErr
()
try
:
try
:
attr
=
self
.
_attrsNS
[(
namespaceURI
,
localName
)]
attr
=
self
.
_attrsNS
[(
namespaceURI
,
localName
)]
except
KeyError
:
except
KeyError
:
...
@@ -810,9 +828,13 @@ class Element(Node):
...
@@ -810,9 +828,13 @@ class Element(Node):
removeAttributeNodeNS
=
removeAttributeNode
removeAttributeNodeNS
=
removeAttributeNode
def
hasAttribute
(
self
,
name
):
def
hasAttribute
(
self
,
name
):
if
self
.
_attrs
is
None
:
return
False
return
name
in
self
.
_attrs
return
name
in
self
.
_attrs
def
hasAttributeNS
(
self
,
namespaceURI
,
localName
):
def
hasAttributeNS
(
self
,
namespaceURI
,
localName
):
if
self
.
_attrsNS
is
None
:
return
False
return
(
namespaceURI
,
localName
)
in
self
.
_attrsNS
return
(
namespaceURI
,
localName
)
in
self
.
_attrsNS
def
getElementsByTagName
(
self
,
name
):
def
getElementsByTagName
(
self
,
name
):
...
@@ -853,6 +875,7 @@ class Element(Node):
...
@@ -853,6 +875,7 @@ class Element(Node):
writer
.
write
(
"/>%s"
%
(
newl
))
writer
.
write
(
"/>%s"
%
(
newl
))
def
_get_attributes
(
self
):
def
_get_attributes
(
self
):
self
.
_ensure_attributes
()
return
NamedNodeMap
(
self
.
_attrs
,
self
.
_attrsNS
,
self
)
return
NamedNodeMap
(
self
.
_attrs
,
self
.
_attrsNS
,
self
)
def
hasAttributes
(
self
):
def
hasAttributes
(
self
):
...
@@ -890,6 +913,7 @@ defproperty(Element, "localName",
...
@@ -890,6 +913,7 @@ defproperty(Element, "localName",
def
_set_attribute_node
(
element
,
attr
):
def
_set_attribute_node
(
element
,
attr
):
_clear_id_cache
(
element
)
_clear_id_cache
(
element
)
element
.
_ensure_attributes
()
element
.
_attrs
[
attr
.
name
]
=
attr
element
.
_attrs
[
attr
.
name
]
=
attr
element
.
_attrsNS
[(
attr
.
namespaceURI
,
attr
.
localName
)]
=
attr
element
.
_attrsNS
[(
attr
.
namespaceURI
,
attr
.
localName
)]
=
attr
...
...
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