MCPcopy Index your code
hub / github.com/aboutcode-org/vulnerablecode / getElementByID

Method getElementByID

vulnerabilities/lib_oval.py:426–459  ·  view source on GitHub ↗

Uses the ovalid argument to determine what type of element is being referenced and locate that element in the OVAL ElementTree. Returns an OvalElement of the appropriate class (OvalDefinition, OvalTest, ...) or None if there is no ElementTree or if a matching item co

(self, ovalid)

Source from the content-addressed store, hash-verified

424 return [OvalVariable(element) for element in element_list]
425
426 def getElementByID(self, ovalid):
427 """
428 Uses the ovalid argument to determine what type of element is being referenced and locate that element
429 in the OVAL ElementTree.
430 Returns an OvalElement of the appropriate class (OvalDefinition, OvalTest, ...)
431 or None if there is no ElementTree or if a matching item could not be found
432
433 @rtype: OvalElement
434 @return: The located element as the appropriate OvalElement subclass, or None if no matching element was found.
435 """
436 if not ovalid:
437 return None
438
439 root = self.getDocumentRoot()
440 if not root:
441 return None
442
443 try:
444 oval_type = OvalElement.getElementTypeFromOvalID(ovalid)
445 except Exception:
446 return None
447
448 if oval_type == OvalDefinition.DEFINITION:
449 return self.id_to_definition[ovalid]
450 elif oval_type == OvalDefinition.TEST:
451 return self.id_to_test[ovalid]
452 elif oval_type == OvalDefinition.OBJECT:
453 return self.id_to_object[ovalid]
454 elif oval_type == OvalDefinition.STATE:
455 return self.id_to_state[ovalid]
456 elif oval_type == OvalDefinition.VARIABLE:
457 return self.id_to_variable[ovalid]
458 else:
459 return None
460
461 def addElement(self, element, replace=True):
462 """

Callers 4

addElementMethod · 0.95
get_pkgs_from_objMethod · 0.80

Calls 2

getDocumentRootMethod · 0.95

Tested by

no test coverage detected