def am_i_online(url, expected_val=None, search_string=None, timeout=5, allow_redirects=True):
 assert (not (search_string and (expected_val is not None))), 'Search string and expected value cannot both be set'
 from kalite.version import user_agent
 try:
  if ((not search_string) and (expected_val is None)):
   response = requests.head(url, headers={'user-agent': user_agent()})
  else:
   response = requests.get(url, timeout=timeout, allow_redirects=allow_redirects, headers={'user-agent': user_agent()})
  if (response.status_code != 200):
   return False
  elif ((not allow_redirects) and (response.url != url)):
   return False
  if (expected_val is not None):
   return (expected_val == response.text)
  elif search_string:
   return (search_string in response.text)
  return True
 except Exception as e:
  return False

def am_i_online ( url , expected_val = None , search_string = None , timeout = 5 , allow_redirects = True ) : assert ( not ( search_string and ( expected_val is not None ) ) ) , 'Search string and expected value cannot both be set' from kalite . version import user_agent try : if ( ( not search_string ) and ( expected_val is None ) ) : response = requests . head ( url , headers = { 'user-agent' : user_agent ( ) } ) else : response = requests . get ( url , timeout = timeout , allow_redirects = allow_redirects , headers = { 'user-agent' : user_agent ( ) } ) if ( response . status_code != 200 ) : return False elif ( ( not allow_redirects ) and ( response . url != url ) ) : return False if ( expected_val is not None ) : return ( expected_val == response . text ) elif search_string : return ( search_string in response . text ) return True except Exception as e : return False
test whether we are online or not .