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)
| 64 | |
| 65 | |
| 66 | def 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 | |
| 94 | def has_xsi_type(node): |
no test coverage detected