Esempio n. 1
0
 def complete_request(self, text):
     line = str_to_unicode(readline.get_line_buffer())
     byte_cursor_pos = readline.get_endidx()
     
     # get_endidx is a byte offset
     # account for multi-byte characters to get correct cursor_pos
     bytes_before_cursor = cast_bytes(line)[:byte_cursor_pos]
     cursor_pos = len(cast_unicode(bytes_before_cursor))
     
     # send completion request to kernel
     # Give the kernel up to 5s to respond
     msg_id = self.client.complete(
         code=line,
         cursor_pos=cursor_pos,
     )
 
     msg = self.client.shell_channel.get_msg(timeout=self.timeout)
     if msg['parent_header']['msg_id'] == msg_id:
         content = msg['content']
         cursor_start = content['cursor_start']
         matches = [ line[:cursor_start] + m for m in content['matches'] ]
         if content["cursor_end"] < cursor_pos:
             extra = line[content["cursor_end"]: cursor_pos]
             matches = [m + extra for m in matches]
         matches = [ unicode_to_str(m) for m in matches ]
         return matches
     return []
Esempio n. 2
0
    def complete_request(self, text):
        line = str_to_unicode(readline.get_line_buffer())
        byte_cursor_pos = readline.get_endidx()

        # get_endidx is a byte offset
        # account for multi-byte characters to get correct cursor_pos
        bytes_before_cursor = cast_bytes(line)[:byte_cursor_pos]
        cursor_pos = len(cast_unicode(bytes_before_cursor))

        # send completion request to kernel
        # Give the kernel up to 5s to respond
        msg_id = self.client.complete(
            code=line,
            cursor_pos=cursor_pos,
        )

        msg = self.client.shell_channel.get_msg(timeout=self.timeout)
        if msg['parent_header']['msg_id'] == msg_id:
            content = msg['content']
            cursor_start = content['cursor_start']
            matches = [line[:cursor_start] + m for m in content['matches']]
            if content["cursor_end"] < cursor_pos:
                extra = line[content["cursor_end"]:cursor_pos]
                matches = [m + extra for m in matches]
            matches = [unicode_to_str(m) for m in matches]
            return matches
        return []
Esempio n. 3
0
    def complete_request(self, text):
        line = readline.get_line_buffer()
        cursor_pos = readline.get_endidx()

        # send completion request to kernel
        # Give the kernel up to 0.5s to respond
        msg_id = self.client.complete(code=line, cursor_pos=cursor_pos)

        msg = self.client.shell_channel.get_msg(timeout=self.timeout)
        if msg["parent_header"]["msg_id"] == msg_id:
            return msg["content"]["matches"]
        return []
def attr_matches(self, text):
    """Compute matches when text contains a dot.

    Assuming the text is of the form NAME.NAME....[NAME], and is
    evaluatable in self.namespace or self.global_namespace, it will be
    evaluated and its attributes (as revealed by dir()) are used as
    possible completions.  (For class instances, class members are are
    also considered.)

    WARNING: this can still invoke arbitrary C code, if an object
    with a __getattr__ hook is evaluated.

    """
    
    force_complete = 1
    #print 'Completer->attr_matches, txt=%r' % text # dbg
    lbuf = readline.get_line_buffer()

    # Another option, seems to work great. Catches things like ''.<tab>
    m = re.match(r"(\S+(\.\w+)*)\.(\w*)$", text)

    if m:
        expr, attr = m.group(1, 3)
    else:
        # force match - eval anything that ends with colon
        if not force_complete:
            return []
                
        m2 = re.match(r"(.+)\.(\w*)$", lbuf)
        if not m2:
            return []
        expr, attr = m2.group(1,2)


    try:
        obj = eval(expr, self.namespace)
    except:
        try:
            obj = eval(expr, self.global_namespace)
        except:
            return []

    words = dir2(obj)

    try:
        words = generics.complete_object(obj, words)
    except TryNext:
        pass
    # Build match list to return
    n = len(attr)
    res = ["%s.%s" % (expr, w) for w in words if w[:n] == attr ]
    return res
Esempio n. 5
0
    def complete_request(self, text):
        line = readline.get_line_buffer()
        cursor_pos = readline.get_endidx()

        # send completion request to kernel
        # Give the kernel up to 0.5s to respond
        msg_id = self.client.shell_channel.complete(text=text,
                                                    line=line,
                                                    cursor_pos=cursor_pos)

        msg = self.client.shell_channel.get_msg(timeout=self.timeout)
        if msg['parent_header']['msg_id'] == msg_id:
            return msg["content"]["matches"]
        return []
Esempio n. 6
0
 def rlcomplete(self, text, state):
     if state == 0:
         line = str_to_unicode(readline.get_line_buffer())
         byte_cursor_pos = readline.get_endidx()
         # get_endidx is a byte offset
         # account for multi-byte characters to get correct cursor_pos
         bytes_before_cursor = cast_bytes(line)[:byte_cursor_pos]
         cursor_pos = len(cast_unicode(bytes_before_cursor))
         try:
             content = self.complete_request(line, cursor_pos)
             self.matches = _construct_readline_matches(line, cursor_pos, content)
         except Empty:
             #print('WARNING: Kernel timeout on tab completion.')
             pass
     
     try:
         return self.matches[state]
     except IndexError:
         return None
Esempio n. 7
0
    def rlcomplete(self, text, state):
        if state == 0:
            line = str_to_unicode(readline.get_line_buffer())
            byte_cursor_pos = readline.get_endidx()
            # get_endidx is a byte offset
            # account for multi-byte characters to get correct cursor_pos
            bytes_before_cursor = cast_bytes(line)[:byte_cursor_pos]
            cursor_pos = len(cast_unicode(bytes_before_cursor))
            try:
                content = self.complete_request(line, cursor_pos)
                self.matches = _construct_readline_matches(
                    line, cursor_pos, content)
            except Empty:
                #print('WARNING: Kernel timeout on tab completion.')
                pass

        try:
            return self.matches[state]
        except IndexError:
            return None