#NEWLINE# def format_message( self , message ) : #NEWLINE# #INDENT# message = self . normalize_message ( message ) #NEWLINE# username = message [ 'n_user' ] #NEWLINE# kind = message . get ( 'kind' ) #NEWLINE# created = None #NEWLINE# group = message [ 'n_group' ] #NEWLINE# topic = message [ 'n_topic' ] #NEWLINE# message_body = message [ 'n_message' ] #NEWLINE# try : #NEWLINE# #INDENT# created = datetime . fromtimestamp ( message [ '_ts' ] ) #NEWLINE# #UNINDENT# except ( KeyError , TypeError ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# if ( not created ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# created = datetime . fromtimestamp ( message [ 'date_created' ] ) #NEWLINE# #UNINDENT# except ( KeyError , TypeError ) : #NEWLINE# #INDENT# created = datetime . now ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( topic ) > 15 ) : #NEWLINE# #INDENT# topic = ( topic [ : 15 ] + '...' ) #NEWLINE# #UNINDENT# if ( group and topic ) : #NEWLINE# #INDENT# label = '[{group}/{topic}]' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# label = '' #NEWLINE# #UNINDENT# body = wrap_string ( message_body , indent = 6 ) . lstrip ( ) #NEWLINE# time = created . strftime ( '%H:%M' ) #NEWLINE# if ( kind == 'message' ) : #NEWLINE# #INDENT# return '{time} <{username}> {label} {body}' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( kind == 'topic' ) : #NEWLINE# #INDENT# return '{time} <{username}> created new topic in #{group}: "{topic}"' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( kind == 'mention' ) : #NEWLINE# #INDENT# return '{time} <{username}> mentioned you: {label} {body}' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( kind == 'topic-delete' ) : #NEWLINE# #INDENT# return '{time} <{username}> deleted a topic' . format ( ** locals ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return '{time} <{username}> [{group}]: {kind}' . format ( ** locals ( ) )