
    *Jfv                     p   U d Z ddlZddlmZmZmZ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 dd
lmZ ddlmZ e
rddlmZ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dd          Z& e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,ee-d<   	 ee.ef         Z/ee-d<   	 d6d"Z0d7d$Z1	 	 	 	 d8d&Z2 ej3        d'          d(e.d)e4d ee         fd*            Z5d+ee&         d e+e&         fd,Z6d-ede&f         d e+e&         fd.Z7d-ede&f         d e+e&         fd/Z8d0ee         d e	fd1Z9ddd eee.                  fd2Z:d3d4d ee;         fd5Z<dS )9z
psycopg row factories
    N)AnyCallableDictListOptional
NamedTupleNoReturn)TYPE_CHECKINGSequenceTupleTypeTypeVar)
namedtuple)	TypeAlias   )pq)errors)Protocol)_as_python_identifier)
BaseCursorCursor)AsyncCursor)PGresultTT)	covariantRowc                   .    e Zd ZdZdee         def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returnc                     d S N )selfr   s     O/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/psycopg/rows.py__call__zRowMaker.__call__.             N)__name__
__module____qualname____doc__r   r   r   r&   r#   r(   r%   r   r   "   s6        	 	 <#;3;;;;;;r(   r   c                   .    e Zd ZdZdddee         f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__cursorzCursor[Any]r    c                     d S r"   r#   )r$   r/   s     r%   r&   zRowFactory.__call__?   r'   r(   Nr)   r*   r+   r,   r   r   r&   r#   r(   r%   r.   r.   1   s7          FE8C=EEEEEEr(   r.   c                   .    e Zd ZdZdddee         fdZdS )AsyncRowFactoryz@
    Like `RowFactory`, taking an async cursor as argument.
    _AsyncRowFactory__cursorzAsyncCursor[Any]r    c                     d S r"   r#   )r$   r4   s     r%   r&   zAsyncRowFactory.__call__G   r'   r(   Nr1   r#   r(   r%   r3   r3   B   s8          K!3JJJJJJJr(   r3   c                   .    e Zd ZdZdddee         fdZdS )BaseRowFactoryzF
    Like `RowFactory`, taking either type of cursor as argument.
    _BaseRowFactory__cursorBaseCursor[Any, Any]r    c                     d S r"   r#   )r$   r8   s     r%   r&   zBaseRowFactory.__call__O   r'   r(   Nr1   r#   r(   r%   r7   r7   J   s8          O!7NHSMNNNNNNr(   r7   .TupleRowDictRowcursorr9   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_rowrA   a   s	     Lr(   RowMaker[DictRow]c                     t          |           t          S dt          t                   dt          t
          t          f         f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    c                 >    t          t          |                     S r"   dictzip)rD   namess    r%   	dict_row_zdict_row.<locals>.dict_row_w   s    Cv&&'''r(   )
_get_names	no_resultr   r   r   str)r=   rJ   rI   s     @r%   dict_rowrN   n   s]    
 vE}((3- (DcN ( ( ( ( ( ( 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(   )pgresultrL   _get_nfields_make_nt	_encodingrange_make)r=   nfieldsntrU   s      @r%   namedtuple_rowr_   }   sl     /C 3G	&"	L%K%K%K%KE'NN%K%K%K	L	L	LB8Or(   i   encrI   c                 Z     t           fd|D                       }t          d|          S )Nc              3   \   K   | ]&}t          |                                        V  'd S r"   )r   decode)rS   nr`   s     r%   rV   z_make_nt.<locals>.<genexpr>   s6      GGA(#77GGGGGGr(   r   )r@   r   )r`   rI   snamess   `  r%   rY   rY      s5    GGGGGGGGGFeV$$$r(   clsc                      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=   r9   r    RowMaker[T]c                 z    t          |           t          S dt          t                   dt          ffd}|S )NrD   r    c           
      J     di t          t          |                     S Nr#   rF   )rD   rf   rI   s    r%   class_row__z2class_row.<locals>.class_row_.<locals>.class_row__   s+    322c%0011222r(   rK   rL   r   r   r   )r=   rl   rI   rf   s     @r%   
class_row_zclass_row.<locals>.class_row_   sY    6""=	3 	3! 	3 	3 	3 	3 	3 	3 	3 r(   )r=   r9   r    rh   r#   )rf   rn   s   ` r%   	class_rowro      s)          r(   funcc                      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    rh   c                 F    dt           t                   dt          ffd}|S )NrD   r    c                      |  S r"   r#   )rD   rp   s    r%   
args_row__z/args_row.<locals>.args_row_.<locals>.args_row__   s    4= r(   )r   r   r   )rr   rv   rp   s     r%   	args_row_zargs_row.<locals>.args_row_   s;    	!x} 	! 	! 	! 	! 	! 	! 	! r(   )rr   rs   r    rh   r#   )rp   rw   s   ` r%   args_rowrx      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=   rs   r    rh   c                 z    t          |           t          S dt          t                   dt          ffd}|S )NrD   r    c           
      J     di t          t          |                     S rk   rF   )rD   rp   rI   s    r%   kwargs_row__z5kwargs_row.<locals>.kwargs_row_.<locals>.kwargs_row__   s+    433$s5&1122333r(   rm   )r=   r|   rI   rp   s     @r%   kwargs_row_zkwargs_row.<locals>.kwargs_row_   sY    6""=	4# 	41 	4 	4 	4 	4 	4 	4 	4 r(   )r=   rs   r    rh   r#   )rp   r}   s   ` r%   
kwargs_rowr~      s)          r(   rD   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)eInterfaceError)rD   s    r%   rL   rL      s     
=
>
>>r(   c                     | j         sd S t                    }|d S | j        fdt          |          D             S )Nc                 `    g | ]*}                     |                                        +S r#   )rR   rc   )rS   rT   r`   rU   s     r%   
<listcomp>z_get_names.<locals>.<listcomp>   s>       %&		!C    r(   )rW   rX   rZ   r[   )r=   r]   r`   rU   s     @@r%   rK   rK      sm    
/C t3Gt

C    */..   r(   rU   r   c                 |    | j         }| 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
COMMAND_OK)rU   r]   s     r%   rX   rX      sC     kG 	
i:%%J*$$$tr(   )r=   r9   r    r>   )r=   r9   r    rB   )r=   r9   r    rO   )=r,   	functoolstypingr   r   r   r   r   r   r	   r
   r   r   r   r   collectionsr   typing_extensionsr    r   r   r   _compatr   
_encodingsr   r=   r   r   cursor_asyncr   psycopg.pq.abcr   
ExecStatusr   r   r   r   r   r   r.   r3   r7   r;   __annotations__rM   r<   rA   rN   r_   	lru_cachebytesrY   ro   rx   r~   rL   rK   intrX   r#   r(   r%   <module>r      s)         L L L L L L L L L L L L L L L L L L @ @ @ @ @ @ @ @ @ @ @ @ @ @ " " " " " " ' ' ' ' ' '                   - - - - - - (********))))))'''''']%
M#	})GC4    get$$$< < < < <x} < < <F F F F F# F F F"K K K K Khsm K K KO O O O OXc] O O O CHo) % % %
 #s(^ # # #
 
 
 
   "   ( S%# %u %j)9 % % % %
47 ~a0    .8CF# q(9     Xc1f% .*;    (?hsm ? ? ? ? ?- (492E    j Xc]      r(   