<s> import time <EOL> def format_date ( then ) : <EOL> if then is None : <EOL> return "<STR_LIT>" <EOL> try : <EOL> now = time . time ( ) <EOL> delta = now - then <EOL> return format_delta ( delta ) <EOL> except ( TypeError , ValueError ) : <EOL> return "<STR_LIT>" <EOL> def format_delta ( delta ) : <EOL> days = delta / ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) <EOL> hours = delta / ( <NUM_LIT> * <NUM_LIT> ) <EOL> mins = delta / <NUM_LIT> <EOL> if days == <NUM_LIT:1> : <EOL> return "<STR_LIT>" % days <EOL> elif days > <NUM_LIT:1> : <EOL> return "<STR_LIT>" % days <EOL> elif hours == <NUM_LIT:1> : <EOL> return "<STR_LIT>" % hours <EOL> elif hours > <NUM_LIT:1> : <EOL> return "<STR_LIT>" % hours <EOL> elif mins == <NUM_LIT:1> : <EOL> return "<STR_LIT>" % mins <EOL> elif mins > <NUM_LIT:1> : <EOL> return "<STR_LIT>" % mins <EOL> else : <EOL> return "<STR_LIT>" <EOL> STYLES = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:6> , <EOL> "<STR_LIT>" : <NUM_LIT:7> <EOL> } <EOL> COLORS = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:6> , <EOL> "<STR_LIT>" : <NUM_LIT:7> <EOL> } <EOL> FOREGROUND = <NUM_LIT:30> <EOL> BACKGROUND = <NUM_LIT> <EOL> ESCAPE = '<STR_LIT>' <EOL> def format_color ( text , usecolor = True , fg = None , bg = None , styles = [ ] ) : <EOL> if not usecolor : <EOL> return text <EOL> bits = [ ] <EOL> if fg is not None : <EOL> if fg not in COLORS : <EOL> raise Exception ( "<STR_LIT>" % fg ) <EOL> bits . append ( ESCAPE % ( FOREGROUND + COLORS [ fg ] ) ) <EOL> if bg is not None : <EOL> if bg not in COLORS : <EOL> raise Exception ( "<STR_LIT>" % bg ) <EOL> bits . append ( ESCAPE % ( BACKGROUND + COLORS [ bg ] ) ) <EOL> for style in styles : <EOL> if style not in STYLES : <EOL> raise Exception ( "<STR_LIT>" % style ) <EOL> bits . append ( ESCAPE % ( STYLES [ style ] ) ) <EOL> bits . append ( text ) <EOL> bits . append ( ESCAPE % STYLES [ "<STR_LIT>" ] ) <EOL> return "<STR_LIT>" . join ( bits ) <EOL> def format_title ( text ) : <EOL> width = len ( text ) <EOL> underline = "<STR_LIT:->" * width <EOL> return text + "<STR_LIT:\n>" + underline + "<STR_LIT:\n>" </s>
