Пример #1
0
def object_xml_repr(value, host = None, depth = 1, memo = None):
    values = [value]
    if hasattr(value, '__class__'):
        if hasattr(value.__class__, '__mro__'):
            values.extend(value.__class__.__mro__)
    elif hasattr(value, '__bases__'):
        considers = [value]
        while considers:
            consider = considers.pop(0)
            values.append(consider)
            considers.extend(consider.__bases__)
    return tags.div(
        tags.p(
            tags.b(repr(value)),
            tags.ol(    # for prettiness
                hasattr(value, '__dict__') and (
                    tags.table(
                        {'class': 'definition'},
                        (
                            tags.tr(
                                tags.th(xml_repr(heading, host, depth - 1, memo)),
                                tags.td(xml_repr(row, host, depth - 1, memo)),
                            )
                            for heading, row in sorted(vars(value).items())
                        )
                    )
                ) or ''
            )
        ) for value in values[::-1]
    )
Пример #2
0
 def message_buffer_body(self, kit):
     tags = kit.tags
     id = kit.next_id()
     command_id = '%s_command' % id
     prompt_id = '%s_prompt' % id
     return tags.div(
         tags.table(
             tags.tr(
                 tags.td(
                     tags.nobr('', id = prompt_id),
                     style = 'vertical-align: bottom;'
                 ),
                 tags.td(
                     CommandBoxWidget(id = command_id),
                     style = 'width: 100%'
                 ),
             ),
             style = '''
                 width: 100%;
             '''
         ),
         Javascript(
             '''shell.open(
                 %s, %s, %s,
                 document.getElementsByTagName('body')[0]
             );''' % (
                 repr(self.session_service.base_path),
                 repr(prompt_id),
                 repr(command_id),
             ),
             {'shell': javascripts.shell,}
         ),
         self.shell_body(kit),
     )
Пример #3
0
def exception_xml_repr(exception, host = None, depth = 1, memo = None):
    exception_type, exception_value, traceback = exc_info()
    stack = extract_tb(traceback)[2:]
    return tags.div(
        {'class': 'python_traceback'},
        len(stack) and (
            tags.p(
                tags.b('Traceback'),
                ' (most recent call last)'
            ),
            tags.ul(
                {'class': 'python_traceback_stack'},
                (
                    tags.li(
                        {'class': 'python_traceback_stack_frame'},
                        'file ', tags.tt(
                            {'class': 'python_traceback_file_name'},
                            file_name
                        ),
                        ', line ', tags.tt(
                            {'class': 'python_traceback_line'},
                            line_number
                        ),
                        ', in ', tags.tt(
                            {'class': 'python_traceback_function_name'},
                            function_name
                        ),
                        text is not None and (
                            tags.br(),
                            tags.code(
                                {
                                    'class': 'python',
                                    'style': 'white-space: pre;',
                                },
                                xml_repr(text),
                            )
                        ) or ''
                    )
                    for 
                        file_name,
                        line_number,
                        function_name,
                        text
                    in
                        stack
                )
            )
        ) or '',
        tags.p(
            tags.b('%s.%s' % (
                exception_type.__module__,
                exception_type.__name__
            )),
            ' ',
            str(exception_value)
        ),
    )
Пример #4
0
    def message_buffer_body(self, kit):
        tags = kit.tags
        id = kit.id
        host = kit.host
        debug = kit.debug

        command_id = '%s_command' % id
        prompt_id = '%s_prompt' % id

        session = self.Session()
        host(service = session, timeout = 20)

        return tags.div(
            tags.table(
                tags.tr(
                    tags.td(
                        tags.nobr('', id = prompt_id),
                        style = 'vertical-align: bottom;'
                    ),
                    tags.td(
                        CommandBoxWidget(id = command_id),
                        style = 'width: 100%'
                    ),
                ),
                style = '''
                    width: 100%;
                '''
            ),
            Javascript(
                "shell.open(%s, %s, %s, %s, {'debug': %s});" % (
                    repr(session.base_path),
                    repr(prompt_id),
                    repr(command_id),
                    repr(id),
                    debug and '1' or '0'
                ),
                {'shell': javascripts.shell,}
            ),
            self.shell_body(kit),
        )
Пример #5
0
 def message(self, message):
     self.queue.append(('message', tags.div(message).xml))