a
    hx                     @   s,  d dl mZm ZmZ d dlmZmZ d dlm	Z	 d dl
m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/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5m6Z6 d dl7m8Z8m9Z9m:Z: d dl;m<Z< e6Z=d	Z>e#Z?d
Z@dZAdZBeCZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKd8dd ZLd
Z@dZAdZBd!d" ZMG d#d$ d$ZNG d%d& d&e3ZOG d'd( d(ePZQG d)d* d*e8ZRG d+d, d,e8ZSG d-d. d.e8ZTG d/d0 d0e8ZUG d1d2 d2e8ZVG d3d4 d4e8ZWG d5d6 d6eWZXg d7ZYdS )9    )datedatetimetime)countislice)	localtime)warn)$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STRINGTEXT
TEXT_ARRAYTIME	TIMESTAMPTIMESTAMPTZUNKNOWN	UUID_TYPEVARCHARVARCHAR_ARRAYXID)ContextCoreConnectionIN_FAILED_TRANSACTIONIN_TRANSACTIONver)DatabaseErrorErrorInterfaceError)RangezMathieu Fenniakz2.0   formatc                 C   s   t | ||S )zConstruct an object holding a date value.

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

    :rtype: :class:`datetime.date`
    )Date)yearmonthday r<   G/var/www/html/efn/efnconsultor/selenium/selenium-4.34.2/pg8000/dbapi.pyPgDateu   s    r>   c                 C   s   t | ||S )zConstruct an object holding a time value.

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

    :rtype: :class:`datetime.time`
    )Time)hourminutesecondr<   r<   r=   PgTime   s    rC   c                 C   s   t | |||||S )zConstruct an object holding a timestamp value.

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

    :rtype: :class:`datetime.datetime`
    )Datetime)r9   r:   r;   r@   rA   rB   r<   r<   r=   	Timestamp   s    rE   c                 C   s   t t| dd  S )a  Construct an object holding a date value from the given ticks value
    (number of seconds since the epoch).

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

    :rtype: :class:`datetime.date`
    N   )r8   r   Zticksr<   r<   r=   DateFromTicks   s    	rH   c                 C   s   t t| dd  S )a  Construct an object holding a time value from the given ticks value
    (number of seconds since the epoch).

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

    :rtype: :class:`datetime.time`
    rF      )r?   r   rG   r<   r<   r=   TimeFromTicks   s    	rJ   c                 C   s   t t| dd  S )a  Construct an object holding a timestamp value from the given ticks value
    (number of seconds since the epoch).

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

    :rtype: :class:`datetime.datetime`
    NrI   )rE   r   rG   r<   r<   r=   TimestampFromTicks   s    	rK   c                 C   s   | S )zConstruct an object holding binary data.

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

    r<   )valuer<   r<   r=   Binary   s    rM   	localhostN8  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sock)
Connection)userrP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r<   r<   r=   connect   s     r_   c              
      s  d}d}d}d}d}d}d}	d}
d}g }g }t d	d
 td}|}d }t|D ]4\}}|d t|k rt||d  nd }||kr@|dkr|| |dkr|}n|}q|dkr|| |}q|dkr|| |dkr|}q|dkr|| |dkr<|	}q| dkr2|dkr2|t| q| dkrf|dkrf|dvrf|dkrf|d n| dkr|dkr|dvr|dkr|}|d n| dkr|dkr|dkr|}|d np| dv r2|dkr2d} |rd}|| n6|dkr
