def importNode(self, node, deep): if node.nodeType == stdlib_node.DOCUMENT_NODE: raise NotSupportedErr("cannot import document nodes") elif node.nodeType == stdlib_node.DOCUMENT_TYPE_NODE: raise NotSupportedErr("cannot import document type nodes") new_tree = self.cloneNode(deep) def set_owner(node): node.ownerDocument = self for child in node.xml_children: set_owner(child) if isinstance(node, tree.element): for attr in node.xml_attributes: set_owner(attr) return new_tree
def createEvent(self, eventType): import Event if eventType in Event.supportedEvents: #Only mutation events are supported return Event.MutationEvent(eventType) else: raise NotSupportedErr()
def createDocument(self, namespaceURI, qualifiedName, doctype): if doctype is not None: raise NotSupportedErr("doctype must be None for Domlettes") doc = Document(u'') if qualifiedName: elem = doc.createElementNS(namespaceURI, qualifiedName) doc.appendChild(elem) return doc
def xml_from_string(text, tree_parser=None): if tree_parser: raise NotSupportedErr( 'XML parsing on CPython 3.7 and older does not support a custom tree parser' ) tree_parser = ET.XMLPullParser parser = tree_parser(events=('start', 'end', 'start-ns', 'end-ns')) parser.feed(text) return _process_all_events(parser)
def get_aoa_gdop_node(estimated, node): """ Calculate geometric dilution of precision for node in estimated formation. Node is in the formation and all other nodes should be neighbors of node. Node should have Neighbors sensorReadings in it memory. """ if 'AoASensor' not in [sensor.name() for sensor in node.sensors]: raise NotSupportedErr('Only angle of arrival based gdop is supported') sensor = node.compositeSensor.get_sensor('AoASensor') sigma = sensor.probabilityFunction.scale for n in estimated: sensor = n.compositeSensor.get_sensor('AoASensor') if sensor.probabilityFunction.scale != sigma: raise NotSupportedErr('All nodes\' AoA sensors should have ' 'same scale') if len(estimated) <= 2: return 0. # Note from Torrieri, Statistical Theory of Passive Location Systems # if measurement sigmas are all equal gdop doesn't depend on sigma. sigma = 1 x, y = estimated[node][:2] fi = [] d = [] for n in estimated: xi, yi = estimated[n][:2] if n != node and n in node.memory['sensorReadings']['Neighbors']: fi.append(arctan2(y - yi, x - xi)) d.append(sqrt((x - xi)**2 + (y - yi)**2)) mi = ni = l = 0 for fii, di in zip(fi, d): mi += (cos(fii) / di / sigma)**2 # (129) l += (sin(fii) / di / sigma)**2 # (130) ni += sin(fii) * cos(fii) / (di * sigma)**2 # (131) sigma1 = sqrt(mi / (mi * l - ni**2)) # (126) sigma2 = sqrt(l / (mi * l - ni**2)) # (127) # sigma12 = sqrt(ni/(mi*l-ni**2)) sigmad = sqrt(sum((di * sigma)**2 for di in d) / len(d)) # (138) return sqrt((sigma1**2 + sigma2**2)) / sigmad # (139)
def importNode(self, importedNode, deep): importType = importedNode.nodeType # No import allow per spec if importType in [Node.DOCUMENT_NODE, Node.DOCUMENT_TYPE_NODE]: raise NotSupportedErr() # Only the EntRef itself is copied since the source and destination # documents might have defined the entity differently #FIXME: If the document being imported into provides a definition for # this entity name, its value is assigned. # Need entity support for this!! elif importType == Node.ENTITY_REFERENCE_NODE: deep = 0 return importedNode.cloneNode(deep, newOwner=self)
def importNode(self, node, deep): # Alien node, use nodeType checks only if node.nodeType == Node.ELEMENT_NODE: element = self.createElementNS(node.namespaceURI, node.nodeName) for attr in node.attributes.values(): if attr.specified: element.setAttributeNS(attr.namespaceURI, attr.name, attr.value) if deep: for child in node.childNodes: element.appendChild(self.importNode(child, deep)) return element if node.nodeType == Node.TEXT_NODE: return self.createTextNode(node.data) if node.nodeType == Node.COMMENT_NODE: return self.createComment(node.data) if node.nodeType == Node.PROCESSING_INSTRUCTION_NODE: return self.createProcessingInstruction(node.target, node.data) raise NotSupportedErr("importing nodeType %d" % node.nodeType)
def xml_from_file(source, tree_parser=None): if tree_parser: raise NotSupportedErr( 'XML parsing on CPython 3.7 and older does not support a custom tree parser' ) tree_parser = ET.XMLPullParser parser = tree_parser(events=('start', 'start-ns')) close_source = False if not hasattr(source, 'read'): source = open(source, 'rb') close_source = True try: while True: data = source.read(65536) if not data: break parser.feed(data) return _process_all_events(parser) finally: if close_source: source.close()
def _4dom_createNotation(*args, **kw): raise NotSupportedErr()
def _4dom_createEntity(*args, **kw): raise NotSupportedErr()
def createProcessingInstruction(*args, **kw): raise NotSupportedErr()
def createEntityReference(*args, **kw): raise NotSupportedErr()
def createCDATASection(*args, **kw): raise NotSupportedErr()
def __setitem__(self, index, item): raise NotSupportedErr()
def _set_currentNode(self, value): if value == None: raise NotSupportedErr() self.__dict__['__currentNode'] = value
def cloneNode(self, deep): raise NotSupportedErr("cloning of attribute nodes")
def _4dom_clone(self, owner): raise NotSupportedErr('Subclass must override')
def cloneNode(self, deep): raise NotSupportedErr("cloning document nodes")
def createRange(self): if not self.implementation.hasFeature('RANGE', '2.0'): raise NotSupportedErr() import Range return Range.Range(self)