1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
U
ß=®dÕã@s¤ddlmZddlZddlZddlZddlZddlZddlZddl    m
Z
ddl m Z ej rrddlmZddlmZGdd    „d    ƒZd
d
d œd d „ZGdd„deƒZdS)é)Ú annotationsN)Údate)Ú    http_dateé)ÚFlask)ÚResponsec@sŽeZdZdZdddœdd„Zdddd    œd
d „Zdd ddd œdd„Zddddœdd„Zddddœdd„Zddddœdd„Z    ddddœdd„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ÚreturncCst |¡|_dS)N)ÚweakrefÚproxyÚ_app)Úselfr
©rúJd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\flask/json/provider.pyÚ__init__%szJSONProvider.__init__út.AnyÚstr©ÚobjÚkwargsr cKst‚dS)z‘Serialize data as JSON.
 
        :param obj: The data to serialize.
        :param kwargs: May be passed to the underlying JSON library.
        N©ÚNotImplementedError©rrrrrrÚdumps(szJSONProvider.dumpsz    t.IO[str])rÚfprr cKs| |j|f|Ž¡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)rrrrrrrÚdump0szJSONProvider.dumpú str | bytes©Úsrr cKst‚dS)zDeserialize data as JSON.
 
        :param s: Text or UTF-8 bytes.
        :param kwargs: May be passed to the underlying JSON library.
        Nr©rr!rrrrÚloads:szJSONProvider.loadszt.IO[t.AnyStr])rrr cKs|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)rrrrrrÚloadBszJSONProvider.loadztuple[t.Any, ...]zdict[str, t.Any]©Úargsrr cCs8|r|rtdƒ‚|s|sdSt|ƒdkr0|dS|p6|S)Nz9app.json.response() takes either args or kwargs, not bothér)Ú    TypeErrorÚlen)rr'rrrrÚ_prepare_response_objJs z"JSONProvider._prepare_response_objrcOs"| ||¡}|jj| |¡dd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)rr'rrrrrÚresponseXs zJSONProvider.responseN) Ú__name__Ú
__module__Ú __qualname__Ú__doc__rrrr#r%r+r0rrrrrs
rr)Úor cCstt|tƒrt|ƒSt|tjtjfƒr,t|ƒStrDt     |¡rDt 
|¡St |dƒrZt|  ¡ƒSt dt|ƒj›dƒ‚dS)NÚ__html__zObject of type z is not JSON serializable)Ú
isinstancerrÚdecimalÚDecimalÚuuidÚUUIDrÚ dataclassesZ is_dataclassZasdictÚhasattrr6r)Útyper1)r5rrrÚ_defaultks
 
 
 r?c@speZdZUdZeeƒZded<dZdZ    dZ
ded<dZ d    d    d
d œd d „Z dd    d    dœdd„Z d    d    ddœdd„ZdS)Ú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 | NoneÚcompactr,rrrcKs8| d|j¡| d|j¡| d|j¡tj|f|Ž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`.
        rAÚ ensure_asciiÚ    sort_keys)Ú
setdefaultrArCrDÚjsonrrrrrr§s
zDefaultJSONProvider.dumpsrr cKstj|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`.
        )rFr#r"rrrr#¶szDefaultJSONProvider.loadsrr&cOsh| ||¡}i}|jdkr"|jjs,|jdkr:| dd¡n | dd¡|jj|j|f|Ž›d|jd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)ú,ú:Ú
r-)r+rBrÚdebugrEr/rr.)rr'rrZ    dump_argsrrrr0¾s  ÿzDefaultJSONProvider.response)r1r2r3r4Ú staticmethodr?rAÚ__annotations__rCrDrBr.rr#r0rrrrr@{s
 ÿ  r@)Ú
__future__rr<r8rFÚtypingÚtr:r ÚdatetimerZ werkzeug.httprÚ TYPE_CHECKINGr
rÚwrappersrrr?r@rrrrÚ<module>s     Y