o
    àý°jø  ã                   @  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r9d dlmZ ddlmZ G dd	„ d	ƒZddd„ZG dd„ deƒZdS )é    )ÚannotationsN)Údate)Ú	http_date)ÚResponseé   )ÚAppc                   @  sV   e Zd ZdZd"dd„Zd#dd„Zd$dd„Zd%dd„Zd&dd„Zd'dd„Z	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
    Úappr   ÚreturnÚNonec                 C  s   t  |¡| _d S )N)ÚweakrefÚproxyÚ_app)Úselfr	   © r   ú†/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/flask/json/provider.pyÚ__init__&   s   zJSONProvider.__init__Úobjút.AnyÚkwargsÚstrc                 K  ó   t ‚)z‘Serialize data as JSON.

        :param obj: The data to serialize.
        :param kwargs: May be passed to the underlying JSON library.
        ©ÚNotImplementedError©r   r   r   r   r   r   Údumps)   ó   zJSONProvider.dumpsÚfpú	t.IO[str]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Úsústr | bytesc                 K  r   )z�Deserialize data as JSON.

        :param s: Text or UTF-8 bytes.
        :param kwargs: May be passed to the underlying JSON library.
        r   ©r   r!   r   r   r   r   Úloads;   r   zJSONProvider.loadsút.IO[t.AnyStr]c                 K  s   | j | ¡ fi |¤ŽS )z»Deserialize 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.loadÚargsútuple[t.Any, ...]údict[str, t.Any]c                 C  s8   |r|rt dƒ‚|s|sd S t|ƒdkr|d S |p|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)r	   r   r
   r   ©r   r   r   r   r
   r   )r   r   r   r   r   r   r
   r   ©r!   r"   r   r   r
   r   )r   r%   r   r   r
   r   )r(   r)   r   r*   r
   r   ©r(   r   r   r   r
   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r    r$   r'   r.   r3   r   r   r   r   r      s    






r   Úor   r
   c                 C  sp   t | tƒr	t| ƒS t | tjtjfƒrt| ƒS tr"t 	| ¡r"t 
| ¡S t| dƒr-t|  ¡ ƒS tdt| ƒj› d�ƒ‚)NÚ__html__zObject of type z is not JSON serializable)Ú
isinstancer   r   ÚdecimalÚDecimalÚuuidÚUUIDr   ÚdataclassesÚis_dataclassÚasdictÚhasattrr<   r,   Útyper7   )r;   r   r   r   Ú_defaultl   s   


rG   c                   @  sb   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„Zddd„Z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   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`.
        rI   Úensure_asciiÚ	sort_keys)Ú
setdefaultrI   rK   rL   Újsonr   r   r   r   r   r   ¦   s   
zDefaultJSONProvider.dumpsr!   r"   c                 K  s   t j|fi |¤ŽS )z–Deserialize data as JSON from a string or bytes.

        :param s: Text or UTF-8 bytes.
        :param kwargs: Passed to :func:`json.loads`.
        )rN   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)ú,ú:Ú
r0   )r.   rJ   r   ÚdebugrM   r2   r   r1   )r   r(   r   r   Ú	dump_argsr   r   r   r3   ½   s   ÿzDefaultJSONProvider.responser4   r5   r6   )r7   r8   r9   r:   ÚstaticmethodrG   rI   Ú__annotations__rK   rL   rJ   r1   r   r$   r3   r   r   r   r   rH   |   s   
 

rH   )r;   r   r
   r   )Ú
__future__r   rB   r>   rN   ÚtypingÚtr@   r   Údatetimer   Úwerkzeug.httpr   ÚTYPE_CHECKINGÚwerkzeug.sansio.responser   Ú
sansio.appr   r   rG   rH   r   r   r   r   Ú<module>   s    
Y