def resolve_adapter(uri):<EOL>
if isinstance(uri, BaseAdapter):<EOL><INDENT>return uri<EOL><DEDENT>parsed = compat.urllib_parse.urlsplit(uri)  <EOL>if not parsed.scheme:<EOL><INDENT>raise with_context(<EOL>exc=InvalidUri(<EOL>'<STR_LIT>',<EOL>),<EOL>context={<EOL>'<STR_LIT>': parsed,<EOL>'<STR_LIT>': uri,<EOL>},<EOL>)<EOL><DEDENT>try:<EOL><INDENT>adapter_type = adapter_registry[parsed.scheme]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise with_context(<EOL>exc=InvalidUri('<STR_LIT>'.format(<EOL>protocol=parsed.scheme,<EOL>)),<EOL>context={<EOL>'<STR_LIT>': parsed,<EOL>'<STR_LIT>': uri,<EOL>},<EOL>)<EOL><DEDENT>return adapter_type.configure(parsed)<EOL>
Given a URI, returns a properly-configured adapter instance.