Allow passing objects to Bundle as args

stix2.1
Greg Back 2017-02-01 14:57:07 -06:00
parent 58fccd7f7d
commit 2a1709a7de
2 changed files with 10 additions and 3 deletions

View File

@ -124,9 +124,10 @@ class Bundle(_STIXBase):
'objects': {},
}
def __init__(self, **kwargs):
# TODO: Allow variable number of arguments to pass "objects" to the
# Bundle constructor
def __init__(self, *args, **kwargs):
# Add any positional arguments to the 'objects' kwarg.
if args:
kwargs['objects'] = kwargs.get('objects', []) + list(args)
super(Bundle, self).__init__(**kwargs)

View File

@ -459,3 +459,9 @@ def test_create_bundle(indicator, malware, relationship):
bundle = stix2.Bundle(objects=[indicator, malware, relationship])
assert str(bundle) == EXPECTED_BUNDLE
def test_create_bundle_with_positional_args(indicator, malware, relationship):
bundle = stix2.Bundle(indicator, malware, relationship)
assert str(bundle) == EXPECTED_BUNDLE