a
    0h                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 d dlmZ ejrrd dlmZ ddlmZ G dd	 d	Zd
d
dddZG dd deZdS )    )annotationsN)date)	http_date)Response   )Appc                   @  s   e Zd ZdZdddddZdddd	d
dZdddddddZddddddZddddddZddddddZ	ddddddZ
d S )!JSONProvidera  A standard set of JSON operations for an application. Subclasses
    of this can be used to customize JSON behavior or use different
    JSON libraries.

    To implement a provider for a specific library, subclass this base
    class and implement at least :meth:`dumps` and :meth:`loads`. All
    other methods have default implementations.

    To use a different provider, either subclass ``Flask`` and set
    :attr:`~flask.Flask.json_provider_class` to a provider class, or set
    :attr:`app.json <flask.Flask.json>` to an instance of the class.

    :param app: An application instance. This will be stored as a
        :class:`weakref.proxy` on the :attr:`_app` attribute.

    .. versionadded:: 2.2
    r   None)appreturnc                 C  s   t || _d S )N)weakrefproxy_app)selfr
    r   A/var/www/auris/lib/python3.9/site-packages/flask/json/provider.py__init__&   s    zJSONProvider.__init__t.Anystrobjkwargsr   c                 K  s   t dS )zSerialize data as JSON.

        :param obj: The data to serialize.
        :param kwargs: May be passed to the underlying JSON library.
        NNotImplementedErrorr   r   r   r   r   r   dumps)   s    zJSONProvider.dumpsz	t.IO[str])r   fpr   r   c                 K  s   | | j|fi | dS )a  Serialize data as JSON and write to a file.

        :param obj: The data to serialize.
        :param fp: A file opened for writing text. Should use the UTF-8
            encoding to be valid JSON.
        :param kwargs: May be passed to the underlying JSON library.
        N)writer   )r   r   r   r   r   r   r   dump1   s    zJSONProvider.dumpstr | bytessr   r   c                 K  s   t dS )zDeserialize data as JSON.

        :param s: Text or UTF-8 bytes.
        :param kwargs: May be passed to the underlying JSON library.
        Nr   r   r!   r   r   r   r   loads;   s    zJSONProvider.loadszt.IO[t.AnyStr])r   r   r   c                 K  s   | j | fi |S )zDeserialize data as JSON read from a file.

        :param fp: A file opened for reading text or UTF-8 bytes.
        :param kwargs: May be passed to the underlying JSON library.
        )r#   read)r   r   r   r   r   r   loadC   s    zJSONProvider.loadztuple[t.Any, ...]zdict[str, t.Any]argsr   r   c                 C  s8   |r|rt d|s|sd S t|dkr0|d S |p6|S )Nz9app.json.response() takes either args or kwargs, not both   r   )	TypeErrorlen)r   r'   r   r   r   r   _prepare_response_objK   s    z"JSONProvider._prepare_response_objr   c                 O  s"   |  ||}| jj| |ddS )a(  Serialize the given arguments as JSON, and return a
        :class:`~flask.Response` object with the ``application/json``
        mimetype.

        The :func:`~flask.json.jsonify` function calls this method for
        the current application.

        Either positional or keyword arguments can be given, not both.
        If no arguments are given, ``None`` is serialized.

        :param args: A single value to serialize, or multiple values to
            treat as a list to serialize.
        :param kwargs: Treat as a dict to serialize.
        application/jsonmimetype)r+   r   response_classr   )r   r'   r   r   r   r   r   responseY   s    zJSONProvider.responseN)__name__
__module____qualname____doc__r   r   r   r#   r%   r+   r0   r   r   r   r   r      s   
r   r   )or   c                 C  st   t | trt| S t | tjtjfr,t| S trDt	| rDt
| S t| drZt|  S tdt| j dd S )N__html__zObject of type z is not JSON serializable)
isinstancer   r   decimalDecimaluuidUUIDr   dataclassesZis_dataclassZasdicthasattrr6   r)   typer1   )r5   r   r   r   _defaultl   s    


r?   c                   @  sp   e Zd ZU dZeeZded< dZdZ	dZ
ded< dZd	d	d
dddZdd	d	dddZd	d	ddddZdS )DefaultJSONProvidera4  Provide JSON operations using Python's built-in :mod:`json`
    library. Serializes the following additional data types:

    -   :class:`datetime.datetime` and :class:`datetime.date` are
        serialized to :rfc:`822` strings. This is the same as the HTTP
        date format.
    -   :class:`uuid.UUID` is serialized to a string.
    -   :class:`dataclasses.dataclass` is passed to
        :func:`dataclasses.asdict`.
    -   :class:`~markupsafe.Markup` (or any object with a ``__html__``
        method) will call the ``__html__`` method to get a string.
    zt.Callable[[t.Any], t.Any]defaultTNzbool | Nonecompactr,   r   r   r   c                 K  s<   | d| j | d| j | d| j tj|fi |S )aI  Serialize data as JSON to a string.

        Keyword arguments are passed to :func:`json.dumps`. Sets some
        parameter defaults from the :attr:`default`,
        :attr:`ensure_ascii`, and :attr:`sort_keys` attributes.

        :param obj: The data to serialize.
        :param kwargs: Passed to :func:`json.dumps`.
        rA   ensure_ascii	sort_keys)
setdefaultrA   rC   rD   jsonr   r   r   r   r   r      s    
zDefaultJSONProvider.dumpsr   r    c                 K  s   t j|fi |S )zDeserialize data as JSON from a string or bytes.

        :param s: Text or UTF-8 bytes.
        :param kwargs: Passed to :func:`json.loads`.
        )rF   r#   r"   r   r   r   r#      s    zDefaultJSONProvider.loadsr   r&   c                 O  sl   |  ||}i }| jdu r"| jjs,| jdu r:|dd n|dd | jj| j|fi | d| jdS )	a  Serialize the given arguments as JSON, and return a
        :class:`~flask.Response` object with it. The response mimetype
        will be "application/json" and can be changed with
        :attr:`mimetype`.

        If :attr:`compact` is ``False`` or debug mode is enabled, the
        output will be formatted to be easier to read.

        Either positional or keyword arguments can be given, not both.
        If no arguments are given, ``None`` is serialized.

        :param args: A single value to serialize, or multiple values to
            treat as a list to serialize.
        :param kwargs: Treat as a dict to serialize.
        NFindentr   
separators),:
r-   )r+   rB   r   debugrE   r/   r   r.   )r   r'   r   r   Z	dump_argsr   r   r   r0      s    zDefaultJSONProvider.response)r1   r2   r3   r4   staticmethodr?   rA   __annotations__rC   rD   rB   r.   r   r#   r0   r   r   r   r   r@   |   s   
r@   )
__future__r   r<   r8   rF   typingtr:   r   datetimer   Zwerkzeug.httpr   TYPE_CHECKINGZwerkzeug.sansio.responser   Z
sansio.appr   r   r?   r@   r   r   r   r   <module>   s   Y