U )._. @sndZddlZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z dd l mZdd l mZdd lmZdd lmZz ddlZWnek rdZYnXd edkZdddddddddg ZddZddZGdddejZGdddejZd-ddZd.d d!Zd"d#Zd/d$dZd0d%dZd1d&dZ d2d'dZ!d(dZ"d)dZ#d*dZ$d+d,Z%dS)3zH flask.json ~~~~~~~~~~ :copyright: 2010 Pallets :license: BSD-3-Clause N)date)datetime)json)Markup) http_date)PY2) text_type) current_app)request\//dumpdumpsloadloads htmlsafe_dumphtmlsafe_dumps JSONDecoder JSONEncoderjsonifycCs&t|dtr"tt||}|S)Nr) isinstancereadbytesio TextIOWrapperBufferedReaderfpencodingr C:\Users\Miouzora\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\flask/json/__init__.py_wrap_reader_for_text/sr"cCs4z|dWn tk r.t||}YnX|S)N)write TypeErrorrrrr r r!_wrap_writer_for_text5s r&c@seZdZdZddZdS)ralThe default Flask JSON encoder. This one extends the default encoder by also supporting ``datetime``, ``UUID``, ``dataclasses``, and ``Markup`` objects. ``datetime`` objects are serialized as RFC 822 datetime strings. This is the same as the HTTP date format. In order to support more data types, override the :meth:`default` method. cCs|t|trt|St|tr,t|St|tjr@t|St rXt |rXt |St |drnt |Stj||S)a&Implement this method in a subclass such that it returns a serializable object for ``o``, or calls the base implementation (to raise a :exc:`TypeError`). For example, to support arbitrary iterators, you could implement default like this:: def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) return JSONEncoder.default(self, o) __html__)rrr utctimetupler timetupleuuidUUIDstr dataclassesZ is_dataclassZasdicthasattrr r'_jsonrdefault)selfor r r!r0Is        zJSONEncoder.defaultN)__name__ __module__ __qualname____doc__r0r r r r!r=s c@seZdZdZdS)raThe default JSON decoder. This one does not change the behavior from the default simplejson decoder. Consult the :mod:`json` documentation for more information. This decoder is not only used for the load functions of this module but also :attr:`~flask.Request`. N)r3r4r5r6r r r r!rgscCs|dkr t}|rntr"|jtjnd}|d|r<|jr<|jn|j|jdsZ|dd|d|jdn|dd|dtdS) z,Inject default arguments for dump functions.NclsZ JSON_AS_ASCII ensure_asciiF sort_keysZJSON_SORT_KEYST) r r blueprintsget blueprint setdefaultZ json_encoderconfigrkwargsappZbpr r r!_dump_arg_defaultsos   rBcCsV|dkr t}|rFtr"|jtjnd}|d|r<|jr<|jn|jn |dtdS)z,Inject default arguments for load functions.Nr7)r r r:r;r<r=Z json_decoderrr?r r r!_load_arg_defaultssrCcCs|dd}|ddtjkr"dSd|kr.dS|tjtjfkrBdS|ddtjtjfkr^d St|dkr|ddd kr~d S|dddd krd S|ddd krdS|dddd krdSt|dkr|drd SdSdS)acDetect which UTF codec was used to encode the given bytes. The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big or little endian. Some editors or libraries may prepend a BOM. :param data: Bytes in unknown UTF encoding. :return: UTF encoding name Nz utf-8-sigutf-8zutf-32rzutf-16sz utf-32-besz utf-16-bez utf-32-lez utf-16-le)codecsBOM_UTF8 BOM_UTF32_BE BOM_UTF32_LE BOM_UTF16_BE BOM_UTF16_LElen startswith)dataheadr r r!detect_encodings*   rScKsFt||d|dd}tj|f|}|dk rBt|trB||}|S)aOSerialize ``obj`` to a JSON-formatted string. If there is an app context pushed, use the current app's configured encoder (:attr:`~flask.Flask.json_encoder`), or fall back to the default :class:`JSONEncoder`. Takes the same arguments as the built-in :func:`json.dumps`, and does some extra configuration based on the application. If the simplejson package is installed, it is preferred. :param obj: Object to serialize to JSON. :param app: App instance to use to configure the JSON encoder. Uses ``current_app`` if not given, and falls back to the default encoder when not in an app context. :param kwargs: Extra arguments passed to :func:`json.dumps`. .. versionchanged:: 1.0.3 ``app`` can be passed directly, rather than requiring an app context for configuration. rArN)rBpopr/rrr encode)objrAr@rrvr r r!rs    cKs>t||d|dd}|dk r*t||}tj||f|dS)z1Like :func:`dumps` but writes into a file object.rTrN)rBrUr&r/r)rWrrAr@rr r r!rs    cKsJt||dt|tr<|dd}|dkr2t|}||}tj|f|S)aXDeserialize an object from a JSON-formatted string ``s``. If there is an app context pushed, use the current app's configured decoder (:attr:`~flask.Flask.json_decoder`), or fall back to the default :class:`JSONDecoder`. Takes the same arguments as the built-in :func:`json.loads`, and does some extra configuration based on the application. If the simplejson package is installed, it is preferred. :param s: JSON string to deserialize. :param app: App instance to use to configure the JSON decoder. Uses ``current_app`` if not given, and falls back to the default encoder when not in an app context. :param kwargs: Extra arguments passed to :func:`json.dumps`. .. versionchanged:: 1.0.3 ``app`` can be passed directly, rather than requiring an app context for configuration. rTrN)rCrrrUrSdecoder/r)srAr@rr r r!rs    cKs4t||dts&t||ddp"d}tj|f|S)z0Like :func:`loads` but reads from a file object.rTrNrG)rCrr"rUr/r)rrAr@r r r!rs cKs@t|f|dddddddd}ts<|d d }|S) a:Works exactly like :func:`dumps` but is safe for use in ``