Ë
    ¼vëj  ã                  ó¾  — U d Z ddlmZ ddlZddlmZmZmZmZm	Z	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 erddlmZ ddlmZ ddlmZ ddlmZ ej@                  jB                  Z!ej@                  jD                  Z"ej@                  jF                  Z#ej@                  jH                  Z$ edd¬«      Z% eddd¬«      Z& G d„ de	e&   «      Z' G d„ de	e&   «      Z( G d„ de	e&   «      Z) G d„ de	e&   «      Z*e+edf   Z,de-d<   	 e.e/ef   Z0de-d <   	 d-d!„Z1d.d"„Z2d/d#„Z3 ejh                  d$«      d0d%„«       Z5d1d&„Z6d2d'„Z7d2d(„Z8d3d)„Z9d4d*„Z:d5d+„Z;d6d,„Z<y)7z
psycopg row factories
é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚ
NamedTupleÚNoReturnÚProtocolÚ	TypeAlias)Ú
namedtuple)ÚCallableÚSequenceé   )Úerrors)Úpq)ÚTypeVar)Ú_as_python_identifier)ÚCursor)ÚPGresult)Ú
BaseCursor)ÚAsyncCursorÚTT)Ú	covariantÚRowÚTupleRow)r   Údefaultc                  ó   — e Zd ZdZdd„Zy)ÚRowMakera«  
    Callable protocol taking a sequence of value and returning an object.

    The sequence of value is what is returned from a database query, already
    adapted to the right Python types. The return value is the object that your
    program would like to receive: by default (`tuple_row()`) it is a simple
    tuple, but it may be any type of object.

    Typically, `!RowMaker` functions are returned by `RowFactory`.
    c                 ó   — y ©N© )ÚselfÚ_RowMaker__valuess     úM/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/psycopg/rows.pyÚ__call__zRowMaker.__call__1   ó   � ó    N)r!   úSequence[Any]Úreturnr   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r   r%   r"   r   r   %   s   „ ñ	ô <r%   r   c                  ó   — e Zd ZdZdd„Zy)Ú
RowFactorya  
    Callable protocol taking a `~psycopg.Cursor` and returning a `RowMaker`.

    A `!RowFactory` is typically called when a `!Cursor` receives a result.
    This way it can inspect the cursor state (for instance the
    `~psycopg.Cursor.description` attribute) and help a `!RowMaker` to create
    a complete object.

    For instance the `dict_row()` `!RowFactory` uses the names of the column to
    define the dictionary key and returns a `!RowMaker` function which would
    use the values to create a dictionary for each record.
    c                 ó   — y r   r   )r    Ú_RowFactory__cursors     r"   r#   zRowFactory.__call__B   r$   r%   N)r0   zCursor[Any]r'   úRowMaker[Row]r(   r   r%   r"   r.   r.   4   s   „ ñô Dr%   r.   c                  ó   — e Zd ZdZdd„Zy)ÚAsyncRowFactoryz@
    Like `RowFactory`, taking an async cursor as argument.
    c                 ó   — y r   r   )r    Ú_AsyncRowFactory__cursors     r"   r#   zAsyncRowFactory.__call__J   r$   r%   N)r5   zAsyncCursor[Any]r'   r1   r(   r   r%   r"   r3   r3   E   s   „ ñô Ir%   r3   c                  ó   — e Zd ZdZdd„Zy)ÚBaseRowFactoryzF
    Like `RowFactory`, taking either type of cursor as argument.
    c                 ó   — y r   r   )r    Ú_BaseRowFactory__cursors     r"   r#   zBaseRowFactory.__call__R   r$   r%   N)r9   úBaseCursor[Any, Any]r'   r1   r(   r   r%   r"   r7   r7   M   s   „ ñô Mr%   r7   .r	   ÚDictRowc                ó   — t         S )zÚRow factory to represent rows as simple tuples.

    This is the default factory, used when `~psycopg.Connection.connect()` or
    `~psycopg.Connection.cursor()` are called without a `!row_factory`
    parameter.

    )Útuple)Úcursors    r"   Ú	tuple_rowr?   d   s	   € ô €Lr%   c                ó:   ‡— t        | «      xŠ�dˆfd„}|S t        S )z…Row factory to represent rows as dictionaries.

    The dictionary keys are taken from the column names of the returned columns.
    c                ó.   •— t        t        ‰| «      «      S r   ©ÚdictÚzip)ÚvaluesÚnamess    €r"   Ú	dict_row_zdict_row.<locals>.dict_row_x   s   ø€ Üœ˜E 6Ó*Ó+Ð+r%   )rE   r&   r'   zdict[str, Any]©Ú
