Allow mixing single objects and lists in bundles

...in bundle constructor

Related: #429.
pull/1/head
Chris Lenk 2020-07-20 00:24:36 -04:00
parent c49703803c
commit 806389117f
2 changed files with 16 additions and 8 deletions

View File

@ -26,10 +26,14 @@ class Bundle(_STIXBase20):
def __init__(self, *args, **kwargs):
# Add any positional arguments to the 'objects' kwarg.
if args:
if isinstance(args[0], list):
kwargs['objects'] = args[0] + list(args[1:]) + kwargs.get('objects', [])
else:
kwargs['objects'] = list(args) + kwargs.get('objects', [])
obj_list = []
for arg in args:
if isinstance(arg, list):
obj_list = obj_list + arg
else:
obj_list.append(arg)
kwargs['objects'] = obj_list + kwargs.get('objects', [])
self._allow_custom = kwargs.get('allow_custom', False)
self._properties['objects'].contained.allow_custom = kwargs.get('allow_custom', False)

View File

@ -23,10 +23,14 @@ class Bundle(_STIXBase21):
def __init__(self, *args, **kwargs):
# Add any positional arguments to the 'objects' kwarg.
if args:
if isinstance(args[0], list):
kwargs['objects'] = args[0] + list(args[1:]) + kwargs.get('objects', [])
else:
kwargs['objects'] = list(args) + kwargs.get('objects', [])
obj_list = []
for arg in args:
if isinstance(arg, list):
obj_list = obj_list + arg
else:
obj_list.append(arg)
kwargs['objects'] = obj_list + kwargs.get('objects', [])
self._allow_custom = kwargs.get('allow_custom', False)
self._properties['objects'].contained.allow_custom = kwargs.get('allow_custom', False)