Example #1
0
    def test_is_sequence(self):
        self.assertTrue(utils.is_sequence([1, 2, 3]))
        self.assertTrue(utils.is_sequence((1, 2, 3)))
        self.assertTrue(utils.is_sequence(set([1, 2, 3])))
        self.assertTrue(utils.is_sequence({1: 1}))

        # Make sure that strings are not sequences.
        self.assertEqual(False, utils.is_sequence("abc"))
Example #2
0
    def test_is_sequence(self):
        self.assertTrue(utils.is_sequence([1,2,3]))
        self.assertTrue(utils.is_sequence((1,2,3)))
        self.assertTrue(utils.is_sequence(set([1,2,3])))
        self.assertTrue(utils.is_sequence({1:1}))

        # Make sure that strings are not sequences.
        self.assertEqual(False, utils.is_sequence("abc"))
Example #3
0
    def ttps(self, value):
        self._inner = []

        if utils.is_sequence(value):
            self.extend(value)
        else:
            self.append(value)
Example #4
0
    def ttps(self, value):
        self._inner = []

        if utils.is_sequence(value):
            self.extend(value)
        else:
            self.append(value)
Example #5
0
 def alternative_id(self, value):
     self._alternative_id = []
     if not value:
         return
     elif utils.is_sequence(value):
         self._alternative_id.extend(x for x in value if x)
     else:
         self._alternative_id.append(value)
Example #6
0
 def alternative_id(self, value):
     self._alternative_id = []
     if not value:
         return
     elif utils.is_sequence(value):
         self._alternative_id.extend(x for x in value if x)
     else:
         self._alternative_id.append(value)
Example #7
0
    def references(self, value):
        self._references = []

        if not value:
            return
        elif utils.is_sequence(value):
            self._references.extend(x for x in value if x)
        else:
            self._references.append(value)
Example #8
0
    def _initialize_inner(self, *args):
        # Check if it was initialized with args=None
        if not any(args):
            return

        for arg in args:
            if utils.is_sequence(arg):
                self.update(arg)
            else:
                self.add(arg)
Example #9
0
    def references(self, value):
        self._references = []

        if not value:
            return
        elif utils.is_sequence(value):
            for v in value:
                self.add_reference(v)
        else:
            self.add_reference(value)
    def references(self, value):
        self._references = []

        if not value:
            return
        elif utils.is_sequence(value):
            for v in value:
                self.add_reference(v)
        else:
            self.add_reference(value)
Example #11
0
    def _initialize_inner(self, *args):
        # Check if it was initialized with args=None
        if not any(args):
            return

        for arg in args:
            if utils.is_sequence(arg):
                self.update(arg)
            else:
                self.add(arg)
Example #12
0
    def observables(self, value):
        """
        The method will automatically create a top ``cybox.core.Observable`` and
        append all ``cybox.core.Observable`` using ``observable_composition``
        property when a ``list`` is given with length greater than 1.

        Note:
            The top level ``cybox.core.Observable`` will set the ``operator``
            property for the ``cybox.core.ObservableComposition`` via the
            ``observable_composition_operator`` property. The value of
            ``operator`` can be changed via ``observable_composition_operator``
            property. By default, the composition layer will be set to ``"OR"``.

        Args:
            value: A ``list`` of ``cybox.core.Observable`` instances or a single
                ``cybox.core.Observable`` instance.

        Raises:
            ValueError: If set to a value that cannot be converted to an
                instance of ``cybox.core.Observable``.
        """
        if not value:
            return

        if isinstance(value, Observable):
            self.observable = value

        elif utils.is_sequence(value):
            if len(value) == 1:
                self.observable = value
                return

            observable_comp = ObservableComposition()
            observable_comp.operator = self.observable_composition_operator

            for element in value:
                observable_comp.add(element)

            self.observable = Observable()
            self.observable.observable_composition = observable_comp
Example #13
0
    def observables(self, value):
        """
        The method will automatically create a top ``cybox.core.Observable`` and
        append all ``cybox.core.Observable`` using ``observable_composition``
        property when a ``list`` is given with length greater than 1.

        Note:
            The top level ``cybox.core.Observable`` will set the ``operator``
            property for the ``cybox.core.ObservableComposition`` via the
            ``observable_composition_operator`` property. The value of
            ``operator`` can be changed via ``observable_composition_operator``
            property. By default, the composition layer will be set to ``"OR"``.

        Args:
            value: A ``list`` of ``cybox.core.Observable`` instances or a single
                ``cybox.core.Observable`` instance.

        Raises:
            ValueError: If set to a value that cannot be converted to an
                instance of ``cybox.core.Observable``.
        """
        if not value:
            return

        if isinstance(value, Observable):
            self.observable = value

        elif utils.is_sequence(value):
            if len(value) == 1:
                self.add_observable(value[0])
                return

            observable_comp = ObservableComposition()
            observable_comp.operator = self.observable_composition_operator

            for element in value:
                observable_comp.add(element)

            self.observable = Observable()
            self.observable.observable_composition = observable_comp