Exemple #1
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name)

        data = {}
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            )
            data['text/plain'] = info_text
            # Provide the structured inspection information to allow the frontend to
            # format as desired.
            argspec = info.get('argspec')
            if argspec:
                defaults = argspec.get('defaults')
                if defaults:
                    argspec['defaults'] = [_to_primitive(x) for x in defaults]
            data['application/json'] = info

        reply_content = {
            'status': 'ok',
            'data': data,
            'metadata': {},
            'found': info['found'],
        }

        return reply_content
Exemple #2
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name)

        data = {}
        # If the object is large, we want to avoid possibly creating its string
        # form, as this is also likely to be large.
        if (info['found'] and info.get('string_form', '')
                == '<Object too large to display>'):
            data['text/plain'] = info['string_form']
            data['application/json'] = info
        elif info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            )
            data['text/plain'] = info_text
            # Provide the structured inspection information to allow the frontend to
            # format as desired.
            argspec = info.get('argspec')
            if argspec:
                defaults = argspec.get('defaults')
                if defaults:
                    argspec['defaults'] = [_to_primitive(x) for x in defaults]
            data['application/json'] = info

        reply_content = {
            'status': 'ok',
            'data': data,
            'metadata': {},
            'found': info['found'],
        }

        return reply_content
Exemple #3
0
    def do_inspect(self, code, cursor_pos, detail_level=0, omit_sections=()):
        name = token_at_cursor(code, cursor_pos)

        reply_content = {'status': 'ok'}
        reply_content['data'] = {}
        reply_content['metadata'] = {}
        try:
            if release.version_info >= (8, ):
                # `omit_sections` keyword will be available in IPython 8, see
                # https://github.com/ipython/ipython/pull/13343
                bundle = self.shell.object_inspect_mime(
                    name,
                    detail_level=detail_level,
                    omit_sections=omit_sections,
                )
            else:
                bundle = self.shell.object_inspect_mime(
                    name, detail_level=detail_level)
            reply_content['data'].update(bundle)
            if not self.shell.enable_html_pager:
                reply_content['data'].pop('text/html')
            reply_content['found'] = True
        except KeyError:
            reply_content['found'] = False

        return reply_content
Exemple #4
0
    def object_info_request(self, msg):
        content = msg['content']
        code = content['code']
        cursor_pos = content['cursor_pos']
        line, _ = code_to_line(code, cursor_pos)

        new_content = msg['content'] = {}
        new_content['oname'] = token_at_cursor(code, cursor_pos)
        new_content['detail_level'] = content['detail_level']
        return msg
Exemple #5
0
 def object_info_request(self, msg):
     content = msg['content']
     code = content['code']
     cursor_pos = content['cursor_pos']
     line, _ = code_to_line(code, cursor_pos)
     
     new_content = msg['content'] = {}
     new_content['oname'] = token_at_cursor(code, cursor_pos)
     new_content['detail_level'] = content['detail_level']
     return msg
Exemple #6
0
    def object_info_request(self, msg):
        content = msg["content"]
        code = content["code"]
        cursor_pos = content["cursor_pos"]
        line, _ = code_to_line(code, cursor_pos)

        new_content = msg["content"] = {}
        new_content["oname"] = token_at_cursor(code, cursor_pos)
        new_content["detail_level"] = content["detail_level"]
        return msg
Exemple #7
0
def expect_token(expected, cell, cursor_pos):
    token = token_at_cursor(cell, cursor_pos)
    offset = 0
    for line in cell.splitlines():
        if offset + len(line) >= cursor_pos:
            break
        else:
            offset += len(line)
    column = cursor_pos - offset
    line_with_cursor = '%s|%s' % (line[:column], line[column:])
    nt.assert_equal(
        token, expected, "Expected %r, got %r in: %r (pos %i)" %
        (expected, token, line_with_cursor, cursor_pos))
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name)

        reply_content = {"status": "ok"}
        reply_content["data"] = data = {}
        reply_content["metadata"] = {}
        reply_content["found"] = info["found"]
        if info["found"]:
            info_text = self.shell.object_inspect_text(name, detail_level=detail_level)
            data["text/plain"] = info_text

        return reply_content
