U a<-@sddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddlmZddlmZejrddlmZdd lmZz ddlZWnek rdZYnXGd d d ejZGd d d ejZd*ejeejfejdddddZd+ejeejfejdddddZd,ejejdejedddZ d-ejej!eejdejddddZ"d.eejdejejdddZ#d/ej!eejdejejdddZ$ejejed d!d"Z%ejej!eejdd#d$d%Z&ejejd&d'd(d)Z'dS)0N)date)htmlsafe_json_dumps) http_date) current_app)request)Flask)Responsecs,eZdZdZejejdfdd ZZS) JSONEncoderaThe default JSON encoder. Handles extra types compared to the built-in :class:`json.JSONEncoder`. - :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. Assign a subclass of this to :attr:`flask.Flask.json_encoder` or :attr:`flask.Blueprint.json_encoder` to override the default. )oreturncs`t|trt|St|tjr&t|Str>t|r>t|St |drTt| St |S)zConvert ``o`` to a JSON serializable type. See :meth:`json.JSONEncoder.default`. Python does not support overriding how basic types like ``str`` or ``list`` are serialized, they are handled before this method. __html__) isinstancerruuidUUIDstr dataclassesZ is_dataclassZasdicthasattrr superdefault)selfr  __class__TC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-e702oxwa\flask\json\__init__.pyr*s     zJSONEncoder.default)__name__ __module__ __qualname____doc__tAnyr __classcell__rrrrr sr c@seZdZdZdS) JSONDecoderzThe default JSON decoder. This does not change any behavior from the built-in :class:`json.JSONDecoder`. Assign a subclass of this to :attr:`flask.Flask.json_decoder` or :attr:`flask.Blueprint.json_decoder` to override the default. N)rrrrrrrrr";sr"r)kwargsappr cCs|dkr t}|rv|j}tr(|jtjnd}|dk rD|jdk rD|j}|d||d|jd|d|jdn|dd|dtdS)z,Inject default arguments for dump functions.Ncls ensure_asciiZ JSON_AS_ASCII sort_keysZJSON_SORT_KEYST) rZ json_encoderr blueprintsget blueprint setdefaultconfigr r#r$r%Zbprrr_dump_arg_defaultsFs  r.cCsb|dkr t}|rR|j}tr(|jtjnd}|dk rD|jdk rD|j}|d|n |dtdS)z,Inject default arguments for load functions.Nr%)rZ json_decoderrr(r)r*r+r"r-rrr_load_arg_defaults[sr/)objr$r#r cKsVt||d|dd}tj|f|}|dk rRtjdtddt|trR| |S|S)a[Serialize an object to a string of JSON. Takes the same arguments as the built-in :func:`json.dumps`, with some defaults from application configuration. :param obj: Object to serialize to JSON. :param app: Use this app's config instead of the active app context or defaults. :param kwargs: Extra arguments passed to :func:`json.dumps`. .. versionchanged:: 2.0 ``encoding`` is deprecated and will be removed in Flask 2.1. .. versionchanged:: 1.0.3 ``app`` can be passed directly, rather than requiring an app context for configuration. r$encodingNz:'encoding' is deprecated and will be removed in Flask 2.1.r stacklevel) r.pop_jsondumpswarningswarnDeprecationWarningrrencode)r0r$r#r2rvrrrr7ms    r7)r0fpr$r#r cKst||d|dd}|dk }z|dWn(tk rVd}t||pNd}YnX|rltjdtdd t j ||f|dS) a@Serialize an object to JSON written to a file object. Takes the same arguments as the built-in :func:`json.dump`, with some defaults from application configuration. :param obj: Object to serialize to JSON. :param fp: File object to write JSON to. :param app: Use this app's config instead of the active app context or defaults. :param kwargs: Extra arguments passed to :func:`json.dump`. .. versionchanged:: 2.0 Writing to a binary file, and the ``encoding`` argument, is deprecated and will be removed in Flask 2.1. r1r2NTzutf-8zfWriting to a binary file, and the 'encoding' argument, is deprecated and will be removed in Flask 2.1.rr3) r.r5write TypeErrorio TextIOWrapperr8r9r:r6dump)r0r=r$r#r2Z show_warningrrrrCs  rC)sr$r#r cKsRt||d|dd}|dk rDtjdtddt|trD||}tj |f|S)aDeserialize an object from a string of JSON. Takes the same arguments as the built-in :func:`json.loads`, with some defaults from application configuration. :param s: JSON string to deserialize. :param app: Use this app's config instead of the active app context or defaults. :param kwargs: Extra arguments passed to :func:`json.loads`. .. versionchanged:: 2.0 ``encoding`` is deprecated and will be removed in Flask 2.1. The data must be a string or UTF-8 bytes. .. versionchanged:: 1.0.3 ``app`` can be passed directly, rather than requiring an app context for configuration. r1r2Nzd'encoding' is deprecated and will be removed in Flask 2.1. The data must be a string or UTF-8 bytes.rr3) r/r5r8r9r:rbytesdecoder6loads)rDr$r#r2rrrrGs    rG)r=r$r#r cKsZt||d|dd}|dk rLtjdtddt|dtrLt ||}t j |f|S)a(Deserialize an object from JSON read from a file object. Takes the same arguments as the built-in :func:`json.load`, with some defaults from application configuration. :param fp: File object to read JSON from. :param app: Use this app's config instead of the active app context or defaults. :param kwargs: Extra arguments passed to :func:`json.load`. .. versionchanged:: 2.0 ``encoding`` is deprecated and will be removed in Flask 2.1. The file must be text mode, or binary mode with UTF-8 bytes. r1r2Nzw'encoding' is deprecated and will be removed in Flask 2.1. The file must be text mode, or binary mode with UTF-8 bytes.rr3r) r/r5r8r9r:rreadrErArBr6load)r=r$r#r2rrrrIs   rI)r0r#r cKst|fdti|S)a6Serialize an object to a string of JSON with :func:`dumps`, then replace HTML-unsafe characters with Unicode escapes and mark the result safe with :class:`~markupsafe.Markup`. This is available in templates as the ``|tojson`` filter. The returned string is safe to render in HTML documents and ``