'Return a string with the Python expression which ends at the
given index, which is empty if there is no real one.'

def get_expression(self):

    if (not self.is_in_code()):
        raise ValueError('get_expression    should    only    be    calledif    index    is    inside    a    code.')
    rawtext = self.rawtext
    bracketing = self.bracketing
    brck_index = self.indexbracket
    brck_limit = bracketing[brck_index][0]
    pos = self.indexinrawtext
    last_identifier_pos = pos
    postdot_phase = True
    while 1:
        while 1:
            if ((pos > brck_limit) and (rawtext[(pos - 1)] in self._whitespace_chars)):
                pos -= 1
            elif ((not postdot_phase) and (pos > brck_limit) and (rawtext[(pos - 1)] == '.')):
                pos -= 1
                postdot_phase = True
            elif ((pos == brck_limit) and (brck_index > 0) and (rawtext[bracketing[(brck_index - 1)][0]] == '#')):
                brck_index -= 2
                brck_limit = bracketing[brck_index][0]
                pos = bracketing[(brck_index + 1)][0]
            else:
                break
        if (not postdot_phase):
            break
        ret = self._eat_identifier(rawtext, brck_limit, pos)
        if ret:
            pos = (pos - ret)
            last_identifier_pos = pos
            postdot_phase = False
        elif (pos == brck_limit):
            level = bracketing[brck_index][1]
            while ((brck_index > 0) and (bracketing[(brck_index - 1)][1] > level)):
                brck_index -= 1
            if (bracketing[brck_index][0] == brck_limit):
                break
            pos = bracketing[brck_index][0]
            brck_index -= 1
            brck_limit = bracketing[brck_index][0]
            last_identifier_pos = pos
            if (rawtext[pos] in '(['):
                pass
            else:
                if (rawtext[pos] in '\'"'):
                    while ((pos > 0) and (rawtext[(pos - 1)] in 'rRbBuU')):
                        pos -= 1
                    last_identifier_pos = pos
                break
        else:
            break
    return rawtext[last_identifier_pos:self.indexinrawtext]
