U
    ÒZj²)  ã                   @  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 ddlmZ ejr~d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é   )Úrequest)ÚFlask)ÚResponsec                   @  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   úV/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/flask/json/provider.pyÚ__init__'   s    zJSONProvider.__init__út.AnyÚstr©ÚobjÚkwargsr   c                 K  s   t ‚dS )z‘Serialize 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|Ž¡ 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   Údump2   s    zJSONProvider.dumpústr | bytes©Úsr   r   c                 K  s   t ‚dS )z�Deserialize 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|Ž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   ÚloadD   s    zJSONProvider.loadzt.Tuple[t.Any, ...]zt.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_objL   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   ÚresponseZ   s    zJSONProvider.responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r$   r*   r/   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   ÚdataclassesÚis_dataclassÚasdictÚhasattrr5   r(   Útyper0   )r4   r   r   r   Ú_defaultm   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  | j j}tr| j j tj¡nd}|dk	r8|jdk	r8|j}|dk	rzddl}| dt¡ | 	d|¡ d|j
krˆ| 	d| j¡ n| 	d| j¡ | j jd }| j jd }|dk	r¾ddl}| dt¡ n| j}|dk	râddl}| d	t¡ n| j}| 	d
|¡ | 	d|¡ tj|f|Ž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`.
        Nr   z~Setting 'json_encoder' on the app or a blueprint is deprecated and will be removed in Flask 2.3. Customize 'app.json' instead.ÚclsrB   ZJSON_AS_ASCIIZJSON_SORT_KEYSzsThe 'JSON_AS_ASCII' config key is deprecated and will be removed in Flask 2.3. Set 'app.json.ensure_ascii' instead.zqThe 'JSON_SORT_KEYS' config key is deprecated and will be removed in Flask 2.3. Set 'app.json.sort_keys' instead.Úensure_asciiÚ	sort_keys)r   Z_json_encoderr   Ú
blueprintsÚgetÚ	blueprintÚwarningsÚwarnÚDeprecationWarningÚ
setdefaultÚ__dict__rB   ÚconfigrE   rF   Újsonr   )r   r   r   rD   ÚbprJ   rE   rF   r   r   r   r   ©   sB    
ü
üüzDefaultJSONProvider.dumpsr   r    c                 K  sn   | j j}tr| j j tj¡nd}|dk	r8|jdk	r8|j}|dk	r`ddl}| dt¡ | 	d|¡ t
j|f|Ž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`.
        Nr   z~Setting 'json_decoder' on the app or a blueprint is deprecated and will be removed in Flask 2.3. Customize 'app.json' instead.rD   )r   Z_json_decoderr   rG   rH   rI   rJ   rK   rL   rM   rP   r"   )r   r!   r   rD   rQ   rJ   r   r   r   r"   è   s    üzDefaultJSONProvider.loadsr   r%   c           	      O  sÈ   |   ||¡}i }| jjd }| jjd }|dk	rLddl}| dt¡ | }n| j}|dkrb| jjsj|dkrx| dd¡ n| d	d
¡ |dk	r¢ddl}| dt¡ n| j	}| jj
| j|f|Ž› d�|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.
        ZJSONIFY_PRETTYPRINT_REGULARZJSONIFY_MIMETYPENr   z|The 'JSONIFY_PRETTYPRINT_REGULAR' config key is deprecated and will be removed in Flask 2.3. Set 'app.json.compact' instead.FÚindentr   Ú
separators)ú,ú:zrThe 'JSONIFY_MIMETYPE' config key is deprecated and will be removed in Flask 2.3. Set 'app.json.mimetype' instead.Ú
r,   )r*   r   rO   rJ   rK   rL   rC   ÚdebugrM   r-   r.   r   )	r   r&   r   r   Z	dump_argsÚprettyr-   rJ   rC   r   r   r   r/     s4    üü ÿzDefaultJSONProvider.response)r0   r1   r2   r3   Ústaticmethodr@   rB   Ú__annotations__rE   rF   rC   r-   r   r"   r/   r   r   r   r   rA   }   s   
ÿ?rA   )Ú
__future__r   r;   r7   rP   ÚtypingÚtr9   r   Údatetimer   Zwerkzeug.httpr   Úglobalsr   ÚTYPE_CHECKINGr   r   Zwrappersr   r	   r@   rA   r   r   r   r   Ú<module>   s   Y