o
    i                     @   s   d dl mZ d dlZd dlZddlmZ ddlmZ ddlm	Z	 zd dl
ZW n ey3   d dlZY nw G dd deZG d	d
 d
eZdS )    )absolute_importN   )	text_type)
BadRequest)detect_utf_encodingc                   @   s0   e Zd Zedd Zedd Zedd ZdS )_JSONModulec                 C   sD   t | tjr
|  S t | tjrt| S t| drt| 	 S t
 )N__html__)
isinstancedatetimedate	isoformatuuidUUIDstrhasattrr   r   	TypeError)o r   Q/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/werkzeug/wrappers/json.py_default   s   
z_JSONModule._defaultc                 K   s8   | dd | d| j | dd tj|fi |S )N
separators),:default	sort_keysT)
setdefaultr   _jsondumps)clsobjkwr   r   r   r      s   z_JSONModule.dumpsc                 K   s.   t | trt| }| |} tj| fi |S )N)r	   bytesr   decoder   loads)sr    encodingr   r   r   r#   %   s   

z_JSONModule.loadsN)__name__
__module____qualname__staticmethodr   classmethodr   r#   r   r   r   r   r      s    

r   c                   @   sN   e Zd ZdZeZedd Zedd Zdd Z	e
e
fZdd
dZdd ZdS )	JSONMixinaD  Mixin to parse :attr:`data` as JSON. Can be mixed in for both
    :class:`~werkzeug.wrappers.Request` and
    :class:`~werkzeug.wrappers.Response` classes.

    If `simplejson`_ is installed it is preferred over Python's built-in
    :mod:`json` module.

    .. _simplejson: https://simplejson.readthedocs.io/en/latest/
    c                 C   s   |   S )zThe parsed JSON data if :attr:`mimetype` indicates JSON
        (:mimetype:`application/json`, see :meth:`is_json`).

        Calls :meth:`get_json` with default arguments.
        )get_json)selfr   r   r   json>   s   zJSONMixin.jsonc                 C   s"   | j }|dkp|do|dS )zCheck if the mimetype indicates JSON data, either
        :mimetype:`application/json` or :mimetype:`application/*+json`.
        zapplication/jsonzapplication/z+json)mimetype
startswithendswith)r-   mtr   r   r   is_jsonG   s
   
zJSONMixin.is_jsonc                 C   s*   z| j |dW S  ty   |    Y S w )Ncache)get_datar   )r-   r5   r   r   r   _get_data_for_jsonS   s
   zJSONMixin._get_data_for_jsonFTc           
   
   C   s   |r| j | tur| j | S |s| jsdS | j|d}z| j|}W nC tyf } z7|r<d}|r;| j \}}||f| _ n| |}|rT| j \}}	||	f| _ W Y d}~|S W Y d}~|S W Y d}~|S d}~ww |rn||f| _ |S )a&  Parse :attr:`data` as JSON.

        If the mimetype does not indicate JSON
        (:mimetype:`application/json`, see :meth:`is_json`), this
        returns ``None``.

        If parsing fails, :meth:`on_json_loading_failed` is called and
        its return value is used as the return value.

        :param force: Ignore the mimetype and always try to parse JSON.
        :param silent: Silence parsing errors and return ``None``
            instead.
        :param cache: Store the parsed JSON to return for subsequent
            calls.
        Nr4   )_cached_jsonEllipsisr3   r7   json_moduler#   
ValueErroron_json_loading_failed)
r-   forcesilentr5   datarve	normal_rv_	silent_rvr   r   r   r,   ^   s8   







 
zJSONMixin.get_jsonc                 C   s   t d|)zCalled if :meth:`get_json` parsing fails and isn't silenced.
        If this method returns a value, it is used as the return value
        for :meth:`get_json`. The default implementation raises
        :exc:`~werkzeug.exceptions.BadRequest`.
        z!Failed to decode JSON object: {0})r   format)r-   rA   r   r   r   r<      s   z JSONMixin.on_json_loading_failedN)FFT)r&   r'   r(   __doc__r   r:   propertyr.   r3   r7   r9   r8   r,   r<   r   r   r   r   r+   /   s    

	
-r+   )
__future__r   r
   r   _compatr   
exceptionsr   utilsr   
simplejsonr   ImportErrorr.   objectr   r+   r   r   r   r   <module>   s    