def authenticate_user_if_possible(request, user):
 if request.line.uri.startswith('/assets/'):
  pass
 elif ('Authorization' in request.headers):
  header = request.headers['authorization']
  if header.startswith('Basic '):
   user = _get_user_via_basic_auth(header)
   if (not user.ANON):
    _turn_off_csrf(request)
 elif (SESSION in request.headers.cookie):
  token = request.headers.cookie[SESSION].value
  user = User.from_session_token(token)
 return {'user': user}

def authenticate_user_if_possible ( request , user ) : if request . line . uri . startswith ( '/assets/' ) : pass elif ( 'Authorization' in request . headers ) : header = request . headers [ 'authorization' ] if header . startswith ( 'Basic ' ) : user = _get_user_via_basic_auth ( header ) if ( not user . ANON ) : _turn_off_csrf ( request ) elif ( SESSION in request . headers . cookie ) : token = request . headers . cookie [ SESSION ] . value user = User . from_session_token ( token ) return { 'user' : user }
this signs the user in .