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
291ed4fb
Commit
291ed4fb
authored
Dec 31, 2000
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Patch #102485 ] Check for legal children when adding children to a DOM node
parent
1a4d77b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
6 deletions
+30
-6
Lib/xml/dom/minidom.py
Lib/xml/dom/minidom.py
+30
-6
No files found.
Lib/xml/dom/minidom.py
View file @
291ed4fb
...
...
@@ -18,6 +18,8 @@ import string
_string
=
string
del
string
from
xml.dom
import
HierarchyRequestErr
# localize the types, and allow support for Unicode values if available:
import
types
_TupleType
=
types
.
TupleType
...
...
@@ -37,7 +39,8 @@ class Node(_Node):
_debug
=
0
_makeParentNodes
=
1
debug
=
None
childNodeTypes
=
()
def
__init__
(
self
):
self
.
childNodes
=
[]
self
.
parentNode
=
None
...
...
@@ -99,6 +102,9 @@ class Node(_Node):
return
self
.
childNodes
[
-
1
]
def
insertBefore
(
self
,
newChild
,
refChild
):
if
newChild
.
nodeType
not
in
self
.
childNodeTypes
:
raise
HierarchyRequestErr
,
\
"%s cannot be child of %s"
%
(
repr
(
newChild
),
repr
(
self
)
)
if
newChild
.
parentNode
is
not
None
:
newChild
.
parentNode
.
removeChild
(
newChild
)
if
refChild
is
None
:
...
...
@@ -119,6 +125,9 @@ class Node(_Node):
return
newChild
def
appendChild
(
self
,
node
):
if
node
.
nodeType
not
in
self
.
childNodeTypes
:
raise
HierarchyRequestErr
,
\
"%s cannot be child of %s"
%
(
repr
(
node
),
repr
(
self
)
)
if
node
.
parentNode
is
not
None
:
node
.
parentNode
.
removeChild
(
node
)
if
self
.
childNodes
:
...
...
@@ -134,6 +143,9 @@ class Node(_Node):
return
node
def
replaceChild
(
self
,
newChild
,
oldChild
):
if
newChild
.
nodeType
not
in
self
.
childNodeTypes
:
raise
HierarchyRequestErr
,
\
"%s cannot be child of %s"
%
(
repr
(
newChild
),
repr
(
self
)
)
if
newChild
.
parentNode
is
not
None
:
newChild
.
parentNode
.
removeChild
(
newChild
)
if
newChild
is
oldChild
:
...
...
@@ -250,7 +262,8 @@ class Attr(Node):
nodeType
=
Node
.
ATTRIBUTE_NODE
attributes
=
None
ownerElement
=
None
childNodeTypes
=
(
Node
.
TEXT_NODE
,
Node
.
ENTITY_REFERENCE_NODE
)
def
__init__
(
self
,
qName
,
namespaceURI
=
""
,
localName
=
None
,
prefix
=
None
):
# skip setattr for performance
d
=
self
.
__dict__
...
...
@@ -374,7 +387,10 @@ class Element(Node):
nodeType
=
Node
.
ELEMENT_NODE
nextSibling
=
None
previousSibling
=
None
childNodeTypes
=
(
Node
.
ELEMENT_NODE
,
Node
.
PROCESSING_INSTRUCTION_NODE
,
Node
.
COMMENT_NODE
,
Node
.
TEXT_NODE
,
Node
.
CDATA_SECTION_NODE
,
Node
.
ENTITY_REFERENCE_NODE
)
def
__init__
(
self
,
tagName
,
namespaceURI
=
""
,
prefix
=
""
,
localName
=
None
):
Node
.
__init__
(
self
)
...
...
@@ -508,7 +524,8 @@ class Comment(Node):
nodeType
=
Node
.
COMMENT_NODE
nodeName
=
"#comment"
attributes
=
None
childNodeTypes
=
()
def
__init__
(
self
,
data
):
Node
.
__init__
(
self
)
self
.
data
=
self
.
nodeValue
=
data
...
...
@@ -519,7 +536,8 @@ class Comment(Node):
class
ProcessingInstruction
(
Node
):
nodeType
=
Node
.
PROCESSING_INSTRUCTION_NODE
attributes
=
None
childNodeTypes
=
()
def
__init__
(
self
,
target
,
data
):
Node
.
__init__
(
self
)
self
.
target
=
self
.
nodeName
=
target
...
...
@@ -532,7 +550,8 @@ class Text(Node):
nodeType
=
Node
.
TEXT_NODE
nodeName
=
"#text"
attributes
=
None
childNodeTypes
=
()
def
__init__
(
self
,
data
):
Node
.
__init__
(
self
)
self
.
data
=
self
.
nodeValue
=
data
...
...
@@ -627,8 +646,13 @@ class Document(Node):
parentNode
=
None
implementation
=
DOMImplementation
()
childNodeTypes
=
(
Node
.
ELEMENT_NODE
,
Node
.
PROCESSING_INSTRUCTION_NODE
,
Node
.
COMMENT_NODE
,
Node
.
DOCUMENT_TYPE_NODE
)
def
appendChild
(
self
,
node
):
if
node
.
nodeType
not
in
self
.
childNodeTypes
:
raise
HierarchyRequestErr
,
\
"%s cannot be child of %s"
%
(
repr
(
node
),
repr
(
self
)
)
if
node
.
parentNode
is
not
None
:
node
.
parentNode
.
removeChild
(
node
)
...
...
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