@classmethod<EOL><INDENT>def _get_storage(cls, uri):<DEDENT>
driver = cls._get_driver(uri.scheme)<EOL>key = uri.username<EOL>secret = uri.password<EOL>container = uri.netloc<EOL>driver_kwargs = {}<EOL>if uri.scheme.startswith('<STR_LIT>'):<EOL><INDENT>if not key:<EOL><INDENT>key = os.environ.get('<STR_LIT>')<EOL><DEDENT>if not secret:<EOL><INDENT>secret = os.environ.get('<STR_LIT>')<EOL><DEDENT>if not (key and secret and container):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if '<STR_LIT>' in os.environ:<EOL><INDENT>driver_kwargs['<STR_LIT>'] = os.environ['<STR_LIT>']<EOL><DEDENT><DEDENT>elif uri.scheme == '<STR_LIT>':<EOL><INDENT>parts = []<EOL>if uri.netloc:<EOL><INDENT>parts.append(uri.netloc)<EOL><DEDENT>if uri.path:<EOL><INDENT>parts.append(uri.path)<EOL><DEDENT>if not parts:<EOL><INDENT>parts.append('<STR_LIT:.>')<EOL><DEDENT>base_path = os.path.abspath('<STR_LIT>'.join(parts))<EOL>key = os.path.dirname(base_path)<EOL>container = os.path.basename(base_path)<EOL><DEDENT>storage = driver(key, secret, **driver_kwargs)<EOL>try:<EOL><INDENT>return storage.get_container(container)<EOL><DEDENT>except ContainerDoesNotExistError:<EOL><INDENT>return storage.create_container(container)<EOL><DEDENT>
Given a URI like local:///srv/repo or s3://key:secret@apt.example.com,
return a libcloud storage or container object.