_get_namesÚ	no_result)r>   rG   rF   s     @r"   Údict_rowrK   q   s*   ø€ ô
 ˜FÓ#Ð#ˆÐ0õ	,ð Ðô Ðr%   c                ó®   ‡— | j                   xŠrAt        ‰«      x}�4t        | j                  gˆfd„t	        |«      D «       ¢­Ž }|j
                  S t        S )zÁRow factory to represent rows as `~collections.namedtuple`.

    The field names are taken from the column names of the returned columns,
    with some mangling to deal with invalid names.
    c              3  ó@   •K  — | ]  }‰j                  |«      –— Œ y ­wr   )Úfname)Ú.0ÚiÚress     €r"   ú	<genexpr>z!namedtuple_row.<locals>.<genexpr>ˆ   s   øè ø€ Ò)O¸1¨#¯)©)°A¯,Ñ)Oùs   ƒ)ÚpgresultÚ_get_nfieldsÚ_make_ntÚ	_encodingÚrangeÚ_makerJ   )r>   ÚnfieldsÚntrQ   s      @r"   Únamedtuple_rowr[   �   sQ   ø€ ð �‰ÐˆÐ´¸SÓ0AÐ%A WÐ$NÜ�f×&Ñ&ÐPÓ)OÄÀgÃÔ)OÒPˆØ�x‰xˆäÐr%   i   c                óš   ‡ — t        ˆ fd„|D «       «      }	 t        d|«      S # t        $ r}t        j                  d|› �«      d ‚d }~ww xY w)Nc              3  óR   •K  — | ]  }t        |j                  ‰«      «      –— Œ  y ­wr   )r   Údecode)rO   ÚnÚencs     €r"   rR   z_make_nt.<locals>.<genexpr>�   s   øè ø€ ÒG¸AÔ(¨¯©°#«×7ÑGùs   ƒ$'r   zcan't create a namedtuple row: )r=   r
   Ú
ValueErrorÚeÚ	DataError)r`   rF   ÚsnamesÚexs   `   r"   rU   rU   Ž   sQ   ø€ äÓGÀÔGÓG€FðLÜ˜% Ó(Ð(øÜò LÜ�k‰kÐ;¸B¸4Ð@ÓAÀtÐKûðLús   —# £	A
¬AÁA
c                ó   ‡ — dˆ fd„}|S )aQ  Generate a row factory to represent rows as instances of the class `!cls`.

    The class must support every output column name as a keyword parameter.

    :param cls: The class to return for each row. It must support the fields
        returned by the query as keyword arguments.
    :rtype: `!Callable[[Cursor],` `RowMaker`\[~T]]
    c                ó>   •‡— t        | «      xŠ�	dˆˆfd„}|S t        S )Nc           
     ó:   •—  ‰di t        t        ‰| «      «      ¤ŽS ©Nr   rB   )rE   ÚclsrF   s    €€r"   Úclass_row__z2class_row.<locals>.class_row_.<locals>.class_row__¤   s   ø€ ÙÑ6œT¤# e¨VÓ"4Ó5Ñ6Ð6r%   ©rE   r&   r'   r   rH   )r>   rk   rF   rj   s     @€r"   Ú
class_row_zclass_row.<locals>.class_row_¡   s(   ù€ Ü Ó'Ð'ˆEÐ4ö7ð Ðô Ðr%   )r>   r:   r'   úRowMaker[T]r   )rj   rm   s   ` r"   Ú	class_rowro   —   s   ø€ õ	ð Ðr%   c                ó   ‡ — dˆ fd„}|S )zÜGenerate a row factory calling `!func` with positional parameters for every row.

    :param func: The function to call for each row. It must support the fields
        returned by the query as positional arguments.
    c                ó   •— dˆfd„}|S )Nc                ó   •—  ‰| Ž S r   r   )rE   Úfuncs    €r"   Ú
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__·   s   ø€ Ù˜�=Ð r%   rl   r   )Úcurrt   rs   s     €r"   Ú	args_row_zargs_row.<locals>.args_row_¶   s   ø€ õ	!ð Ðr%   )ru   úBaseCursor[Any, T]r'   rn   r   )rs   rv   s   ` r"   Úargs_rowrx   ¯   s   ø€ õð Ðr%   c                ó   ‡ — dˆ fd„}|S )zÖGenerate a row factory calling `!func` with keyword parameters for every row.

    :param func: The function to call for each row. It must support the fields
        returned by the query as keyword arguments.
    c                ó>   •‡— t        | «      xŠ�	dˆˆfd„}|S t        S )Nc           
     ó:   •—  ‰di t        t        ‰| «      «      ¤ŽS ri   rB   )rE   rs   rF   s    €€r"   Úkwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__É   s   ø€ ÙÑ7œd¤3 u¨fÓ#5Ó6Ñ7Ð7r%   rl   rH   )r>   r|   rF   rs   s     @€r"   Úkwargs_row_zkwargs_row.<locals>.kwargs_row_Æ   s(   ù€ Ü Ó'Ð'ˆEÐ4ö8ð  Ðô Ðr%   )r>   rw   r'   rn   r   )rs   r}   s   ` r"   Ú
