예제 #1
0
    def insertBefore(self, newChild, refChild):
        #newChild = preAddHook(newChild)
        if isinstance(newChild, DocumentFragment):
            for c in tuple(newChild.childNodes):
                self.insertBefore(c, refChild)
            return newChild

        # Already owned, remove from its current parent
        if newChild.parentNode is not None:
            newChild.parentNode.removeChild(newChild)
        if refChild is None:
            self.appendChild(newChild)
        else:
            try:
                index = self.childNodes.index(refChild)
            except ValueError:
                raise NotFoundErr()
            self.childNodes.insert(index, newChild)
            newChild.nextSibling = refChild
            refChild.previousSibling = newChild
            if index:
                node = self.childNodes[index-1]
                node.nextSibling = newChild
                newChild.previousSibling = newChild
            else:
                newChild.previousSibling = None
                self.firstChild = newChild
            newChild.parentNode = self
        return newChild
예제 #2
0
파일: FtNode.py 프로젝트: OYZQ/odoo_qingjia
    def replaceChild(self, newChild, oldChild):
        if newChild.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
            refChild = oldChild.nextSibling
            self.removeChild(oldChild)
            self.insertBefore(newChild, refChild)
        else:
            self._4dom_validateNode(newChild)
            #Make sure the oldChild is indeed our child
            try:
                index = self.__dict__['__childNodes'].index(oldChild)
            except:
                raise NotFoundErr()

            self.__dict__['__childNodes'][index] = newChild
            if newChild.parentNode is not None:
                newChild.parentNode.removeChild(newChild)

            newChild._4dom_setHierarchy(self,
                                        oldChild.previousSibling,
                                        oldChild.nextSibling)

            oldChild._4dom_fireMutationEvent('DOMNodeRemoved',relatedNode=self)
            oldChild._4dom_setHierarchy(None, None, None)

            newChild._4dom_fireMutationEvent('DOMNodeInserted',relatedNode=self)
            self._4dom_fireMutationEvent('DOMSubtreeModified')
        return oldChild
예제 #3
0
 def removeNamedItem(self, name):
     old = self.get(name)
     if not old:
         raise NotFoundErr()
     del self[name]
     self._positions.remove(name)
     return old
예제 #4
0
파일: FtNode.py 프로젝트: OYZQ/odoo_qingjia
    def insertBefore(self, newChild, refChild):
        if refChild is None:
            return self.appendChild(newChild)
        elif newChild.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
            while newChild.firstChild:
                self.insertBefore(newChild.firstChild, refChild)
        else:
            #Make sure the newChild is all it is cracked up to be
            self._4dom_validateNode(newChild)

            #Make sure the refChild is indeed our child
            try:
                index = self.__dict__['__childNodes'].index(refChild)
            except:
                raise NotFoundErr()

            #Remove from old parent
            if newChild.parentNode != None:
                newChild.parentNode.removeChild(newChild);

            #Insert it
            self.__dict__['__childNodes'].insert(index, newChild)

            #Update the child caches
            newChild._4dom_setHierarchy(self, refChild.previousSibling, refChild)

            newChild._4dom_fireMutationEvent('DOMNodeInserted',relatedNode=self)
            self._4dom_fireMutationEvent('DOMSubtreeModified')
        return newChild
예제 #5
0
def _get_metadata(metadata, element, tag):
    values = []

    try:
        metadatadom = minidom.parse(metadata)
    except ExpatError as e:
        raise ExpatError("%s: %s" % (
            metadata,
            e,
        ))

    try:
        elements = metadatadom.getElementsByTagName(element)
        if not elements:
            return values
    except NotFoundErr:
        return values

    try:
        for _element in elements:
            node = _element.getElementsByTagName(tag)

            try:
                values.append(node[0].childNodes[0].data)
            except IndexError:
                pass
    except NotFoundErr:
        raise NotFoundErr("%s: Malformed input: missing 'flag' tag(s)" %
                          (metadata))

    metadatadom.unlink()
    return values
예제 #6
0
    def removeChild(self, oldChild):
        #oldChild = self.preRemoveHook(oldChild)
        import sys
        #print>>sys.stderr, id(self), type(self)        
        try:
            self.childNodes.remove(oldChild)
        except ValueError:
            #import sys
            #print 'should eq', oldChild.parentNode == self.childNodes[0].parentNode and self.childNodes[0].alias == oldChild.alias
            #print oldChild.parentNode, self.childNodes[0].parentNode, self.childNodes[0].alias, oldChild.alias 
            #print>>sys.stderr, 'self', self, id(self), type(self)        
            #print>>sys.stderr, 'oldchild', oldChild
            #print>>sys.stderr, 'firstchild', self.firstChild 
            #print>>sys.stderr, 'childNodes', self.childNodes
            #print>>sys.stderr, oldChild.parentNode, self.childNodes[0].parentNode 
            #print>>sys.stderr, oldChild.alias, self.childNodes[0].alias
            
            raise NotFoundErr()

        if oldChild.nextSibling is not None:
            oldChild.nextSibling.previousSibling = oldChild.previousSibling
        else:
            self.lastChild = oldChild.previousSibling

        if oldChild.previousSibling is not None:
            oldChild.previousSibling.nextSibling = oldChild.nextSibling
        else:
            self.firstChild = oldChild.nextSibling

        oldChild.nextSibling = oldChild.previousSibling = None
        oldChild.parentNode = None
        return oldChild
예제 #7
0
def _get_metadata(metadata, element, tag):
	values = []

	try:
		metadatadom = minidom.parse(metadata)
	except ExpatError as e:
		raise ExpatError("%s: %s" % (metadata, e,))

	try:
		elements = metadatadom.getElementsByTagName(element)
		if not elements:
			return values
	except NotFoundErr:
		return values

	try:
		for _element in elements:
			node = _element.getElementsByTagName(tag)

			if tag == "herd" and (not node or not node[0].childNodes):
