def sortlevel(self, level=0, ascending=True, sort_remaining=True):
        from pandas.core.sorting import indexer_from_factorized
        if isinstance(level, (str, int)):
            level = [level]
        level = [self._get_level_number(lev) for lev in level]
        sortorder = None
        if isinstance(ascending, list):
            if not len(level) == len(ascending):
                raise ValueError("level must have same length as ascending")
            from pandas.core.sorting import lexsort_indexer
            indexer = lexsort_indexer([self.codes[lev] for lev in level],
                                      orders=ascending)
        else:
            codes = list(self.codes)
            shape = list(self.levshape)
            primary = tuple(codes[lev] for lev in level)
            primshp = tuple(shape[lev] for lev in level)
            for lev in sorted(level, reverse=True):
                codes.pop(lev)
                shape.pop(lev)
            if sort_remaining:
                primary += primary + tuple(codes)
                primshp += primshp + tuple(shape)
            else:
                sortorder = level[0]
            indexer = indexer_from_factorized(primary, primshp,
                                              compress=False)
            if not ascending:
                indexer = indexer[::-1]
        indexer = ensure_platform_int(indexer)
        new_codes = [level_codes.take(indexer) for level_codes in self.codes]
        new_index = MultiIndex(codes=new_codes, levels=self.levels,
                               names=self.names, sortorder=sortorder,
                               verify_integrity=False)
        return new_index, indexer