;iddlmZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ej r ddlmZddlmZGdd Zdd ZGddeZdS)) annotationsN)date) http_date)Response)AppcJeZdZdZddZdd ZddZddZddZd dZ d!dZ dS)" JSONProvideraA 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 ` 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 apprreturnNonec8tj||_dS)N)weakrefproxy_app)selfr s GC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\flask/json/provider.py__init__zJSONProvider.__init__&s s++ objt.Anykwargsstrc t)zSerialize data as JSON. :param obj: The data to serialize. :param kwargs: May be passed to the underlying JSON library. NotImplementedErrorrrrs rdumpszJSONProvider.dumps) "!rfp t.IO[str]c H||j|fi|dS)aSerialize 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)rrr rs rdumpzJSONProvider.dump1s0 C**6**+++++rs str | bytesc t)zDeserialize data as JSON. :param s: Text or UTF-8 bytes. :param kwargs: May be passed to the underlying JSON library. rrr%rs rloadszJSONProvider.loads;rrt.IO[t.AnyStr]c B|j|fi|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)rr rs rloadzJSONProvider.loadCs& tz"''))..v...rargstuple[t.Any, ...]dict[str, t.Any]cr|r|rtd|s|sdSt|dkr|dS|p|S)Nz9app.json.response() takes either args or kwargs, not bothr) TypeErrorlen)rr.rs r_prepare_response_objz"JSONProvider._prepare_response_objKsZ  YF YWXX X F 4 t99>>7N~vrrc|||}|j||dS)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/jsonmimetype)r5rresponse_classr)rr.rrs rresponsezJSONProvider.responseYs?((v66y'' 3BT'UUUrN)r rr r rrrrr r)rrr r!rrr r r%r&rrr r)r r*rrr r)r.r/rr0r rr.rrrr r) __name__ __module__ __qualname____doc__rrr$r)r-r5r;rrr r s$,,,,"""",,,,""""////    VVVVVVrr orr ct|trt|St|tjt jfrt|Str(tj |rtj |St|dr!t| Stdt|jd)N__html__zObject of type z is not JSON serializable) isinstancerrdecimalDecimaluuidUUIDr dataclasses is_dataclassasdicthasattrrFr3typer?)rDs r_defaultrQls!T||!goty1221vv %{/22%!!$$$q*!1::<<   Qd1gg&6QQQ R RRrcpeZdZUdZeeZded< dZ dZ dZ ded< dZ ddZ ddZ ddZdS)DefaultJSONProvidera4Provide 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. zt.Callable[[t.Any], t.Any]defaultTNz bool | Nonecompactr7rrrr rc |d|j|d|j|d|jt j|fi|S)aISerialize 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`. rT ensure_ascii sort_keys) setdefaultrTrWrXjsonrrs rrzDefaultJSONProvider.dumpsse )T\222.$*;<<<+t~666z#(((((rr%r&c &tj|fi|S)zDeserialize data as JSON from a string or bytes. :param s: Text or UTF-8 bytes. :param kwargs: Passed to :func:`json.loads`. )rZr)r(s rr)zDefaultJSONProvider.loadss z!&&v&&&rr.rc$|||}i}|j |jjs |jdur|ddn|dd|j|j|fi|d|jS) aSerialize 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. NFindentr separators),: r8)r5rUrdebugrYr:rr9)rr.rr dump_argss rr;zDefaultJSONProvider.responses ((v66&( L TY_ 9N9N  1 - - - -  z : : :y''tz#++++ / / /$-(   rr<r=r>)r?r@rArB staticmethodrQrT__annotations__rWrXrUr9rr)r;rCrrrSrS|s  +7,x*@*@G@@@@ L I  G "H/ ) ) ) )''''      rrS)rDrr r) __future__rrLrHrZtypingtrJrdatetimer werkzeug.httpr TYPE_CHECKINGwerkzeug.sansio.responser sansio.apprr rQrSrCrrrns4""""""  ######?!111111      VVVVVVVVVVVVVVVVr S S S S [ [ [ [ [ ,[ [ [ [ [ r