
    R
h                       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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         Z/de-d <   	 dEd%Z0dFd'Z1dGd)Z2 ej3        d*          dHd0            Z4dId4Z5dJd7Z6dJd8Z7dKd:Z8dLd>Z9dMd@Z:dNdDZ;dS )Oz
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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     W/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/psycopg/rows.py__call__zRowMaker.__call__2             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%   r1   s     r&   r'   zRowFactory.__call__C   r(   r)   N)r1   r2   r!   r3   r*   r$   r)   r&   r0   r0   5   s)          DCCCCCr)   r0   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!   r3   c                    d S r#   r$   )r%   r7   s     r&   r'   zAsyncRowFactory.__call__K   r(   r)   N)r7   r8   r!   r3   r*   r$   r)   r&   r6   r6   F   s)          IHHHHHr)   r6   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!   r3   c                    d S r#   r$   )r%   r<   s     r&   r'   zBaseRowFactory.__call__S   r(   r)   N)r<   r=   r!   r3   r*   r$   r)   r&   r;   r;   N   s)          MLLLLLr)   r;   .r   DictRowcursorr=   r!   RowMaker[TupleRow]c                    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)r@   s    r&   	tuple_rowrD   e   s	     Lr)   RowMaker[DictRow]c                D    t          |           t          S dfd}|S )zRow 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)rG   namess    r&   	dict_row_zdict_row.<locals>.dict_row_{   s    Cv&&'''r)   )rG   r    r!   rH   
_get_names	no_result)r@   rN   rM   s     @r&   dict_rowrR   r   sC    
 vE}( ( ( ( ( ( r)   RowMaker[NamedTuple]c                    | j         st          S t                    }|t          S t          | j        gfdt          |          D             R  }|j        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.
    Nc              3  B   K   | ]}                     |          V  d S r#   )fname).0iress     r&   	<genexpr>z!namedtuple_row.<locals>.<genexpr>   s-      %K%Kqciill%K%K%K%K%K%Kr)   )pgresultrQ   _get_nfields_make_nt	_encodingrange_make)r@   nfieldsntrY   s      @r&   namedtuple_rowrc      sl     /C 3G	&"	L%K%K%K%KE'NN%K%K%K	L	L	LB8Or)   i   encstrrM   bytestype[NamedTuple]c                Z     t           fd|D                       }t          d|          S )Nc              3  \   K   | ]&}t          |                                        V  'd S r#   )r   decode)rW   nrd   s     r&   rZ   z_make_nt.<locals>.<genexpr>   s6      GGA(#77GGGGGGr)   r   )rC   r   )rd   rM   snamess   `  r&   r]   r]      s5    GGGGGGGGGFeV$$$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          |           t          S dfd}|S )NrG   r    r!   r   c           
     J     di t          t          |                     S Nr$   rJ   )rG   rm   rM   s    r&   class_row__z2class_row.<locals>.class_row_.<locals>.class_row__   s+    322c%0011222r)   rG   r    r!   r   rO   )r@   ru   rM   rm   s     @r&   
class_row_zclass_row.<locals>.class_row_   sG    6""=	3 	3 	3 	3 	3 	3 	3 r)   )r@   r=   r!   rq   r$   )rm   rw   s   ` r&   	class_rowrx      s)          r)   funcCallable[..., T]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.
    curBaseCursor[Any, T]r!   rq   c                    dfd}|S )NrG   r    r!   r   c                     |  S r#   r$   )rG   ry   s    r&   
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__   s    4= r)   rv   r$   )r|   r   ry   s     r&   	args_row_zargs_row.<locals>.args_row_   s)    	! 	! 	! 	! 	! 	! r)   )r|   r}   r!   rq   r$   )ry   r   s   ` r&   args_rowr      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.
    r@   r}   r!   rq   c                H    t          |           t          S dfd}|S )NrG   r    r!   r   c           
     J     di t          t          |                     S rt   rJ   )rG   ry   rM   s    r&   kwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__   s+    433$s5&1122333r)   rv   rO   )r@   r   rM   ry   s     @r&   kwargs_row_zkwargs_row.<locals>.kwargs_row_   sG    6""=	4 	4 	4 	4 	4 	4 	4 r)   )r@   r}   r!   rq   r$   )ry   r   s   ` r&   
kwargs_rowr      s)          r)   RowMaker[Any]c                    | j         }|st          S t          |          }|t          S |dk     rt          j        d          d	d}|S )
zR
    Generate a row factory returning the first column
    as a scalar value.
    Nr   zat least one column expectedrG   r    r!   r   c                    | d         S )Nr   r$   rG   s    r&   scalar_row_zscalar_row.<locals>.scalar_row_   s    ayr)   )rG   r    r!   r   )r[   rQ   r\   eProgrammingError)r@   rY   ra   r   s       r&   
scalar_rowr      sh    
 /C 3G{{ !?@@@    r)   rG   r    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&   rQ   rQ      s     
=
>
>>r)   list[str] | Nonec                    | j         sd S t                    }|d S | j        fdt          |          D             S )Nc                `    g | ]*}                     |                                        +S r$   )rV   rj   )rW   rX   rd   rY   s     r&   
<listcomp>z_get_names.<locals>.<listcomp>   s>       %&		!C    r)   )r[   r\   r^   r_   )r@   ra   rd   rY   s     @@r&   rP   rP      sm    
/C t3Gt

C    */..   r)   rY   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)ra   status	TUPLES_OKSINGLE_TUPLETUPLES_CHUNK
COMMAND_OK)rY   ra   s     r&   r\   r\     sP     kG 	
i:%%:%%J*$$$tr)   )r@   r=   r!   rA   )r@   r=   r!   rE   )r@   r=   r!   rS   )rd   re   rM   rf   r!   rg   )rm   rn   r!   ro   )ry   rz   r!   ro   )r@   r=   r!   r   )rG   r    r!   r	   )r@   r=   r!   r   )rY   r   r!   r   )<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   r6   r;   r   __annotations__re   r?   rD   rR   rc   	lru_cacher]   rx   r   r   r   rQ   rP   r\   r$   r)   r&   <module>r      s     # " " " " "     5 5 5 5 5 5 5 5 5 5 5 5 B B B B B B B B B B B B B B " " " " " "             ' ' ' ' ' ' ' ' - - - - - - *''''''(((((())))))]%
M#	})})GC4    getZ888< < < < <x} < < <D D D D D# D D D"I I I I Ihsm I I IM M M M MXc] M M M CHo % % % %
 #s(^ # # # #
 
 
 
      $ S% % % %
   .       (   ,? ? ? ?        r)   