d}n&|dkr(|}|t| ntdn
|| n@||kr|dkrt|
r`d}
n|dkrpd}
n|}|| n||kr|dkr|}|| n||kr|dkr|dkr|}|| n||	kr|dkr|dkr|}|| nx||kr^| dkr|d   |7  < |d u sJ| s\|d!kr\|}z2||d  dd }|dt	|d   |d = W n* t
y   |dt	t|  Y n0 n| dkrN|d"kr0|dkr0|}z2||d  dd }|dt	|d   |d = W n* t
y,   |dt	t|  Y n0 n|d#v r<n|d   |7  < n| dkr|}n"||kr|| |d$kr|}|}qN| d%v r }nt fd&d'|D }d||fS )(Nr   r6      rF         rI   Fc                 S   s   dt |  S )N$)str)xr<   r<   r=   <lambda>
      z$convert_paramstyle.<locals>.<lambda>'E"-rc   qmark?numeric:z:=named pyformat%()r7   rr   r7   Tsz*Only %s and %% are supported in the query.\_)z()
)rn   rl   r7   c                 3   s   | ]} | V  qd S Nr<   ).0pargsr<   r=   	<genexpr>  rg   z%convert_paramstyle.<locals>.<genexpr>)mapr   	enumeratelenappendnextr4   isalnumindexrd   
ValueErrortuplejoin)Zstylequeryr   OUTSIDE	INSIDE_SQ	INSIDE_QI	INSIDE_ES	INSIDE_PN	INSIDE_COZ	INSIDE_DQin_quote_escapeZin_param_escapeplaceholdersoutput_queryZ	param_idxstateprev_cicnext_cpidxvalsr<   r~   r=   convert_paramstyle   s     






(



















r   c                   @   s   e Zd Zdd Zedd Zedd Zedd Zd!ddZdd Z	d"ddZ
dd Zdd Zdd Zd#ddZdd Zdd Zdd Zd$dd Zd
S )%Cursorc                 C   s"   || _ d| _d | _d | _d| _d S )Nr6   r<   )_c	arraysize_context	_row_iter_input_oids)self
connectionr<   r<   r=   __init__  s
    zCursor.__init__c                 C   s   t ddd | jS )Nz'DB-API extension cursor.connection usedrF   
stacklevel)r   r   r   r<   r<   r=   r     s    zCursor.connectionc                 C   s   | j }|d u rdS |jS )Nrw   )r   	row_count)r   contextr<   r<   r=   rowcount  s    zCursor.rowcountc              
   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   nametype_oid)r   columnsr   r   )r   r   row_descr   colr<   r<   r=   description  s    "zCursor.descriptionr<   Nc              
   C   s   z| j js| j js| j d t|dkrB|du rB| j || _n(tt||\}}| j j||| j	|d| _| jj
du r~d| _nt| jj
| _d| _	W nR ty } z:| j du rtdn| j jdu rtdn|W Y d}~n
d}~0 0 g | _d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)r   oidsstreamr<   Cursor closedconnection is closed)r   _in_transaction
autocommitexecute_simpler   r   r   
paramstyleexecute_unnamedr   rowsr   iterAttributeErrorr4   _sockinput_types)r   	operationr   r   	statementr   er<   r<   r=   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_d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   Nrw   )r   r   r   r   r   r   r-   sum)r   r   
param_sets	rowcounts
input_oids
parametersr<   r<   r=   executemany  s    
zCursor.executemanyc              
   C   s   |d u rg n|}d| dd dd |D  d }zHtd||\}}| jj||d| _| jjd u rld | _nt| jj| _W nR ty } z:| jd u rt	d	n| jj
d u rt	d
n|W Y d }~n
d }~0 0 d S )NzCALL rt   z, c                 S   s   g | ]}d qS )z%sr<   )r|   rx   r<   r<   r=   
<listcomp>
  rg   z#Cursor.callproc.<locals>.<listcomp>ry   r7   )r   r   r   )r   r   r   r   r   r   r   r   r   r4   r   )r   Zprocnamer   r   r   r   r   r   r<   r<   r=   callproc  s    $


zCursor.callprocc                 C   s<   z
t | W S  ty   Y dS  ty6   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)r   StopIteration	TypeErrorProgrammingErrorr   r<   r<   r=   fetchone  s    

zCursor.fetchonec                 C   s   | S )zoA cursor object is iterable to retrieve the rows from a query.

        This is a DBAPI 2.0 extension.
        r<   r   r<   r<   r=   __iter__/  s    zCursor.__iter__c              
   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   r   r   )r   r   r<   r<   r=   __next__6  s    




zCursor.__next__c                 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   )r   r   r   r   r   )r   numr<   r<   r=   	fetchmanyF  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   r   r<   r<   r=   fetchall\  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   r   r<   r<   r=   closel  s    zCursor.closec              	   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)
isinstanceintr!   KeyErrorr(   r   r   )r   sizesr   sizeoidr<   r<   r=   setinputsizest  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.
        Nr<   )r   r   columnr<   r<   r=   setoutputsize  s    zCursor.setoutputsize)r<   N)N)N)N)__name__
__module____qualname__r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   r<   r<   r=   r     s$   	



6

r   c                       s   e Zd Z f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edd Zdd Zedd Zdd Z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 )&r]   c                    s   t  j|i | d| _d S )NF)superr   r   )r   r   kwargs	__class__r<   r=   r     s    zConnection.__init__c                 C   s
   |  tS r{   )	_getErrorWarningr   r<   r<   r=   rf     rg   zConnection.<lambda>c                 C   s
   |  tS r{   )r   r3   r   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   r4   r   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   r2   r   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   OperationalErrorr   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   IntegrityErrorr   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   InternalErrorr   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   r   r   r<   r<   r=   rf     rg   c                 C   s
   |  tS r{   )r   NotSupportedErrorr   r<   r<   r=   rf     rg   c                 C   s   t d|j ddd |S )NzDB-API extension connection.z usedrF   r   )r   r   )r   errorr<   r<   r=   r     s    zConnection._getErrorc                 C   s   | j ttfv S r{   )_transaction_statusr0   r/   r   r<   r<   r=   r     s    zConnection._in_transactionc                 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/>`_.
        )r   r   r<   r<   r=   cursor  s    zConnection.cursorc                 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   r   r<   r<   r=   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   r   r<   r<   r=   r     s    zConnection.rollbackc                 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)r<   )r   	format_idglobal_transaction_idbranch_qualifierr<   r<   r=   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   )r   r   r<   r<   r=   	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';r6   N)r   r   r   r<   r<   r=   tpc_prepare  s    zConnection.tpc_prepareNc                 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';r6   )r   r   r   tpc_recoverr   r   r   r   previous_autocommit_moder<   r<   r=   
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';r6   )r   r   r   r   r   r   r   r<   r<   r=   tpc_rollback  s    
zConnection.tpc_rollbackc                    sJ   z< 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   rq   )r   )r|   rowr   r<   r=   r   7  rg   z*Connection.tpc_recover.<locals>.<listcomp>N)r   r   r   r   )r   r   cursr<   r   r=   r   +  s    
zConnection.tpc_recover)N)N)r   r   r   r   r   r   r3   r4   r2   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r<   r<   r   r=   r]     s,   
	

