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) ), )
def command(self, text): kit = self.kit tags = kit.tags self.message(( 'Sorry, this ', tags.b('service'), ' is ', tags.b('not ready'), '. ', 'The administrator has not finished configuring ', 'this service properly.' ))
def shallow_list_xml_repr(value, host = None, memo = None): return tags.span( name_repr(value, memo), tags.b(' ['), iter_join( tags.b(', '), ( shallow_xml_repr(item, host, memo) for item in value ) ), tags.b(']'), )
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] )
def shallow_dict_xml_repr(value, host = None, memo = None): return tags.span( name_repr(value, memo), tags.b(' {'), iter_join( tags.b(', '), ( ( shallow_xml_repr(key, host, memo), tags.b(': '), repr(inner) ) for key, inner in value.items() ) ), tags.b('}'), )
def shallow_str_xml_repr(value): lines = value.split("\n") return tags.span( tags.code( lines[0], style = 'white-space: pre;' ), len(lines) > 1 and tags.b('...') or '', )
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 ) ) )
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()) ) ) ) )
def __shallow_xml_repr__(self): return tags.b('my shallow repr')
def __xml_repr__(self): return tags.b('my repr')