U Dx`6j<@slddlmZmZddlmZddlZddlmZmZm Z m Z m Z m Z m Z 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/m0Z0m1Z1m2Z2m3Z3m4Z4ddl5m6Z6ddl7m8Z8m9Z9m:Z:ddl;me#Z?d Z@dZAd ZBd(ddZCd Z@dZAd ZBddZDGdddZEGddde6ZFGdddeGZHGddde8ZIGddde8ZJGddde8ZKGd d!d!e8ZLGd"d#d#e8ZMGd$d%d%e8ZNGd&d'd'eNZOeHeIe8eCe:eMe9eJeKeLeNeFeEe eee,e-e.e/ee$e%e"ee(e eeeeee0e!e?e e e eeeeeeeeeeee e#e&e'e)e*e+e1e2e3e4gr?r@rArBrCrDrErFrGrJ3/tmp/pip-target-zr53vnty/lib/python/pg8000/dbapi.pyconnectJsrLc 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)'Nrr7FcSs dt|S)N$)str)xrJrJrKyz$convert_paramstyle..'E"-qmark?numeric:z:=rQnamedpyformat%()r:r`r:Tsz*Only %s and %% are supported in the query.\_)z() )r\rZr:c3s|]}|VqdSNrJ).0pargsrJrK sz%convert_paramstyle..) mapr enumeratelenappendnextr6isalnumindexrR ValueErrortuplejoin)stylequeryrmZOUTSIDEZ INSIDE_SQZ INSIDE_QIZ INSIDE_ESZ INSIDE_PNZ INSIDE_COZin_quote_escapeZin_param_escapeZ placeholdersZ output_queryZ param_idxstateZprev_cicZnext_cZpidxvalsrJrlrKconvert_paramstylejs                           rc@seZdZddZeddZeddZeddZd!d d Zd dZ d"ddZ ddZ ddZ ddZ d#ddZddZddZddZd$dd Zd S)%CursorcCs"||_d|_d|_d|_d|_dS)Nr7)_c arraysize_context _row_iter _input_oids)self connectionrJrJrK__init__s zCursor.__init__cCstddd|jS)Nz'DB-API extension cursor.connection usedrN stacklevel)rrrrJrJrKrs zCursor.connectioncCs|j}|dkrdS|jS)Nre)r row_count)rcontextrJrJrKrowcountszCursor.rowcountc Csf|j}|dkrdS|j}|dkr$dSt|dkr4dSg}|D]$}||d|ddddddfq<|S)NrnameZtype_oid)rcolumnsrqrr)rrZrow_descrcolrJrJrK description s zCursor.descriptionrJNc 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~Z input_oidsstreamN Cursor closedconnection is closed)rin_transaction autocommitexecute_unnamedr paramstylerriterrowsrAttributeErrorr6_sockZ input_types)r operationrmr statementr~erJrJrKexecutes&      zCursor.executecCsDg}|D]}|||||jjqd|kr4dnt||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. reN)rrrrrsum)rrZ param_setsZ rowcounts parametersrJrJrK executemanyPs  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 rbz, cSsg|]}dqS)z%srJ)rjrfrJrJrK hsz#Cursor.callproc..rgr:)r~rr) rxrrrrrrrrr6r)rZprocnamerrmrrr~rrJrJrKcallproces      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)rs StopIteration TypeErrorProgrammingErrorrrJrJrKfetchoneys  zCursor.fetchonecCs|S)zoA cursor object is iterable to retrieve the rows from a query. This is a DBAPI 2.0 extension. rJrrJrJrK__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)rsrrrrrrqr)rrrJrJrK__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)rwrrrr)rnumrJrJrK fetchmanys zCursor.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)rwrrrrJrJrKfetchalls  zCursor.fetchallcCs d|_dS)zCloses the cursor. This method is part of the `DBAPI 2.0 specification `_. N)rrrJrJrKclosesz Cursor.closec Gsdg}|D]P}t|tr|}n2z|jj|\}}Wntk rLtjj}YnX||q||_ dS)z`_, however, it is not implemented by pg8000. NrJ)rrcolumnrJrJrK setoutputsizeszCursor.setoutputsize)rJN)N)N)N)__name__ __module__ __qualname__rpropertyrrrrrrrrrrrrrrrJrJrJrKrs$     1  rc@seZdZeddZeddZeddZeddZeddZeddZ eddZ ed dZ ed dZ d d Z d dZddZddZddZddZddZd ddZd!ddZddZdS)"rHcCs |tSri) _getErrorWarningrrJrJrKrTrUzConnection.cCs |tSri)rr5rrJrJrKrTrUcCs |tSri)rr6rrJrJrKrTrUcCs |tSri)rr4rrJrJrKrTrUcCs |tSri)rOperationalErrorrrJrJrKrTrUcCs |tSri)rIntegrityErrorrrJrJrKrTrUcCs |tSri)r InternalErrorrrJrJrKrTrUcCs |tSri)rrrrJrJrKrTrUcCs |tSri)rNotSupportedErrorrrJrJrKrTrUcCstd|jdd|S)Nz#DB-API extension connection.%s usedrNr)rr)rerrorrJrJrKrszConnection._getErrorcCst|S)zCreates a :class:`Cursor` object bound to this connection. This function is part of the `DBAPI 2.0 specification `_. )rrrJrJrKcursorszConnection.cursorcCs|ddS)zCommits the current database transaction. This function is part of the `DBAPI 2.0 specification `_. commitN)rrrJrJrKrszConnection.commitcCs|js dS|ddS)zRolls back the current database transaction. This function is part of the `DBAPI 2.0 specification `_. Nrollback)rrrrJrJrKr szConnection.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)rJ)rZ format_idZglobal_transaction_idZbranch_qualifierrJrJrKxidszConnection.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)rrrJrJrK 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';r7N)rrrrJrJrK tpc_prepare0s 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';r7)rrr tpc_recoverrrrrprevious_autocommit_moderJrJrK tpc_commit=s  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';r7)rrrrrrrrJrJrK tpc_rollbackbs  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)rr_)r)rjrowrrJrKrsz*Connection.tpc_recover..N)rrrr)rrZcursrJrrKrs zConnection.tpc_recover)N)N)rrrrrr5r6r4rrrrrrrrrrrrrrrrJrJrJrKrHs*           % "rHc@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__rJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@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 `_. NrrJrJrJrKrsrc@seZdZdZdS)ArrayContentNotSupportedErrorz Raised when attempting to transmit an array where the base type is not supported for binary data transfer by the interface. NrrJrJrJrKrsr) r;Nr<NNNNNTNN)Q itertoolsrrwarningsrrZpg8000.convertersrrrrr r r r r rrrrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2Z pg8000.corer3Zpg8000.exceptionsr4r5r6_versionr8 __version__ __author__ZROWIDZapilevelZ threadsafetyrrLrrrH Exceptionrrrrrrrr__all__rJrJrJrKs        w.