ó
( È\c           @   sŒ   d  Z  d d l m Z m Z m Z d d l Z d d l m Z e j e ƒ d e	 f d „  ƒ  Yƒ Z
 e j e ƒ d e	 f d	 „  ƒ  Yƒ Z d S(
   s2   Implement the Base class for Driver and Connectioniÿÿÿÿ(   t   ABCMetat   abstractmethodt   abstractpropertyNi   (   t   DriverRegistryt
   BaseDriverc           B   sY   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 RS(   s§  
    class BaseDriver(object):

    This is a base class for different server types.
    Inherit this class to implement different type of database driver
    implementation.

    (For PostgreSQL/EDB Postgres Advanced Server, we will be using psycopg2)

    Abstract Properties:
    -------- ----------
    * Version (string):
        Current version string for the database server

    * libpq_version (string):
        Current version string for the used libpq library

    Abstract Methods:
    -------- -------
    * get_connection(*args, **kwargs)
    - It should return a Connection class object, which may/may not be
      connected to the database server.

    * release_connection(*args, **kwargs)
    - Implement the connection release logic

    * gc()
    - Implement this function to release the connections assigned in the
      session, which has not been pinged from more than the idle timeout
      configuration.
    c         C   s   d  S(   N(    (   t   cls(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   Version5   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   libpq_version9   s    c         O   s   d  S(   N(    (   t   selft   argst   kwargs(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   get_connection=   s    c         O   s   d  S(   N(    (   R   R	   R
   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   release_connectionA   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   gcE   s    (
   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   R   (    (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyR      s    t   BaseConnectionc           B   sy  e  Z d  Z d Z d Z d Z d Z d Z d Z d Z	 d Z
 e d „  ƒ Z e d e d	 „ ƒ Z e d e d
 „ ƒ Z e d e d „ ƒ Z e d e d „ ƒ Z e d e d „ ƒ Z e d e d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e e e d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d d „ ƒ Z  RS(   sß  
    class BaseConnection(object)

        It is a base class for database connection. A different connection
        drive must implement this to expose abstract methods for this server.

        General idea is to create a wrapper around the actual driver
        implementation. It will be instantiated by the driver factory
        basically. And, they should not be instantiated directly.


    Abstract Methods:
    -------- -------
    * connect(**kwargs)
      - Define this method to connect the server using that particular driver
        implementation.

    * execute_scalar(query, params, formatted_exception_msg)
      - Implement this method to execute the given query and returns single
        datum result.

    * execute_async(query, params, formatted_exception_msg)
      - Implement this method to execute the given query asynchronously and
      returns result.

    * execute_void(query, params, formatted_exception_msg)
      - Implement this method to execute the given query with no result.

    * execute_2darray(query, params, formatted_exception_msg)
      - Implement this method to execute the given query and returns the result
        as a 2 dimensional array.

    * execute_dict(query, params, formatted_exception_msg)
      - Implement this method to execute the given query and returns the result
        as an array of dict (column name -> value) format.

    * def async_fetchmany_2darray(records=-1, formatted_exception_msg=False):
      - Implement this method to retrieve result of asynchronous connection and
        polling with no_result flag set to True.
        This returns the result as a 2 dimensional array.
        If records is -1 then fetchmany will behave as fetchall.

    * connected()
      - Implement this method to get the status of the connection. It should
        return True for connected, otherwise False

    * reset()
      - Implement this method to reconnect the database server (if possible)

    * transaction_status()
      - Implement this method to get the transaction status for this
        connection. Range of return values different for each driver type.

    * ping()
      - Implement this method to ping the server. There are times, a connection
        has been lost, but - the connection driver does not know about it. This
        can be helpful to figure out the actual reason for query failure.

    * _release()
      - Implement this method to release the connection object. This should not
        be directly called using the connection object itself.

      NOTE: Please use BaseDriver.release_connection(...) for releasing the
            connection object for better memory management, and connection pool
            management.

    * _wait(conn)
      - Implement this method to wait for asynchronous connection to finish the
        execution, hence - it must be a blocking call.

    * _wait_timeout(conn, time)
      - Implement this method to wait for asynchronous connection with timeout.
        This must be a non blocking call.

    * poll(formatted_exception_msg, no_result)
      - Implement this method to poll the data of query running on asynchronous
        connection.

    * cancel_transaction(conn_id, did=None)
      - Implement this method to cancel the running transaction.

    * messages()
      - Implement this method to return the list of the messages/notices from
        the database server.

    * rows_affected()
      - Implement this method to get the rows affected by the last command
        executed on the server.
    i   i   i   i   i   gš™™™™™É?i † c         K   s   d  S(   N(    (   R   R
   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   connect¯   s    c         C   s   d  S(   N(    (   R   t   queryt   paramst   formatted_exception_msg(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   execute_scalar³   s    c         C   s   d  S(   N(    (   R   R   R   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   execute_async¸   s    c         C   s   d  S(   N(    (   R   R   R   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   execute_void½   s    c         C   s   d  S(   N(    (   R   R   R   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   execute_2darrayÂ   s    c         C   s   d  S(   N(    (   R   R   R   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   execute_dictÇ   s    iÿÿÿÿc         C   s   d  S(   N(    (   R   t   recordsR   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   async_fetchmany_2darrayÌ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt	   connectedÑ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   resetÕ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   transaction_statusÙ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   pingÝ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   _releaseá   s    c         C   s   d  S(   N(    (   R   t   conn(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   _waitå   s    c         C   s   d  S(   N(    (   R   R"   t   time(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   _wait_timeouté   s    c         C   s   d  S(   N(    (   R   R   t	   no_result(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   pollí   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   status_messageñ   s    c         C   s   d  S(   N(    (   R   (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   rows_affectedõ   s    c         C   s   d  S(   N(    (   R   t   conn_idt   did(    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   cancel_transactionù   s    N(!   R   R   R   t   ASYNC_OKt   ASYNC_READ_TIMEOUTt   ASYNC_WRITE_TIMEOUTt   ASYNC_NOT_CONNECTEDt   ASYNC_EXECUTION_ABORTEDt   ASYNC_TIMEOUTt   ASYNC_WAIT_TIMEOUTt   ASYNC_NOTICE_MAXLENGTHR   R   t   Nonet   FalseR   t   TrueR   R   R   R   R   R   R   R   R    R!   R#   R%   R'   R(   R)   R,   (    (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyR   J   sR   Z(   R   t   abcR    R   R   t   sixt   registryR   t   add_metaclasst   objectR   R   (    (    (    s8   /usr/share/pgadmin4/web/pgadmin/utils/driver/abstract.pyt   <module>
   s   6