Merge pull request #430 from oasis-open/bundle-objs-and-lists

Allow mixing single objects and lists in bundle constructor
pull/1/head
Emmanuelle Vargas-Gonzalez 2020-07-22 13:00:22 -04:00 committed by GitHub
commit bb82beeec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View File

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