
    ,h                       % 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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   \RB                  RD                  r"\RB                  RF                  r#\RB                  RH                  r$\RB                  RJ                  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   r/S\-S '    S-S! jr0S.S" jr1S/S# jr2\Rf                  " S$5      S0S% j5       r4S1S& jr5S2S' jr6S2S( jr7S3S) jr8S4S* jr9S5S+ jr:S6S, jr;g)7z
psycopg row factories
    )annotationsN)TYPE_CHECKINGAnyCallableDict)
NamedTupleNoReturnProtocolSequenceTuple)
namedtuple   )errors)pq)	TypeAliasTypeVar)_as_python_identifier)PGresult)Cursor)
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     G/var/www/html/Ai_home/venv/lib/python3.13/site-packages/psycopg/rows.py__call__RowMaker.__call__2   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)
RowFactory5   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__C   s    r(   r"   N)r6   zCursor[Any]r*   RowMaker[Row]r+   r"   r(   r%   r3   r3   5   s     Dr(   r3   c                  "    \ rS rSrSrSS jrSrg)AsyncRowFactoryF   z8
Like `RowFactory`, taking an async cursor as argument.
c                    g r!   r"   )r#   _AsyncRowFactory__cursors     r%   r&   AsyncRowFactory.__call__K   s    Sr(   r"   N)r=   zAsyncCursor[Any]r*   r8   r+   r"   r(   r%   r:   r:   F   s     Ir(   r:   c                  "    \ rS rSrSrSS jrSrg)BaseRowFactoryN   z>
Like `RowFactory`, taking either type of cursor as argument.
c                    g r!   r"   )r#   _BaseRowFactory__cursors     r%   r&   BaseRowFactory.__call__S   s    r(   r"   N)rC   BaseCursor[Any, Any]r*   r8   r+   r"   r(   r%   r@   r@   N   s     Mr(   r@   .r   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_rowrJ   e   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_y   s    E6*++r(   )rP   r)   r*   zdict[str, Any]
_get_names	no_result)rI   rR   rQ   s     @r%   dict_rowrW   r   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
                  $ [        $ )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  D   >#    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_makerV   )rI   nfieldsntr]   s      @r%   namedtuple_rowrh      sQ     S0A%AW$Nf&&P)Og)OPxxr(   i   c                F   ^  [        U 4S jU 5       5      n[        SU5      $ )Nc              3  V   >#    U H  n[        UR                  T5      5      v   M!     g 7fr!   )r   decode)r[   nencs     r%   r^   _make_nt.<locals>.<genexpr>   s"     GA(#77s   &)r   )rH   r   )rm   rQ   snamess   `  r%   rb   rb      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b  SUU4S jjnU$ [        $ )Nc           
     :   > T" S0 [        [        TU 5      5      D6$ Nr"   rM   )rP   clsrQ   s    r%   class_row__2class_row.<locals>.class_row_.<locals>.class_row__   s    6T#eV"4566r(   rP   r)   r*   r   rT   )rI   ru   rQ   rt   s     @r%   
class_row_class_row.<locals>.class_row_   s-    ''E47 7  r(   )rI   rE   r*   RowMaker[T]r"   )rt   rx   s   ` r%   	class_rowr{      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"   )rP   funcs    r%   
args_row__/args_row.<locals>.args_row_.<locals>.args_row__   s    = r(   rw   r"   )curr   r   s     r%   	args_row_args_row.<locals>.args_row_   s    	! r(   )r   BaseCursor[Any, T]r*   rz   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b  SUU4S jjnU$ [        $ )Nc           
     :   > T" S0 [        [        TU 5      5      D6$ rs   rM   )rP   r   rQ   s    r%   kwargs_row__5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__   s    7d3uf#5677r(   rw   rT   )rI   r   rQ   r   s     @r%   kwargs_row_kwargs_row.<locals>.kwargs_row_   s-    ''E48 8   r(   )rI   r   r*   rz   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"   rP   s    r%   scalar_row_scalar_row.<locals>.scalar_row_   s    !9r(   )rP   r)   r*   r   )r`   ra   eProgrammingErrorrV   )rI   r]   rf   r   s       r%   
scalar_rowr      sP    
 S0A%AW$NQ;$$%CDD	  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%   rV   rV      s     

=
>>r(   c                    U R                   =n(       aR  [        U5      =nbD  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`   ra   rc   rd   rZ   rk   )rI   r]   rf   rm   r\   s        r%   rU   rU      sf    S0A%AW$N.3Gn
.<IIaL$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)rf   status	TUPLES_OKSINGLE_TUPLETUPLES_CHUNK
COMMAND_OK)r]   rf   s     r%   ra   ra      sI     kkG 	

i::%::%JJ*$r(   )rI   rE   r*   zRowMaker[TupleRow])rI   rE   r*   zRowMaker[DictRow])rI   rE   r*   zRowMaker[NamedTuple])rm   strrQ   bytesr*   ztype[NamedTuple])rt   ztype[T]r*   BaseRowFactory[T])r   zCallable[..., T]r*   r   )rI   rE   r*   zRowMaker[Any])rP   r)   r*   r	   )rI   rE   r*   zlist[str] | None)r]   r   r*   z
int | None)<r0   
__future__r   	functoolstypingr   r   r   r   r   r	   r
   r   r   collectionsr    r   r   r   _compatr   r   
_encodingsr   psycopg.pq.abcr   rI   r   _cursor_baser   cursor_asyncr   
ExecStatusr   r   r   r   r   r   r   r3   r:   r@   r   __annotations__r   rF   rJ   rW   rh   	lru_cacherb   r{   r   r   r   rV   rU   ra   r"   r(   r%   <module>r      s]   #  5 5 B B "   ' -'()]]%%
MM##	}}))}}))C4  etZ8<x} <D# D"Ihsm IMXc] M CHo) %
 #s(^ #
 
 S% %
0 *$?r(   