Exemplo n.º 1
0
    def execute(self, command):
        kit = self.kit
        tags = kit.tags

        self.update()
    
        # Execute the command
        if use_highlight:
            self.message(tags.p(tags.nobr(self.prompt, ' ', highlight(command))))
        else:
            self.message(tags.p(tags.nobr(self.prompt, command)))

        exception = None
        result = None
        try:

            # Capture stdout so we can exec print commands
            redirector = StdoutRedirector()
            try:
            
                try:
                    result = eval(command, self.globals, self.locals)
                except SyntaxError:
                    exec command in self.locals

            finally:

                # release stdout
                redirector.close()

                # print the standard output
                self.message(html_repr(redirector.get()))

        except Exception, exception:
            pass
Exemplo n.º 2
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)
        ),
    )
Exemplo n.º 3
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]
    )
Exemplo n.º 4
0
def iterable_xml_repr(value, host = None, depth = 1, memo = None):
    # find tables
    return tags.p(
        tags.b(name_repr(value, memo)),
        tags.ol(
            {'start': 0},
            {'class': 'python_list'},
            (
                tags.li(
                    xml_repr(item, host, depth - 1, memo)
                )
                for item in value
            )
        )
    )
Exemplo n.º 5
0
def dict_xml_repr(value, host = None, depth = 1, memo = None):
    return tags.p(
        tags.b(name_repr(value, memo)),
        tags.ol(    # for prettiness
            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(value.items())
                )
            )
        )
    )
Exemplo n.º 6
0
def json_service(kit, json):
    return Page(title="Page", body_content=(tags.h1("Title"), tags.p("Content")))
Exemplo n.º 7
0
 def body_content(self):
     return (
         tags.h1('Not Found'),
         tags.p(self.path())
     )