<s> import bottle <EOL> from bottle import post , request , response , parse_auth <EOL> import json <EOL> class WebHookHandler : <EOL> def __init__ ( self , username , password , callback , log ) : <EOL> self . username = username <EOL> self . password = password <EOL> self . callback = callback <EOL> self . log = log <EOL> self . application = bottle . Bottle ( ) <EOL> self . application . route ( '<STR_LIT:/>' , method = '<STR_LIT:POST>' , callback = self . handle ) <EOL> def _raise ( self , code , message ) : <EOL> if self . log : <EOL> self . log . error ( '<STR_LIT>' , code , message ) <EOL> raise bottle . HTTPError ( code , message ) <EOL> def require_auth ( fn ) : <EOL> def check ( self , * args , ** kwargs ) : <EOL> auth = request . get_header ( '<STR_LIT>' ) <EOL> if auth : <EOL> ( user , password ) = parse_auth ( auth ) <EOL> if user == self . username and password == self . password : <EOL> return fn ( self , * args , ** kwargs ) <EOL> self . _raise ( <NUM_LIT> , '<STR_LIT>' ) <EOL> return check <EOL> @ require_auth <EOL> def handle ( self ) : <EOL> if self . log : <EOL> self . log . debug ( '<STR_LIT>' , data ) <EOL> self . callback ( request . json ) <EOL> return "<STR_LIT:OK>" </s>
