33
44# external
55from mixbox import fields
6+ from mixbox import entities
67from mixbox .cache import Cached
78
89# internal
1112from stix .bindings .stix_common import IdentityType
1213
1314
15+ class IdentityFactory (entities .EntityFactory ):
16+ @classmethod
17+ def entity_class (cls , key ):
18+ import stix .extensions .identity .ciq_identity_3_0 # noqa
19+ return stix .lookup_extension (key , default = Identity )
20+
21+
1422class Identity (Cached , stix .Entity ):
1523 _binding = common_binding
1624 _namespace = 'http://stix.mitre.org/common-1'
@@ -29,52 +37,6 @@ def __init__(self, id_=None, idref=None, name=None, related_identities=None):
2937 self .name = name
3038 self .related_identities = related_identities
3139
32- @staticmethod
33- def lookup_class (xsi_type ):
34- if not xsi_type :
35- raise ValueError ("xsi:type is required" )
36-
37- return stix .lookup_extension (xsi_type )
38-
39- @classmethod
40- def from_obj (cls , obj , partial = None ):
41- import stix .extensions .identity .ciq_identity_3_0 # noqa
42-
43- if not obj :
44- return None
45-
46- if not partial :
47- klass = stix .lookup_extension (obj , default = cls )
48- partial = klass .from_obj (obj , partial = klass ())
49- else :
50- partial .id_ = obj .id
51- partial .idref = obj .idref
52- partial .name = obj .Name
53- partial .related_identities = RelatedIdentities .from_obj (obj .Related_Identities )
54-
55- return partial
56-
57- @classmethod
58- def from_dict (cls , cls_dict , partial = None ):
59- import stix .extensions .identity .ciq_identity_3_0 # noqa
60-
61- if not cls_dict :
62- return None
63-
64- get = cls_dict .get
65-
66- if not partial :
67- klass = stix .lookup_extension (get ('xsi:type' ), default = cls )
68- partial = klass .from_dict (cls_dict , klass ())
69- else :
70- partial .name = get ('name' )
71- partial .id_ = get ('id' )
72- partial .idref = get ('idref' )
73- partial .related_identities = \
74- RelatedIdentities .from_dict (get ('related_identities' ))
75-
76- return partial
77-
7840
7941# We can't import RelatedIdentity until we have defined the Identity class.
8042from stix .common .related import RelatedIdentity
0 commit comments