U
    Ú²gy
  ã                   @  s<  d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddl
mZ dd	l
mZ dd
lmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ erÔddlmZ ddlmZ ddl m!Z! ej"j#Z#ej"j$Z$G dd„ deeef ƒZ%G dd„ de%def ee ƒZ&G dd„ de%def ee ƒZ'dS )z%
psycopg client-side binding cursors
é    )Úannotations)ÚTYPE_CHECKING)Úpartialé   )ÚPostgresQueryÚPostgresClientQuery)Úpq)Úadapt)Úerrors)ÚConnectionTypeÚQueryÚParams)ÚRow)ÚCursor)ÚPrepare)Ú
BaseCursor)ÚAsyncCursor)ÚAny)Ú
Connection)ÚAsyncConnectionc                   @  sT   e Zd ZeZdddddœdd„Zddd	œd
ddddœdd„Zdd
dddœdd„ZdS )ÚClientCursorMixinNr   zParams | NoneÚstr)ÚqueryÚparamsÚreturnc                 C  s(   t  | ¡| _|  ||¡}|j | jj¡S )z£
        Return the query and parameters merged.

        Parameters are adapted and merged to the query the same way that
        `!execute()` would do.

        )r	   ZTransformerZ_txZ_convert_queryr   ÚdecodeÚencoding)Úselfr   r   Úpgq© r   ú9/tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/client_cursor.pyÚmogrify$   s    zClientCursorMixin.mogrifyF)Úforce_extendedÚbinaryr   Úboolzbool | NoneÚNone)r   r"   r#   r   c                C  s„   |d kr| j }n|rtnt}|tkr.t d¡‚|| _| jjr\| jjj 	t
| jj|jd ƒ¡ n$|rr| j |jd ¡ n| j |j¡ d S )Nz0client-side cursors don't support binary results)ÚformatÚBINARYÚTEXTÚeZNotSupportedErrorZ_queryZ_connZ	_pipelineZcommand_queueÚappendr   Z_pgconnZsend_query_paramsr   Z
send_query)r   r   r"   r#   Úfmtr   r   r    Ú_execute_send0   s    ÿ
ÿzClientCursorMixin._execute_sendztuple[Prepare, bytes])r   Úpreparer   c                 C  s
   t jdfS )Nó    )r   ÚNO)r   r   r-   r   r   r    Ú_get_preparedP   s    zClientCursorMixin._get_prepared)N)N)Ú__name__Ú
__module__Ú__qualname__r   Z
_query_clsr!   r,   r0   r   r   r   r    r   !   s   û! ÿr   c                   @  s   e Zd ZdZdS )ÚClientCursorÚpsycopgN©r1   r2   r3   r   r   r   r    r4   V   s   r4   zConnection[Any]c                   @  s   e Zd ZdZdS )ÚAsyncClientCursorr5   Nr6   r   r   r   r    r7   Z   s   r7   zAsyncConnection[Any]N)(Ú__doc__Ú
__future__r   Útypingr   Ú	functoolsr   Z_queriesr   r   Ú r   r	   r
   r)   Úabcr   r   r   Zrowsr   Úcursorr   Z
_preparingr   Z_cursor_baser   Zcursor_asyncr   r   Ú
connectionr   Zconnection_asyncr   ZFormatr(   r'   r   r4   r7   r   r   r   r    Ú<module>   s2   5

 ÿ