Server IP : 209.38.156.173 / Your IP : 216.73.216.122 [ Web Server : Apache/2.4.52 (Ubuntu) System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.1.2-1ubuntu2.22 Disable Function : NONE Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /lib/python3/dist-packages/josepy/__pycache__/ |
Upload File : |
o h9Ra�G � @ s� d Z ddlZddlZddlZddlmZmZmZmZm Z m Z mZ ddlm Z ddlZddlmZmZmZmZ e�e�Z d1deded ed eegef deegef defd d�ZG dd� d�ZG dd� de�ZG dd� dej�ZG dd� dejejed�Z de!defdd�Z"d2dedee# dede!fdd�Z$de!defd d!�Z%d2dedee# dede!fd"d#�Z&d$ejj'defd%d&�Z(d'edejj'fd(d)�Z)d*ejj'defd+d,�Z*d'edejj'fd-d.�Z+G d/d0� d0e �Z,dS )3z�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)�Dict�Type�Any�Callable�List�Mapping�Optional)�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 �2/usr/lib/python3/dist-packages/josepy/json_util.py�field s �r c @ s e Zd ZdZdZ d#dedededeegef d eegef d dfdd�Z e d ed efdd��Zd ed efdd�Zded d fdd�Z deegef d d fdd�Zdeegef d d fdd�Zd ed efdd�Zd ed efdd�Ze d ed efdd ��Ze d ed efd!d"��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 r r r r r c C sD || _ || _|| _|d u r| jn|| _|d u r| j| _d S || _d S �N)r r r �default_decoderr �default_encoderr )�selfr r r r r r r r �__init__B s zField.__init__�valuec C s t |t� o| S )z�Is the provided value considered "empty" for this field? This is useful for subclasses that might want to override the definition of being empty, e.g. for some more exotic data types. )� isinstance�bool��clsr! r r r �_emptyM s zField._emptyc C s | � |�o| jS )zOmit the value in output?)r&