<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def connect(host, username, password, **kwargs):
 """ Connect and login to routeros device. Upon success return a Api class. :param host: Hostname to connecto to. May be ipv4,ipv6,FQDN. :param username: Username to login with. :param password: Password to login with. Only ASCII characters allowed. :param timeout: Socket timeout. Defaults to 10. :param port: Destination port to be used. Defaults to 8728. :param saddr: Source address to bind to. :param subclass: Subclass of Api class. Defaults to Api class from library. :param ssl_wrapper: Callable (e.g. ssl.SSLContext instance) to wrap socket with. :param login_methods: Tuple with callables to login methods to try in order. """

    arguments = ChainMap(kwargs, defaults)
    transport = create_transport(host, **arguments)
    protocol = ApiProtocol(transport=transport, encoding=arguments['encoding'])
    api = arguments['subclass'](protocol=protocol)

    for method in arguments['login_methods']:
        try:
            method(api=api, username=username, password=password)
            return api
        except (TrapError, MultiTrapError):
            pass
        except (ConnectionError, FatalError):
            transport.close()
            raise