MCPcopy Create free account
hub / github.com/STIXProject/python-stix / lookup_extension

Function lookup_extension

stix/bindings/__init__.py:66–91  ·  view source on GitHub ↗

Looks up the binding class for `typeinfo`, which is a namespace/typename pairing. Args: typeinfo: An lxml Element node or a stix.bindings.TypeInfo namedtuple. default: A binding class that will be returned if typeinfo is an Element without an xsi:type attribute.

(typeinfo, default=None)

Source from the content-addressed store, hash-verified

64
65
66def lookup_extension(typeinfo, default=None):
67 """Looks up the binding class for `typeinfo`, which is a namespace/typename
68 pairing.
69
70 Args:
71 typeinfo: An lxml Element node or a stix.bindings.TypeInfo namedtuple.
72 default: A binding class that will be returned if typeinfo is an
73 Element without an xsi:type attribute.
74
75 Returns:
76 A binding class that has been registered for the namespace and typename
77 found on `typeinfo`.
78
79 """
80 if not isinstance(typeinfo, TypeInfo):
81 if has_xsi_type(typeinfo):
82 typeinfo = get_type_info(typeinfo)
83 elif default:
84 return default
85
86 if typeinfo in _BINDING_EXTENSION_MAP:
87 return _BINDING_EXTENSION_MAP[typeinfo]
88
89 fmt = "No class implemented or registered for XML type '{%s}%s'"
90 error = fmt % (typeinfo.ns, typeinfo.typename)
91 raise NotImplementedError(error)
92
93
94def has_xsi_type(node):

Callers 15

buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90
buildChildrenMethod · 0.90

Calls 2

has_xsi_typeFunction · 0.85
get_type_infoFunction · 0.85

Tested by

no test coverage detected