<s> """<STR_LIT>""" <EOL> from flask import request , Response , current_app <EOL> from functools import wraps <EOL> def check_auth ( username , password , expected_user , expected_pw ) : <EOL> """<STR_LIT>""" <EOL> return username == expected_user and password == expected_pw <EOL> def authenticate ( ) : <EOL> """<STR_LIT>""" <EOL> return Response ( '<STR_LIT>' <EOL> '<STR_LIT>' , <NUM_LIT> , <EOL> { '<STR_LIT>' : '<STR_LIT>' } <EOL> ) <EOL> def requires_basicauth ( f ) : <EOL> @ wraps ( f ) <EOL> def decorated ( * args , ** kwargs ) : <EOL> user = current_app . config . get ( '<STR_LIT>' ) <EOL> pw = current_app . config . get ( '<STR_LIT>' ) <EOL> auth = request . authorization <EOL> if user and pw : <EOL> if not auth or not check_auth ( auth . username , auth . password , user , pw ) : <EOL> return authenticate ( ) <EOL> return f ( * args , ** kwargs ) <EOL> return decorated </s>
