§
    YŠtj¡  ã                  óº  — 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         j!        Z!ej         j"        Z"ej         j#        Z#ej         j$        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 <   	 dEd%„Z1dFd'„Z2dGd)„Z3 ej4        d*¦  «        dHd0„¦   «         Z5dId4„Z6dJd7„Z7dJd8„Z8dKd:„Z9dLd>„Z:dMd@„Z;dNdD„Z<dS )Oz
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dS )	Ú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`.
    Ú_RowMaker__valuesúSequence[Any]Úreturnr   c                ó   — d S ©N© )Úselfr   s     úJ/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/psycopg/rows.pyÚ__call__zRowMaker.__call__1   ó   € € € ó    N)r   r   r   r   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r"   r'   r$   r   r   %   s(   € € € € € ð	ð 	ð <Ð;Ð;Ð;Ð;Ð;r'   r   c                  ó   — e Zd ZdZdd„ZdS )	Ú
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.
    Ú_RowFactory__cursorúCursor[Any]r   úRowMaker[Row]c                ó   — d S r!   r"   )r#   r/   s     r$   r%   zRowFactory.__call__B   r&   r'   N)r/   r0   r   r1   r(   r"   r'   r$   r.   r.   4   s)   € € € € € ðð ð DÐCÐCÐCÐCÐCr'   r.   c                  ó   — e Zd ZdZdd„ZdS )	ÚAsyncRowFactoryz@
    Like `RowFactory`, taking an async cursor as argument.
    Ú_AsyncRowFactory__cursorúAsyncCursor[Any]r   r1   c                ó   — d S r!   r"   )r#   r5   s     r$   r%   zAsyncRowFactory.__call__J   r&   r'   N)r5   r6   r   r1   r(   r"   r'   r$   r4   r4   E   s)   € € € € € ðð ð IÐHÐHÐHÐHÐHr'   r4   c                  ó   — e Zd ZdZdd„ZdS )	ÚBaseRowFactoryzF
    Like `RowFactory`, taking either type of cursor as argument.
    Ú_BaseRowFactory__cursorúBaseCursor[Any, Any]r   r1   c                ó   — d S r!   r"   )r#   r:   s     r$   r%   zBaseRowFactory.__call__R   r&   r'   N)r:   r;   r   r1   r(   r"   r'   r$   r9   r9   M   s)   € € € € € ðð ð MÐLÐLÐLÐLÐLr'   r9   .r	   ÚDictRowÚcursorr;   r   úRowMaker[TupleRow]c                ó   — 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)r>   s    r$   Ú	tuple_rowrB   d   s	   € õ €Lr'   úRowMaker[DictRow]c                óD   ‡— 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.
    NÚvaluesr   r   údict[str, Any]c                ó>   •— t          t          ‰| ¦  «        ¦  «        S r!   ©ÚdictÚzip)rE   Únamess    €r$   Ú	dict_row_zdict_row.<locals>.dict_row_x   s   ø€ Ý�˜E 6Ñ*Ô*Ñ+Ô+Ð+r'   )rE   r   r   rF   ©Ú
_get_namesÚ	no_result)r>   rL   rK   s     @r$   Údict_rowrP   q   sF   ø€ õ
 ˜FÑ#Ô#Ð#ˆÐ0ð	,ð 	,ð 	,ð 	,ð 	,ð 	,ð Ðõ Ðr'   úRowMaker[NamedTuple]c                óª   ‡— | j         xŠrCt          ‰¦  «        x}�2t          | j        gˆfd„t	          |¦  «        D ¦   «         ¢R Ž }|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.
    Nc              3  óB   •K  — | ]}‰                      |¦  «        V — Œd S r!   )Úfname)Ú.0ÚiÚress     €r$   ú	<genexpr>z!namedtuple_row.<locals>.<genexpr>ˆ   s-   øè è € Ð)OÐ)O¸1¨#¯)ª)°A©,¬,Ð)OÐ)OÐ)OÐ)OÐ)OÐ)Or'   )ÚpgresultÚ_get_nfieldsÚ_make_ntÚ	_encodingÚrangeÚ_makerO   )r>   ÚnfieldsÚntrW   s      @r$   Únamedtuple_rowra   �   sf   ø€ ð ŒÐˆð µ¸SÑ0AÔ0AÐ%A WÐ$NÝ�fÔ&ÐPÐ)OÐ)OÐ)OÐ)OÅÀgÁÄÐ)OÑ)OÔ)OÐPÐPÐPˆØŒxˆåÐr'   i   ÚencÚstrrK   Úbytesútype[NamedTuple]c                óZ   ‡ — t          ˆ fd„|D ¦   «         ¦  «        }t          d|¦  «        S )Nc              3  ó\   •K  — | ]&}t          |                     ‰¦  «        ¦  «        V — Œ'd S r!   )r   Údecode)rU   Únrb   s     €r$   rX   z_make_nt.<locals>.<genexpr>�   s6   øè è € ÐGÐG¸AÕ(¨¯ª°#©¬Ñ7Ô7ÐGÐGÐGÐGÐGÐGr'   r   )rA   r
   )rb   rK   Úsnamess   `  r$   r[   r[   Ž   s5   ø€ åÐGÐGÐGÐGÀÐGÑGÔGÑGÔG€FÝ�e˜VÑ$Ô$Ð$r'   Úclsútype[T]úBaseRowFactory[T]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]]
    r>   r;   r   úRowMaker[T]c                óH   •‡— t          | ¦  «        xŠ�	dˆˆfd„}|S t          S )NrE   r   r   r   c           
     óJ   •—  ‰di t          t          ‰| ¦  «        ¦  «        ¤ŽS ©Nr"   rH   )rE   rk   rK   s    €€r$   Úclass_row__z2class_row.<locals>.class_row_.<locals>.class_row__¡   s+   ø€ Ø�sÐ6Ð6�T¥# e¨VÑ"4Ô"4Ñ5Ô5Ð6Ð6Ð6r'   ©rE   r   r   r   rM   )r>   rs   rK   rk   s     @€r$   Ú
class_row_zclass_row.<locals>.class_row_ž   sJ   øø€ Ý Ñ'Ô'Ð'ˆEÐ4ð7ð 7ð 7ð 7ð 7ð 7ð 7ð Ðõ Ðr'   )r>   r;   r   ro   r"   )rk   ru   s   ` r$   Ú	class_rowrv   ”   s)   ø€ ð	ð 	ð 	ð 	ð 	ð 	ð Ðr'   ÚfuncúCallable[..., T]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.
    ÚcurúBaseCursor[Any, T]r   ro   c                ó   •— dˆfd„}|S )NrE   r   r   r   c                ó   •—  ‰| Ž S r!   r"   )rE   rw   s    €r$   Ú
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__´   s   ø€ Ø�4˜�=Ð r'   rt   r"   )rz   r~   rw   s     €r$   Ú	args_row_zargs_row.<locals>.args_row_³   s)   ø€ ð	!ð 	!ð 	!ð 	!ð 	!ð 	!ð Ðr'   )rz   r{   r   ro   r"   )rw   r   s   ` r$   Úargs_rowr€   ¬   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.
    r>   r{   r   ro   c                óH   •‡— t          | ¦  «        xŠ�	dˆˆfd„}|S t          S )NrE   r   r   r   c           
     óJ   •—  ‰di t          t          ‰| ¦  «        ¦  «        ¤ŽS rr   rH   )rE   rw   rK   s    €€r$   Úkwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__Æ   s+   ø€ Ø�tÐ7Ð7�d¥3 u¨fÑ#5Ô#5Ñ6Ô6Ð7Ð7Ð7r'   rt   rM   )r>   r„   rK   rw   s     @€r$   Úkwargs_row_zkwargs_row.<locals>.kwargs_row_Ã   sJ   øø€ Ý Ñ'Ô'Ð'ˆEÐ4ð8ð 8ð 8ð 8ð 8ð 8ð 8ð  Ðõ Ðr'   )r>   r{   r   ro   r"   )rw   r…   s   ` r$   Ú
kwargs_rowr†   ¼   s)   ø€ ð	ð 	ð 	ð 	ð 	ð 	ð Ðr'   úRowMaker[Any]c                ó„   — | j         x}r1t          |¦  «        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.
    Nr   zat least one column expectedrE   r   r   r   c                ó   — | d         S )Nr   r"   ©rE   s    r$   Úscalar_row_zscalar_row.<locals>.scalar_row_Ú   s   € Ø˜!”9Ðr'   )rE   r   r   r   )rY   rZ   ÚeÚProgrammingErrorrO   )r>   rW   r_   r‹   s       r$   Ú
scalar_rowrŽ   Ñ   sd   € ð
 ŒÐˆð 
µ¸SÑ0AÔ0AÐ%A WÐ$NØ�QŠ;ˆ;ÝÔ$Ð%CÑDÔDÐDð	ð 	ð 	ð 	ð Ðõ Ðr'   rE   r   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$   rO   rO   ã   s   € õ Ô
Ð=Ñ
>Ô
>Ð>r'   úlist[str] | Nonec                ó„   ‡‡— | j         xŠr4t          ‰¦  «        x}�#| j        Šˆˆfd„t          |¦  «        D ¦   «         S d S )Nc                ó`   •— g | ]*}‰                      |¦  «                             ‰¦  «        ‘Œ+S r"   )rT   rh   )rU   rV   rb   rW   s     €€r$   ú
<listcomp>z_get_names.<locals>.<listcomp>ð   s>   ø€ ð 
ð 
ð 
Ø)*ˆC�IŠI�a‰LŒL×Ò Ñ$Ô$ð
ð 
ð 
r'   )rY   rZ   r\   r]   )r>   r_   rb   rW   s     @@r$   rN   rN   í   sj   øø€ ØŒÐˆð µ¸SÑ0AÔ0AÐ%A WÐ$NØÔˆð
ð 
ð 
ð 
ð 
Ý.3°G©n¬nð
ñ 
ô 
ð 	
ð ˆtr'   rW   r   ú
int | Nonec                óœ   — | j         }| j        t          k    s2| j        t          k    s"| j        t          k    s| j        t
          k    r|r|S dS )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)r_   ÚstatusÚ	TUPLES_OKÚSINGLE_TUPLEÚTUPLES_CHUNKÚ
COMMAND_OK)rW   r_   s     r$   rZ   rZ   ÷   sP   € ð Œk€Gð 	Œ
•iÒÐØŒ:�Ò%Ð%ØŒ:�Ò%Ð%àŒJ�*Ò$Ð$¨Ð$àˆàˆtr'   )r>   r;   r   r?   )r>   r;   r   rC   )r>   r;   r   rQ   )rb   rc   rK   rd   r   re   )rk   rl   r   rm   )rw   rx   r   rm   )r>   r;   r   r‡   )rE   r   r   r   )r>   r;   r   r‘   )rW   r   r   r•   )=r,   Ú
__future__r   Ú	functoolsÚtypingr   r   r   r   r   r	   Úcollectionsr
   Úcollections.abcr   r   Ú r   rŒ   r   Ú_compatr   Ú
_encodingsr   r>   r   Úpq.abcr   Ú_cursor_baser   Úcursor_asyncr   Ú
ExecStatusr›   r˜   r™   rš   r   r   r   r.   r4   r9   rA   r   Ú__annotations__rI   rc   r=   rB   rP   ra   Ú	lru_cacher[   rv   r€   r†   rŽ   rO   rN   rZ   r"   r'   r$   ú<module>rª      sŠ  ððð ð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PÐ PØ "Ð "Ð "Ð "Ð "Ð "Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø -Ð -Ð -Ð -Ð -Ð -àð *ØÐÐÐÐÐØ Ð Ð Ð Ð Ð Ø(Ð(Ð(Ð(Ð(Ð(Ø)Ð)Ð)Ð)Ð)Ð)àŒ]Ô%€
ØŒMÔ#€	ØŒ}Ô)€ØŒ}Ô)€à€GˆC˜4Ð Ñ Ô €ð €gˆe˜t¨ZÐ8Ñ8Ô8€ð<ð <ð <ð <ð <ˆx˜Œ}ñ <ô <ð <ðDð Dð Dð Dð D�˜#”ñ Dô Dð Dð"Ið Ið Ið Ið I�h˜s”mñ Iô Ið IðMð Mð Mð Mð M�X˜c”]ñ Mô Mð Mð ˜C ˜H”o€Ð %Ð %Ð %Ñ %ðð
 ˜#˜s˜(”^€Ð #Ð #Ð #Ñ #ðð
ð 
ð 
ð 
ðð ð ð ð 
ð 
ð 
ð 
ð €Ô�SÑÔð%ð %ð %ñ Ôð%ð
ð ð ð ð0ð ð ð ð ð ð ð ð*ð ð ð ð$?ð ?ð ?ð ?ðð ð ð ðð ð ð ð ð r'   