Ë
    é#0hñ  ã                   ó„   — d Z ddlZddlmZmZ ddlmZmZmZ dZdZ	dZ
dZ G d	„ d
«      Z	 	 dd„Zdd„Zdd„Zdd„Zdd„Zy)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                   ó6   — e Zd ZdZd	d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)
Ú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                 óR   — || _         d | _        |xs t        j                  | _        y ©N)ÚadaptedÚ_connÚjsonÚdumpsÚ_dumps)Úselfr   r   s      úL/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/psycopg2/_json.pyÚ__init__zJson.__init__8   s    € ØˆŒØˆŒ
ØÒ)œtŸz™zˆ�ó    c                 ó   — |t         u r| S y r   )r   )r   Úprotos     r   Ú__conform__zJson.__conform__=   s   € Ø”IÑØˆKð r   c                 ó$   — | j                  |«      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     r   r   z
Json.dumpsA   s   € ð �{‰{˜3ÓÐr   c                 ó   — || _         y r   )r   )r   Úconns     r   ÚpreparezJson.prepareJ   s	   € Øˆ�
r   c                 ó¼   — | j                  | j                  «      }t        |«      }| j                  �|j	                  | j                  «       |j                  «       S r   )r   r   r   r   r   Ú	getquoted)r   ÚsÚqss      r   r    zJson.getquotedM   sC   € Ø�J‰J�t—|‘|Ó$ˆÜ˜!‹_ˆØ�:‰:Ð!Ø�J‰J�t—z‘zÔ"Ø�|‰|‹~Ðr   c                 óB   — | j                  «       j                  dd«      S )NÚasciiÚreplace)r    Údecode)r   s    r   Ú__str__zJson.__str__T   s   € à�~‰~Ó×&Ñ& w°	Ó:Ð:r   r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r    r'   © r   r   r   r   .   s%   „ ñó*ò
ò òòó;r   r   c                 óÄ   — |€t        | |«      \  }}t        ||||j                  «       ¬«      \  }}t        || xr | xs d«       |�t        || xr | xs d«       ||fS )a  Create 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_jsonr9   Y   st   € ð2 €{Ü'¨°dÓ;‰ˆˆYä.ØˆY˜e¨$¯*©*«,ô8�O€Dˆ)ô �$˜H˜Ò5¨Ò=¸Ô>àÐÜ�i X Ò!>°,Ò!FÀ$ÔGà�ˆ?Ðr   c                 ó2   — t        | ||t        t        ¬«      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()`.
    )r3   r4   r.   r5   r6   )r9   ÚJSON_OIDÚJSONARRAY_OID©r3   r4   r.   s      r   Úregister_default_jsonr>   €   s   € ô  l¸XØœ¬]ô<ð <r   c                 ó4   — t        | ||t        t        d¬«      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)r3   r4   r.   r5   r6   r/   )r9   Ú	JSONB_OIDÚJSONBARRAY_OIDr=   s      r   Úregister_default_jsonbrC   �   s    € ô  l¸XØœ¬nÀ7ôLð Lr   c                 óˆ   ‡— ‰€t         j                  Šˆfd„}t        | f||«      }|�t        |f|› d�|«      }||fS d}||fS )z&Create typecasters for json data type.Nc                 ó   •— | €y  ‰| «      S r   r,   )r!   Úcurr.   s     €r   Útypecast_jsonz/_create_json_typecasters.<locals>.typecast_jsonŸ   s   ø€ Øˆ9ØÙ�Q‹xˆr   ÚARRAY)r   r.   r   r   )r5   r6   r.   r/   rG   r7   r8   s     `    r   r1   r1   š   sa   ø€ à€}Ü—
‘
ˆôô
 �S�G˜T =Ó1€DØÐÜ" I =°T°F¸%°.À$ÓGˆ	ð �ˆ?Ðð ˆ	à�ˆ?Ðr   c                 óH  — ddl m} ddlm}  || «      \  }}|j                  }|j
                  j                  dk\  xr dxs d}|j                  d|z  |f«       |j                  «       }||k7  r|j                  s|j                  «        |s|j                  |› 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)	r3   r/   rJ   rK   r   ÚcursÚconn_statusrL   Úrs	            r   r0   r0   ­   s§   € å9Ý0á! ,Ó/�J€Dˆ$ð —+‘+€Kð �y‰y×'Ñ'¨5Ñ0Ò?°ZÒIÀ6€Hð 	‡L�LØ@Ø
ñ	Ø�Gôð 	�‰‹€Að Ð+Ò+°D·O²OØ�‰ŒáØ×#Ñ# t fÐ,@Ð$AÓBÐBà€Hr   )NFNNNr   )NFN)Nr7   )r   )r+   r   Úpsycopg2._psycopgr   r   r   r   r   r;   r<   rA   rB   r   r9   r>   rC   r1   r0   r,   r   r   ú<module>r\      s_   ðñó< ç 5ß EÑ Eð €Ø€ð €	Ø€÷(;ñ (;ðV <@Ø17ó$óN
<ó
Lóô&r   