From 2a1709a7de707a9cfc21221d0799d35502c81355 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 1 Feb 2017 14:57:07 -0600 Subject: [PATCH] Allow passing objects to Bundle as args --- stix2/__init__.py | 7 ++++--- stix2/test/test_stix2.py | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/stix2/__init__.py b/stix2/__init__.py index 52c549d..82b8989 100644 --- a/stix2/__init__.py +++ b/stix2/__init__.py @@ -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) diff --git a/stix2/test/test_stix2.py b/stix2/test/test_stix2.py index 511ee08..4bca1bb 100644 --- a/stix2/test/test_stix2.py +++ b/stix2/test/test_stix2.py @@ -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