File: //lib/python3.9/site-packages/josepy/__pycache__/json_util.cpython-39.opt-1.pyc
a
�BgtH � @ s� d Z ddlZddlZddlZddlmZmZmZmZm Z m
Z
mZmZm
Z
ddlmZ ddlmZmZmZmZ e�e�Zd/eeeeeegef eeegef ed�dd �ZG d
d� d�ZG dd
� d
e�ZG dd� dej�Ze
ddd�ZG dd� dej ej!ed�Z"e#ed�dd�Z$d0eee% ee#d�dd�Z&e#ed�dd�Z'd1eee% ee#d�dd �Z(ej)ed!�d"d#�Z*eej)d$�d%d&�Z+ej)ed'�d(d)�Z,eej)d$�d*d+�Z-e
d,d-d�Z.G d.d-� d-e"�Z/dS )2z�JSON (de)serialization framework.
The framework presented here is somewhat based on `Go's "json" package`_
(especially the ``omitempty`` functionality).
.. _`Go's "json" package`: http://golang.org/pkg/encoding/json/
� N) �Any�Callable�Dict�Iterable�List�Mapping�Optional�Type�TypeVar)�crypto)�b64�errors�
interfaces�utilF�� json_name�default� omitempty�decoder�encoder�returnc C s t | ||||d�S )a4 Convenient function to declare a :class:`Field` with proper type annotations.
This function allows to write the following code:
import josepy
class JSON(josepy.JSONObjectWithFields):
typ: str = josepy.field('type')
def other_type(self) -> str:
return self.typ
�r r r r r )�_TypedFieldr � r �4/usr/lib/python3.9/site-packages/josepy/json_util.py�field s
�r c @ s� e Zd ZdZdZdeeeee egef ee egef dd�dd�Z
eeed�d d
��Zeed�dd�Z
ed d
�dd�Ze egef d d�dd�Ze egef d d�dd�Zeed�dd�Zeed�dd�Zeeed�dd��Zeeed�dd��ZdS )�Fielda� JSON object field.
:class:`Field` is meant to be used together with
:class:`JSONObjectWithFields`.
``encoder`` (``decoder``) is a callable that accepts a single
parameter, i.e. a value to be encoded (decoded), and returns the
serialized (deserialized) value. In case of errors it should raise
:class:`~josepy.errors.SerializationError`
(:class:`~josepy.errors.DeserializationError`).
Note, that ``decoder`` should perform partial serialization only.
:ivar str json_name: Name of the field when encoded to JSON.
:ivar default: Default value (used when not present in JSON object).
:ivar bool omitempty: If ``True`` and the field value is empty, then
it will not be included in the serialized JSON object, and
``default`` will be used for deserialization. Otherwise, if ``False``,
field is considered as required, value will always be included in the
serialized JSON objected, and it must also be present when
deserializing.
)r r r �fdec�fencNFr c C s>