<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def basic_auth_tween_factory(handler, registry):
 """Do basic authentication, parse HTTP_AUTHORIZATION and set remote_user variable to request """

    def basic_auth_tween(request):
        remote_user = get_remote_user(request)
        if remote_user is not None:
            request.environ['REMOTE_USER'] = remote_user[0]
        return handler(request)
    return basic_auth_tween