� E�g����dZddlZddlmZmZddlmZmZmZdZdZ dZ dZ Gd �d ��Z dd �Z dd�Zdd�Zdd�Zdd�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�r��i�i�c�8�eZdZdZd d�Zd�Zd�Zd�Zd�Zd�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. Nc�H�||_d|_|p tj|_dS�N)�adapted�_conn�json�dumps�_dumps)�selfrrs �^/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/psycopg2/_json.py�__init__z Json.__init__8s"���� ��� ��)�t�z�� � � �c��|tur|SdSr )r)r�protos r� __conform__zJson.__conform__=s�� �I� � ��K� � rc�,�|�|��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�objs rrz Json.dumpsAs���{�{�3���rc��||_dSr )r)r�conns r�preparez Json.prepareJs ���� � � rc��|�|j��}t|��}|j�|�|j��|���Sr )rrrrr� getquoted)r�s�qss rr zJson.getquotedMsJ�� �J�J�t�|� $� $�� �!�_�_�� �:� !� �J�J�t�z� "� "� "��|�|�~�~�rc�R�|����dd��S)N�ascii�replace)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)�loads�name)�_get_json_oids�_create_json_typecasters�upperr)� conn_or_curs�globallyr.�oid� array_oidr/�JSON� JSONARRAYs r� register_jsonr9Ys���2 �{�'� �d�;�;���Y�.� �Y�e�$�*�*�,�,�8�8�8�O�D�)��$�H� �5��=��>�>�>����i�X��!>�,�!F�$�G�G�G� ��?�rc�>�t|||tt���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()`. )r3r4r.r5r6)r9�JSON_OID� JSONARRAY_OID�r3r4r.s r�register_default_jsonr>�s&�� �l�X���]� <� <� <�<rc�@�t|||ttd���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()`. �jsonb)r3r4r.r5r6r/)r9� JSONB_OID�JSONBARRAY_OIDr=s r�register_default_jsonbrC�s,�� �l�X���n�7� L� L� L�Lrr7c����� tj��fd�}t|f||��}|�t|f|�d�|��}nd}||fS)z&Create typecasters for json data type.Nc�"��|�dS�|��Sr r,)r!�curr.s �r� typecast_jsonz/_create_json_typecasters.<locals>.typecast_json�s��� �9��4��u�Q�x�x�r�ARRAY)rr.rr)r5r6r.r/rGr7r8s ` rr1r1�sm��� �}�� ������� �S�G�T�=� 1� 1�D���"�I�=�T�.�.�.�$�G�G� � �� � ��?�rc�B�ddlm}ddlm}||��\}}|j}|jjdkrdpd}|�d|z|f��|���}||kr|j s|� ��|s|� |�d����|S) Nr)�STATUS_IN_TRANSACTION)�_solve_conn_cursi�9�typarray�NULLz6SELECT t.oid, %s FROM pg_type t WHERE t.typname = %%s;z data type not found) �psycopg2.extensionsrJ�psycopg2.extrasrK�status�info�server_version�execute�fetchone� autocommit�rollback�ProgrammingError) r3r/rJrKr�curs� conn_statusrL�rs rr0r0�s���9�9�9�9�9�9�0�0�0�0�0�0�!�!�,�/�/�J�D�$��+�K��y�'�5�0�?�Z�I�6�H� �L�L�@� � ��G���� � � ���A��+�+�+�D�O�+� � � ���� �C��#�#�t�$A�$A�$A�B�B�B� �Hr)NFNNNr)NFN)Nr7)r)r+r�psycopg2._psycopgrrrrrr;r<rArBr r9r>rCr1r0r,rr�<module>r\s ����< � � � �5�5�5�5�5�5�5�5�E�E�E�E�E�E�E�E�E�E� ��� � � ���(;�(;�(;�(;�(;�(;�(;�(;�V<@�17�$�$�$�$�N <� <� <� <� L� L� L� L�����& � � � � � r
Memory