File: //opt/alt/python311/lib/python3.11/site-packages/jsons/__pycache__/_load_impl.cpython-311.pyc
�
)�;f� � �: � d Z ddlZddlmZ ddlmZmZmZmZmZm Z ddl
mZ ddlm
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZ dd lmZmZmZ d!d
e
dd�ded
ee e dedee deee eg ef f defd�Z!dede"d
edefd�Z# d"de d
ee e deee ef defd�Z$ d#de%d
ee e de deee ef def
d�Z&ded
edededeeee' f f
d�Z(ded
edefd�Z)ded
efd �Z*dS )$zt
PRIVATE MODULE: do not import (from) it directly.
This module contains functionality for loading stuff from json.
� N)�JSONDecodeError)�Optional�Dict�Callable�Tuple�Any�Type)�clear)�StateHolder�get_cls_from_str�get_class_name�get_cls_and_meta�determine_precedence�VALID_TYPES�T�can_match_with_none)�get_deserializer)�validate)�DeserializationError�
JsonsError�DecodeErrorF)�strict� fork_inst�attr_getters�json_obj�clsr r r �returnc � � t | |� � t | ||� � rt | ||� � | S t |t � � rt || |� � }|}t
| |||� dd� � � � \ }}t ||� � }|� dd� � } d|i|�|||d||ud��}
t | ||| fi |
��S )a�
Deserialize the given ``json_obj`` to an object of type ``cls``. If the
contents of ``json_obj`` do not match the interface of ``cls``, a
DeserializationError is raised.
If ``json_obj`` contains a value that belongs to a custom class, there must
be a type hint present for that value in ``cls`` to let this function know
what type it should deserialize that value to.
**Example**:
>>> from typing import List
>>> import jsons
>>> class Person:
... # No type hint required for name
... def __init__(self, name):
... self.name = name
>>> class Family:
... # Person is a custom class, use a type hint
... def __init__(self, persons: List[Person]):
... self.persons = persons
>>> loaded = jsons.load({'persons': [{'name': 'John'}]}, Family)
>>> loaded.persons[0].name
'John'
If no ``cls`` is given, a dict is simply returned, but contained values
(e.g. serialized ``datetime`` values) are still deserialized.
If `strict` mode is off and the type of `json_obj` exactly matches `cls`
then `json_obj` is simply returned.
:param json_obj: the dict that is to be deserialized.
:param cls: a matching class of which an instance should be returned.
:param strict: a bool to determine if the deserializer should be strict
(i.e. fail on a partially deserialized `json_obj` or on `None`).
:param fork_inst: if given, it uses this fork of ``JsonSerializable``.
:param attr_getters: a ``dict`` that may hold callables that return values
for certain attributes.
:param kwargs: the keyword args are passed on to the deserializer function.
:return: an instance of ``cls`` if given, a dict otherwise.
�
_inferred_clsF�_initialT�
meta_hints)r r r r r )
�_check_for_none�_should_skipr �
isinstance�strr �!_check_and_get_cls_and_meta_hints�getr �_do_load)r r r r r �kwargs�original_clsr! �deserializer�initial�kwargs_s �C/opt/alt/python311/lib/python3.11/site-packages/jsons/_load_impl.py�loadr/ s � �d �H�c�"�"�"��H�c�6�*�*� ���3� �*�*�*����#�s��� 9��s�H�i�8�8���L�7��#�y�&�*�*�_�e�"D�"D�F� F�O�C�� $�C��3�3�L� �j�j��T�*�*�G� �j��
�� ��$���L�0�� � �G� �H�l�C��D�D�G�D�D�D� r+ r, c � � t |d�� � }|�$t d� |� � | |� � � || |fi |��}t |||d � � |rt � � |S # t
$ rR}t � � t
|t � � r� d� | ||� � }t || |� � |�d }~ww xY w)NT��fully_qualifiedzNo deserializer for type "{}"r z.Could not deserialize value "{}" into "{}". {})r
r �formatr r
� Exceptionr$ r ) r r+ r r, r) �cls_name�result�err�messages r. r( r( h s� � �
�c�4�8�8�8�H���"�#B�#I�#I�(�#S�#S�U]�_b�c�c�c�
���h��6�6�v�6�6�����f�[�1�2�2�2� � ��G�G�G��
�� � D� D� D�
�����c�:�&�&� ��B�I�I�(�T\�^a�b�b��"�7�H�c�:�:��C�����D���s �!A, �,
C�6A
C�C�str_�jdkwargsc � � |pi } t j | fi |��}t ||g|�R i |��S # t $ r}t d| ||� � |�d}~ww xY w)ak
Extend ``json.loads``, allowing a string to be loaded into a dict or a
Python instance of type ``cls``. Any extra (keyword) arguments are passed
on to ``json.loads``.
:param str_: the string that is to be loaded.
:param cls: a matching class of which an instance should be returned.
:param jdkwargs: extra keyword arguments for ``json.loads`` (not
``jsons.loads``!)
:param args: extra arguments for ``jsons.loads``.
:param kwargs: extra keyword arguments for ``jsons.loads``.
:return: a JSON-type object (dict, str, list, etc.) or an instance of type
``cls`` if given.
z:Could not load a dict; the given string is not valid JSON.N)�json�loadsr/ r r )r: r r; �argsr) �objr8 s r. r>