OXIESEC PANEL
- Current Dir:
/
/
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
jsons
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
09/05/2025 09:36:16 AM
rwxr-xr-x
📄
__init__.py
11.57 KB
03/16/2023 12:57:19 PM
rw-r--r--
📁
__pycache__
-
03/16/2023 12:57:19 PM
rwxr-xr-x
📄
_cache.py
1.23 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_common_impl.py
5.89 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_compatibility_impl.py
3.06 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_datetime_impl.py
4.98 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_dump_impl.py
4.01 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_extra_impl.py
1.7 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_fork_impl.py
1.39 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_key_transformers.py
1.32 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_lizers_impl.py
5.73 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_load_impl.py
8.16 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_multitasking.py
2.34 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_package_info.py
376 bytes
03/16/2023 12:57:19 PM
rw-r--r--
📄
_transform_impl.py
1.48 KB
03/16/2023 12:57:19 PM
rw-r--r--
📄
_validation.py
2.64 KB
03/16/2023 12:57:19 PM
rw-r--r--
📁
classes
-
03/16/2023 12:57:19 PM
rwxr-xr-x
📄
decorators.py
6.62 KB
03/16/2023 12:57:19 PM
rw-r--r--
📁
deserializers
-
03/16/2023 12:57:19 PM
rwxr-xr-x
📄
exceptions.py
6.02 KB
03/16/2023 12:57:19 PM
rw-r--r--
📁
serializers
-
03/16/2023 12:57:19 PM
rwxr-xr-x
Editing: _dump_impl.py
Close
""" PRIVATE MODULE: do not import (from) it directly. This module contains functionality for dumping stuff to json. """ import json from typing import Optional, Dict from jsons._cache import clear from jsons._common_impl import StateHolder from jsons._extra_impl import announce_class from jsons._lizers_impl import get_serializer from jsons.exceptions import SerializationError def dump(obj: object, cls: Optional[type] = None, *, strict: bool = False, fork_inst: Optional[type] = StateHolder, **kwargs) -> object: """ Serialize the given ``obj`` to a JSON equivalent type (e.g. dict, list, int, ...). The way objects are serialized can be finetuned by setting serializer functions for the specific type using ``set_serializer``. You can also provide ``cls`` to specify that ``obj`` needs to be serialized as if it was of type ``cls`` (meaning to only take into account attributes from ``cls``). The type ``cls`` must have a ``__slots__`` defined. Any type will do, but in most cases you may want ``cls`` to be a base class of ``obj``. :param obj: a Python instance of any sort. :param cls: if given, ``obj`` will be dumped as if it is of type ``type``. :param strict: a bool to determine if the serializer should be strict (i.e. only dumping stuff that is known to ``cls``). :param fork_inst: if given, it uses this fork of ``JsonSerializable``. :param kwargs: the keyword args are passed on to the serializer function. :return: the serialized obj as a JSON type. """ cls_ = cls or obj.__class__ serializer = get_serializer(cls_, fork_inst) # Is this the initial call or a nested? initial = kwargs.get('_initial', True) kwargs_ = { 'fork_inst': fork_inst, '_initial': False, 'strict': strict, **kwargs } announce_class(cls_, fork_inst=fork_inst) return _do_dump(obj, serializer, cls, initial, kwargs_) def _do_dump(obj, serializer, cls, initial, kwargs): try: result = serializer(obj, cls=cls, **kwargs) if initial: clear() return result except Exception as err: clear() raise SerializationError(str(err)) from err def dumps(obj: object, jdkwargs: Optional[Dict[str, object]] = None, *args, **kwargs) -> str: """ Extend ``json.dumps``, allowing any Python instance to be dumped to a string. Any extra (keyword) arguments are passed on to ``json.dumps``. :param obj: the object that is to be dumped to a string. :param jdkwargs: extra keyword arguments for ``json.dumps`` (not ``jsons.dumps``!) :param args: extra arguments for ``jsons.dumps``. :param kwargs: Keyword arguments that are passed on through the serialization process. passed on to the serializer function. :return: ``obj`` as a ``str``. """ jdkwargs = jdkwargs or {} dumped = dump(obj, *args, **kwargs) return json.dumps(dumped, **jdkwargs) def dumpb(obj: object, encoding: str = 'utf-8', jdkwargs: Optional[Dict[str, object]] = None, *args, **kwargs) -> bytes: """ Extend ``json.dumps``, allowing any Python instance to be dumped to bytes. Any extra (keyword) arguments are passed on to ``json.dumps``. :param obj: the object that is to be dumped to bytes. :param encoding: the encoding that is used to transform to bytes. :param jdkwargs: extra keyword arguments for ``json.dumps`` (not ``jsons.dumps``!) :param args: extra arguments for ``jsons.dumps``. :param kwargs: Keyword arguments that are passed on through the serialization process. passed on to the serializer function. :return: ``obj`` as ``bytes``. """ jdkwargs = jdkwargs or {} dumped_dict = dump(obj, *args, **kwargs) dumped_str = json.dumps(dumped_dict, **jdkwargs) return dumped_str.encode(encoding=encoding)