a
    hd                     @   s  d dl mZmZ d dlmZ d dlmZ d dl	Z	d dl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z1m2Z2m3Z4m5Z6 d dl7m8Z8m9Z9m:Z:m;Z;m<Z< d dl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZK d dlLmMZMmNZNmOZO e<ZPd	ZQeZRe)ZSe ZTZUe ZVe!ZWeZXdddZYdZZdZ[dZ\G dd dZ]G dd de9Z^dd Z_G dd dZ`g dZadS )    )datetime)islice)warnN))BIGINTBOOLEANBOOLEAN_ARRAYBYTESCHAR
CHAR_ARRAYDATEFLOATFLOAT_ARRAYINET
INT2VECTORINTEGERINTEGER_ARRAYINTERVALJSONJSONBMACADDRNAME
NAME_ARRAYNULLTYPENUMERICNUMERIC_ARRAYOID
PGIntervalPY_PGRangeSTRINGTEXT
TEXT_ARRAYTIME	TIMESTAMPTIMESTAMPTZUNKNOWN	UUID_TYPEVARCHARVARCHAR_ARRAYXIDinterval_inmake_paramspg_interval_inpg_interval_out)ContextCoreConnectionIN_FAILED_TRANSACTIONIN_TRANSACTIONver)BINARYBinary	DataErrorDateFromTicksIntegrityErrorInternalErrorNotSupportedErrorOperationalErrorProgrammingErrorTimeFromTicks	TimestampTimestampFromTicksWarningconvert_paramstyle)DatabaseErrorErrorInterfaceErrorzMathieu Fenniak	localhost8  Tc                 C   s"   t | |||||||||	|
||dS )N)hostdatabaseportpasswordsource_address	unix_sockssl_contexttimeouttcp_keepaliveapplication_namereplicationstartup_params)
Connection)userrG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR    rU   H/var/www/html/efn/efnconsultor/selenium/selenium-4.34.2/pg8000/legacy.pyconnects   s    rW   z2.0   formatc                   @   s   e Zd Zd%ddZdd Zdd Zedd	 Zed
d Zedd Z	dd Z
d&ddZdd Zdd Zd'ddZdd Zdd Zdd Zdd  Zd(d!d"Zd#d$ ZdS ))CursorNc                 C   s:   || _ d| _|d u rtj| _n|| _d | _d | _d| _d S )NrX   rU   )_c	arraysizepg8000
paramstyle_context	_row_iter_input_oids)self
connectionr^   rU   rU   rV   __init__   s    
zCursor.__init__c                 C   s   | S NrU   rb   rU   rU   rV   	__enter__   s    zCursor.__enter__c                 C   s   |    d S re   )close)rb   exc_type	exc_value	tracebackrU   rU   rV   __exit__   s    zCursor.__exit__c                 C   s   t ddd | jS )Nz'DB-API extension cursor.connection used   
stacklevel)r   r[   rf   rU   rU   rV   rc      s    zCursor.connectionc                 C   s   | j }|d u rdS |jS )N)r_   	row_count)rb   contextrU   rU   rV   rowcount   s    zCursor.rowcountc                 C   s   |   S re   )_getDescriptionrf   rU   rU   rV   <lambda>       zCursor.<lambda>c              
   C   sf   | j }|d u rd S |j}|d u r$d S t|dkr4d S g }|D ]$}||d |d d d d d d f q<|S )Nr   nameZtype_oid)r_   columnslenappend)rb   rr   row_descrx   colrU   rU   rV   rt      s    "zCursor._getDescriptionrU   c              
   C   sl  z| j js| j js| j d t|dkrB|du rB| j || _n*t| j||\}}| j j||| j	|d| _| jj
du r|g n| jj
}t|| _d| _	W n ty } z:| j du rtdn| j jdu rtdn|W Y d}~nd}~0  ty` } z`|jd }t|trD|d }	|	d	kr&t}
n|	d
kr6t}
nt}
|
|nt|W Y d}~n
d}~0 0 g | _| S )ae  Executes a database operation.  Parameters may be provided as a
        sequence, or as a mapping, depending upon the value of
        :data:`pg8000.paramstyle`.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.

        :param operation:
            The SQL statement to execute.

        :param args:
            If :data:`paramstyle` is ``qmark``, ``numeric``, or ``format``,
            this argument should be an array of parameters to bind into the
            statement.  If :data:`paramstyle` is ``named``, the argument should
            be a dict mapping of parameters.  If the :data:`paramstyle` is
            ``pyformat``, the argument value may be either an array or a
            mapping.

        :param stream: This is a pg8000 extension for use with the PostgreSQL
            `COPY
            <http://www.postgresql.org/docs/current/static/sql-copy.html>`_
            command. For a COPY FROM the parameter must be a readable file-like
            object, and for COPY TO it must be writable.

            .. versionadded:: 1.9.11
        begin transactionr   N)valsoidsstreamrU   Cursor closedconnection is closedC2800023505)r[   _in_transaction
autocommitZexecute_simplery   r_   rA   r^   execute_unnamedra   rowsiterr`   AttributeErrorrD   _sockrB   args
isinstancedictr8   r<   Zinput_types)rb   	operationr   r   	statementr~   r   emsgresponse_codeclsrU   rU   rV   execute   s>    









zCursor.executec                 C   sn   g }| j }|D ]$}|| _ | || || jj qt|dkrLtd| _nd|v r^d| j_nt|| j_| S )a1  Prepare a database operation, and then execute it against all
        parameter sequences or mappings provided.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.

        :param operation:
            The SQL statement to execute
        :param parameter_sets:
            A sequence of parameters to execute the statement with. The values
            in the sequence should be sequences or mappings of parameters, the
            same as the args argument of the :meth:`execute` method.
        r   Nrp   )ra   r   rz   r_   rq   ry   r/   sum)rb   r   Z
param_setsZ	rowcountsZ
input_oids
parametersrU   rU   rV   executemany"  s    
zCursor.executemanyc                 C   sT   z
t | W S  ty   Y dS  ty6   tdY n tyN   tdY n0 dS )a   Fetch the next row of a query result set.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.

        :returns:
            A row as a sequence of field values, or ``None`` if no more rows
            are available.
        N#attempting to use unexecuted cursor)nextStopIteration	TypeErrorr<   r   rf   rU   rU   rV   fetchone@  s    

zCursor.fetchonec                 C   s>   zt t| |du r| jn|W S  ty8   tdY n0 dS )a  Fetches the next set of rows of a query result.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.

        :param size:

            The number of rows to fetch when called.  If not provided, the
            :attr:`arraysize` attribute value is used instead.

        :returns:

            A sequence, each entry of which is a sequence of field values
            making up a row.  If no more rows are available, an empty sequence
            will be returned.
        Nr   )tupler   r\   r   r<   )rb   ZnumrU   rU   rV   	fetchmanyS  s    zCursor.fetchmanyc                 C   s*   z
t | W S  ty$   tdY n0 dS )a$  Fetches all remaining rows of a query result.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.

        :returns:

            A sequence, each entry of which is a sequence of field values
            making up a row.
        r   N)r   r   r<   rf   rU   rU   rV   fetchalli  s    
zCursor.fetchallc                 C   s
   d| _ dS )zCloses the cursor.

        This method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        N)r[   rf   rU   rU   rV   rh   y  s    zCursor.closec                 C   s   | S )zoA cursor object is iterable to retrieve the rows from a query.

        This is a DBAPI 2.0 extension.
        rU   rf   rU   rU   rV   __iter__  s    zCursor.__iter__c              	   G   sV   g }|D ]B}t |tr|}n$zt| }W n ty>   t}Y n0 || q|| _dS )z3This method is part of the `DBAPI 2.0 specificationN)r   intr   KeyErrorr&   rz   ra   )rb   Zsizesr   sizeZoidrU   rU   rV   setinputsizes  s    

