Skip to content

Commit

Permalink
Modified VocabString class resolution to return a VocabString class i…
Browse files Browse the repository at this point in the history
…f xsi:type lookups failed. Fixes #266.
  • Loading branch information
Bryan Worrell committed Jun 3, 2015
1 parent 4973631 commit 05342c6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions stix/common/vocabs.py
Expand Up @@ -56,14 +56,17 @@ def __eq__(self, other):
def is_plain(self):
"""Whether the VocabString can be represented as a single value."""
return (
self._XSI_TYPE is None and
self.xsi_type is None and
self.vocab_name is None and
self.vocab_reference is None
)

@staticmethod
def lookup_class(xsi_type):
return stix.lookup_extension(xsi_type, default=VocabString)
try:
return stix.lookup_extension(xsi_type, default=VocabString)
except ValueError:
return VocabString

def to_obj(self, return_obj=None, ns_info=None):
super(VocabString, self).to_obj(return_obj=return_obj, ns_info=ns_info)
Expand Down Expand Up @@ -105,7 +108,7 @@ def from_obj(cls, vocab_obj, return_obj=None):
return None

if not return_obj:
klass = stix.lookup_extension(vocab_obj.xsi_type, default=cls)
klass = cls.lookup_class(vocab_obj.xsi_type)
return klass.from_obj(vocab_obj, return_obj=klass())

# xsi_type should be set automatically by the class's constructor.
Expand All @@ -127,7 +130,7 @@ def from_dict(cls, vocab_dict, return_obj=None):
if not return_obj:
if isinstance(vocab_dict, dict):
get = vocab_dict.get
klass = stix.lookup_extension(get('xsi:type'), default=cls)
klass = cls.lookup_class(get('xsi:type'))
return klass.from_dict(vocab_dict, return_obj=klass())
else:
return_obj = cls()
Expand Down

0 comments on commit 05342c6

Please sign in to comment.