Ë
    ÛqjÑ  ã                  óÎ  — U d Z ddlmZ ddlZddlmZmZmZmZ ddlm	Z	m
Z
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 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jB                  jD                  Z"ejB                  jF                  Z#ejB                  jH                  Z$ejB                  jJ                  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   Z/d e-d!<   	 d.d"„Z0d/d#„Z1d0d$„Z2 ejf                  d%«      d1d&„«       Z4d2d'„Z5d3d(„Z6d3d)„Z7d4d*„Z8d5d+„Z9d6d,„Z:d7d-„Z;y)8z
psycopg row factories
é    )ÚannotationsN)ÚAnyÚCallableÚ
NamedTupleÚNoReturn)ÚTYPE_CHECKINGÚProtocolÚSequence)ÚDictÚTuple)Ú
namedtupleé   )Úpq)Úerrors)Ú	TypeAliasÚTypeVar)Ú_as_python_identifier)ÚCursor)Ú
BaseCursor)ÚAsyncCursor)ÚPGresultÚ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/kelly-backend/venv/lib/python3.12/site-packages/psycopg/rows.pyÚ__call__zRowMaker.__call__2   s   € ¸ó    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__C   s   € Àr&   N)r1   zCursor[Any]r(   úRowMaker[Row]r)   r!   r&   r$   r/   r/   5   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__K   s   € ÀSr&   N)r6   zAsyncCursor[Any]r(   r2   r)   r!   r&   r$   r4   r4   F   s   „ ñô Ir&   r4   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__S   s   € Èr&   N)r:   úBaseCursor[Any, Any]r(   r2   r)   r!   r&   r$   r8   r8   N   s   „ ñô Mr&   r8   .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@   e   s	   € ô €Lr&   c                ó:   ‡— t        | «      Š‰€t        S dˆfd„}|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_{   s   ø€ Ü”C˜˜vÓ&Ó'Ð'r&   )rF   r'   r(   zdict[str, Any]©Ú
_get_namesÚ	no_result)r?   rH   rG   s     @r$   Údict_rowrL   r   s'   ø€ ô
 �vÓ€EØ€}ÜÐõ(ð Ðr&   c                óº   ‡— | j                   Š‰st        S t        ‰«      }|€t        S t        | j                  gˆfd„t        |«      D «       ¢­Ž }|j                  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   øè ø€ Ð%K¹N°q c§i¡i°§l¹Nùs   ƒ)ÚpgresultrK   Ú_get_nfieldsÚ_make_ntÚ	_encodingÚrangeÚ_make)r?   ÚnfieldsÚntrR   s      @r$   Únamedtuple_rowr\   �   sT   ø€ ð �/‰/€CÙÜÐä˜3Ó€GØ€ÜÐä	�&×"Ñ"Ð	LÓ%K¼EÀ'¼NÓ%KÒ	L€BØ�8‰8€Or&   i   c                óD   ‡ — t        ˆ fd„|D «       «      }t        d|«      S )Nc              3  óR   •K  — | ]  }t        |j                  ‰«      «      –— Œ  y ­wr    )r   Údecode)rP   ÚnÚencs     €r$   rS   z_make_nt.<locals>.<genexpr>•   s    øè ø€ ÐGÁ¸AÔ(¨¯©°#«×7Áùs   ƒ$'r   )r>   r   )ra   rG   Úsnamess   `  r$   rV   rV   “   s    ø€ äÓGÁÓGÓG€FÜ�e˜VÓ$Ð$r&   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        | «      Š‰€t        S dˆˆfd„}|S )Nc           
     ó:   •—  ‰di t        t        ‰| «      «      ¤ŽS ©Nr!   rC   )rF   ÚclsrG   s    €€r$   Úclass_row__z2class_row.<locals>.class_row_.<locals>.class_row__¨   s   ø€ ÙÑ2œœc %¨Ó0Ó1Ñ2Ð2r&   ©rF   r'   r(   r   rI   )r?   rh   rG   rg   s     @€r$   Ú
class_row_zclass_row.<locals>.class_row_£   s%   ù€ Ü˜6Ó"ˆØˆ=ÜÐö	3ð Ðr&   )r?   r;   r(   úRowMaker[T]r!   )rg   rj   s   ` r$   Ú	class_rowrl   ™   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!   )rF   Úfuncs    €r$   Ú
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__¸   s   ø€ Ù˜�=Ð r&   ri   r!   )Úcurrq   rp   s     €r$   Ú	args_row_zargs_row.<locals>.args_row_·   s   ø€ õ	!ð Ðr&   )rr   úBaseCursor[Any, T]r(   rk   r!   )rp   rs   s   ` r$   Úargs_rowru   °   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        | «      Š‰€t        S dˆˆfd„}|S )Nc           
     ó:   •—  ‰di t        t        ‰| «      «      ¤ŽS rf   rC   )rF   rp   rG   s    €€r$   Úkwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__Ì   s   ø€ ÙÑ3œ$œs 5¨&Ó1Ó2Ñ3Ð3r&   ri   rI   )r?   ry   rG   rp   s     @€r$   Úkwargs_row_zkwargs_row.<locals>.kwargs_row_Ç   s%   ù€ Ü˜6Ó"ˆØˆ=ÜÐö	4ð Ðr&   )r?   rt   r(   rk   r!   )rp   rz   s   ` r$   Ú