zCursor.setinputsizesc                 C   s   dS )zThis method is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_, however, it is not
        implemented by pg8000.
        NrU   )rb   r   ZcolumnrU   rU   rV   setoutputsize  s    zCursor.setoutputsizec              
   C   s   zt | jW S  ty4   | jd u r.tdn Y nV ty } z>| jd u rVtdnt| jjdkrptdn|W Y d }~n
d }~0 0 d S )NzA query hasn't been issued.r   zno result set)r   r`   r   r_   r<   r   ry   rx   )rb   r   rU   rU   rV   __next__  s    




zCursor.__next__)N)rU   N)N)N)__name__
__module____qualname__rd   rg   rl   propertyrc   rs   descriptionrt   r   r   r   r   r   rh   r   r   r   r   rU   rU   rU   rV   rZ      s&   



E

rZ   c                       s  e Zd Zedd Zedd Zedd Zedd Zedd Zedd Z	edd Z
ed	d Zed
d Z fddZdd Zdd Zedd Zedd Zdd Zdd Zd*ddZdd Zdd Zd d! Zd"d# Zd+d$d%Zd,d&d'Zd(d) Z  ZS )-rS   c                 C   s
   |  tS re   )	_getErrorr@   rf   rU   rU   rV   ru     rv   zConnection.<lambda>c                 C   s
   |  tS re   )r   rC   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   rD   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   rB   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   r;   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   r8   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   r9   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   r<   rf   rU   rU   rV   ru     rv   c                 C   s
   |  tS re   )r   r:   rf   rU   rU   rV   ru     rv   c              
      s   zt  j|i | W nr ty } zZ|jd }t|trl|d }|dkrPt}n|dkr^t}nt}||nt|W Y d }~n