$
#r]   c                   @   s   e Zd ZdZdS )r   zGeneric exception raised for important database warnings like data
    truncations.  This exception is not currently used by pg8000.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr   r   r   __doc__r<   r<   r<   r=   r   <  s   r   c                   @   s   e Zd ZdZdS )	DataErrorzGeneric exception raised for errors that are due to problems with the
    processed data.  This exception is not currently raised by pg8000.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r  G  s   r  c                   @   s   e Zd ZdZdS )r   a=  
    Generic exception raised for errors that are related to the database's
    operation and not necessarily under the control of the programmer. This
    exception is currently never raised by pg8000.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r   R  s   	r   c                   @   s   e Zd ZdZdS )r   a  
    Generic exception raised when the relational integrity of the database is
    affected.  This exception is not currently raised by pg8000.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r   _  s   r   c                   @   s   e Zd ZdZdS )r   aN  Generic exception raised when the database encounters an internal error.
    This is currently only raised when unexpected state occurs in the pg8000
    interface itself, and is typically the result of a interface bug.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r   k  s   r   c                   @   s   e Zd ZdZdS )r   a&  Generic exception raised for programming errors.  For example, this
    exception is raised if more parameter fields are in a query string than
    there are available parameters.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r   w  s   r   c                   @   s   e Zd ZdZdS )r   zGeneric exception raised in case a method or database API was used which
    is not supported by the database.

    This exception is part of the `DBAPI 2.0 specification
    <http://www.python.org/dev/peps/pep-0249/>`_.
    Nr  r<   r<   r<   r=   r     s   r   c                   @   s   e Zd ZdZdS )ArrayContentNotSupportedErrorz
    Raised when attempting to transmit an array where the base type is not
    supported for binary data transfer by the interface.
    Nr  r<   r<   r<   r=   r    s   r  ):r	   BINARYr
   r   r   rM   r   r   r]   r   r   r  r2   r8   rH   r3   r   r   r   r   r   r   r   r   r4   r   r   r   r   r   r   r   r   r   r   r   r   r    r   ROWIDr5   r"   r#   r$   r%   r&   r'   r?   rJ   rE   rK   r(   r)   r*   r+   r   r,   r_   )rN   NrO   NNNNNTNNNN)Zr   r   r8   rD   r   r?   	itertoolsr   r   r   warningsr   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,   pg8000.corer-   r.   r/   r0   r1   pg8000.exceptionsr2   r3   r4   pg8000.typesr5   __version__
__author__r  apilevelthreadsafetyr   bytesr  r>   rC   rE   rH   rJ   rK   rM   r_   r   r   r]   	Exceptionr   r  r   r   r   r   r   r  __all__r<   r<   r<   r=   <module>   sl   &
             
"
    2	