0[:dZddlZddlmZmZddlmZmZmZdZdZ dZ dZ Gd d Z dd Z ddZddZddZddZdS)zImplementation of the JSON adaptation objects This module exists to avoid a circular import problem: pyscopg2.extras depends on psycopg2.extension, so I can't create the default JSON typecasters in extensions importing register_json from extras. N) ISQLQuote QuotedString)new_typenew_array_type register_typeriic8eZdZdZd dZdZdZdZdZdZ dS) Jsona An `~psycopg2.extensions.ISQLQuote` wrapper to adapt a Python object to :sql:`json` data type. `!Json` can be used to wrap any object supported by the provided *dumps* function. If none is provided, the standard :py:func:`json.dumps()` is used. NcH||_d|_|p tj|_dSN)adapted_connjsondumps_dumps)selfrrs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/psycopg2/_json.py__init__z Json.__init__8s"  )tz c|tur|SdSr )r)rprotos r __conform__zJson.__conform__=s I  K  rc,||S)zSerialize *obj* in JSON format. The default is to call `!json.dumps()` or the *dumps* function provided in the constructor. You can override this method to create a customized JSON wrapper. )r)robjs rrz Json.dumpsAs{{3rc||_dSr )r)rconns rpreparez Json.prepareJs  rc||j}t|}|j||j|Sr )rrrrr getquoted)rsqss rr zJson.getquotedMsJ JJt| $ $ !__ : ! JJtz " " "||~~rcR|ddS)Nasciireplace)r decode)rs r__str__z Json.__str__Ts"~~&&w :::rr ) __name__ __module__ __qualname____doc__rrrrr r'rrr r .s}****    ;;;;;rr Frc|t||\}}t||||\}}t|| r|pd|t|| r|pd||fS)aCreate and register typecasters converting :sql:`json` type to Python objects. :param conn_or_curs: a connection or cursor used to find the :sql:`json` and :sql:`json[]` oids; the typecasters are registered in a scope limited to this object, unless *globally* is set to `!True`. It can be `!None` if the oids are provided :param globally: if `!False` register the typecasters only on *conn_or_curs*, otherwise register them globally :param loads: the function used to parse the data into a Python object. If `!None` use `!json.loads()`, where `!json` is the module chosen according to the Python version (see above) :param oid: the OID of the :sql:`json` type if known; If not, it will be queried on *conn_or_curs* :param array_oid: the OID of the :sql:`json[]` array type if known; if not, it will be queried on *conn_or_curs* :param name: the name of the data type to look for in *conn_or_curs* The connection or cursor passed to the function will be used to query the database and look for the OID of the :sql:`json` type (or an alternative type if *name* if provided). No query is performed if *oid* and *array_oid* are provided. Raise `~psycopg2.ProgrammingError` if the type is not found. N)loadsname)_get_json_oids_create_json_typecastersupperr) conn_or_cursgloballyr.oid array_oidr/JSON JSONARRAYs r register_jsonr9Ys2 {' d;;Y. Ye$**,,888OD)$H 5=>>>iX!>,!F$GGG ?rc>t|||ttS)a{ Create and register :sql:`json` typecasters for PostgreSQL 9.2 and following. Since PostgreSQL 9.2 :sql:`json` is a builtin type, hence its oid is known and fixed. This function allows specifying a customized *loads* function for the default :sql:`json` type without querying the database. All the parameters have the same meaning of `register_json()`. )r3r4r.r5r6)r9JSON_OID JSONARRAY_OIDr3r4r.s rregister_default_jsonr>s& lX] < < <.typecast_jsons 94uQxxrARRAY)rr.rr)r5r6r.r/rGr7r8s ` rr1r1sm }  SGT= 1 1D"I=T...$GG  ?rcBddlm}ddlm}||\}}|j}|jjdkrdpd}|d|z|f|}||kr|j s| |s| |d|S) Nr)STATUS_IN_TRANSACTION)_solve_conn_cursi9typarrayNULLz6SELECT t.oid, %s FROM pg_type t WHERE t.typname = %%s;z data type not found) psycopg2.extensionsrJpsycopg2.extrasrKstatusinfoserver_versionexecutefetchone autocommitrollbackProgrammingError) r3r/rJrKrcurs conn_statusrLrs rr0r0s999999000000!!,//JD$+Ky'50?ZI6H LL@  G A+++DO+  C##t$A$A$ABBB Hr)NFNNNr)NFN)Nr7)r)r+rpsycopg2._psycopgrrrrrr;r<rArBr r9r>rCr1r0r,rrr\s < 55555555EEEEEEEEEE    (;(;(;(;(;(;(;(;V<@17$$$$N < < < < L L L L&      r