HEX
Server: LiteSpeed
System: Linux standart9.isimtescil.net 3.10.0-962.3.2.lve1.5.26.7.el7.x86_64 #1 SMP Wed Oct 2 07:53:12 EDT 2019 x86_64
User: karalev (5310)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //opt/alt/python37/lib64/python3.7/site-packages/psycopg2/__pycache__/_json.cpython-37.pyc
B

*��]Z�@s�dZddlZddlmZmZddlmZmZmZddlm	Z	dZ
dZdZd	Z
Gd
d�de�Zddd�Zddd�Zddd�Zddd�Zddd�ZdS)z�Implementation 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_type�new_array_type�
register_type)�PY2�r��i�i�c@sPeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Ze	rDd
d�Z
ndd�Z
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.

    NcCs||_d|_|ptj|_dS)N)�adapted�_conn�json�dumps�_dumps)�selfrr�r�A/opt/alt/python37/lib64/python3.7/site-packages/psycopg2/_json.py�__init__8sz
Json.__init__cCs|tkr|SdS)N)r)r�protorrr�__conform__=szJson.__conform__cCs
|�|�S)z�Serialize *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)r�objrrrrAsz
Json.dumpscCs
||_dS)N)r)r�connrrr�prepareJszJson.preparecCs2|�|j�}t|�}|jdk	r*|�|j�|��S)N)rrrrr�	getquoted)r�sZqsrrrrMs

zJson.getquotedcCs|��S)N)r)rrrr�__str__UszJson.__str__cCs|���dd�S)N�ascii�replace)r�decode)rrrrrXs)N)�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrrr
.s	
	
r
Fr
cCsf|dkrt||�\}}t||||��d�\}}t||r<|p>d�|dk	r^t||rX|pZd�||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)�loads�name)�_get_json_oids�_create_json_typecasters�upperr)�conn_or_curs�globallyr#�oid�	array_oidr$�JSON�	JSONARRAYrrr�
register_json]sr.cCst|||ttd�S)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()`.
    )r(r)r#r*r+)r.�JSON_OID�
JSONARRAY_OID)r(r)r#rrr�register_default_json�s	r1cCst|||ttdd�S)a^
    Create and register :sql:`jsonb` typecasters for PostgreSQL 9.4 and following.

    As in `register_default_json()`, the function allows to register a
    customized *loads* function for the :sql:`jsonb` type at its known oid for
    PostgreSQL 9.4 and following versions.  All the parameters have the same
    meaning of `register_json()`.
    Zjsonb)r(r)r#r*r+r$)r.�	JSONB_OID�JSONBARRAY_OID)r(r)r#rrr�register_default_jsonb�s	r4r,csP�dkrtj��fdd�}t|f||�}|dk	rDt|fd||�}nd}||fS)z&Create typecasters for json data type.Ncs|dkrdS�|�S)Nr)rZcur)r#rr�
typecast_json�sz/_create_json_typecasters.<locals>.typecast_jsonz%sARRAY)r
r#rr)r*r+r#r$r5r,r-r)r#rr&�sr&c	Cs�ddlm}ddlm}||�\}}|j}|jjdkr:dp<d}|�d||f�|��}||krn|j	sn|�
�|s�|�d|��|S)	Nr)�STATUS_IN_TRANSACTION)�_solve_conn_cursi�9�typarrayZNULLz6SELECT t.oid, %s FROM pg_type t WHERE t.typname = %%s;z%s data type not found)Zpsycopg2.extensionsr6Zpsycopg2.extrasr7Zstatus�infoZserver_versionZexecuteZfetchoneZ
autocommitZrollbackZProgrammingError)	r(r$r6r7rZcursZconn_statusr8�rrrrr%�sr%)NFNNNr
)NFN)NFN)Nr,)r
)r"r
Zpsycopg2._psycopgrrrrrZpsycopg2.compatrr/r0r2r3�objectr
r.r1r4r&r%rrrr�<module>s/
&