def js_alert(ident, level, message):
 return ('try {add_message("%(ident)s", "%(level)s", "%(message)s");}\ncatch(err) {alert("%(levelup)s: %(message)s");}\n' % {'ident': ident, 'level': level, 'levelup': level.upper(), 'message': message.replace('"', '\\"')})

def js_alert ( ident , level , message ) : return ( 'try {add_message("%(ident)s", "%(level)s", "%(message)s");}\ncatch(err) {alert("%(levelup)s: %(message)s");}\n' % { 'ident' : ident , 'level' : level , 'levelup' : level . upper ( ) , 'message' : message . replace ( '"' , '\\"' ) } )
this function returns a string containing js code to generate an alert message .