예제 #1
0
    def matches(self, cursor_offset, line, **kwargs):
        if 'locals_' not in kwargs:
            return None
        locals_ = kwargs['locals_']

        r = self.locate(cursor_offset, line)
        if r is None:
            return None
        member_part = r[2]
        _, _, dexpr = lineparts.current_array_with_indexer(cursor_offset, line)
        try:
            locals_['temp_val_from_array'] = safe_eval(dexpr, locals_)
        except (EvaluationError, NameError, IndexError, AttributeError,
                TypeError):
            return set()

        temp_line = line.replace(member_part, 'temp_val_from_array.')

        matches = self.completer.matches(len(temp_line), temp_line, **kwargs)
        matches_with_correct_name = \
            set([match.replace('temp_val_from_array.', member_part) for match in matches])

        del locals_['temp_val_from_array']

        return matches_with_correct_name
예제 #2
0
파일: foo.py 프로젝트: axs221/bpython
    def matches(self, cursor_offset, line, **kwargs):
        if 'locals_' not in kwargs:
            return None
        locals_ = kwargs['locals_']

        r = self.locate(cursor_offset, line)
        if r is None:
            return None
        _, _, dexpr = lineparts.current_array_with_indexer(cursor_offset, line)
        try:
            obj = safe_eval(dexpr, locals_)  # TODO
            # obj = eval(dexpr)
        except EvaluationError:
            return set()

        attrs = dir('')
        if not py3:
            # decode attributes
            attrs = (att.decode('ascii') for att in attrs)

        matches = set(att for att in attrs if att.startswith(r.word))
        if not r.word.startswith('_'):
            return set(match for match in matches if not match.startswith('_'))
        return matches
예제 #3
0
파일: foo.py 프로젝트: shawnaxsom/bpython
    def matches(self, cursor_offset, line, **kwargs):
        if 'locals_' not in kwargs:
            return None
        locals_ = kwargs['locals_']

        r = self.locate(cursor_offset, line)
        if r is None:
            return None
        _, _, dexpr = lineparts.current_array_with_indexer(cursor_offset, line)
        try:
            obj = safe_eval(dexpr, locals_)  # TODO
            # obj = eval(dexpr)
        except EvaluationError:
            return set()

        attrs = dir('')
        if not py3:
            # decode attributes
            attrs = (att.decode('ascii') for att in attrs)

        matches = set(att for att in attrs if att.startswith(r.word))
        if not r.word.startswith('_'):
            return set(match for match in matches if not match.startswith('_'))
        return matches
예제 #4
0
    def matches(self, cursor_offset, line, **kwargs):
        if 'locals_' not in kwargs:
            return None
        locals_ = kwargs['locals_']

        r = self.locate(cursor_offset, line)
        if r is None:
            return None
        member_part = r[2]
        _, _, dexpr = lineparts.current_array_with_indexer(cursor_offset, line)
        try:
            locals_['temp_val_from_array'] = safe_eval(dexpr, locals_)
        except (EvaluationError, NameError, IndexError, AttributeError, TypeError):
            return set()

        temp_line = line.replace(member_part, 'temp_val_from_array.')

        matches = self.completer.matches(len(temp_line), temp_line, **kwargs)
        matches_with_correct_name = \
            set([match.replace('temp_val_from_array.', member_part) for match in matches])

        del locals_['temp_val_from_array']

        return matches_with_correct_name