human
Complete this python program:
def AdjustCandidateInsertionText(candidates):
assistant
#Here is the Python code you requested.

    """This function adjusts the candidate insertion text to take into account the
    text that\s currently in front of the cursor.
    For instance (\|\ represents the cursor):
    1. Buffer state: \foo.|bar\
    2. A completion candidate of \zoobar\ is shown and the user selects it.
    3. Buffer state: \foo.zoobar|bar\ instead of \foo.zoo|bar\ which is what the
    user wanted.
    This function changes candidates to resolve that issue.
    It could be argued that the user actually wants the final buffer state to be
    \foo.zoobar|\ (the cursor at the end), but that would be much more difficult
    to implement and is probably not worth doing.
    """
    def NewCandidateInsertionText(to_insert, text_after_cursor):
        overlap_len = OverlapLength(to_insert, text_after_cursor)
        if overlap_len:
            return to_insert[:(- overlap_len)]
        return to_insert
    text_after_cursor = vimsupport.TextAfterCursor()
    if (not text_after_cursor):
        return candidates
    new_candidates = []
    for candidate in candidates:
        if isinstance(candidate, dict):
            new_candidate = candidate.copy()
            if (u'abbr' not in new_candidate):
                new_candidate[u'abbr'] = new_candidate[u'word']
            new_candidate[u'word'] = NewCandidateInsertionText(new_candidate[u'word'], text_after_cursor)
            new_candidates.append(new_candidate)
        elif (isinstance(candidate, str) or isinstance(candidate, bytes)):
            new_candidates.append({u'abbr': candidate, u'word': NewCandidateInsertionText(candidate, text_after_cursor)})
    return new_candidates