def startup_connection(self):
    user = self.options['user']
    database = self.options['database']
    session_label = self.options['session_label']
    os_user_name = (DEFAULT_USER if DEFAULT_USER else '')
    password = self.options['password']
    self.write(messages.Startup(user, database, session_label, os_user_name))
    while True:
        message = self.read_message()
        if isinstance(message, messages.Authentication):
            if (message.code == messages.Authentication.OK):
                self._logger.info('User {} successfully authenticated'.format(self.options['user']))
            elif (message.code == messages.Authentication.CHANGE_PASSWORD):
                msg = 'The password for user {} has expired'.format(self.options['user'])
                self._logger.error(msg)
                raise errors.ConnectionError(msg)
            elif (message.code == messages.Authentication.PASSWORD_GRACE):
                self._logger.warning('The password for user {} will expire soon. Please consider changing it.'.format(self.options['user']))
            elif (message.code == messages.Authentication.GSS):
                self.make_GSS_authentication()
            else:
                self.write(messages.Password(password, message.code, {'user': user, 'salt': getattr(message, 'salt', None), 'usersalt': getattr(message, 'usersalt', None)}))
        elif isinstance(message, messages.BackendKeyData):
            self.backend_pid = message.pid
            self.backend_key = message.key
        elif isinstance(message, messages.ReadyForQuery):
            break
        elif isinstance(message, messages.ErrorResponse):
            self._logger.error(message.error_message())
            raise errors.ConnectionError(message.error_message())
        else:
            msg = 'Received unexpected startup message: {0}'.format(message)
            self._logger.error(msg)
            raise errors.MessageError(msg)
def startup_connection(self):
    user = self.options['user']
    database = self.options['database']
    session_label = self.options['session_label']
    os_user_name = (DEFAULT_USER if DEFAULT_USER else )
    password = self.options['password']
    self.write(messages.Startup(user, database, session_label, os_user_name))
    while True:
        message = self.read_message()
        if isinstance(message, messages.Authentication):
            if (message.code == messages.Authentication.OK):
                self._logger.info('User {} successfully authenticated'.format(self.options['user']))
            elif (message.code == messages.Authentication.CHANGE_PASSWORD):
                msg = 'The password for user {} has expired'.format(self.options['user'])
                self._logger.error(msg)
                raise errors.ConnectionError(msg)
            elif (message.code == messages.Authentication.PASSWORD_GRACE):
                self._logger.warning('The password for user {} will expire soon. Please consider changing it.'.format(self.options['user']))
            elif (message.code == messages.Authentication.GSS):
                self.make_GSS_authentication()
            else:
                self.write(messages.Password(password, message.code, {'user': user, 'salt': getattr(message, 'salt', None), 'usersalt': getattr(message, 'usersalt', None)}))
        elif isinstance(message, messages.BackendKeyData):
            self.backend_pid = message.pid
            self.backend_key = message.key
        elif isinstance(message, messages.ReadyForQuery):
            break
        elif isinstance(message, messages.ErrorResponse):
            self._logger.error(message.error_message())
            raise errors.ConnectionError(message.error_message())
        else:
            msg = 'Received unexpected startup message: {0}'.format(message)
            self._logger.error(msg)
            raise errors.MessageError(msg)