Ejemplo n.º 1
0
    def db(self, name='_system', username='******', password='', verify=False):
        """Connect to a database and return the database API wrapper.

        :param name: Database name.
        :type name: str | unicode
        :param username: Username for basic authentication.
        :type username: str | unicode
        :param password: Password for basic authentication.
        :type password: str | unicode
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection to ArangoDB fails.
        """
        connection = Connection(url=self._url,
                                db=name,
                                username=username,
                                password=password,
                                http_client=self._http_client)
        database = StandardDatabase(connection)

        if verify:  # Check the server connection by making a read API call
            try:
                database.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError('bad connection: {}'.format(err))

        return database
Ejemplo n.º 2
0
    def db(self, name='_system', username='******', password='', verify=False):
        """Connect to an ArangoDB database and return the database API wrapper.

        :param name: Database name.
        :type name: str | unicode
        :param username: Username for basic authentication.
        :type username: str | unicode
        :param password: Password for basic authentication.
        :type password: str | unicode
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection fails.
        """
        connection = Connection(hosts=self._hosts,
                                host_resolver=self._host_resolver,
                                sessions=self._sessions,
                                db_name=name,
                                username=username,
                                password=password,
                                http_client=self._http,
                                serializer=self._serializer,
                                deserializer=self._deserializer)
        if verify:
            try:
                connection.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError('bad connection: {}'.format(err))

        return StandardDatabase(connection)
Ejemplo n.º 3
0
    def __init__(self,
                 protocol='http',
                 host='127.0.0.1',
                 port=8529,
                 username='******',
                 password='',
                 verify=False,
                 http_client=None,
                 enable_logging=True):

        self._protocol = protocol
        self._host = host
        self._port = port
        self._username = username
        self._password = password
        self._http_client = http_client or DefaultHTTPClient()
        self._logging = enable_logging
        self._conn = Connection(protocol=self._protocol,
                                host=self._host,
                                port=self._port,
                                database='_system',
                                username=self._username,
                                password=self._password,
                                http_client=self._http_client,
                                enable_logging=self._logging)
        self._wal = WriteAheadLog(self._conn)

        if verify:
            self.verify()
Ejemplo n.º 4
0
    def __init__(self,
                 protocol='http',
                 host='127.0.0.1',
                 port=8529,
                 username='******',
                 password='',
                 verify=False,
                 http_client=None,
                 enable_logging=True,
                 check_cert=True,
                 use_session=True,
                 logger=None):

        self._protocol = protocol
        self._host = host
        self._port = port
        self._username = username
        self._password = password
        self._http_client = DefaultHTTPClient(
            use_session=use_session,
            check_cert=check_cert) if http_client is None else http_client
        self._logging_enabled = enable_logging
        self._conn = Connection(protocol=self._protocol,
                                host=self._host,
                                port=self._port,
                                database='_system',
                                username=self._username,
                                password=self._password,
                                http_client=self._http_client,
                                enable_logging=self._logging_enabled,
                                logger=logger)
        self._wal = WriteAheadLog(self._conn)

        if verify:
            self.verify()
Ejemplo n.º 5
0
    def database(self, name, username=None, password=None):
        """Return the database object.

        :param name: the name of the database
        :type name: str
        :param username: the username for authentication (if set, overrides
            the username specified during the client initialization)
        :type username: str
        :param password: the password for authentication (if set, overrides
            the password specified during the client initialization
        :type password: str
        :returns: the database object
        :rtype: arango.database.Database
        """
        return Database(
            Connection(protocol=self._protocol,
                       host=self._host,
                       port=self._port,
                       database=name,
                       username=username or self._username,
                       password=password or self._password,
                       http_client=self._http_client,
                       enable_logging=self._logging))