How to use the jsonpickle.util.is_primitive function in jsonpickle

To help you get started, we’ve selected a few jsonpickle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jsonpickle / jsonpickle / tests / util_tests.py View on Github external
def test_is_primitive_bool(self):
        self.assertTrue(util.is_primitive(True))
        self.assertTrue(util.is_primitive(False))
github jsonpickle / jsonpickle / tests / util_tests.py View on Github external
def test_is_primitive_str(self):
        self.assertTrue(util.is_primitive('hello'))
        self.assertTrue(util.is_primitive(''))
github jsonpickle / jsonpickle / tests / util_tests.py View on Github external
def test_is_primitive_float(self):
        self.assertTrue(util.is_primitive(0))
        self.assertTrue(util.is_primitive(3.5))
        self.assertTrue(util.is_primitive(-3.5))
        self.assertTrue(util.is_primitive(float(3)))
github jsonpickle / jsonpickle / tests / util_tests.py View on Github external
def test_is_primitive_unicode(self):
        self.assertTrue(util.is_primitive(unicode('hello')))
        self.assertTrue(util.is_primitive(unicode('')))
        self.assertTrue(util.is_primitive(unicode('hello')))
github jsonpickle / jsonpickle / tests / util_tests.py View on Github external
def test_is_primitive_object(self):
        self.assertFalse(util.is_primitive(Thing('test')))
github joaquimrocha / SeriesFinale / src / jsonpickle / pickler.py View on Github external
>>> p.flatten(False)
        False
        >>> p.flatten([1, 2, 3, 4])
        [1, 2, 3, 4]
        >>> p.flatten((1,2,))[tags.TUPLE]
        [1, 2]
        >>> p.flatten({'key': 'value'})
        {'key': 'value'}
        """

        self._push()
        
        if self._depth == self._max_depth:
            return self._pop(repr(obj))

        if util.is_primitive(obj):
            return self._pop(obj)

        if util.is_list(obj):
            return self._pop([ self.flatten(v) for v in obj ])

        # We handle tuples and sets by encoding them in a "(tuple|set)dict"
        if util.is_tuple(obj):
            return self._pop({tags.TUPLE: [ self.flatten(v) for v in obj ]})

        if util.is_set(obj):
            return self._pop({tags.SET: [ self.flatten(v) for v in obj ]})

        if util.is_dictionary(obj):
            return self._pop(self._flatten_dict_obj(obj, obj.__class__()))

        if util.is_type(obj):
github jsonpickle / jsonpickle / jsonpickle / pickler.py View on Github external
def _get_flattener(self, obj):

        if PY2 and isinstance(obj, types.FileType):
            return self._flatten_file

        if util.is_bytes(obj):
            return self._flatten_bytestring

        if util.is_primitive(obj):
            return lambda obj: obj

        # Decimal is a primitive when use_decimal is True
        if self._use_decimal and isinstance(obj, decimal.Decimal):
            return lambda obj: obj

        list_recurse = self._list_recurse

        if util.is_list(obj):
            if self._mkref(obj):
                return list_recurse
            else:
                self._push()
                return self._getref

        # We handle tuples and sets by encoding them in a "(tuple|set)dict"
github git-cola / git-cola / jsonpickle / pickler.py View on Github external
>>> p.flatten(False)
        False
        >>> p.flatten([1, 2, 3, 4])
        [1, 2, 3, 4]
        >>> p.flatten((1,2,))[tags.TUPLE]
        [1, 2]
        >>> p.flatten({'key': 'value'})
        {'key': 'value'}
        """

        self._push()

        if self._depth == self._max_depth:
            return self._pop(repr(obj))

        if util.is_primitive(obj):
            return self._pop(obj)

        if util.is_list(obj):
            return self._pop([ self.flatten(v) for v in obj ])

        # We handle tuples and sets by encoding them in a "(tuple|set)dict"
        if util.is_tuple(obj):
            return self._pop({tags.TUPLE: [ self.flatten(v) for v in obj ]})

        if util.is_set(obj):
            return self._pop({tags.SET: [ self.flatten(v) for v in obj ]})

        if util.is_dictionary(obj):
            return self._pop(self._flatten_dict_obj(obj, obj.__class__()))

        if util.is_type(obj):