d }~0 0 t	| dd| _
d| _d S )Nr   r   r   r   Znamed)r^   F)superrd   rB   r   r   r   rD   r8   r<   rZ   _run_cursorr   )rb   r   kwargsr   r   r   r   	__class__rU   rV   rd     s    


zConnection.__init__c                 C   s   t d|j dd |S )Nz#DB-API extension connection.%s usedrm   rn   )r   r   )rb   errorrU   rU   rV   r     s    zConnection._getErrorc                 C   s   t | S )zCreates a :class:`Cursor` object bound to this
        connection.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        )rZ   rf   rU   rU   rV   cursor  s    zConnection.cursorc                 C   s
   | j  S re   )r   rt   rf   rU   rU   rV   r     s    zConnection.descriptionc                 C   s   | j ttfv S re   )Z_transaction_statusr2   r1   rf   rU   rU   rV   r     s    zConnection._in_transactionc                 C   s   |  d dS )zCommits the current database transaction.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        commitN)r   rf   rU   rU   rV   r     s    zConnection.commitc                 C   s   | j s
dS | d dS )zRolls back the current database transaction.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        Nrollback)r   r   rf   rU   rU   rV   r     s    zConnection.rollbackNc                 K   s8   | j j|||d | j jjd u r&t S t| j jjS d S )N)r   )r   r   r_   r   r   )rb   Zsqlr   paramsrU   rU   rV   run  s    zConnection.runc                 C   s
   t | |S re   )PreparedStatement)rb   r   rU   rU   rV   prepare  s    zConnection.preparec                 C   s
   |||fS )a)  Create a Transaction IDs (only global_transaction_id is used in pg)
        format_id and branch_qualifier are not used in postgres
        global_transaction_id may be any string identifier supported by
        postgres returns a tuple
        (format_id, global_transaction_id, branch_qualifier)rU   )rb   Z	format_idZglobal_transaction_idZbranch_qualifierrU   rU   rV   xid  s    zConnection.xidc                 C   s   || _ | jr| d dS )a.  Begins a TPC transaction with the given transaction ID xid.

        This method should be called outside of a transaction (i.e. nothing may
        have executed since the last .commit() or .rollback()).

        Furthermore, it is an error to call .commit() or .rollback() within the
        TPC transaction. A ProgrammingError is raised, if the application calls
        .commit() or .rollback() during an active TPC transaction.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        r}   N)_xidr   r   )rb   r   rU   rU   rV   	tpc_begin
  s    zConnection.tpc_beginc                 C   s   d| j d f }| | dS )a  Performs the first phase of a transaction started with .tpc_begin().
        A ProgrammingError is be raised if this method is called outside of a
        TPC transaction.

        After calling .tpc_prepare(), no statements can be executed until
        .tpc_commit() or .tpc_rollback() have been called.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        zPREPARE TRANSACTION '%s';rX   N)r   r   )rb   qrU   rU   rV   tpc_prepare  s    zConnection.tpc_preparec                 C   sr   |du r| j }|du rtdz@| j}d| _||  v rN| d|d f  n|   W || _n|| _0 d| _ dS )a%  When called with no arguments, .tpc_commit() commits a TPC
        transaction previously prepared with .tpc_prepare().

        If .tpc_commit() is called prior to .tpc_prepare(), a single phase
        commit is performed. A transaction manager may choose to do this if
        only a single resource is participating in the global transaction.

        When called with a transaction ID xid, the database commits the given
        transaction. If an invalid transaction ID is provided, a
        ProgrammingError will be raised. This form should be called outside of
        a transaction, and is intended for use in recovery.

        On return, the TPC transaction is ended.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        Nz.Cannot tpc_commit() without a TPC transaction!TzCOMMIT PREPARED '%s';rX   )r   r<   r   tpc_recoverr   r   rb   r   previous_autocommit_moderU   rU   rV   
