File: //opt/alt/python37/lib/python3.7/site-packages/jsons/__pycache__/_load_impl.cpython-37.pyc
B
�P�e� � @ s� d Z ddlZddlmZ ddlmZmZmZmZmZm Z ddl
mZ ddlm
Z
mZmZmZmZmZmZmZ ddlmZ ddlmZ dd lmZmZmZ d"d
e
dd�eee e eee eee eg ef f ed�d
d�Z!ee"eed�dd�Z#d#e ee e eee ef ed�dd�Z$d$e%ee e e eee ef ed�dd�Z&eeeeeeee' f d�dd�Z(eeed�dd�Z)eed�d d!�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 K s� t | |� t| ||�r&t| ||� | S t|t�r<t|| |�}|}t| |||�dd��\}}t||�}|�dd�} d|i||||d||k d��}
t | ||| f|
�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 �kwargsZoriginal_clsr �deserializer�initial�kwargs_� r+ �A/opt/alt/python37/lib/python3.7/site-packages/jsons/_load_impl.py�load s&