Format: application/x-python-code
⬇ Download File (7.5 KB)
   1  o
   2  
   3  D'h��@s�ddlmZddlZddlZddlZddlZddlZddlZddl	m
   4  Z
   5  ddlmZej
   6  r9ddlmZddlmZGdd	�d	�Zdd
   7  d�ZGdd�de�ZdS)�)�annotationsN)�date)�	http_date)�Response�)�Appc@sVeZdZdZd"dd�Zd#dd
   8  �Zd$dd�Zd%dd�Zd&dd�Zd'dd�Z	d(dd �Z
   9  d!S))�JSONProvidera�A standard set of JSON operations for an application. Subclasses
  10      of this can be used to customize JSON behavior or use different
  11      JSON libraries.
  12  
  13      To implement a provider for a specific library, subclass this base
  14      class and implement at least :meth:`dumps` and :meth:`loads`. All
  15      other methods have default implementations.
  16  
  17      To use a different provider, either subclass ``Flask`` and set
  18      :attr:`~flask.Flask.json_provider_class` to a provider class, or set
  19      :attr:`app.json <flask.Flask.json>` to an instance of the class.
  20  
  21      :param app: An application instance. This will be stored as a
  22          :class:`weakref.proxy` on the :attr:`_app` attribute.
  23  
  24      .. versionadded:: 2.2
  25      �appr�return�NonecCst�|�|_dS)N)�weakref�proxy�_app)�selfr	�r�IC:\Users\shubh\Videos\agent\nova\Lib\site-packages\flask/json/provider.py�__init__&szJSONProvider.__init__�obj�t.Any�kwargs�strcK�t�)z�Serialize data as JSON.
  26  
  27          :param obj: The data to serialize.
  28          :param kwargs: May be passed to the underlying JSON library.
  29          ��NotImplementedError�rrrrrr�dumps)�zJSONProvider.dumps�fp�	t.IO[str]cKs|�|j|fi|���dS)aSerialize data as JSON and write to a file.
  30  
  31          :param obj: The data to serialize.
  32          :param fp: A file opened for writing text. Should use the UTF-8
  33              encoding to be valid JSON.
  34          :param kwargs: May be passed to the underlying JSON library.
  35          N)�writer)rrrrrrr�dump1szJSONProvider.dump�s�str | bytescKr)z�Deserialize data as JSON.
  36  
  37          :param s: Text or UTF-8 bytes.
  38          :param kwargs: May be passed to the underlying JSON library.
  39          r�rr!rrrr�loads;rzJSONProvider.loads�t.IO[t.AnyStr]cKs|j|��fi|��S)z�Deserialize data as JSON read from a file.
  40  
  41          :param fp: A file opened for reading text or UTF-8 bytes.
  42          :param kwargs: May be passed to the underlying JSON library.
  43          )r$�read)rrrrrr�loadCszJSONProvider.load�args�tuple[t.Any, ...]�dict[str, t.Any]cCs8|r|rtd��|s|sdSt|�dkr|dS|p|S)Nz9app.json.response() takes either args or kwargs, not both�r)�	TypeError�len)rr(rrrr�_prepare_response_objKsz"JSONProvider._prepare_response_objrcOs"|�||�}|jj|�|�dd�S)a(Serialize the given arguments as JSON, and return a
  44          :class:`~flask.Response` object with the ``application/json``
  45          mimetype.
  46  
  47          The :func:`~flask.json.jsonify` function calls this method for
  48          the current application.
  49  
  50          Either positional or keyword arguments can be given, not both.
  51          If no arguments are given, ``None`` is serialized.
  52  
  53          :param args: A single value to serialize, or multiple values to
  54              treat as a list to serialize.
  55          :param kwargs: Treat as a dict to serialize.
  56          �application/json��mimetype)r.r�response_classr)rr(rrrrr�responseYszJSONProvider.responseN)r	rr
  57  r�rrrrr
  58  r)rrrrrrr
  59  r�r!r"rrr
  60  r)rr%rrr
  61  r)r(r)rr*r
  62  r�r(rrrr
  63  r)�__name__�
  64  __module__�__qualname__�__doc__rrr r$r'r.r3rrrrrs
  65  
  66  
  67  
  68  
  69  
  70  
  71  r�orr
  72  cCspt|t�r	t|�St|tjtjf�rt|�Str"t�	|�r"t�
  73  |�St|d�r-t|���St
  74  dt|�j�d���)N�__html__zObject of type z is not JSON serializable)�
  75  isinstancerr�decimal�Decimal�uuid�UUIDr�dataclasses�is_dataclass�asdict�hasattrr<r,�typer7)r;rrr�_defaultls
  76  
  77  
  78  rGc@sbeZdZUdZee�Zded<	dZ	dZ		dZ
  79  ded<	dZ	ddd�Zddd�Z
  80  ddd�ZdS)�DefaultJSONProvidera4Provide JSON operations using Python's built-in :mod:`json`
  81      library. Serializes the following additional data types:
  82  
  83      -   :class:`datetime.datetime` and :class:`datetime.date` are
  84          serialized to :rfc:`822` strings. This is the same as the HTTP
  85          date format.
  86      -   :class:`uuid.UUID` is serialized to a string.
  87      -   :class:`dataclasses.dataclass` is passed to
  88          :func:`dataclasses.asdict`.
  89      -   :class:`~markupsafe.Markup` (or any object with a ``__html__``
  90          method) will call the ``__html__`` method to get a string.
  91      zt.Callable[[t.Any], t.Any]�defaultTNzbool | None�compactr/rrrr
  92  rcKs<|�d|j�|�d|j�|�d|j�tj|fi|��S)aISerialize data as JSON to a string.
  93  
  94          Keyword arguments are passed to :func:`json.dumps`. Sets some
  95          parameter defaults from the :attr:`default`,
  96          :attr:`ensure_ascii`, and :attr:`sort_keys` attributes.
  97  
  98          :param obj: The data to serialize.
  99          :param kwargs: Passed to :func:`json.dumps`.
 100          rI�ensure_ascii�	sort_keys)�
 101  setdefaultrIrKrL�jsonrrrrrr�s
 102  zDefaultJSONProvider.dumpsr!r"cKstj|fi|��S)z�Deserialize data as JSON from a string or bytes.
 103  
 104          :param s: Text or UTF-8 bytes.
 105          :param kwargs: Passed to :func:`json.loads`.
 106          )rNr$r#rrrr$�szDefaultJSONProvider.loadsr(rcOsl|�||�}i}|jdur|jjs|jdur|�dd�n|�dd�|jj|j|fi|���d�|jd�S)	a�Serialize the given arguments as JSON, and return a
 107          :class:`~flask.Response` object with it. The response mimetype
 108          will be "application/json" and can be changed with
 109          :attr:`mimetype`.
 110  
 111          If :attr:`compact` is ``False`` or debug mode is enabled, the
 112          output will be formatted to be easier to read.
 113  
 114          Either positional or keyword arguments can be given, not both.
 115          If no arguments are given, ``None`` is serialized.
 116  
 117          :param args: A single value to serialize, or multiple values to
 118              treat as a list to serialize.
 119          :param kwargs: Treat as a dict to serialize.
 120          NF�indentr�
 121  separators)�,�:�
 122  r0)r.rJr�debugrMr2rr1)rr(rrZ	dump_argsrrrr3�s�zDefaultJSONProvider.responser4r5r6)r7r8r9r:�staticmethodrGrI�__annotations__rKrLrJr1rr$r3rrrrrH|s
 123  
 124  
 125  
 126  rH)r;rr
 127  r)�
 128  __future__rrBr>rN�typing�tr@r�datetimerZ
 129  werkzeug.httpr�
 130  TYPE_CHECKINGZwerkzeug.sansio.responserZ
 131  sansio.apprrrGrHrrrr�<module>s
 132  Y