'Like Renderer.render(), but accept theme in place of matcher_info'

def do_render(self, mode, width, side, line, output_raw, output_width, segment_info, theme):

    segments = list(theme.get_segments(side, line, segment_info, mode))
    current_width = 0
    self._prepare_segments(segments, (output_width or width))
    if (not width):
        if output_width:
            current_width = self._render_length(theme, segments, self.compute_divider_widths(theme))
        return construct_returned_value((self.hl_join([segment[u'_rendered_hl'] for segment in self._render_segments(theme, segments)]) + self.hlstyle()), segments, current_width, output_raw, output_width)
    divider_widths = self.compute_divider_widths(theme)
    segments_priority = sorted((segment for segment in segments if (segment[u'priority'] is not None)), key=(lambda segment: segment[u'priority']), reverse=True)
    no_priority_segments = filter((lambda segment: (segment[u'priority'] is None)), segments)
    current_width = self._render_length(theme, segments, divider_widths)
    if (current_width > width):
        for segment in chain(segments_priority, no_priority_segments):
            if (segment[u'truncate'] is not None):
                segment[u'contents'] = segment[u'truncate'](self.pl, (current_width - width), segment)
        segments_priority = iter(segments_priority)
        if ((current_width > width) and (len(segments) > 100)):
            diff = (current_width - width)
            for segment in segments_priority:
                segments.remove(segment)
                diff -= segment[u'_len']
                if (diff <= 0):
                    break
            current_width = self._render_length(theme, segments, divider_widths)
        if (current_width > width):
            for segment in segments_priority:
                segments.remove(segment)
                current_width = self._render_length(theme, segments, divider_widths)
                if (current_width <= width):
                    break
    del segments_priority
    segments_spacers = [segment for segment in segments if (segment[u'expand'] is not None)]
    if segments_spacers:
        (distribute_len, distribute_len_remainder) = divmod((width - current_width), len(segments_spacers))
        for segment in segments_spacers:
            segment[u'contents'] = segment[u'expand'](self.pl, (distribute_len + (1 if (distribute_len_remainder > 0) else 0)), segment)
            distribute_len_remainder -= 1
        current_width = width
    elif output_width:
        current_width = self._render_length(theme, segments, divider_widths)
    rendered_highlighted = self.hl_join([segment[u'_rendered_hl'] for segment in self._render_segments(theme, segments)])
    if rendered_highlighted:
        rendered_highlighted += self.hlstyle()
    return construct_returned_value(rendered_highlighted, segments, current_width, output_raw, output_width)
