U CB`Gt9@sddlmZmZmZddlmZmZddlm Z ddl m Z ddl Z ddl mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm 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/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6d d l7m8Z8e8d Z9[8d Z:e$Z;d Ze?Z@ddZAddZBddZCddZDddZEddZFddZGdbd d!ZHd Zd"d#ZIGd$d%d%ZJGd&d'd'e2ZKGd(d)d)eLZMGd*d+d+e4ZNGd,d-d-e4ZOGd.d/d/e4ZPGd0d1d1e4ZQGd2d3d3e4ZRGd4d5d5e4ZSGd6d7d7eSZTd8d9d:d;dd'd%d?d+d@dAddBdCdDdEdFdGdHdId/dJd1dKdLdMdNdOdPdQdRd5dSd-dTd3dUdVdWdXdYdZd[d\dddd]d^d_d`d)dad!g9ZUdS)c)datedatetimetime)countislice) localtime)warnN)#BIGINTBOOLEAN BOOLEAN_ARRAYBYTESCHAR CHAR_ARRAYDATEFLOAT FLOAT_ARRAYINET INT2VECTORINTEGER INTEGER_ARRAYINTERVALJSONJSONBMACADDRNAME NAME_ARRAYNULLTYPENUMERIC NUMERIC_ARRAYOID PGIntervalSTRINGTEXT TEXT_ARRAYTIME TIMESTAMP TIMESTAMPTZUNKNOWN UUID_TYPEVARCHAR VARCHAR_ARRAYXID)CoreConnection) DatabaseErrorErrorInterfaceError) get_versionsversionzMathieu Fenniakz2.0formatcCs t|||S)zConstuct an object holding a date value. This function is part of the `DBAPI 2.0 specification `_. :rtype: :class:`datetime.date` )Date)yearmonthdayr8[C:\Users\shjeevan\PycharmProjects\Verisk-XactWare\venv3.8\Lib\site-packages\pg8000/dbapi.pyPgDatemsr:cCs t|||S)zConstruct an object holding a time value. This function is part of the `DBAPI 2.0 specification `_. :rtype: :class:`datetime.time` )Time)hourminutesecondr8r8r9PgTimexsr?cCst||||||S)zConstruct an object holding a timestamp value. This function is part of the `DBAPI 2.0 specification `_. :rtype: :class:`datetime.datetime` )Datetime)r5r6r7r<r=r>r8r8r9 TimestampsrAcCstt|ddS)aConstruct 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 `_. :rtype: :class:`datetime.date` N)r4rZticksr8r8r9 DateFromTickss rDcCstt|ddS)aConstruct an objet 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 `_. :rtype: :class:`datetime.time` rB)r;rrCr8r8r9 TimeFromTickss rFcCstt|ddS)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 `_. :rtype: :class:`datetime.datetime` NrE)rArrCr8r8r9TimestampFromTickss rGcCs|S)zConstruct an object holding binary data. This function is part of the `DBAPI 2.0 specification `_. r8)valuer8r8r9BinarysrI localhost8Tc Cs t|||||||||| | | d S)N) hostdatabaseportpasswordsource_address unix_sock ssl_contexttimeout tcp_keepaliveapplication_name replication) Connection) userrLrMrNrOrPrQrRrSrTrUrVr8r8r9connectsrYc sfd}d}d}d}d}d}d} d} g} g} tdd td} |}d}t|D]\}}|dt|krr||d}nd}||kr|d kr| ||d kr|}n|}q,|d kr| ||}q,|d kr| ||d kr|}q,|dkr |dkr | t| q,|dkr>|dkr>|dkr>|dkr>| dn|dkrv|dkrv|dkrv|dkrv|}| dn|dkr|dkr|dkr|}| dnp|dkr |dkr d}| rd} | |n6|dkrd} n&|dkr|}| t| ntdn | |n||krZ|d krL| r8d} n|d krHd} n|}| |n||kr|d krr|}| |n||kr|d kr|dkr|}| |n|||kr |dkrX| d|7<|dks|s|d kr|}z2| | ddd}| dt |d| d=Wn,t k rT| dt t| YnXn|dkr|d!kr|dkr|}z2| | ddd}| dt |d| d=Wn,t k r| dt t| YnXn|d"krn| d|7<n|dkr,|}n"||kr,| ||d#kr,|}|}qJ|d$krB}nt fd%d&| D}d | |fS)'Nrr0rBFcSs dt|S)N$)str)xr8r8r9z$convert_paramstyle..'E"-qmark?numeric:z:=r]namedpyformat%()r3rlr3Tsz*Only %s and %% are supported in the query.\_)z() )rhrfr3c3s|]}|VqdSNr8).0pargsr8r9 ssz%convert_paramstyle..) mapr enumeratelenappendnextr/isalnumindexr^ ValueErrortuplejoin)stylequeryryZOUTSIDEZ INSIDE_SQZ INSIDE_QIZ INSIDE_ESZ INSIDE_PNZ INSIDE_COZin_quote_escapeZin_param_escapeZ placeholdersZ output_queryZ param_idxstateZprev_cicZnext_cZpidxvalsr8rxr9convert_paramstyles     (                      rc@seZdZddZeddZeddZeddZd!d d Zd dZ d"ddZ ddZ ddZ ddZ d#ddZddZddZddZd$dd Zd S)%CursorcCs"||_d|_d|_d|_d|_dS)Nr0)_c arraysize_context _row_iter _input_oids)self connectionr8r8r9__init__ys zCursor.__init__cCstddd|jS)Nz'DB-API extension cursor.connection usedrB stacklevel)rrrr8r8r9rs zCursor.connectioncCs|j}|dkrdS|jS)Nrq)r row_count)rcontextr8r8r9rowcountszCursor.rowcountc Csf|j}|dkrdS|j}|dkr$dSt|dkr4dSg}|D]$}||d|ddddddfq<|S)NrnameZtype_oid)rcolumnsr}r~)rrZrow_descrcolr8r8r9 descriptions "zCursor.descriptionr8Nc Csz\|jjs|jjs|jdtt||\}}|jj|||j|d|_t|jj |_ d|_WnPt k r}z2|jdkrt dn|jj dkrt dn|W5d}~XYnXg|_dS)aeExecutes 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 `_. :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 `_ 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 transaction)r input_oidsstreamN Cursor closedconnection is closed)rin_transaction autocommitexecute_unnamedr paramstylerriterrowsrAttributeErrorr/_sockZ input_types)r operationryr statementrer8r8r9executes&      zCursor.executecCsPg}|j}|D]$}||_|||||jjqd|kr@dnt||j_dS)a1Prepare a database operation, and then execute it against all parameter sequences or mappings provided. This method is part of the `DBAPI 2.0 specification `_. :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. rqN)rrr~rrsum)rrZ param_setsZ rowcountsr parametersr8r8r9 executemanys zCursor.executemanyc Cs|dkr gn|}d|dddd|Dd}z4td||\}}|jj||d|_t|jj|_WnPtk r}z2|jdkrt d n|jj dkrt d n|W5d}~XYnXdS) NzCALL rnz, cSsg|]}dqS)z%sr8)rvrrr8r8r9 sz#Cursor.callproc..rsr3)rrr) rrrrrrrrrr/r)rZprocnamerryrrrrr8r8r9callprocs$    zCursor.callproccCs@z t|WStk r YdStk r:tdYnXdS)a Fetch the next row of a query result set. This method is part of the `DBAPI 2.0 specification `_. :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 TypeErrorProgrammingErrorrr8r8r9fetchones  zCursor.fetchonecCs|S)zoA cursor object is iterable to retrieve the rows from a query. This is a DBAPI 2.0 extension. r8rr8r8r9__iter__szCursor.__iter__c Csz t|jWStk r6|jdkr0tdnYnTtk r}z6|jdkrZtdnt|jjdkrttdn|W5d}~XYnXdS)NzA query hasn't been issued.rz no result set)rrrrrrr}r)rrr8r8r9__next__s      zCursor.__next__cCs@ztt||dkr|jn|WStk r:tdYnXdS)aFetches the next set of rows of a query result. This method is part of the `DBAPI 2.0 specification `_. :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)rrrrr)rnumr8r8r9 fetchmany'szCursor.fetchmanycCs,z t|WStk r&tdYnXdS)a$Fetches all remaining rows of a query result. This method is part of the `DBAPI 2.0 specification `_. :returns: A sequence, each entry of which is a sequence of field values making up a row. rN)rrrrr8r8r9fetchall=s  zCursor.fetchallcCs d|_dS)zCloses the cursor. This method is part of the `DBAPI 2.0 specification `_. N)rrr8r8r9closeMsz Cursor.closec Gsdg}|D]P}t|tr|}n2z|jj|\}}Wntk rLtjj}YnX||q||_ dS)z3This method is part of the `DBAPI 2.0 specificationN) isinstanceintrZpy_typesKeyErrorpg8000 convertersr'r~r)rsizesZoidssizeoidrrr8r8r9 setinputsizesUs  zCursor.setinputsizescCsdS)zThis method is part of the `DBAPI 2.0 specification `_, however, it is not implemented by pg8000. Nr8)rrcolumnr8r8r9 setoutputsizedszCursor.setoutputsize)r8N)N)N)N)__name__ __module__ __qualname__rpropertyrrrrrrrrrrrrrrr8r8r8r9rxs$     1  rc@seZdZeddZeddZeddZeddZeddZeddZ eddZ ed dZ ed dZ d d Z d dZddZddZddZddZddZd ddZd!ddZddZdS)"rWcCs |tSru) _getErrorWarningrr8r8r9r`orazConnection.cCs |tSru)rr.rr8r8r9r`pracCs |tSru)rr/rr8r8r9r`qracCs |tSru)rr-rr8r8r9r`rracCs |tSru)rOperationalErrorrr8r8r9r`sracCs |tSru)rIntegrityErrorrr8r8r9r`tracCs |tSru)r InternalErrorrr8r8r9r`uracCs |tSru)rrrr8r8r9r`vracCs |tSru)rNotSupportedErrorrr8r8r9r`wracCstd|jdd|S)Nz#DB-API extension connection.%s usedrBr)rr)rerrorr8r8r9ryszConnection._getErrorcCst|S)zCreates a :class:`Cursor` object bound to this connection. This function is part of the `DBAPI 2.0 specification `_. )rrr8r8r9cursor}szConnection.cursorcCs|ddS)zCommits the current database transaction. This function is part of the `DBAPI 2.0 specification `_. commitN)rrr8r8r9rszConnection.commitcCs|js dS|ddS)zRolls back the current database transaction. This function is part of the `DBAPI 2.0 specification `_. Nrollback)rrrr8r8r9rszConnection.rollbackcCs |||fS)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)r8)rZ format_idZglobal_transaction_idZbranch_qualifierr8r8r9xidszConnection.xidcCs||_|jr|ddS)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 `_. rN)_xidrr)rrr8r8r9 tpc_begins zConnection.tpc_begincCs|d|jdfdS)aPerforms 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 `_. zPREPARE TRANSACTION '%s';r0N)rrrr8r8r9 tpc_prepares zConnection.tpc_prepareNcCsl|dkr|j}|dkrtdz:|j}d|_||krN|d|dfn|W5||_Xd|_dS)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 `_. Nz.Cannot tpc_commit() without a TPC transaction!TzCOMMIT PREPARED '%s';r0)rrr tpc_recoverrrrrprevious_autocommit_moder8r8r9 tpc_commits  zConnection.tpc_commitcCsl|dkr|j}|dkrtdz:|j}d|_||krN|d|dfn|W5||_Xd|_dS)aDWhen 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 `_. Nz9Cannot tpc_rollback() without a TPC prepared transaction!TzROLLBACK PREPARED '%s';r0)rrrrrrrr8r8r9 tpc_rollbacks  zConnection.tpc_rollbackcsFz8j}d_}|dfdd|DWS|_XdS)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 `_. Tz!select gid FROM pg_prepared_xactscsg|]}d|ddqS)rrk)r)rvrowrr8r9rsz*Connection.tpc_recover..N)rrrr)rrZcursr8rr9rs zConnection.tpc_recover)N)N)rrrrrr.r/r-rrrrrrrrrrrrrrrr8r8r8r9rWls&            $ #rWc@seZdZdZdS)rzGeneric 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 `_. Nrrr__doc__r8r8r8r9rsrc@seZdZdZdS) 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 `_. Nrr8r8r8r9r!src@seZdZdZdS)ra= 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 `_. Nrr8r8r8r9r,s rc@seZdZdZdS)ra 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 `_. Nrr8r8r8r9r9src@seZdZdZdS)raNGeneric 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 `_. Nrr8r8r8r9rEsrc@seZdZdZdS)ra&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 `_. Nrr8r8r8r9rQsrc@seZdZdZdS)rzGeneric 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 `_. Nrr8r8r8r9r]src@seZdZdZdS)ArrayContentNotSupportedErrorz Raised when attempting to transmit an array where the base type is not supported for binary data transfer by the interface. Nrr8r8r8r9rhsrr BINARYr r r r rrr-r4r.rrrrrrrr/rrrrrrrrrr ROWIDr!r"r#r$r%r&r;r'r(r)r*r+) rJNrKNNNNNTNN)Vrrr4r@rr; itertoolsrrrwarningsrrZpg8000.convertersr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+Z pg8000.corer,Zpg8000.exceptionsr-r.r/_versionr1 __version__ __author__rZapilevelZ threadsafetyrbytesrr:r?rArDrFrGrIrYrrrW Exceptionrrrrrrrr__all__r8r8r8r9s  %              u+