'Get completed text in before and after parts'

def get_completed_text(self, text):

    if (self.sep is None):
        return (text, u'')
    else:
        cursor_pos = self.original_cursor_pos
        if (cursor_pos is None):
            cursor_pos = self.cursorPosition()
        self.original_cursor_pos = None
        curtext = unicode(self.text())
        before_text = curtext[:cursor_pos]
        after_text = curtext[cursor_pos:].rstrip()
        before_text = self.sep.join(before_text.split(self.sep)[:(-1)]).rstrip()
        if before_text:
            if self.space_before_sep:
                before_text += u'    '
            before_text += (self.sep + u'    ')
        if (self.add_separator or after_text):
            if self.space_before_sep:
                text = (text.rstrip() + u'    ')
            completed_text = ((text + self.sep) + u'    ')
        else:
            completed_text = text
        return ((before_text + completed_text), after_text)
