JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/josepy/__pycache__/interfaces.cpython-39.opt-1.pyc

a

�Bgn�@sldZddlZddlZddlmZmZddlmZmZm	Z	m
Z
ddlmZe	ddd�Z
Gd	d�dejd
�ZdS)zJOSE interfaces.�N)�Mapping�Sequence)�Any�Type�TypeVar�Union)�errors�GenericJSONDeSerializable�JSONDeSerializable)�boundc@s�eZdZdZejed�dd��Zed�dd�Ze	eje
eeed�dd	���Ze	e
ee
eefed
�dd��Zeed
�dd�Zed�dd�Ze	ded�dd��ZdS)r
a�Interface for (de)serializable JSON objects.

    Please recall, that standard Python library implements
    :class:`json.JSONEncoder` and :class:`json.JSONDecoder` that perform
    translations based on respective :ref:`conversion tables
    <conversion-table>` that look pretty much like the one below (for
    complete tables see relevant Python documentation):

    .. _conversion-table:

    ======  ======
     JSON   Python
    ======  ======
    object  dict
    ...     ...
    ======  ======

    While the above **conversion table** is about translation of JSON
    documents to/from the basic Python types only,
    :class:`JSONDeSerializable` introduces the following two concepts:

      serialization
        Turning an arbitrary Python object into Python object that can
        be encoded into a JSON document. **Full serialization** produces
        a Python object composed of only basic types as required by the
        :ref:`conversion table <conversion-table>`. **Partial
        serialization** (accomplished by :meth:`to_partial_json`)
        produces a Python object that might also be built from other
        :class:`JSONDeSerializable` objects.

      deserialization
        Turning a decoded Python object (necessarily one of the basic
        types as required by the :ref:`conversion table
        <conversion-table>`) into an arbitrary Python object.

    Serialization produces **serialized object** ("partially serialized
    object" or "fully serialized object" for partial and full
    serialization respectively) and deserialization produces
    **deserialized object**, both usually denoted in the source code as
    ``jobj``.

    Wording in the official Python documentation might be confusing
    after reading the above, but in the light of those definitions, one
    can view :meth:`json.JSONDecoder.decode` as decoder and
    deserializer of basic types, :meth:`json.JSONEncoder.default` as
    serializer of basic types, :meth:`json.JSONEncoder.encode`  as
    serializer and encoder of basic types.

    One could extend :mod:`json` to support arbitrary object
    (de)serialization either by:

      - overriding :meth:`json.JSONDecoder.decode` and
        :meth:`json.JSONEncoder.default` in subclasses

      - or passing ``object_hook`` argument (or ``object_hook_pairs``)
        to :func:`json.load`/:func:`json.loads` or ``default`` argument
        for :func:`json.dump`/:func:`json.dumps`.

    Interestingly, ``default`` is required to perform only partial
    serialization, as :func:`json.dumps` applies ``default``
    recursively. This is the idea behind making :meth:`to_partial_json`
    produce only partial serialization, while providing custom
    :meth:`json_dumps` that dumps with ``default`` set to
    :meth:`json_dump_default`.

    To make further documentation a bit more concrete, please, consider
    the following imaginatory implementation example::

      class Foo(JSONDeSerializable):
          def to_partial_json(self):
              return 'foo'

          @classmethod
          def from_json(cls, jobj):
              return Foo()

      class Bar(JSONDeSerializable):
          def to_partial_json(self):
              return [Foo(), Foo()]

          @classmethod
          def from_json(cls, jobj):
              return Bar()

    )�returncCs
t��dS)a�Partially serialize.

        Following the example, **partial serialization** means the following::

          assert isinstance(Bar().to_partial_json()[0], Foo)
          assert isinstance(Bar().to_partial_json()[1], Foo)

          # in particular...
          assert Bar().to_partial_json() != ['foo', 'foo']

        :raises josepy.errors.SerializationError:
            in case of any serialization error.
        :returns: Partially serializable object.

        N)�NotImplementedError��self�r�5/usr/lib/python3.9/site-packages/josepy/interfaces.py�to_partial_jsoncsz"JSONDeSerializable.to_partial_jsoncsttd��fdd���|�S)aDFully serialize.

        Again, following the example from before, **full serialization**
        means the following::

          assert Bar().to_json() == ['foo', 'foo']

        :raises josepy.errors.SerializationError:
            in case of any serialization error.
        :returns: Fully serialized object.

        )�objrcs�t|t�r�|���St|t�r$|St|t�r@�fdd�|D�St|t�r`t�fdd�|D��St|t�r��fdd�|��D�S|SdS)Ncsg|]}�|��qSrr��.0Zsubobj��
_serializerr�
<listcomp>��zBJSONDeSerializable.to_json.<locals>._serialize.<locals>.<listcomp>c3s|]}�|�VqdS)Nrrrrr�	<genexpr>�rzAJSONDeSerializable.to_json.<locals>._serialize.<locals>.<genexpr>csi|]\}}�|��|��qSrr)r�key�valuerrr�
<dictcomp>�rzBJSONDeSerializable.to_json.<locals>._serialize.<locals>.<dictcomp>)	�
isinstancer
r�str�listr�tupler�items)rrrrr�s




z.JSONDeSerializable.to_json.<locals>._serialize)rrrrr�to_jsonvszJSONDeSerializable.to_json)�cls�jobjrcCs|�S)a�Deserialize a decoded JSON document.

        :param jobj: Python object, composed of only other basic data
            types, as decoded from JSON document. Not necessarily
            :class:`dict` (as decoded from "JSON object" document).

        :raises josepy.errors.DeserializationError:
            if decoding was unsuccessful, e.g. in case of unparseable
            X509 certificate, or wrong padding in JOSE base64 encoded
            string, etc.

        r)r$r%rrr�	from_json�szJSONDeSerializable.from_json)r$�json_stringrc
CsHzt�|�}Wn.ty<}zt�|��WYd}~n
d}~00|�|�S)z&Deserialize from JSON document string.N)�json�loads�
ValueErrorrZDeserializationErrorr&)r$r'r)�errorrrr�
json_loads�s
 zJSONDeSerializable.json_loads)�kwargsrcKstj|fd|ji|��S)zsDump to JSON string using proper serializer.

        :returns: JSON document string.
        :rtype: str

        �default)r(�dumps�json_dump_default)rr-rrr�
json_dumps�szJSONDeSerializable.json_dumpscCs|jdddd�S)zNDump the object to pretty JSON document string.

        :rtype: str

        T�)�,z: )Z	sort_keys�indentZ
separators)r1rrrr�json_dumps_pretty�sz$JSONDeSerializable.json_dumps_pretty)�
python_objectrcCs&t|t�r|��Stt|�d��dS)a�Serialize Python object.

        This function is meant to be passed as ``default`` to
        :func:`json.dump` or :func:`json.dumps`. They call
        ``default(python_object)`` only for non-basic Python types, so
        this function necessarily raises :class:`TypeError` if
        ``python_object`` is not an instance of
        :class:`IJSONSerializable`.

        Please read the class docstring for more information.

        z is not JSON serializableN)rr
r�	TypeError�repr)r$r6rrrr0�s
z$JSONDeSerializable.json_dump_defaultN)�__name__�
__module__�__qualname__�__doc__�abc�abstractmethodrrr#�classmethodrr	r&rr�bytesr,r1r5r0rrrrr
sV �
	)�	metaclass)r<r=r(�collections.abcrr�typingrrrrZjosepyrr	�ABCMetar
rrrr�<module>s
Back to Directory  nL+D550H?Mx ,D"v]qv;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