📄 ftnode.py
字号:
next.__dict__['__previousSibling'] = prev
childNode._4dom_setHierarchy(None, None, None)
return childNode
def appendChild(self, newChild):
if newChild.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
while newChild.childNodes:
self.appendChild(newChild.childNodes[0])
else:
self._4dom_validateNode(newChild)
# Remove from old parent
if newChild.parentNode != None:
newChild.parentNode.removeChild(newChild);
last = self.lastChild
self.childNodes.append(newChild)
newChild._4dom_setHierarchy(self, last, None)
newChild._4dom_fireMutationEvent('DOMNodeInserted',relatedNode=self)
self._4dom_fireMutationEvent('DOMSubtreeModified')
return newChild
def hasChildNodes(self):
return self.__dict__['__childNodes'].length != 0
def cloneNode(self, deep, newOwner=None, readOnly=0):
# Get constructor values
clone = self._4dom_clone(newOwner or self.ownerDocument)
# Set when cloning EntRef children
readOnly and clone._4dom_setReadOnly(readOnly)
# Copy the child nodes if deep
if deep and self.nodeType != Node.ATTRIBUTE_NODE:
# Children of EntRefs are cloned readOnly
if self.nodeType == Node.ENTITY_REFERENCE_NODE:
readOnly = 1
for child in self.childNodes:
new_child = child.cloneNode(1, newOwner, readOnly)
clone.appendChild(new_child)
return clone
def normalize(self):
# This one needs to join all adjacent text nodes
node = self.firstChild
while node:
if node.nodeType == Node.TEXT_NODE:
next = node.nextSibling
while next and next.nodeType == Node.TEXT_NODE:
node.appendData(next.data)
node.parentNode.removeChild(next)
next = node.nextSibling
if not node.length:
# Remove any empty text nodes
node.parentNode.removeChild(node)
elif node.nodeType == Node.ELEMENT_NODE:
for attr in node.attributes:
attr.normalize()
node.normalize()
node = node.nextSibling
def supports(self, feature, version):
return implementation.hasFeature(feature,version)
#
# Event Target interface implementation
#
def dispatchEvent(self, evt):
if not evt.type:
raise UnspecifiedEventTypeErr()
# the list of my ancestors for capture or bubbling
# we are lazy, so we initialize this list only if required
if evt._4dom_propagate and \
(evt.eventPhase == evt.CAPTURING_PHASE or evt.bubbles):
ancestors = [self]
while ancestors[-1].parentNode :
ancestors.append(ancestors[-1].parentNode)
# event capture
if evt._4dom_propagate and evt.eventPhase == evt.CAPTURING_PHASE :
ancestors.reverse()
for a in ancestors[:-1]:
evt.currentTarget = a
for captor in a.capture_listeners[evt.type]:
captor.handleEvent(evt)
if not evt._4dom_propagate:
break
# let's put back the list in the right order
# and move on to the next phase
ancestors.reverse()
evt.eventPhase = evt.AT_TARGET
# event handling by the target
if evt._4dom_propagate and evt.eventPhase == evt.AT_TARGET :
evt.currentTarget = self
for listener in self.listeners[evt.type]:
listener.handleEvent(evt)
# prepare for the next phase, if necessary
if evt.bubbles:
evt.eventPhase = evt.BUBBLING_PHASE
# event bubbling
if evt._4dom_propagate and evt.eventPhase == evt.BUBBLING_PHASE :
for a in ancestors[1:]:
evt.currentTarget = a
for listener in a.listeners[evt.type]:
listener.handleEvent(evt)
if not evt._4dom_propagate:
break
return evt._4dom_preventDefaultCalled
### Unsupported, undocumented DOM Level 3 methods ###
### documented in the Python binding ###
def isSameNode(self, other):
return self == other
### Internal Methods ###
#Functions not defined in the standard
#All are fourthought internal functions
#and should only be called by you if you specifically
#don't want your program to run :)
def _4dom_setattr(self, name, value):
self.__dict__[name] = value
def _4dom_fireMutationEvent(self,eventType,target=None,
relatedNode=None,prevValue=None,
newValue=None,attrName=None,attrChange=None):
if self.supports('MutationEvents', 2.0):
evt = self.ownerDocument.createEvent(eventType)
evt.target = target or self
evt.initMutationEvent(eventType,evt.eventSpec[eventType],0,
relatedNode,prevValue,newValue,attrName)
evt.attrChange = attrChange
evt.target.dispatchEvent(evt)
def _4dom_validateNode(self, newNode):
if not newNode.nodeType in self.__class__._allowedChildren:
raise HierarchyRequestErr()
if self.ownerDocument != newNode.ownerDocument:
raise WrongDocumentErr()
def _4dom_setHierarchy(self, parent, previous, next):
self.__dict__['__parentNode'] = parent
if previous:
previous.__dict__['__nextSibling'] = self
self.__dict__['__previousSibling'] = previous
self.__dict__['__nextSibling'] = next
if next:
next.__dict__['__previousSibling'] = self
return
def _4dom_setParentNode(self, parent):
self.__dict__['__parentNode'] = parent
def _4dom_setNextSibling(self,next):
self.__dict__['__nextSibling'] = next
def _4dom_setPreviousSibling(self,prev):
self.__dict__['__previousSibling'] = prev
def _4dom_setOwnerDocument(self, owner):
self.__dict__['__ownerDocument'] = owner
def _4dom_setReadOnly(self, flag):
self.__dict__['__readOnly'] = flag
### Helper Functions For Cloning ###
def _4dom_clone(self, owner):
raise NotSupportedErr('Subclass must override')
def __getinitargs__(self):
return (self.__dict__['__ownerDocument'],
self.__dict__['__namespaceURI'],
self.__dict__['__prefix'],
self.__dict__['__localName']
)
def __getstate__(self):
return self.__dict__['__childNodes']
def __setstate__(self, children):
self.__dict__['__childNodes'].extend(list(children))
prev = None
for child in children:
child._4dom_setHierarchy(self, prev, None)
prev = child
### Attribute Access Mappings ###
_readComputedAttrs = {'nodeName':_get_nodeName,
'nodeValue':_get_nodeValue,
'nodeType':_get_nodeType,
'parentNode':_get_parentNode,
'childNodes':_get_childNodes,
'firstChild':_get_firstChild,
'lastChild':_get_lastChild,
'previousSibling':_get_previousSibling,
'nextSibling':_get_nextSibling,
'attributes':_get_attributes,
'ownerDocument':_get_ownerDocument,
'namespaceURI':_get_namespaceURI,
'prefix':_get_prefix,
'localName':_get_localName
}
_writeComputedAttrs = {'nodeValue':_set_nodeValue,
'prefix':_set_prefix
}
# Create the read-only list of attributes
_readOnlyAttrs = filter(lambda k,m=_writeComputedAttrs: not m.has_key(k),
_readComputedAttrs.keys())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -