
    (ph                       % S r SSKJr  SSKrSSKJrJrJrJr  SSKJ	r	J
r
Jr  SSKJr  SSKJr  SS	KJr  SS
KJr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>                  R@                  r \R>                  RB                  r!\R>                  RD                  r"\R>                  RF                  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r*S\+S'    S r,S\+S!'    S.S" jr-S/S# jr.S0S$ jr/\R`                  " S%5      S1S& j5       r1S2S' jr2S3S( jr3S3S) jr4S4S* jr5S5S+ jr6S6S, jr7S7S- jr8g)8z
psycopg row factories
    )annotationsN)AnyCallable
NamedTupleNoReturn)TYPE_CHECKINGProtocolSequence)
namedtuple   )pq)errors)	TypeAliasTypeVar)_as_python_identifier)Cursor)
BaseCursor)AsyncCursor)PGresult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     ?/var/www/html/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)
RowFactory4   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)AsyncRowFactoryE   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)BaseRowFactoryM   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>   ztuple[Any, ...]r   dict[str, Any]DictRowc                    [         $ )zRow 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_rowrI   d   s	     Lr&   c                @   ^ [        U 5      mTc  [        $ 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_z   s    Cv&''r&   )rO   r'   r(   rD   
_get_names	no_result)rH   rQ   rP   s     @r#   dict_rowrV   q   s'    
 vE}( r&   c                   ^ U R                   mT(       d  [        $ [        T5      nUc  [        $ [        U R                  /U4S j[        U5       5       Q76 nUR                  $ )zRow 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     %KNqciillNs   !)pgresultrU   _get_nfields_make_nt	_encodingrange_make)rH   nfieldsntr\   s      @r#   namedtuple_rowrg      sT     //C3G	&""	L%KE'N%K	LB88Or&   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)rZ   nencs     r#   r]   _make_nt.<locals>.<genexpr>   s"     GA(#77s   '*r   )rG   r   )rl   rP   snamess   `  r#   ra   ra      s     GGGFeV$$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Tc  [        $ SUU4S jjnU$ )Nc           
     :   > T" S0 [        [        TU 5      5      D6$ Nr    rL   )rO   clsrP   s    r#   class_row__2class_row.<locals>.class_row_.<locals>.class_row__   s    2c%0122r&   rO   r'   r(   r   rS   )rH   rt   rP   rs   s     @r#   
class_row_class_row.<locals>.class_row_   s*    6"=	3 	3 r&   )rH   rC   r(   RowMaker[T]r    )rs   rw   s   ` r#   	class_rowrz      s     r&   c                   ^  SU 4S jjnU$ )zGenerate 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    )rO   funcs    r#   
args_row__/args_row.<locals>.args_row_.<locals>.args_row__   s    = r&   rv   r    )curr   r~   s     r#   	args_row_args_row.<locals>.args_row_   s    	! r&   )r   BaseCursor[Any, T]r(   ry   r    )r~   r   s   ` r#   args_rowr      s     r&   c                   ^  SU 4S jjnU$ )zGenerate 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Tc  [        $ SUU4S jjnU$ )Nc           
     :   > T" S0 [        [        TU 5      5      D6$ rr   rL   )rO   r~   rP   s    r#   kwargs_row__5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__   s    3$s5&1233r&   rv   rS   )rH   r   rP   r~   s     @r#   kwargs_row_kwargs_row.<locals>.kwargs_row_   s*    6"=	4 	4 r&   )rH   r   r(   ry   r    )r~   r   s   ` r#   
kwargs_rowr      s     r&   c                    U R                   nU(       d  [        $ [        U5      nUc  [        $ 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    rO   s    r#   scalar_row_scalar_row.<locals>.scalar_row_   s    ayr&   )rO   r'   r(   r   )r_   rU   r`   eProgrammingError)rH   r\   re   r   s       r#   
scalar_rowr      sQ    
 //C3G{  !?@@ r&   c                .    [         R                  " S5      e)zA `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#   rU   rU      s     

=
>>r&   c                    U R                   nU(       d  g [        U5      nUc  g U R                  n[        U5       Vs/ s H"  oAR	                  U5      R                  U5      PM$     sn$ s  snf r   )r_   r`   rb   rc   rY   rj   )rH   r\   re   rl   r[   s        r#   rT   rT      sd    
//C3G


C*/.*8Q		!C .  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)re   status	TUPLES_OKSINGLE_TUPLETUPLES_CHUNK
COMMAND_OK)r\   re   s     r#   r`   r`     sI     kkG 	

i::%::%JJ*$r&   )rH   rC   r(   zRowMaker[TupleRow])rH   rC   r(   zRowMaker[DictRow])rH   rC   r(   zRowMaker[NamedTuple])rl   strrP   bytesr(   ztype[NamedTuple])rs   ztype[T]r(   BaseRowFactory[T])r~   zCallable[..., T]r(   r   )rH   rC   r(   zRowMaker[Any])rO   r'   r(   r   )rH   rC   r(   zlist[str] | None)r\   r   r(   z
int | None)9r.   
__future__r   	functoolstypingr   r   r   r   r   r	   r
   collectionsr    r   r   r   _compatr   r   
_encodingsr   rH   r   _cursor_baser   cursor_asyncr   psycopg.pq.abcr   
ExecStatusr   r   r   r   r   r   r   r1   r8   r>   r   __annotations__rE   rI   rV   rg   	lru_cachera   rz   r   r   r   rU   rT   r`   r    r&   r#   <module>r      sM   #  6 6 4 4 "   ' -()']]%%
MM##	}}))}}))C4  etZ8<x} <D# D"Ihsm IMXc] M () '
 & %
$ S% %
. (,?r&   