kwargs_rowr{   À   s   ø€ õð Ðr&   c                ó�   — | j                   }|st        S t        |«      }|€t        S |dk  rt        j                  d«      ‚dd„}|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!   ©rF   s    r$   Úscalar_row_zscalar_row.<locals>.scalar_row_ä   s   € Ø�a‰yÐr&   )rF   r'   r(   r   )rT   rK   rU   ÚeÚProgrammingError)r?   rR   rZ   r   s       r$   Ú
scalar_rowr‚   Ô   sQ   € ð
 �/‰/€CÙÜÐä˜3Ó€GØ€ÜÐà�‚{Ü× Ñ Ð!?Ó@Ð@óð Ð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)r€   ÚInterfaceErrorr~   s    r$   rK   rK   ê   s   € ô ×
Ñ
Ð=Ó
>Ð>r&   c                óÌ   — | j                   }|sy t        |«      }|€y | j                  }t        |«      D �cg c]"  }|j	                  |«      j                  |«      ‘Œ$ c}S c c}w r    )rT   rU   rW   rX   rO   r_   )r?   rR   rZ   ra   rQ   s        r$   rJ   rJ   ô   sf   € Ø
�/‰/€CÙØä˜3Ó€GØ€Øà
×
Ñ
€Cä*/°¬.óÙ*8 Qˆ�	‰	�!‹×Ñ˜CÕ ¨.ñð ùò 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)rZ   ÚstatusÚ	TUPLES_OKÚSINGLE_TUPLEÚTUPLES_CHUNKÚ
COMMAND_OK)rR   rZ   s     r$   rU   rU     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])ra   ÚstrrG   Úbytesr(   ztype[NamedTuple])rg   ztype[T]r(   úBaseRowFactory[T])rp   zCallable[..., T]r(   rŽ   )r?   r;   r(   zRowMaker[Any])rF   r'   r(   r   )r?   r;   r(   zlist[str] | None)rR   r   r(   z
int | None)<r-   Ú
__future__r   Ú	functoolsÚtypingr   r   r   r   r   r	   r
   r   r   Úcollectionsr   Ú r   r   r€   Ú_compatr   r   Ú
_encodingsr   r?   r   Ú_cursor_baser   Úcursor_asyncr   Úpsycopg.pq.abcr   Ú
ExecStatusr‹   rˆ   r‰   rŠ   r   r   r   r/   r4   r8   r   Ú__annotations__rŒ   r<   r@   rL   r\   Ú	lru_cacherV   rl   ru   r{   r‚   rK   rJ   rU   r!   r&   r$   Ú<module>rœ      sb  ðòõ #ã ß 6Ó 6ß 4Ñ 4ß Ý "å Ý ß 'Ý -áÝÝ(Ý)Ý'à�]‰]×%Ñ%€
Ø�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Óò%ó ð%ó
ó.ó ó(ó,?óôr&   