Skip to content

Commit

Permalink
Merge pull request #430 from oasis-open/bundle-objs-and-lists
Browse files Browse the repository at this point in the history
Allow mixing single objects and lists in bundle constructor
  • Loading branch information
emmanvg authored Jul 22, 2020
2 parents c497038 + 8063891 commit bb82bee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions stix2/v20/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions stix2/v21/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bb82bee

Please sign in to comment.