PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/serializers/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/self/root/opt/saltstack/salt/lib/python3.10/site-packages/salt/serializers/json.py

"""
    salt.serializers.json
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Implements JSON serializer.

    It's just a wrapper around json (or simplejson if available).
"""

import salt.utils.json
from salt.serializers import DeserializationError, SerializationError

try:
    import simplejson as _json
except ImportError:
    import json as _json  # pylint: disable=blacklisted-import


__all__ = ["deserialize", "serialize", "available"]

available = True


def deserialize(stream_or_string, **options):
    """
    Deserialize any string or stream like object into a Python data structure.

    :param stream_or_string: stream or string to deserialize.
    :param options: options given to lower json/simplejson module.
    """

    try:
        if not isinstance(stream_or_string, (bytes, str)):
            return salt.utils.json.load(stream_or_string, _json_module=_json, **options)

        if isinstance(stream_or_string, bytes):
            stream_or_string = stream_or_string.decode("utf-8")

        return salt.utils.json.loads(stream_or_string, _json_module=_json)
    except Exception as error:  # pylint: disable=broad-except
        raise DeserializationError(error)


def serialize(obj, **options):
    """
    Serialize Python data to JSON.

    :param obj: the data structure to serialize
    :param options: options given to lower json/simplejson module.
    """

    try:
        if "fp" in options:
            return salt.utils.json.dump(obj, _json_module=_json, **options)
        else:
            return salt.utils.json.dumps(obj, _json_module=_json, **options)
    except Exception as error:  # pylint: disable=broad-except
        raise SerializationError(error)