'Translate non-printable characters and calculate segment width'

def _prepare_segments(self, segments, calculate_contents_len):

    for segment in segments:
        segment[u'contents'] = translate_np(segment[u'contents'])
    if calculate_contents_len:
        for segment in segments:
            if segment[u'literal_contents'][1]:
                segment[u'_contents_len'] = segment[u'literal_contents'][0]
            else:
                segment[u'_contents_len'] = self.strwidth(segment[u'contents'])
