ó
    Ð]j¡  ã                  óÒ  • % S r SSKJr  SSKrSSKJrJrJrJrJ	r	J
r
  SSKJr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  \(       a  SSKJr  SSKJr  SSKJr  SSKJr  \R@                  RB                  r!\R@                  RD                  r"\R@                  RF                  r#\R@                  RH                  r$\" SSS9r%\" SSSS9r& " S S\	\&   5      r' " S S\	\&   5      r( " S S\	\&   5      r) " S S\	\&   5      r*\+\S4   r,S\-S'    \.\/\4   r0S\-S '    S-S! jr1S.S" jr2S/S# jr3\Rh                  " S$5      S0S% j5       r5S1S& jr6S2S' jr7S2S( jr8S3S) jr9S4S* jr:S5S+ jr;S6S, jr<g)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                  ó"   • \ rS rSrSrSS jrSrg)ÚRowMakeré%   a�  
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                ó   • g ©N© )ÚselfÚ_RowMaker__valuess     ÚI/home/mande/repo/quber/.venv/lib/python3.13/site-packages/psycopg/rows.pyÚ__call__ÚRowMaker.__call__1   s   € ¸ó    r    N)r"   úSequence[Any]Úreturnr   ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   Ú__static_attributes__r    r&   r#   r   r   %   s   † ñ	÷ <r&   r   c                  ó"   • \ rS rSrSrSS jrSrg)Ú
RowFactoryé4   aø  
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                ó   • g r   r    )r!   Ú_RowFactory__cursors     r#   r$   ÚRowFactory.__call__B   s   € Àr&   r    N)r4   zCursor[Any]r(   úRowMaker[Row]r)   r    r&   r#   r1   r1   4   s   † ñ÷ Dr&   r1   c                  ó"   • \ rS rSrSrSS jrSrg)ÚAsyncRowFactoryéE   z8
Like `RowFactory`, taking an async cursor as argument.
c                ó   • g r   r    )r!   Ú_AsyncRowFactory__cursors     r#   r$   ÚAsyncRowFactory.__call__J   s   € ÀSr&   r    N)r;   zAsyncCursor[Any]r(   r6   r)   r    r&   r#   r8   r8   E   s   † ñ÷ Ir&   r8   c                  ó"   • \ rS rSrSrSS jrSrg)ÚBaseRowFactoryéM   z>
Like `RowFactory`, taking either type of cursor as argument.
c                ó   • g r   r    )r!   Ú_BaseRowFactory__cursors     r#   r$   ÚBaseRowFactory.__call__R   s   € Èr&   r    N)rA   úBaseCursor[Any, Any]r(   r6   r)   r    r&   r#   r>   r>   M   s   † ñ÷ Mr&   r>   .r	   ÚDictRowc                ó   • [         $ )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_rowrH   d   s	   € ô €Lr&   c                ó@   ^• [        U 5      =mb
  SU4S jjnU$ [        $ )z}Row factory to represent rows as dictionaries.

The dictionary keys are taken from the column names of the returned columns.
c                ó.   >• [        [        TU 5      5      $ r   ©ÚdictÚzip)ÚvaluesÚnamess    €r#   Ú	dict_row_Údict_row.<locals>.dict_row_x   s   ø€ Üœ˜E 6Ó*Ó+Ð+r&   )rN   r'   r(   zdict[str, Any]©Ú
_get_namesÚ	no_result)rG   rP   rO   s     @r#   Údict_rowrU   q   s*   ø€ ô
 ˜FÓ#Ð#ˆÑ0÷	,ð Ðô Ðr&   c                ó¼   ^• U R                   =m(       aC  [        T5      =nb5  [        U R                  /U4S j[	        U5       5       Q76 nUR
                  $ [        $ )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  óF   >#   • U  H  nTR                  U5      v •  M     g 7fr   )Úfname)Ú.0ÚiÚress     €r#   Ú	<genexpr>Ú!namedtuple_row.<locals>.<genexpr>ˆ   s   øé € Ð)OÂ¸1¨#¯)©)°A¯,¨,Âùs   ƒ!)ÚpgresultÚ_get_nfieldsÚ_make_ntÚ	_encodingÚrangeÚ_makerT   )rG   ÚnfieldsÚntr[   s      @r#   Únamedtuple_rowrf   �   sQ   ø€ ð �‰ÐˆÕ´¸SÓ0AÐ%A WÑ$NÜ�f×&Ñ&ÐPÔ)OÄÀgÄÓ)OÒPˆØ�x‰xˆäÐr&   i   c                óF   ^ • [        U 4S jU 5       5      n[        SU5      $ )Nc              3  óX   >#   • U  H  n[        UR                  T5      5      v •  M!     g 7fr   )r   Údecode)rY   ÚnÚencs     €r#   r\   Ú_make_nt.<locals>.<genexpr>�   s"   øé € ÐGÂ¸AÔ(¨¯©°#«×7Ð7Âùs   ƒ'*r   )rF   r
   )rk   rO   Úsnamess   `  r#   r`   r`   Ž   s    ø€ äÔGÁÓGÓG€FÜ�e˜VÓ$Ð$r&   c                ó   ^ • SU 4S jjnU$ )a=  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                óD   >^• [        U 5      =mb  SUU4S jjnU$ [        $ )Nc           
     ó:   >• T" S0 [        [        TU 5      5      D6$ ©Nr    rK   )rN   ÚclsrO   s    €€r#   Úclass_row__Ú2class_row.<locals>.class_row_.<locals>.class_row__¡   s   ø€ ÙÑ6œT¤# e¨VÓ"4Ó5Ñ6Ð6r&   ©rN   r'   r(   r   rR   )rG   rs   rO   rr   s     @€r#   Ú
class_row_Úclass_row.<locals>.class_row_ž   s-   ù€ Ü Ó'Ð'ˆEÑ4÷7ð 7ð Ðô Ðr&   )rG   rC   r(   úRowMaker[T]r    )rr   rv   s   ` r#   Ú	class_rowry   ”   s   ø€ ÷	ð Ðr&   c                ó   ^ • SU 4S jjnU$ )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                ó   >• SU4S jjnU$ )Nc                ó   >• T" U 6 $ r   r    )rN   Úfuncs    €r#   Ú
args_row__Ú/args_row.<locals>.args_row_.<locals>.args_row__´   s   ø€ Ù˜�=Ð r&   ru   r    )Úcurr~   r}   s     €r#   Ú	args_row_Úargs_row.<locals>.args_row_³   s   ø€ ÷	!ð Ðr&   )r€   úBaseCursor[Any, T]r(   rx   r    )r}   r�   s   ` r#   Úargs_rowr„   ¬   s   ø€ ÷ð Ðr&   c                ó   ^ • SU 4S jjnU$ )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                óD   >^• [        U 5      =mb  SUU4S jjnU$ [        $ )Nc           
     ó:   >• T" S0 [        [        TU 5      5      D6$ rq   rK   )rN   r}   rO   s    €€r#   Úkwargs_row__Ú5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__Æ   s   ø€ ÙÑ7œd¤3 u¨fÓ#5Ó6Ñ7Ð7r&   ru   rR   )rG   rˆ   rO   r}   s     @€r#   Úkwargs_row_Úkwargs_row.<locals>.kwargs_row_Ã   s-   ù€ Ü Ó'Ð'ˆEÑ4÷8ð 8ð  Ðô Ðr&   )rG   rƒ   r(   rx   r    )r}   rŠ   s   ` r#   Ú
