Пример #1
0
    def connect(self, kwargs):
        global connection_list
        kw = process_connect_string.process([], kwargs, True)

        if verbose:
            print('%s trying to connect %s', (version, repr(kw)))
        # kwargs has been loaded with all the values we need
        try:
            conn = adodbapi.connect(kw)
            if verbose:
                print("result = %s", repr(conn))
            self.server_connection = conn
            connection_list.append(self)
            return True
        except api.Error, e:
            return e
Пример #2
0
    def connect(self, kwargs):
        global connection_list
        kw = process_connect_string.process([], kwargs, True)

        if verbose:
            print('%s trying to connect %s', (version, repr(kw)))
        # kwargs has been loaded with all the values we need
        try:
            conn = adodbapi.connect(kw)
            if verbose:
                print("result = %s", repr(conn))
            self.server_connection = conn
            connection_list.append(self)
            return True
        except api.Error, e:
            return e
Пример #3
0
def connect(*args, **kwargs):  # --> a db-api connection object
    """Connect to a database.

    call using:
    :connection_string -- An ADODB formatted connection string, see:
         * http://www.connectionstrings.com
         * http://www.asp101.com/articles/john/connstring/default.asp
    :timeout -- A command timeout value, in seconds (default 30 seconds)
    """
    co = Connection()  # make an empty connection object

    kwargs = process_connect_string.process(args, kwargs, True)

    try:  # connect to the database, using the connection information in kwargs
        co.connect(kwargs)
        return co
    except (Exception), e:
        message = 'Error opening connection to "%s"' % co.connection_string
        raise api.OperationalError(e, message)
Пример #4
0
def connect(*args, **kwargs): # --> a db-api connection object
    """Connect to a database.

    call using:
    :connection_string -- An ADODB formatted connection string, see:
         * http://www.connectionstrings.com
         * http://www.asp101.com/articles/john/connstring/default.asp
    :timeout -- A command timeout value, in seconds (default 30 seconds)
    """
    co = Connection() # make an empty connection object

    kwargs = process_connect_string.process(args, kwargs, True)

    try:  # connect to the database, using the connection information in kwargs
       co.connect(kwargs)
       return co
    except (Exception) as e:
        message =  'Error opening connection to "%s"' % co.connection_string
        raise api.OperationalError(e, message)
Пример #5
0
def connect(*args, **kwargs): # --> a remote db-api connection object
    """Create and open a remote db-api database connection object"""
    # process the argument list the programmer gave us
    kwargs = process_connect_string.process(args, kwargs)
    # the "proxy_xxx" keys tell us where to find the PyRO proxy server
    kwargs.setdefault('pyro_connection', 'PYRO:ado.connection@%(proxy_host)s:%(proxy_port)s')
    if not 'proxy_port' in kwargs:
        try:
            pport = os.environ['PROXY_PORT']
        except KeyError:
            pport = 9099
        kwargs['proxy_port'] = pport
    if not 'proxy_host' in kwargs or not kwargs['proxy_host']:
        try:
            phost = os.environ['PROXY_HOST']
        except KeyError:
            phost = '[::1]' # '127.0.0.1'
        kwargs['proxy_host'] = phost
    ado_uri = kwargs['pyro_connection'] % kwargs
    # ask PyRO make us a remote connection object
    auto_retry = 3
    while auto_retry:
        try:
            dispatcher = Pyro4.Proxy(ado_uri)
            if 'comm_timeout' in kwargs:
                dispatcher._pyroTimeout = float(kwargs['comm_timeout'])
            uri = dispatcher.make_connection()
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError ('Cannot create connection to=%s' % ado_uri)

    conn_uri = fix_uri(uri, kwargs)  # get a host connection from the proxy server
    while auto_retry:
        try:
            host_conn = Pyro4.Proxy(conn_uri) # bring up an exclusive Pyro connection for my ADO connection
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError ('Cannot create ADO connection object using=%s' % conn_uri)
    if 'comm_timeout' in kwargs:
        host_conn._pyroTimeout = float(kwargs['comm_timeout'])
    # make a local clone
    myConn = Connection()
    while auto_retry:
        try:
            myConn.connect(kwargs, host_conn) # call my connect method -- hand him the host connection
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError ('Pyro error creating connection to/thru=%s' % repr(kwargs))
        except _BaseException, e:
            raise api.DatabaseError('Error creating remote connection to=%s, e=%s, %s' % (repr(kwargs), repr(e),sys.exc_info()[2]))
Пример #6
0
def connect(*args, **kwargs):  # --> a remote db-api connection object
    """Create and open a remote db-api database connection object"""
    # process the argument list the programmer gave us
    kwargs = process_connect_string.process(args, kwargs)
    # the "proxy_xxx" keys tell us where to find the PyRO proxy server
    kwargs.setdefault('pyro_connection',
                      'PYRO:ado.connection@%(proxy_host)s:%(proxy_port)s')
    if not 'proxy_port' in kwargs:
        try:
            pport = os.environ['PROXY_PORT']
        except KeyError:
            pport = 9099
        kwargs['proxy_port'] = pport
    if not 'proxy_host' in kwargs or not kwargs['proxy_host']:
        try:
            phost = os.environ['PROXY_HOST']
        except KeyError:
            phost = '[::1]'  # '127.0.0.1'
        kwargs['proxy_host'] = phost
    ado_uri = kwargs['pyro_connection'] % kwargs
    # ask PyRO make us a remote connection object
    auto_retry = 3
    while auto_retry:
        try:
            dispatcher = Pyro4.Proxy(ado_uri)
            if 'comm_timeout' in kwargs:
                dispatcher._pyroTimeout = float(kwargs['comm_timeout'])
            uri = dispatcher.make_connection()
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError('Cannot create connection to=%s' %
                                        ado_uri)

    conn_uri = fix_uri(uri,
                       kwargs)  # get a host connection from the proxy server
    while auto_retry:
        try:
            host_conn = Pyro4.Proxy(
                conn_uri
            )  # bring up an exclusive Pyro connection for my ADO connection
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError(
                    'Cannot create ADO connection object using=%s' % conn_uri)
    if 'comm_timeout' in kwargs:
        host_conn._pyroTimeout = float(kwargs['comm_timeout'])
    # make a local clone
    myConn = Connection()
    while auto_retry:
        try:
            myConn.connect(
                kwargs, host_conn
            )  # call my connect method -- hand him the host connection
            break
        except Pyro4.core.errors.PyroError:
            auto_retry -= 1
            if auto_retry:
                time.sleep(1)
            else:
                raise api.DatabaseError(
                    'Pyro error creating connection to/thru=%s' % repr(kwargs))
        except _BaseException, e:
            raise api.DatabaseError(
                'Error creating remote connection to=%s, e=%s, %s' %
                (repr(kwargs), repr(e), sys.exc_info()[2]))