tpc_commit)  s    
zConnection.tpc_commitc                 C   sr   |du r| j }|du rtdz@| j}d| _||  v rN| d|d f  n|   W || _n|| _0 d| _ dS )aD  When called with no arguments, .tpc_rollback() rolls back a TPC
        transaction. It may be called before or after .tpc_prepare().

        When called with a transaction ID xid, it rolls back the given
        transaction. If an invalid transaction ID is provided, a
        ProgrammingError is raised. This form should be called outside of a
        transaction, and is intended for use in recovery.

        On return, the TPC transaction is ended.

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        Nz9Cannot tpc_rollback() without a TPC prepared transaction!TzROLLBACK PREPARED '%s';rX   )r   r<   r   r   r   r   r   rU   rU   rV   tpc_rollbackM  s    
zConnection.tpc_rollbackc                    sF   z8 j }d _   }|d  fdd|D W | _ S | _ 0 dS )zReturns a list of pending transaction IDs suitable for use with
        .tpc_commit(xid) or .tpc_rollback(xid).

        This function is part of the `DBAPI 2.0 specification
        <http://www.python.org/dev/peps/pep-0249/>`_.
        Tz!select gid FROM pg_prepared_xactsc                    s   g | ]}  d |d  dqS )r    )r   ).0rowrf   rU   rV   
<listcomp>|  rv   z*Connection.tpc_recover.<locals>.<listcomp>N)r   r   r   )rb   r   ZcursrU   rf   rV   r   p  s    
zConnection.tpc_recover)N)N)N)r   r   r   r   r@   rC   rD   rB   r;   r8   r9   r<   r:   rd   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__rU   rU   r   rV   rS     s4   	




$
#rS   c              
      sn  d}d}d}d}d}d}d}g  g }|}	d }
t | D ]\}}|d t| k r\| |d  }nd }|	|kr|dkr|| |
d	kr|}	q|}	nj|d
kr|| |}	nR|dkr|| |
dkr|}	n2|dkr|dvr|
dkr|}	 d n
|| nR|	|kr>|dkr0|rd}n|dkr,d}n|}	|| n|	|krb|d
krV|}	|| n|	|kr|dkr|
dkr|}	|| n|	|kr, d  |7  < |d u s| sN|dkrN|}	z2  d dd}|dt|d    d= W n* ty(   |dtt   Y n0 n"|	|krN|| |dkrN|}	|}
q4 fdd}d||fS )Nr   rX      rm         F'E"-:z:=r   T\rp   _$
c                    s   t  fddD S )Nc                 3   s   | ]} | V  qd S re   rU   )r   pr   rU   rV   	<genexpr>  rv   z2to_statement.<locals>.make_vals.<locals>.<genexpr>)r   r   Zplaceholdersr   rV   	make_vals  s    zto_statement.<locals>.make_vals)	enumeratery   rz   isalnumindexstr
ValueErrorjoin)ZqueryZOUTSIDEZ	INSIDE_SQZ	INSIDE_QIZ	INSIDE_ESZ	INSIDE_PNZ	INSIDE_COZin_quote_escapeZoutput_querystateZprev_cicZnext_cZpidxr   rU   r   rV   to_statement  s    













r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 C   s6   || _ || _t|\}| _||d\| _| _| _d S )NrU   )conr   r   	make_argsZprepare_statementname_binr{   input_funcs)rb   r   r   r   rU   rU   rV   rd     s    zPreparedStatement.__init__c              
   K   s   t | jj| |}z>| jjs2| jjs2| jd | j| j|| j	| j
| j| _W nR ty } z:| jd u rvtdn| jjd u rtdn|W Y d }~n
d }~0 0 | jjd u rt S t| jjS )Nr}   r   r   )r,   r   Zpy_typesr   r   r   r   Zexecute_namedr   r{   r   r   r_   r   rD   r   r   r   )rb   r~   r   r   rU   rU   rV   r     s    



zPreparedStatement.runc                 C   s   | j | j d | _ d S re   )r   Zclose_prepared_statementr   rf   rU   rU   rV   rh     s    zPreparedStatement.closeN)r   r   r   rd   r   rh   rU   rU   rU   rV   r     s   r   )@
BIGINTEGERr4   r   r   r	   r5   r
   r   rS   rZ   r   DATETIMEDECIMALDECIMAL_ARRAYr6   rB   Dater7   rC   r   r   r   r   r   r   r   r8   rD   r9   r   r   r   r   r   r   NUMBERr:   r   r;   r   r<   ROWIDr   r    r!   r"   r#   	TIMEDELTAr$   r%   Timer=   r>   r?   r&   r'   r(   r)   r@   r*   rW   pginterval_inpginterval_outtimedelta_in)rE   NrF   NNNNNTNNN)bdatetimer   r   r   r   	itertoolsr   warningsr   r]   Zpg8000.convertersr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r-   r   r.   r   Zpg8000.corer/   r0   r1   r2   r3   Zpg8000.dbapir4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   Zpg8000.exceptionsrB   rC   rD   __version__
__author__r   r   r   r   r   r   r   rW   apilevelthreadsafetyr^   rZ   rS   r   r   __all__rU   rU   rU   rV   <module>   sN   +@            
 
  
 SU!