'Maps RevisionOptions to BranchNames, inserting them into the key'

def _map_revision_to_branch(self, key, revision=None):

    if isinstance(key, (LibraryLocator, LibraryUsageLocator)):
        draft_branch = ModuleStoreEnum.BranchName.library
        published_branch = ModuleStoreEnum.BranchName.library
    else:
        draft_branch = ModuleStoreEnum.BranchName.draft
        published_branch = ModuleStoreEnum.BranchName.published
    if (revision == ModuleStoreEnum.RevisionOption.published_only):
        return key.for_branch(published_branch)
    elif (revision == ModuleStoreEnum.RevisionOption.draft_only):
        return key.for_branch(draft_branch)
    elif (revision is None):
        if (key.branch is not None):
            return key
        elif (self.get_branch_setting(key) == ModuleStoreEnum.Branch.draft_preferred):
            return key.for_branch(draft_branch)
        else:
            return key.for_branch(published_branch)
    else:
        raise UnsupportedRevisionError()
