File: //opt/alt/python311/lib/python3.11/site-packages/jsons/__pycache__/_dump_impl.cpython-311.pyc
�
)�;f � � � d Z ddlZddlmZmZ ddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ dd ed
�dedee d
edee def
d�Zd� Z ddedeeeef defd�Z ddededeeeef defd�ZdS )zr
PRIVATE MODULE: do not import (from) it directly.
This module contains functionality for dumping stuff to json.
� N)�Optional�Dict)�clear)�StateHolder)�announce_class)�get_serializer)�SerializationErrorF)�strict� fork_inst�obj�clsr
r �returnc � � |p| j }t ||� � }|� dd� � }|d|d�|�}t ||�� � t | ||||� � S )a�
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.
�_initialTF)r r r
)r )� __class__r �getr �_do_dump) r r
r
r �kwargs�cls_�
serializer�initial�kwargs_s �C/opt/alt/python311/lib/python3.11/site-packages/jsons/_dump_impl.py�dumpr s� � �4 ��#�-�D���i�0�0�J� �j�j��T�*�*�G� ���� � � �G� �4�9�-�-�-�-��C��S�'�7�;�;�;� c � � || fd|i|��}|rt � � |S # t $ r0}t � � t t |� � � � |�d }~ww xY w)Nr
)r � Exceptionr �str)r r r
r r �result�errs r r r : sw � �4���C�3�3�S�3�F�3�3��� ��G�G�G��
��� 4� 4� 4�
���� ��S���*�*��3�����4���s � �
A�+A�A�jdkwargsc �N � |pi }t | g|�R i |��}t j |fi |��S )a
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``.
)r �json�dumps)r r! �argsr �dumpeds r r$ r$ E sB � �"