#				print >> stderr, "'%s' is missing a <herd> tag or it is empty," % metadata
#				print >> stderr, "please file a bug at https://bugs.gentoo.org and refer to http://www.gentoo.org/proj/en/devrel/handbook/handbook.xml?part=2&chap=4"
				values.append("no-herd")
				continue

			try:
				values.append(node[0].childNodes[0].data)
			except IndexError:
				pass
	except NotFoundErr:
		raise NotFoundErr("%s: Malformed input: missing 'flag' tag(s)" % (metadata))

	metadatadom.unlink()
	return values
예제 #8
0
    def removeAttributeNode(self, oldAttr):
        for key, attr in self.attributes.items():
            if attr is oldAttr:
                del self.attributes[key]
                attr.ownerElement = attr.parentNode = None
                return attr

        raise NotFoundErr()
예제 #9
0
 def removeNamedItemNS(self, namespaceURI, localName):
     name = (namespaceURI, localName)
     old = self.get(name)
     if not old:
         raise NotFoundErr()
     del self[name]
     self._positions.remove(name)
     return old
예제 #10
0
 def deleteWork(data, identifier, param):
     deleted_work_count = (
         session.query(WorkResource)
         .filter(WorkResource.id == identifier)
         .delete()
     )
     if deleted_work_count > 0:
         return {"message": "OK", "count": deleted_work_count}
     else:
         raise NotFoundErr("Work not found")
예제 #11
0
 def removeNamedItemNS(self, namespaceURI, localName):
     if namespaceURI == '':
         raise NamespaceErr("Use None instead of '' for empty namespace")
     name = (namespaceURI, localName)
     old = self.get(name)
     if not old:
         raise NotFoundErr()
     del self[name]
     self._positions.remove(name)
     return old
예제 #12
0
 def get_element(self, node, tag, attribute, value):
     ret = None
     elements = node.getElementsByTagName(tag)
     for element in elements:
         if value == element.getAttribute(attribute):
             ret = element
             break
     if not ret:
         raise NotFoundErr('Could not find <%s %s="%s">' %
             (tag, attribute, value))
     return ret
예제 #13
0
 def showWork(data, identifier, param):
     if identifier < 0:
         results = session.query(WorkResource).all()
         return [result.asDict() for result in results]
     else:
         result = (
             session.query(WorkResource)
             .filter(WorkResource.id == identifier)
             .first()
         )
         if result is None:
             raise NotFoundErr("Work not found")
         return result.asDict()
예제 #14
0
 def updateWork(data, identifier, param):
     if not data:
         return {
             "message": "OK",
             "count": 0,
         }
     verified_data = UpdateWorkData.create(data, ignore_extra=ignore_extra)
     updated_work_count = (
         session.query(WorkResource)
         .filter(WorkResource.id == identifier)
         .update(verified_data.serialize())
     )
     if updated_work_count > 0:
         return {"message": "OK", "count": updated_work_count}
     else:
         raise NotFoundErr("Work not found")
예제 #15
0
파일: FtNode.py 프로젝트: OYZQ/odoo_qingjia
    def removeChild(self, childNode):
        #Make sure the childNode is indeed our child
        #FIXME: more efficient using list.remove()
        try:
            self.__dict__['__childNodes'].remove(childNode)
        except:
            raise NotFoundErr()
        childNode._4dom_fireMutationEvent('DOMNodeRemoved',relatedNode=self)
        self._4dom_fireMutationEvent('DOMSubtreeModified')

        # Adjust caches
        prev = childNode.previousSibling
        next = childNode.nextSibling
        if prev:
            prev.__dict__['__nextSibling'] = next
        if next:
            next.__dict__['__previousSibling'] = prev

        childNode._4dom_setHierarchy(None, None, None)
        return childNode
예제 #16
0
    def __getattr__(self, item):
        if isinstance(self.dom, NodeList):
            for node in self.dom:
                try:
                    return getattr(XMLAccessor(node), item)
                except BaseException:
                    pass
            from xml.dom import NotFoundErr

            raise NotFoundErr(item)
        else:
            try:
                node = self.dom.getElementsByTagName(item)
                if not node:
                    attrs = self.dom._attrs
                    return AttrDict(attrs)[item].nodeValue
                if isinstance(node, NodeList) and len(node) == 1:
                    node = node[0]
                return XMLAccessor(node)
            except BaseException:
                return getattr(self.dom, item)
예제 #17
0
    def replaceChild(self, newChild, oldChild):
        #newChild = self.preAddHook(newChild)
        if isinstance(newChild, DocumentFragment):
            refChild = oldChild.nextSibling
            self.removeChild(oldChild)
            return self.insertBefore(newChild, refChild)

        try:
            index = self.childNodes.index(oldChild)
        except ValueError:
            raise NotFoundErr()
        
        if newChild is oldChild:
            # Nothing to do
            return

        if newChild.parentNode is not None:
            newChild.parentNode.removeChild(newChild)

        self.childNodes[index] = newChild
        newChild.parentNode = self
        newChild.previousSibling = oldChild.previousSibling
        newChild.nextSibling = oldChild.nextSibling
        if newChild.previousSibling is not None:
            newChild.previousSibling.nextSibling = newChild
        else:
            self.firstChild = newChild

        if newChild.nextSibling is not None:
            newChild.nextSibling.previousSibling = newChild
        else:
            self.lastChild = newChild
        
        oldChild.nextSibling = oldChild.previousSibling = None
        oldChild.parentNode = None
        return oldChild