def expect_token(expected, cell, cursor_pos):
    token = token_at_cursor(cell, cursor_pos)
    offset = 0
    for line in cell.splitlines():
        if offset + len(line) >= cursor_pos:
            break
        else:
            offset += len(line)
    column = cursor_pos - offset
    line_with_cursor = '%s|%s' % (line[:column], line[column:])
    nt.assert_equal(token, expected,
        "Expected %r, got %r in: %r (pos %i)" % (
        expected, token, line_with_cursor, cursor_pos)
    )
Exemple #10
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name)

        reply_content = {'status' : 'ok'}
        reply_content['data'] = data = {}
        reply_content['metadata'] = {}
        reply_content['found'] = info['found']
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            )
            data['text/plain'] = info_text

        return reply_content
Exemple #11
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)
        info = self.shell.object_inspect(name)

        reply_content = {'status': 'ok'}
        reply_content['data'] = data = {}
        reply_content['metadata'] = {}
        reply_content['found'] = info['found']
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=detail_level,
            )
            data['text/plain'] = info_text

        return reply_content
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)

        reply_content = {'status': 'ok'}
        reply_content['data'] = {}
        reply_content['metadata'] = {}
        try:
            reply_content['data'].update(
                self.shell.object_inspect_mime(name,
                                               detail_level=detail_level))
            if not self.shell.enable_html_pager:
                reply_content['data'].pop('text/html')
            reply_content['found'] = True
        except KeyError:
            reply_content['found'] = False

        return reply_content
Exemple #13
0
    def do_inspect(self, code, cursor_pos, detail_level=0):
        name = token_at_cursor(code, cursor_pos)

        reply_content = {'status' : 'ok'}
        reply_content['data'] = {}
        reply_content['metadata'] = {}
        try:
            reply_content['data'].update(
                self.shell.object_inspect_mime(
                    name,
                    detail_level=detail_level
                )
            )
            if not self.shell.enable_html_pager:
                reply_content['data'].pop('text/html')
            reply_content['found'] = True
        except KeyError:
            reply_content['found'] = False

        return reply_content
Exemple #14
0
 def inspect_request(self, stream, ident, parent):
     content = parent['content']
     
     name = token_at_cursor(content['code'], content['cursor_pos'])
     info = self.shell.object_inspect(name)
     
     reply_content = {'status' : 'ok'}
     reply_content['data'] = data = {}
     reply_content['metadata'] = {}
     reply_content['found'] = info['found']
     if info['found']:
         info_text = self.shell.object_inspect_text(
             name,
             detail_level=content.get('detail_level', 0),
         )
         reply_content['data']['text/plain'] = info_text
     # Before we send this object over, we scrub it for JSON usage
     reply_content = json_clean(reply_content)
     msg = self.session.send(stream, 'inspect_reply',
                             reply_content, parent, ident)
     self.log.debug("%s", msg)
Exemple #15
0
    def inspect_request(self, stream, ident, parent):
        content = parent['content']

        name = token_at_cursor(content['code'], content['cursor_pos'])
        info = self.shell.object_inspect(name)

        reply_content = {'status': 'ok'}
        reply_content['data'] = data = {}
        reply_content['metadata'] = {}
        reply_content['found'] = info['found']
        if info['found']:
            info_text = self.shell.object_inspect_text(
                name,
                detail_level=content.get('detail_level', 0),
            )
            reply_content['data']['text/plain'] = info_text
        # Before we send this object over, we scrub it for JSON usage
        reply_content = json_clean(reply_content)
        msg = self.session.send(stream, 'inspect_reply', reply_content, parent,
                                ident)
        self.log.debug("%s", msg)
Exemple #16
0
  def do_inspect(self, code, cursor_pos, detail_level=0):
    name = token_at_cursor(code, cursor_pos)
    info = self.shell.object_inspect(name)

    data = {}
    if info['found']:
      info_text = self.shell.object_inspect_text(
          name,
          detail_level=detail_level,
      )
      data['text/plain'] = info_text
      # Provide the structured inspection information to allow the frontend to
      # format as desired.
      data['application/json'] = info

    reply_content = {
        'status': 'ok',
        'data': data,
        'metadata': {},
        'found': info['found'],
    }

    return reply_content