#NEWLINE# def test_complex_custom_formatting( self ) : #NEWLINE# #INDENT# class User ( object ) : #NEWLINE# #INDENT# def __init__( self , id , username ) : #NEWLINE# #INDENT# self . id = id #NEWLINE# self . username = username #NEWLINE# #UNINDENT# def __html_format__( self , format_spec ) : #NEWLINE# #INDENT# if ( format_spec == 'link' ) : #NEWLINE# #INDENT# return Markup ( '<a href="/user/{0}">{1}</a>' ) . format ( self . id , self . __html__ ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if format_spec : #NEWLINE# #INDENT# raise ValueError ( 'Invalid format spec' ) #NEWLINE# #UNINDENT# #UNINDENT# return self . __html__ ( ) #NEWLINE# #UNINDENT# def __html__( self ) : #NEWLINE# #INDENT# return Markup ( '<span class=user>{0}</span>' ) . format ( self . username ) #NEWLINE# #UNINDENT# #UNINDENT# user = User ( 1 , 'foo' ) #NEWLINE# assert ( Markup ( '<p>User: {0:link}' ) . format ( self ) == Markup ( '<p>User: <a href="/user/1"><span class=user>foo</span></a>' ) )