kwargs_rowr~   ¿   s   ø€ õ	ð Ðr%   c                ó„   — | j                   x}r-t        |«      x}� |dk  rt        j                  d«      ‚dd„}|S t        S )zR
    Generate a row factory returning the first column
    as a scalar value.
    r   zat least one column expectedc                ó   — | d   S )Nr   r   ©rE   s    r"   Úscalar_row_zscalar_row.<locals>.scalar_row_Ý   s   € Ø˜!‘9Ðr%   )rE   r&   r'   r   )rS   rT   rb   ÚProgrammingErrorrJ   )r>   rQ   rY   r‚   s       r"   Ú
scalar_rowr„   Ô   sP   € ð
 �‰ÐˆÐ´¸SÓ0AÐ%A WÐ$NØ�QŠ;Ü×$Ñ$Ð%CÓDÐDó	ð Ðô Ðr%   c                ó,   — t        j                  d«      ‚)zâA `RowMaker` that always fail.

    It can be used as return value for a `RowFactory` called with no result.
    Note that the `!RowFactory` *will* be called with no result, but the
    resulting `!RowMaker` never should.
    z the cursor doesn't have a result)rb   ÚInterfaceErrorr�   s    r"   rJ   rJ   æ   s   € ô ×
Ñ
Ð=Ó
>Ð>r%   c                óÊ   — | j                   x}rPt        |«      x}�C| j                  }t        |«      D �cg c]"  }|j	                  |«      j                  |«      ‘Œ$ c}S y c c}w r   )rS   rT   rV   rW   rN   r^   )r>   rQ   rY   r`   rP   s        r"   rI   rI   ð   sd   € Ø�‰ÐˆÐ´¸SÓ0AÐ%A WÐ$NØ×Ñˆä.3°G«nö
Ø)*ˆC�I‰I�a‹L×Ñ Õ$ò
ð 	
ð ùò	
s   µ'A c                ó¼   — | j                   }| j                  t        k(  s;| j                  t        k(  s(| j                  t        k(  s| j                  t
        k(  r|r|S y)z˜
    Return the number of columns in a result, if it returns tuples else None

    Take into account the special case of results with zero columns.
    N)rY   ÚstatusÚ	TUPLES_OKÚSINGLE_TUPLEÚTUPLES_CHUNKÚ
COMMAND_OK)rQ   rY   s     r"   rT   rT   ú   sI   € ð �k‰k€Gð 	�
‰
”iÒØ�:‰:œÒ%Ø�:‰:œÒ%à�J‰Jœ*Ò$©àˆàr%   )r>   r:   r'   zRowMaker[TupleRow])r>   r:   r'   zRowMaker[DictRow])r>   r:   r'   zRowMaker[NamedTuple])r`   ÚstrrF   Úbytesr'   ztype[NamedTuple])rj   ztype[T]r'   úBaseRowFactory[T])rs   zCallable[..., T]r'   r�   )r>   r:   r'   zRowMaker[Any])rE   r&   r'   r   )r>   r:   r'   zlist[str] | None)rQ   r   r'   z
int | None)=r,   Ú
__future__r   Ú	functoolsÚtypingr   r   r   r   r   r	   Úcollectionsr
   Úcollections.abcr   r   Ú r   rb   r   Ú_compatr   Ú
_encodingsr   r>   r   Úpq.abcr   Ú_cursor_baser   Úcursor_asyncr   Ú
ExecStatusr�   rŠ   r‹   rŒ   r   r   r   r.   r3   r7   r=   r   Ú__annotations__rC   rŽ   r;   r?   rK   r[   Ú	lru_cacherU   ro   rx   r~   r„   rJ   rI   rT   r   r%   r"   ú<module>rŸ      s^  ðòõ #ã ß P× PÝ "ß .å Ý Ý Ý -áÝÝ Ý(Ý)à�]‰]×%Ñ%€
Ø�M‰M×#Ñ#€	Ø�}‰}×)Ñ)€Ø�}‰}×)Ñ)€áˆC˜4Ô €ñ ˆe˜t¨ZÔ8€ô<ˆx˜‰}ô <ôD�˜#‘ô Dô"I�h˜s‘mô IôM�X˜c‘]ô Mð ˜C ˜H‘o€ˆ)Ó %ðð
 ˜#˜s˜(‘^€ˆÓ #ðó
óó 
ð €×Ñ�SÓòLó ðLóó0ó ó*ó$?óôr%   