kwargs_rowrŒ   ¼   s   ø€ ÷	ð Ðr&   c                ó–   • U R                   =n(       a1  [        U5      =nb#  US:  a  [        R                  " S5      eSS jnU$ [        $ )zF
Generate a row factory returning the first column
as a scalar value.
r   zat least one column expectedc                ó   • U S   $ )Nr   r    ©rN   s    r#   Úscalar_row_Úscalar_row.<locals>.scalar_row_Ú   s   € Ø˜!‘9Ðr&   )rN   r'   r(   r   )r^   r_   ÚeÚProgrammingErrorrT   )rG   r[   rd   r�   s       r#   Ú
scalar_rowr”   Ñ   sP   € ð
 �‰ÐˆÕ´¸SÓ0AÐ%A WÑ$NØ�Q‹;Ü×$Ò$Ð%CÓDÐDô	ð Ðô Ðr&   c                ó.   • [         R                  " S5      e)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#   rT   rT   ã   s   € ô ×
Ò
Ð=Ó
>Ð>r&   c                óÚ   • U R                   =n(       aS  [        U5      =nbE  U R                  n[        U5       Vs/ s H"  oAR	                  U5      R                  U5      PM$     sn$ g s  snf r   )r^   r_   ra   rb   rX   ri   )rG   r[   rd   rk   rZ   s        r#   rS   rS   í   sf   € Ø�‰ÐˆÕ´¸SÓ0AÐ%A WÑ$NØ×Ñˆä.3°G¬nó
Ú.<¨�I‰I�a‹L×Ñ Ö$©nñ
ð 	
ð ùò	
s   »)A(c                óÎ   • U R                   nU R                  [        :X  dC  U R                  [        :X  d/  U R                  [        :X  d  U R                  [
        :X  a	  U(       a  U$ g)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)rd   ÚstatusÚ	TUPLES_OKÚSINGLE_TUPLEÚTUPLES_CHUNKÚ
COMMAND_OK)r[   rd   s     r#   r_   r_   ÷   sI   € ð �k‰k€Gð 	�
‰
”iÓØ�:‰:œÓ%Ø�:‰:œÓ%à�J‰Jœ*Ó$®àˆàr&   )rG   rC   r(   zRowMaker[TupleRow])rG   rC   r(   zRowMaker[DictRow])rG   rC   r(   zRowMaker[NamedTuple])rk   ÚstrrO   Úbytesr(   ztype[NamedTuple])rr   ztype[T]r(   úBaseRowFactory[T])r}   zCallable[..., T]r(   r    )rG   rC   r(   zRowMaker[Any])rN   r'   r(   r   )rG   rC   r(   zlist[str] | None)r[   r   r(   z
int | None)=r.   Ú
__future__r   Ú	functoolsÚtypingr   r   r   r   r   r	   Úcollectionsr
   Úcollections.abcr   r   Ú r   r’   r   Ú_compatr   Ú
_encodingsr   rG   r   Úpq.abcr   Ú_cursor_baser   Úcursor_asyncr   Ú
ExecStatusr�   rš   r›   rœ   r   r   r   r1   r8   r>   rF   r   Ú__annotations__rL   rž   rD   rH   rU   rf   Ú	lru_cacher`   ry   r„   rŒ   r”   rT   rS   r_   r    r&   r#   Ú<module>r¯      sZ  ðòõ #ã ß 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Óó%ó ð%ô
ô0ô ô*ô$?ôõr&   