
    i                       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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"Z1d/d#Z2 ejf                  d$      d0d%       Z4d1d&Z5d2d'Z6d2d(Z7d3d)Z8d4d*Z9d5d+Z:d6d,Z;y)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                      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     l/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/rows.py__call__zRowMaker.__call__2           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   r&   r'   N)r2   zCursor[Any]r)   RowMaker[Row]r*   r!   r'   r$   r0   r0   5   s     Dr'   r0   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   r&   r'   N)r7   zAsyncCursor[Any]r)   r3   r*   r!   r'   r$   r5   r5   F   s     Ir'   r5   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   r&   r'   N)r;   BaseCursor[Any, Any]r)   r3   r*   r!   r'   r$   r9   r9   N   s     Mr'   r9   .r   DictRowc                    t         S )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_rowrA   e   s	     Lr'   c                :    t        |       xdfd}|S t        S )zRow 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_y   s    E6*++r'   )rG   r(   r)   zdict[str, Any]
_get_names	no_result)r@   rI   rH   s     @r$   dict_rowrM   r   s*    
 F##0	,  r'   c                    | j                   xrAt              x}4t        | j                  gfdt	        |      D         }|j
                  S t        S )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  @   K   | ]  }j                  |        y wr    )fname).0iress     r$   	<genexpr>z!namedtuple_row.<locals>.<genexpr>   s     )O1#))A,)Os   )pgresult_get_nfields_make_nt	_encodingrange_makerL   )r@   nfieldsntrS   s      @r$   namedtuple_rowr]      sQ     S0A%AW$Nf&&P)Og)OPxxr'   i   c                D     t         fd|D              }t        d|      S )Nc              3  R   K   | ]  }t        |j                                 y wr    )r   decode)rQ   nencs     r$   rT   z_make_nt.<locals>.<genexpr>   s     GA(#7Gs   $'r   )r?   r   )rb   rH   snamess   `  r$   rW   rW      s     GGGFeV$$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        |       x	dfd}|S t        S )Nc           
     :     di t        t        |             S Nr!   rD   )rG   clsrH   s    r$   class_row__z2class_row.<locals>.class_row_.<locals>.class_row__   s    6T#eV"4566r'   rG   r(   r)   r   rJ   )r@   ri   rH   rh   s     @r$   
class_row_zclass_row.<locals>.class_row_   s(    ''E47  r'   )r@   r<   r)   RowMaker[T]r!   )rh   rk   s   ` r$   	class_rowrm      s    	 r'   c                     d fd}|S )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                    dfd}|S )Nc                     |  S r    r!   )rG   funcs    r$   
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__   s    = r'   rj   r!   )currr   rq   s     r$   	args_row_zargs_row.<locals>.args_row_   s    	! r'   )rs   BaseCursor[Any, T]r)   rl   r!   )rq   rt   s   ` r$   args_rowrv      s     r'   c                     d fd}|S )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                >    t        |       x	dfd}|S t        S )Nc           
     :     di t        t        |             S rg   rD   )rG   rq   rH   s    r$   kwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__   s    7d3uf#5677r'   rj   rJ   )r@   rz   rH   rq   s     @r$   kwargs_row_zkwargs_row.<locals>.kwargs_row_   s(    ''E48   r'   )r@   ru   r)   rl   r!   )rq   r{   s   ` r$   
kwargs_rowr|      s    	 r'   c                    | j                   x}r-t        |      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.
    r   zat least one column expectedc                    | d   S )Nr   r!   rG   s    r$   scalar_row_zscalar_row.<locals>.scalar_row_   s    !9r'   )rG   r(   r)   r   )rU   rV   eProgrammingErrorrL   )r@   rS   r[   r   s       r$   
scalar_rowr      sP    
 S0A%AW$NQ;$$%CDD	  r'   c                ,    t        j                  d      )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$   rL   rL      s     

=
>>r'   c                    | j                   x}rPt        |      x}C| j                  }t        |      D cg c]"  }|j	                  |      j                  |      $ c}S y c c}w r    )rU   rV   rX   rY   rP   r`   )r@   rS   r[   rb   rR   s        r$   rK   rK      sd    S0A%AW$N.3Gn
)*CIIaL$
 	
 	
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)r[   status	TUPLES_OKSINGLE_TUPLETUPLES_CHUNK
COMMAND_OK)rS   r[   s     r$   rV   rV      sI     kkG 	

i::%::%JJ*$r'   )r@   r<   r)   zRowMaker[TupleRow])r@   r<   r)   zRowMaker[DictRow])r@   r<   r)   zRowMaker[NamedTuple])rb   strrH   bytesr)   ztype[NamedTuple])rh   ztype[T]r)   BaseRowFactory[T])rq   zCallable[..., T]r)   r   )r@   r<   r)   zRowMaker[Any])rG   r(   r)   r	   )r@   r<   r)   zlist[str] | None)rS   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   psycopg.pq.abcr   r@   r   _cursor_baser   cursor_asyncr   
ExecStatusr   r   r   r   r   r   r   r0   r5   r9   r   __annotations__r   r=   rA   rM   r]   	lru_cacherW   rm   rv   r|   r   rL   rK   rV   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'   